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
diff --git a/src/compiler/Diagnostics.cpp b/src/compiler/Diagnostics.cpp
index 5f93a03..8aa1cb6 100644
--- a/src/compiler/Diagnostics.cpp
+++ b/src/compiler/Diagnostics.cpp
@@ -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 @@
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 @@
const pp::SourceLocation& loc,
const std::string& text)
{
+ writeInfo(severity(id), loc, message(id), text, "");
}
diff --git a/src/compiler/Diagnostics.h b/src/compiler/Diagnostics.h
index 43a1306..3670414 100644
--- a/src/compiler/Diagnostics.h
+++ b/src/compiler/Diagnostics.h
@@ -19,6 +19,9 @@
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 @@
private:
TInfoSink& mInfoSink;
+ int mNumErrors;
+ int mNumWarnings;
};
#endif // COMPILER_DIAGNOSTICS_H_
diff --git a/src/compiler/ParseHelper.cpp b/src/compiler/ParseHelper.cpp
index 79bddea..db1323d 100644
--- a/src/compiler/ParseHelper.cpp
+++ b/src/compiler/ParseHelper.cpp
@@ -184,7 +184,6 @@
diagnostics.writeInfo(pp::Diagnostics::ERROR,
srcLoc, reason, token, extraInfo);
- ++numErrors;
}
void TParseContext::warning(TSourceLoc loc,
@@ -1510,7 +1509,7 @@
glslang_finalize(context);
- return (error == 0) && (context->numErrors == 0) ? 0 : 1;
+ return (error == 0) && (context->numErrors() == 0) ? 0 : 1;
}
diff --git a/src/compiler/ParseHelper.h b/src/compiler/ParseHelper.h
index 8dee8fd..6405161 100644
--- a/src/compiler/ParseHelper.h
+++ b/src/compiler/ParseHelper.h
@@ -33,7 +33,6 @@
compileOptions(options),
sourcePath(sourcePath),
treeRoot(0),
- numErrors(0),
lexAfterType(false),
loopNestingLevel(0),
structNestingLevel(0),
@@ -52,7 +51,6 @@
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 @@
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="");
diff --git a/src/compiler/preprocessor/new/Diagnostics.cpp b/src/compiler/preprocessor/new/Diagnostics.cpp
index 7b32540..6360a18 100644
--- a/src/compiler/preprocessor/new/Diagnostics.cpp
+++ b/src/compiler/preprocessor/new/Diagnostics.cpp
@@ -35,4 +35,84 @@
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
diff --git a/src/compiler/preprocessor/new/Diagnostics.h b/src/compiler/preprocessor/new/Diagnostics.h
index 1a75a9c..4b982a1 100644
--- a/src/compiler/preprocessor/new/Diagnostics.h
+++ b/src/compiler/preprocessor/new/Diagnostics.h
@@ -72,6 +72,7 @@
protected:
Severity severity(ID id);
+ std::string message(ID id);
virtual void print(ID id,
const SourceLocation& loc,