Tidy up a bit
This commit is contained in:
@@ -101,6 +101,20 @@ namespace Preprocesser
|
|||||||
std::cout << "\t}\n";
|
std::cout << "\t}\n";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
else if (token->type == TT::PP_REFERENCE)
|
||||||
|
{
|
||||||
|
// Reference expansion based on latest constant
|
||||||
|
const auto found = const_map.find(token->content);
|
||||||
|
if (found == const_map.end())
|
||||||
|
return new Err{ET::UNKNOWN_NAME_IN_REFERENCE, token};
|
||||||
|
|
||||||
|
std::vector<Unit> preprocessed;
|
||||||
|
Err *err = preprocess(found->second.body, preprocessed, new_token_bag,
|
||||||
|
const_map, file_map, depth + 1);
|
||||||
|
if (err)
|
||||||
|
return new Err{ET::IN_ERROR, token, err};
|
||||||
|
units.push_back(Unit{token, preprocessed});
|
||||||
|
}
|
||||||
else if (token->type == TT::PP_USE)
|
else if (token->type == TT::PP_USE)
|
||||||
{
|
{
|
||||||
// Ensure string in next token
|
// Ensure string in next token
|
||||||
@@ -152,20 +166,6 @@ namespace Preprocesser
|
|||||||
else
|
else
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
else if (token->type == TT::PP_REFERENCE)
|
|
||||||
{
|
|
||||||
// Reference expansion based on latest constant
|
|
||||||
const auto found = const_map.find(token->content);
|
|
||||||
if (found == const_map.end())
|
|
||||||
return new Err{ET::UNKNOWN_NAME_IN_REFERENCE, token};
|
|
||||||
|
|
||||||
std::vector<Unit> preprocessed;
|
|
||||||
Err *err = preprocess(found->second.body, preprocessed, new_token_bag,
|
|
||||||
const_map, file_map, depth + 1);
|
|
||||||
if (err)
|
|
||||||
return new Err{ET::IN_ERROR, token, err};
|
|
||||||
units.push_back(Unit{token, preprocessed});
|
|
||||||
}
|
|
||||||
else if (token->type == TT::PP_END)
|
else if (token->type == TT::PP_END)
|
||||||
return new Err{ET::NO_CONST_AROUND, token};
|
return new Err{ET::NO_CONST_AROUND, token};
|
||||||
else
|
else
|
||||||
@@ -228,15 +228,13 @@ namespace Preprocesser
|
|||||||
std::string to_string(const Err &err)
|
std::string to_string(const Err &err)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
// Reverse traversal of err linked list
|
// Reverse traversal of the linked list of errors
|
||||||
std::vector<Err *> errors;
|
std::vector<Err *> errors;
|
||||||
errors.push_back((Err *)&err);
|
errors.push_back((Err *)&err);
|
||||||
for (Err *e = err.child_error; e; e = e->child_error)
|
for (Err *e = err.child_error; e; e = e->child_error)
|
||||||
errors.insert(errors.begin(), e);
|
errors.insert(errors.begin(), e);
|
||||||
for (size_t depth = 0; depth < errors.size(); ++depth)
|
for (size_t depth = 0; depth < errors.size(); ++depth)
|
||||||
{
|
{
|
||||||
// for (size_t i = 0; i < depth; ++i)
|
|
||||||
// ss << " ";
|
|
||||||
const Err &e = *errors[depth];
|
const Err &e = *errors[depth];
|
||||||
ss << e.token->source_name << ":" << e.token->line << ":"
|
ss << e.token->source_name << ":" << e.token->line << ":"
|
||||||
<< e.token->column << ": " << to_string(e.type);
|
<< e.token->column << ": " << to_string(e.type);
|
||||||
|
|||||||
@@ -68,14 +68,14 @@ namespace Preprocesser
|
|||||||
~Err(void);
|
~Err(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Err *preprocess(std::vector<Lexer::Token *> tokens, std::vector<Unit> &units,
|
||||||
|
std::vector<Lexer::Token *> &new_token_bag, Map &const_map,
|
||||||
|
Map &file_map, int depth = 0);
|
||||||
|
|
||||||
std::string to_string(const Unit &, int depth = 0);
|
std::string to_string(const Unit &, int depth = 0);
|
||||||
std::string to_string(const Err::Type &);
|
std::string to_string(const Err::Type &);
|
||||||
std::string to_string(const Err &);
|
std::string to_string(const Err &);
|
||||||
std::ostream &operator<<(std::ostream &, const Unit &);
|
std::ostream &operator<<(std::ostream &, const Unit &);
|
||||||
std::ostream &operator<<(std::ostream &, const Err &);
|
std::ostream &operator<<(std::ostream &, const Err &);
|
||||||
|
|
||||||
Err *preprocess(std::vector<Lexer::Token *> tokens, std::vector<Unit> &units,
|
|
||||||
std::vector<Lexer::Token *> &new_token_bag, Map &const_map,
|
|
||||||
Map &file_map, int depth = 0);
|
|
||||||
}; // namespace Preprocesser
|
}; // namespace Preprocesser
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user