store all parse tree entries in node objects
This commit is contained in:
parent
aca67c1a54
commit
e1f1bbcbb8
@ -10,4 +10,5 @@ Node::Node(int _type)
|
||||
list = new std::vector<Node *>();
|
||||
break;
|
||||
}
|
||||
declarator_name = nullptr;
|
||||
}
|
||||
|
@ -19,18 +19,15 @@ public:
|
||||
std::string * text;
|
||||
} token;
|
||||
std::vector<Node *> * list;
|
||||
struct
|
||||
{
|
||||
std::string * name;
|
||||
} declarator;
|
||||
};
|
||||
std::string * declarator_name;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
NODE_TYPE_NULL,
|
||||
NODE_TYPE_TOKEN,
|
||||
NODE_TYPE_LIST,
|
||||
NODE_TYPE_DECLARATOR,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -195,9 +195,33 @@ void handle_parse_error(const char * str, const YYLTYPE * yylloc)
|
||||
display_error_source(yylloc->last_line, yylloc->last_column);
|
||||
}
|
||||
|
||||
void observe_type_name(const std::string & type_name)
|
||||
const std::string * find_declarator_name(const Node * node)
|
||||
{
|
||||
type_names.insert(type_name);
|
||||
if (node->declarator_name != nullptr)
|
||||
{
|
||||
return node->declarator_name;
|
||||
}
|
||||
if (node->type == NODE_TYPE_LIST)
|
||||
{
|
||||
for (auto n : *node->list)
|
||||
{
|
||||
const std::string * s = find_declarator_name(n);
|
||||
if (s != nullptr)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void observe_type_name(const Node * node)
|
||||
{
|
||||
const std::string * declarator_name = find_declarator_name(node);
|
||||
if (declarator_name != nullptr)
|
||||
{
|
||||
type_names.insert(*declarator_name);
|
||||
}
|
||||
}
|
||||
|
||||
static const char * builtin_types[] = {
|
||||
|
@ -12,7 +12,7 @@ extern std::unordered_set<std::string> type_names;
|
||||
|
||||
void parse(const char * filename);
|
||||
void handle_parse_error(const char * str, const YYLTYPE * yylloc);
|
||||
void observe_type_name(const std::string & type_name);
|
||||
void observe_type_name(const Node * node);
|
||||
bool is_type_name(const std::string & type_name);
|
||||
|
||||
#endif
|
||||
|
1042
src/parser/parser.yc
1042
src/parser/parser.yc
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user