Commit 6b495719 by alokp@chromium.org

Moved error-counting to Diagnostics so that errors generated during…

Moved error-counting to Diagnostics so that errors generated during preprocessing is included in the count. Enabled logging of preprocessor diagnostics into info-log. Review URL: https://codereview.appspot.com/6354047 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1177 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent f115592d
......@@ -6,10 +6,14 @@
#include "compiler/Diagnostics.h"
#include "compiler/debug.h"
#include "compiler/InfoSink.h"
#include "compiler/preprocessor/new/SourceLocation.h"
TDiagnostics::TDiagnostics(TInfoSink& infoSink) : mInfoSink(infoSink)
TDiagnostics::TDiagnostics(TInfoSink& infoSink) :
mInfoSink(infoSink),
mNumErrors(0),
mNumWarnings(0)
{
}
......@@ -23,9 +27,23 @@ void TDiagnostics::writeInfo(Severity severity,
const std::string& token,
const std::string& extra)
{
TInfoSinkBase& sink = mInfoSink.info;
TPrefixType prefix = severity == ERROR ? EPrefixError : EPrefixWarning;
TPrefixType prefix = EPrefixNone;
switch (severity)
{
case ERROR:
++mNumErrors;
prefix = EPrefixError;
break;
case WARNING:
++mNumWarnings;
prefix = EPrefixWarning;
break;
default:
UNREACHABLE();
break;
}
TInfoSinkBase& sink = mInfoSink.info;
/* VC++ format: file(linenum) : error #: 'token' : extrainfo */
sink.prefix(prefix);
sink.location(EncodeSourceLoc(loc.file, loc.line));
......@@ -41,4 +59,5 @@ void TDiagnostics::print(ID id,
const pp::SourceLocation& loc,
const std::string& text)
{
writeInfo(severity(id), loc, message(id), text, "");
}
......@@ -19,6 +19,9 @@ class TDiagnostics : public pp::Diagnostics
TInfoSink& infoSink() { return mInfoSink; }
int numErrors() const { return mNumErrors; }
int numWarnings() const { return mNumWarnings; }
void writeInfo(Severity severity,
const pp::SourceLocation& loc,
const std::string& reason,
......@@ -34,6 +37,8 @@ class TDiagnostics : public pp::Diagnostics
private:
TInfoSink& mInfoSink;
int mNumErrors;
int mNumWarnings;
};
#endif // COMPILER_DIAGNOSTICS_H_
......@@ -184,7 +184,6 @@ void TParseContext::error(TSourceLoc loc,
diagnostics.writeInfo(pp::Diagnostics::ERROR,
srcLoc, reason, token, extraInfo);
++numErrors;
}
void TParseContext::warning(TSourceLoc loc,
......@@ -1510,7 +1509,7 @@ int PaParseStrings(int count, const char* const string[], const int length[],
glslang_finalize(context);
return (error == 0) && (context->numErrors == 0) ? 0 : 1;
return (error == 0) && (context->numErrors() == 0) ? 0 : 1;
}
......
......@@ -33,7 +33,6 @@ struct TParseContext {
compileOptions(options),
sourcePath(sourcePath),
treeRoot(0),
numErrors(0),
lexAfterType(false),
loopNestingLevel(0),
structNestingLevel(0),
......@@ -52,7 +51,6 @@ struct TParseContext {
int compileOptions;
const char* sourcePath; // Path of source file or NULL.
TIntermNode* treeRoot; // root of parse tree being created
int numErrors;
bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier
int loopNestingLevel; // 0 if outside all loops
int structNestingLevel; // incremented while parsing a struct declaration
......@@ -67,6 +65,7 @@ struct TParseContext {
pp::Preprocessor preprocessor;
void* scanner;
int numErrors() const { return diagnostics.numErrors(); }
TInfoSink& infoSink() { return diagnostics.infoSink(); }
void error(TSourceLoc loc, const char *reason, const char* token,
const char* extraInfo="");
......
......@@ -35,4 +35,84 @@ Diagnostics::Severity Diagnostics::severity(ID id)
return ERROR;
}
std::string Diagnostics::message(ID id)
{
switch (id)
{
// Errors begin.
case INTERNAL_ERROR:
return "internal error";
case OUT_OF_MEMORY:
return "out of memory";
case INVALID_CHARACTER:
return "invalid character";
case INVALID_NUMBER:
return "invalid number";
case INVALID_EXPRESSION:
return "invalid expression";
case DIVISION_BY_ZERO:
return "division by zero";
case EOF_IN_COMMENT:
return "unexpected end of file found in comment";
case EOF_IN_DIRECTIVE:
return "unexpected end of file found in directive";
case UNEXPECTED_TOKEN:
return "unexpected token";
case DIRECTIVE_INVALID_NAME:
return "invalid directive name";
case MACRO_NAME_RESERVED:
return "macro name is reserved";
case MACRO_REDEFINED:
return "macro redefined";
case MACRO_PREDEFINED_REDEFINED:
return "predefined macro redefined";
case MACRO_PREDEFINED_UNDEFINED:
return "predefined macro undefined";
case MACRO_UNTERMINATED_INVOCATION:
return "unterminated macro invocation";
case MACRO_TOO_FEW_ARGS:
return "Not enough arguments for macro";
case MACRO_TOO_MANY_ARGS:
return "Too many arguments for macro";
case CONDITIONAL_ENDIF_WITHOUT_IF:
return "unexpected #endif found without a matching #if";
case CONDITIONAL_ELSE_WITHOUT_IF:
return "unexpected #else found without a matching #if";
case CONDITIONAL_ELSE_AFTER_ELSE:
return "unexpected #else found after another #else";
case CONDITIONAL_ELIF_WITHOUT_IF:
return "unexpected #elif found without a matching #if";
case CONDITIONAL_ELIF_AFTER_ELSE:
return "unexpected #elif found after #else";
case CONDITIONAL_UNTERMINATED:
return "unexpected end of file found in conditional block";
case INVALID_EXTENSION_NAME:
return "invalid extension name";
case INVALID_EXTENSION_BEHAVIOR:
return "invalid extension behavior";
case INVALID_EXTENSION_DIRECTIVE:
return "invalid extension directive";
case INVALID_VERSION_NUMBER:
return "invalid version number";
case INVALID_VERSION_DIRECTIVE:
return "invalid version directive";
case INVALID_LINE_NUMBER:
return "invalid line number";
case INVALID_FILE_NUMBER:
return "invalid file number";
case INVALID_LINE_DIRECTIVE:
return "invalid line directive";
// Errors end.
// Warnings begin.
case CONDITIONAL_UNEXPECTED_TOKEN:
return "unexpected token after conditional expression";
case UNRECOGNIZED_PRAGMA:
return "unrecognized pragma";
// Warnings end.
default:
assert(false);
return "";
}
}
} // namespace pp
......@@ -72,6 +72,7 @@ class Diagnostics
protected:
Severity severity(ID id);
std::string message(ID id);
virtual void print(ID id,
const SourceLocation& loc,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment