Refactored glslang grammar files to make:
- lexer and parser reentrant
- line number handling automatic
Caveats:
- The preprocessor is still not thread-safe and full of bugs. I have another not-yet-ready patch to replace the preprocessor.
- The grammar files use options that are not supported by the old versions of flex and bison checked into compiler/tools. So I need to check-in the generated lexer-parser along with a shell script to generate them.
Review URL: http://codereview.appspot.com/2992041
git-svn-id: https://angleproject.googlecode.com/svn/trunk@475 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/Compiler.cpp b/src/compiler/Compiler.cpp
index 7e8a835..dc5a8a1 100644
--- a/src/compiler/Compiler.cpp
+++ b/src/compiler/Compiler.cpp
@@ -19,8 +19,6 @@
GlobalParseContext = &parseContext;
- setInitialState();
-
assert(symbolTable.isEmpty());
//
// Parse the built-ins. This should only happen once per
@@ -31,13 +29,6 @@
// are preserved, and the test for an empty table fails.
//
symbolTable.push();
-
- //Initialize the Preprocessor
- if (InitPreprocessor())
- {
- infoSink.info.message(EPrefixInternalError, "Unable to intialize the Preprocessor");
- return false;
- }
for (TBuiltInStrings::const_iterator i = builtInStrings.begin(); i != builtInStrings.end(); ++i)
{
@@ -46,7 +37,7 @@
if (builtInLengths <= 0)
continue;
- if (PaParseStrings(&builtInShaders, &builtInLengths, 1, parseContext) != 0)
+ if (PaParseStrings(1, &builtInShaders, &builtInLengths, &parseContext) != 0)
{
infoSink.info.message(EPrefixInternalError, "Unable to parse built-ins");
return false;
@@ -55,19 +46,9 @@
IdentifyBuiltIns(type, spec, resources, symbolTable);
- FinalizePreprocessor();
-
return true;
}
-static void DefineExtensionMacros(const TExtensionBehavior& extBehavior)
-{
- for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
- iter != extBehavior.end(); ++iter) {
- PredefineIntMacro(iter->first.c_str(), 1);
- }
-}
-
TCompiler::TCompiler(ShShaderType type, ShShaderSpec spec)
: shaderType(type),
shaderSpec(spec)
@@ -101,11 +82,6 @@
TParseContext parseContext(symbolTable, extensionBehavior, intermediate,
shaderType, shaderSpec, infoSink);
GlobalParseContext = &parseContext;
- setInitialState();
-
- // Initialize preprocessor.
- InitPreprocessor();
- DefineExtensionMacros(extensionBehavior);
// We preserve symbols at the built-in level from compile-to-compile.
// Start pushing the user-defined symbols at global level.
@@ -115,7 +91,7 @@
// Parse shader.
bool success =
- (PaParseStrings(shaderStrings, 0, numStrings, parseContext) == 0) &&
+ (PaParseStrings(numStrings, shaderStrings, NULL, &parseContext) == 0) &&
(parseContext.treeRoot != NULL);
if (success) {
success = intermediate.postProcess(parseContext.treeRoot);
@@ -136,7 +112,6 @@
// throwing away all but the built-ins.
while (!symbolTable.atBuiltInLevel())
symbolTable.pop();
- FinalizePreprocessor();
return success;
}