lexer: return TYPE_NAME instead of IDENTIFIER for identifiers that were previously typedeffed
This commit is contained in:
parent
0a2e719f2c
commit
25f7c43d3b
@ -199,3 +199,8 @@ void observe_type_name(const std::string & type_name)
|
|||||||
{
|
{
|
||||||
type_names.insert(type_name);
|
type_names.insert(type_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_type_name(const std::string & type_name)
|
||||||
|
{
|
||||||
|
return type_names.count(type_name) != 0u;
|
||||||
|
}
|
||||||
|
@ -13,5 +13,6 @@ extern std::unordered_set<std::string> type_names;
|
|||||||
void parse(const char * filename);
|
void parse(const char * filename);
|
||||||
void handle_parse_error(const char * str, const YYLTYPE * yylloc);
|
void handle_parse_error(const char * str, const YYLTYPE * yylloc);
|
||||||
void observe_type_name(const std::string & type_name);
|
void observe_type_name(const std::string & type_name);
|
||||||
|
bool is_type_name(const std::string & type_name);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -175,7 +175,16 @@ L?\" {
|
|||||||
[^\\\"]+ *build_string += yytext;
|
[^\\\"]+ *build_string += yytext;
|
||||||
}
|
}
|
||||||
|
|
||||||
[a-zA-Z_][a-zA-Z_0-9]* return IDENTIFIER;
|
[a-zA-Z_][a-zA-Z_0-9]* {
|
||||||
|
if (is_type_name(yytext))
|
||||||
|
{
|
||||||
|
return TYPE_NAME;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return IDENTIFIER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
^[ ]*#[ ]+[0-9]+[ ]+\".+\".*$ {
|
^[ ]*#[ ]+[0-9]+[ ]+\".+\".*$ {
|
||||||
handle_loc(yytext);
|
handle_loc(yytext);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#define yyerror(msg) handle_parse_error(msg, &yylloc)
|
#define yyerror(msg) handle_parse_error(msg, &yylloc)
|
||||||
|
|
||||||
@ -262,6 +263,18 @@ constant_expression
|
|||||||
declaration
|
declaration
|
||||||
: declaration_specifiers SEMICOLON
|
: declaration_specifiers SEMICOLON
|
||||||
| declaration_specifiers init_declarator_list SEMICOLON {
|
| declaration_specifiers init_declarator_list SEMICOLON {
|
||||||
|
for (auto d_s : *$1->list)
|
||||||
|
{
|
||||||
|
if ((d_s->type == NODE_TYPE_TOKEN) &&
|
||||||
|
(*d_s->token.text == "typedef"))
|
||||||
|
{
|
||||||
|
for (auto d : *$2->list)
|
||||||
|
{
|
||||||
|
observe_type_name(*d->declarator.name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user