store all parse tree entries in node objects

This commit is contained in:
Josh Holtrop 2018-05-19 22:49:32 -04:00
parent aca67c1a54
commit e1f1bbcbb8
5 changed files with 856 additions and 224 deletions

View File

@ -10,4 +10,5 @@ Node::Node(int _type)
list = new std::vector<Node *>();
break;
}
declarator_name = nullptr;
}

View File

@ -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

View File

@ -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[] = {

View File

@ -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

File diff suppressed because it is too large Load Diff