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;
|
const ID* current_decl_id = 0;
|
||||||
|
|
||||||
int yyerror(const char msg[])
|
int yyerror(const char msg[]) {
|
||||||
{
|
|
||||||
auto n = strlen(msg) + yyleng + 64;
|
auto n = strlen(msg) + yyleng + 64;
|
||||||
char* msgbuf = new char[n];
|
char* msgbuf = new char[n];
|
||||||
|
|
||||||
|
|
|
@ -45,22 +45,19 @@ int line_number = 1;
|
||||||
int begin_pac_primitive(int tok);
|
int begin_pac_primitive(int tok);
|
||||||
int end_pac_primitive();
|
int end_pac_primitive();
|
||||||
|
|
||||||
int string_token(int tok)
|
int string_token(int tok) {
|
||||||
{
|
|
||||||
yylval.str = copy_string(yytext);
|
yylval.str = copy_string(yytext);
|
||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
int char_token(int tok)
|
int char_token(int tok) {
|
||||||
{
|
|
||||||
yylval.val = yytext[0];
|
yylval.val = yytext[0];
|
||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
void include_file(const char* filename);
|
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
|
#ifdef _MSC_VER
|
||||||
return std::filesystem::path(s).parent_path().string();
|
return std::filesystem::path(s).parent_path().string();
|
||||||
#else
|
#else
|
||||||
|
@ -77,6 +74,7 @@ std::string do_dirname(std::string_view s)
|
||||||
return res;
|
return res;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
/* EC -- embedded code state */
|
/* EC -- embedded code state */
|
||||||
|
@ -283,40 +281,32 @@ ESCSEQ (\\([^\n]|[0-7]{3}|x[[:xdigit:]]{2}))
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
void begin_RE()
|
void begin_RE() {
|
||||||
{
|
|
||||||
BEGIN(RE);
|
BEGIN(RE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void end_RE()
|
void end_RE() { BEGIN(INITIAL); }
|
||||||
{
|
|
||||||
BEGIN(INITIAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The DECL state is deprecated
|
// The DECL state is deprecated
|
||||||
void begin_decl()
|
void begin_decl() {
|
||||||
{
|
|
||||||
// BEGIN(DECL);
|
// BEGIN(DECL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void end_decl()
|
void end_decl() {
|
||||||
{
|
|
||||||
// BEGIN(INITIAL);
|
// BEGIN(INITIAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int begin_pac_primitive(int tok)
|
int begin_pac_primitive(int tok) {
|
||||||
{
|
|
||||||
BEGIN(PP);
|
BEGIN(PP);
|
||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
int end_pac_primitive()
|
int end_pac_primitive() {
|
||||||
{
|
|
||||||
BEGIN(EC);
|
BEGIN(EC);
|
||||||
return TOK_END_PAC;
|
return TOK_END_PAC;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int MAX_INCLUDE_DEPTH = 100;
|
constexpr int MAX_INCLUDE_DEPTH = 100;
|
||||||
|
|
||||||
struct IncludeState {
|
struct IncludeState {
|
||||||
YY_BUFFER_STATE yystate;
|
YY_BUFFER_STATE yystate;
|
||||||
|
@ -327,29 +317,21 @@ struct IncludeState {
|
||||||
IncludeState include_stack[MAX_INCLUDE_DEPTH];
|
IncludeState include_stack[MAX_INCLUDE_DEPTH];
|
||||||
int include_stack_ptr = 0;
|
int include_stack_ptr = 0;
|
||||||
|
|
||||||
void switch_to_file(FILE *fp)
|
void switch_to_file(FILE* fp) { yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE)); }
|
||||||
{
|
|
||||||
yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
|
|
||||||
}
|
|
||||||
|
|
||||||
void switch_to_file(const char *filename)
|
void switch_to_file(const char* filename) {
|
||||||
{
|
if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
|
||||||
if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Includes nested too deeply");
|
fprintf(stderr, "Includes nested too deeply");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
IncludeState state =
|
IncludeState state = {YY_CURRENT_BUFFER, input_filename, line_number};
|
||||||
{ YY_CURRENT_BUFFER, input_filename, line_number };
|
|
||||||
include_stack[include_stack_ptr++] = state;
|
include_stack[include_stack_ptr++] = state;
|
||||||
|
|
||||||
FILE* fp = fopen(filename, "r");
|
FILE* fp = fopen(filename, "r");
|
||||||
|
|
||||||
if ( ! fp )
|
if ( ! fp ) {
|
||||||
{
|
fprintf(stderr, "%s:%d: error: cannot include file \"%s\"\n", input_filename.c_str(), line_number, filename);
|
||||||
fprintf(stderr, "%s:%d: error: cannot include file \"%s\"\n",
|
|
||||||
input_filename.c_str(), line_number,filename);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,35 +343,28 @@ void switch_to_file(const char *filename)
|
||||||
fprintf(stderr, "switching to file %s\n", input_filename.c_str());
|
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);
|
ASSERT(filename);
|
||||||
|
|
||||||
string full_filename;
|
string full_filename;
|
||||||
if ( filename[0] == '/' )
|
if ( filename[0] == '/' )
|
||||||
full_filename = filename;
|
full_filename = filename;
|
||||||
else if ( filename[0] == '.' )
|
else if ( filename[0] == '.' ) {
|
||||||
{
|
|
||||||
string dir = do_dirname(input_filename);
|
string dir = do_dirname(input_filename);
|
||||||
|
|
||||||
if ( ! dir.empty() )
|
if ( ! dir.empty() )
|
||||||
full_filename = dir + "/" + filename;
|
full_filename = dir + "/" + filename;
|
||||||
else
|
else {
|
||||||
{
|
fprintf(stderr, "%s:%d error: cannot include file \"%s\": %s\n", input_filename.c_str(), line_number,
|
||||||
fprintf(stderr, "%s:%d error: cannot include file \"%s\": %s\n",
|
filename, strerror(errno));
|
||||||
input_filename.c_str(), line_number, filename,
|
|
||||||
strerror(errno));
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
int i;
|
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;
|
full_filename = FLAGS_include_directories[i] + filename;
|
||||||
DEBUG_MSG("Try include file: \"%s\"\n",
|
DEBUG_MSG("Try include file: \"%s\"\n", full_filename.c_str());
|
||||||
full_filename.c_str());
|
|
||||||
if ( access(full_filename.c_str(), R_OK) == 0 )
|
if ( access(full_filename.c_str(), R_OK) == 0 )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -400,8 +375,7 @@ void include_file(const char *filename)
|
||||||
switch_to_file(full_filename.c_str());
|
switch_to_file(full_filename.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
int yywrap()
|
int yywrap() {
|
||||||
{
|
|
||||||
yy_delete_buffer(YY_CURRENT_BUFFER);
|
yy_delete_buffer(YY_CURRENT_BUFFER);
|
||||||
--include_stack_ptr;
|
--include_stack_ptr;
|
||||||
if ( include_stack_ptr < 0 )
|
if ( include_stack_ptr < 0 )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue