mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 09:07:43 +00:00
HECL Compiler bug fixes
This commit is contained in:
@@ -17,6 +17,32 @@ namespace HECL
|
||||
namespace Frontend
|
||||
{
|
||||
|
||||
std::string Diagnostics::sourceDiagString(const SourceLocation& l, bool ansi) const
|
||||
{
|
||||
std::string::const_iterator it = m_source.begin();
|
||||
for (int i=1 ; i<l.line ; ++i)
|
||||
{
|
||||
while (*it != '\n' && it != m_source.end())
|
||||
++it;
|
||||
if (*it == '\n')
|
||||
++it;
|
||||
}
|
||||
std::string::const_iterator begin = it;
|
||||
while (*it != '\n' && it != m_source.end())
|
||||
++it;
|
||||
std::string::const_iterator end = it;
|
||||
|
||||
std::string retval(begin, end);
|
||||
retval += '\n';
|
||||
for (int i=1 ; i<l.col ; ++i)
|
||||
retval += ' ';
|
||||
if (ansi)
|
||||
retval += GREEN "^" NORMAL;
|
||||
else
|
||||
retval += '^';
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Diagnostics::reportParserErr(const SourceLocation& l, const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@@ -31,11 +57,11 @@ void Diagnostics::reportParserErr(const SourceLocation& l, const char* fmt, ...)
|
||||
#endif
|
||||
va_end(ap);
|
||||
if (LogVisor::XtermColor)
|
||||
LogModule.report(LogVisor::FatalError, RED "Error parsing" NORMAL " '%s' " YELLOW "@%d:%d " NORMAL "\n%s",
|
||||
m_name.c_str(), l.line, l.col, result);
|
||||
LogModule.report(LogVisor::FatalError, CYAN "[Parser]" NORMAL " %s " YELLOW "@%d:%d " NORMAL "\n%s\n%s",
|
||||
m_name.c_str(), l.line, l.col, result, sourceDiagString(l, true).c_str());
|
||||
else
|
||||
LogModule.report(LogVisor::FatalError, "Error parsing '%s' @%d:%d\n%s",
|
||||
m_name.c_str(), l.line, l.col, result);
|
||||
LogModule.report(LogVisor::FatalError, "[Parser] %s @%d:%d\n%s\n%s",
|
||||
m_name.c_str(), l.line, l.col, result, sourceDiagString(l, false).c_str());
|
||||
free(result);
|
||||
}
|
||||
|
||||
@@ -53,11 +79,11 @@ void Diagnostics::reportLexerErr(const SourceLocation& l, const char* fmt, ...)
|
||||
#endif
|
||||
va_end(ap);
|
||||
if (LogVisor::XtermColor)
|
||||
LogModule.report(LogVisor::FatalError, RED "Error lexing" NORMAL " '%s' " YELLOW "@%d:%d " NORMAL "\n%s",
|
||||
m_name.c_str(), l.line, l.col, result);
|
||||
LogModule.report(LogVisor::FatalError, CYAN "[Lexer]" NORMAL " %s " YELLOW "@%d:%d " NORMAL "\n%s\n%s",
|
||||
m_name.c_str(), l.line, l.col, result, sourceDiagString(l, true).c_str());
|
||||
else
|
||||
LogModule.report(LogVisor::FatalError, "Error lexing '%s' @%d:%d\n%s",
|
||||
m_name.c_str(), l.line, l.col, result);
|
||||
LogModule.report(LogVisor::FatalError, "[Lexer] %s @%d:%d\n%s\n%s",
|
||||
m_name.c_str(), l.line, l.col, result, sourceDiagString(l, false).c_str());
|
||||
free(result);
|
||||
}
|
||||
|
||||
@@ -75,11 +101,11 @@ void Diagnostics::reportCompileErr(const SourceLocation& l, const char* fmt, ...
|
||||
#endif
|
||||
va_end(ap);
|
||||
if (LogVisor::XtermColor)
|
||||
LogModule.report(LogVisor::FatalError, RED "Error compiling" NORMAL " '%s' " YELLOW "@%d:%d " NORMAL "\n%s",
|
||||
m_name.c_str(), l.line, l.col, result);
|
||||
LogModule.report(LogVisor::FatalError, CYAN "[Compiler]" NORMAL " %s " YELLOW "@%d:%d " NORMAL "\n%s\n%s",
|
||||
m_name.c_str(), l.line, l.col, result, sourceDiagString(l, true).c_str());
|
||||
else
|
||||
LogModule.report(LogVisor::FatalError, "Error compiling '%s' @%d:%d\n%s",
|
||||
m_name.c_str(), l.line, l.col, result);
|
||||
LogModule.report(LogVisor::FatalError, "[Compiler] %s @%d:%d\n%s\n%s",
|
||||
m_name.c_str(), l.line, l.col, result, sourceDiagString(l, false).c_str());
|
||||
free(result);
|
||||
}
|
||||
|
||||
@@ -97,11 +123,11 @@ void Diagnostics::reportBackendErr(const SourceLocation& l, const char* fmt, ...
|
||||
#endif
|
||||
va_end(ap);
|
||||
if (LogVisor::XtermColor)
|
||||
LogModule.report(LogVisor::FatalError, RED "Backend error" NORMAL " in '%s' " YELLOW "@%d:%d " NORMAL "\n%s",
|
||||
m_name.c_str(), l.line, l.col, result);
|
||||
LogModule.report(LogVisor::FatalError, CYAN "[Backend]" NORMAL " %s " YELLOW "@%d:%d " NORMAL "\n%s\n%s",
|
||||
m_name.c_str(), l.line, l.col, result, sourceDiagString(l, true).c_str());
|
||||
else
|
||||
LogModule.report(LogVisor::FatalError, "Backend error in '%s' @%d:%d\n%s",
|
||||
m_name.c_str(), l.line, l.col, result);
|
||||
LogModule.report(LogVisor::FatalError, "[Backend] %s @%d:%d\n%s\n%s",
|
||||
m_name.c_str(), l.line, l.col, result, sourceDiagString(l, false).c_str());
|
||||
free(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,28 @@ void Lexer::ReconnectArithmetic(OperationNode* sn, OperationNode** lastSub, Oper
|
||||
*newSub = sn;
|
||||
}
|
||||
|
||||
void Lexer::PrintChain(const Lexer::OperationNode* begin, const Lexer::OperationNode* end)
|
||||
{
|
||||
for (const Lexer::OperationNode* n = begin ; n != end ; n = n->m_next)
|
||||
{
|
||||
printf("%3d %s %s\n", n->m_tok.m_location.col, n->m_tok.typeString(),
|
||||
n->m_tok.m_tokenString.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void Lexer::PrintTree(const Lexer::OperationNode* node, int indent)
|
||||
{
|
||||
for (const Lexer::OperationNode* n = node ; n ; n = n->m_next)
|
||||
{
|
||||
for (int i=0 ; i<indent ; ++i)
|
||||
printf(" ");
|
||||
printf("%3d %s %s\n", n->m_tok.m_location.col, n->m_tok.typeString(),
|
||||
n->m_tok.m_tokenString.c_str());
|
||||
if (n->m_sub)
|
||||
PrintTree(n->m_sub, indent + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void Lexer::reset()
|
||||
{
|
||||
m_root = nullptr;
|
||||
@@ -157,7 +179,7 @@ void Lexer::consumeAllTokens(Parser& parser)
|
||||
}
|
||||
else if (n->m_tok.m_type == Parser::TokenFunctionEnd)
|
||||
{
|
||||
if (n->m_prev->m_tok.m_type != Parser::TokenEvalGroupStart)
|
||||
if (n->m_prev->m_tok.m_type != Parser::TokenFunctionStart)
|
||||
{
|
||||
m_pool.emplace_front(std::move(
|
||||
Parser::Token(Parser::TokenEvalGroupEnd, n->m_tok.m_location)));
|
||||
@@ -230,10 +252,15 @@ void Lexer::consumeAllTokens(Parser& parser)
|
||||
if (sn->m_tok.m_type == Parser::TokenFunctionEnd)
|
||||
{
|
||||
n.m_sub = n.m_next;
|
||||
if (n.m_next == sn)
|
||||
n.m_sub = nullptr;
|
||||
n.m_next = sn->m_next;
|
||||
sn->m_next->m_prev = &n;
|
||||
n.m_sub->m_prev = nullptr;
|
||||
sn->m_prev->m_next = nullptr;
|
||||
if (sn->m_next)
|
||||
sn->m_next->m_prev = &n;
|
||||
if (n.m_sub)
|
||||
n.m_sub->m_prev = nullptr;
|
||||
if (sn->m_prev)
|
||||
sn->m_prev->m_next = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -310,6 +337,13 @@ void Lexer::consumeAllTokens(Parser& parser)
|
||||
}
|
||||
}
|
||||
|
||||
if (HECL::VerbosityLevel)
|
||||
{
|
||||
printf("%s\n", m_diag.getSource().c_str());
|
||||
PrintTree(firstNode);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* Done! */
|
||||
m_root = firstNode->m_next;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user