mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
binpac: Run clang-format on c++ code embedded in pac_parse.{ll,yy}
This commit is contained in:
parent
ea0ffd3ec1
commit
64b3265eb8
2 changed files with 125 additions and 152 deletions
|
@ -1073,8 +1073,7 @@ optlinebreaker : /* nothing */
|
|||
|
||||
const ID* current_decl_id = 0;
|
||||
|
||||
int yyerror(const char msg[])
|
||||
{
|
||||
int yyerror(const char msg[]) {
|
||||
auto n = strlen(msg) + yyleng + 64;
|
||||
char* msgbuf = new char[n];
|
||||
|
||||
|
|
|
@ -45,22 +45,19 @@ int line_number = 1;
|
|||
int begin_pac_primitive(int tok);
|
||||
int end_pac_primitive();
|
||||
|
||||
int string_token(int tok)
|
||||
{
|
||||
int string_token(int tok) {
|
||||
yylval.str = copy_string(yytext);
|
||||
return tok;
|
||||
}
|
||||
|
||||
int char_token(int tok)
|
||||
{
|
||||
int char_token(int tok) {
|
||||
yylval.val = yytext[0];
|
||||
return tok;
|
||||
}
|
||||
|
||||
void include_file(const char* filename);
|
||||
|
||||
std::string do_dirname(std::string_view s)
|
||||
{
|
||||
std::string do_dirname(std::string_view s) {
|
||||
#ifdef _MSC_VER
|
||||
return std::filesystem::path(s).parent_path().string();
|
||||
#else
|
||||
|
@ -77,6 +74,7 @@ std::string do_dirname(std::string_view s)
|
|||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
/* EC -- embedded code state */
|
||||
|
@ -283,40 +281,32 @@ ESCSEQ (\\([^\n]|[0-7]{3}|x[[:xdigit:]]{2}))
|
|||
|
||||
%%
|
||||
|
||||
void begin_RE()
|
||||
{
|
||||
void begin_RE() {
|
||||
BEGIN(RE);
|
||||
}
|
||||
|
||||
void end_RE()
|
||||
{
|
||||
BEGIN(INITIAL);
|
||||
}
|
||||
void end_RE() { BEGIN(INITIAL); }
|
||||
|
||||
// The DECL state is deprecated
|
||||
void begin_decl()
|
||||
{
|
||||
void begin_decl() {
|
||||
// BEGIN(DECL);
|
||||
}
|
||||
|
||||
void end_decl()
|
||||
{
|
||||
void end_decl() {
|
||||
// BEGIN(INITIAL);
|
||||
}
|
||||
|
||||
int begin_pac_primitive(int tok)
|
||||
{
|
||||
int begin_pac_primitive(int tok) {
|
||||
BEGIN(PP);
|
||||
return tok;
|
||||
}
|
||||
|
||||
int end_pac_primitive()
|
||||
{
|
||||
int end_pac_primitive() {
|
||||
BEGIN(EC);
|
||||
return TOK_END_PAC;
|
||||
}
|
||||
|
||||
const int MAX_INCLUDE_DEPTH = 100;
|
||||
constexpr int MAX_INCLUDE_DEPTH = 100;
|
||||
|
||||
struct IncludeState {
|
||||
YY_BUFFER_STATE yystate;
|
||||
|
@ -327,29 +317,21 @@ struct IncludeState {
|
|||
IncludeState include_stack[MAX_INCLUDE_DEPTH];
|
||||
int include_stack_ptr = 0;
|
||||
|
||||
void switch_to_file(FILE *fp)
|
||||
{
|
||||
yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
|
||||
}
|
||||
void switch_to_file(FILE* fp) { yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE)); }
|
||||
|
||||
void switch_to_file(const char *filename)
|
||||
{
|
||||
if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
|
||||
{
|
||||
void switch_to_file(const char* filename) {
|
||||
if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
|
||||
fprintf(stderr, "Includes nested too deeply");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
IncludeState state =
|
||||
{ YY_CURRENT_BUFFER, input_filename, line_number };
|
||||
IncludeState state = {YY_CURRENT_BUFFER, input_filename, line_number};
|
||||
include_stack[include_stack_ptr++] = state;
|
||||
|
||||
FILE* fp = fopen(filename, "r");
|
||||
|
||||
if ( ! fp )
|
||||
{
|
||||
fprintf(stderr, "%s:%d: error: cannot include file \"%s\"\n",
|
||||
input_filename.c_str(), line_number,filename);
|
||||
if ( ! fp ) {
|
||||
fprintf(stderr, "%s:%d: error: cannot include file \"%s\"\n", input_filename.c_str(), line_number, filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -361,35 +343,28 @@ void switch_to_file(const char *filename)
|
|||
fprintf(stderr, "switching to file %s\n", input_filename.c_str());
|
||||
}
|
||||
|
||||
void include_file(const char *filename)
|
||||
{
|
||||
void include_file(const char* filename) {
|
||||
ASSERT(filename);
|
||||
|
||||
string full_filename;
|
||||
if ( filename[0] == '/' )
|
||||
full_filename = filename;
|
||||
else if ( filename[0] == '.' )
|
||||
{
|
||||
else if ( filename[0] == '.' ) {
|
||||
string dir = do_dirname(input_filename);
|
||||
|
||||
if ( ! dir.empty() )
|
||||
full_filename = dir + "/" + filename;
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "%s:%d error: cannot include file \"%s\": %s\n",
|
||||
input_filename.c_str(), line_number, filename,
|
||||
strerror(errno));
|
||||
else {
|
||||
fprintf(stderr, "%s:%d error: cannot include file \"%s\": %s\n", input_filename.c_str(), line_number,
|
||||
filename, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
int i;
|
||||
for ( i = 0; i < (int) FLAGS_include_directories.size(); ++i )
|
||||
{
|
||||
for ( i = 0; i < (int)FLAGS_include_directories.size(); ++i ) {
|
||||
full_filename = FLAGS_include_directories[i] + filename;
|
||||
DEBUG_MSG("Try include file: \"%s\"\n",
|
||||
full_filename.c_str());
|
||||
DEBUG_MSG("Try include file: \"%s\"\n", full_filename.c_str());
|
||||
if ( access(full_filename.c_str(), R_OK) == 0 )
|
||||
break;
|
||||
}
|
||||
|
@ -400,8 +375,7 @@ void include_file(const char *filename)
|
|||
switch_to_file(full_filename.c_str());
|
||||
}
|
||||
|
||||
int yywrap()
|
||||
{
|
||||
int yywrap() {
|
||||
yy_delete_buffer(YY_CURRENT_BUFFER);
|
||||
--include_stack_ptr;
|
||||
if ( include_stack_ptr < 0 )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue