Commit 5f1a0b79 by John Kessenich

Eliminate flex as the GLSL lexical analyzer, going from two nested lexical…

Eliminate flex as the GLSL lexical analyzer, going from two nested lexical analyzers down to one, leaving just the preprocessor's lexical analysis. A new layer replaces it, to translate from the preprocessor's view of tokenization to glslang's view of tokenization. Also: - change source locations from an int to TSourceLoc (shader number, line number) throughout - various improvements to the preprocessor git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@22277 e7fa87d3-cd2b-0410-9028-fcbf551c1848
parent 73ed17a8
...@@ -125,5 +125,9 @@ int linenumber = __LINE__; ...@@ -125,5 +125,9 @@ int linenumber = __LINE__;
int filenumber = __FILE__; int filenumber = __FILE__;
int version = __VERSION__; int version = __VERSION__;
#define PI (3.14)
#define TWOPI (2.0 * PI)
float twoPi = TWOPI;
#define PASTE(a,b) a ## b #define PASTE(a,b) a ## b
float PASTE(tod, ay) = 17; float PASTE(tod, ay) = 17;
#version 300 es #version 300 es
// this file cont\ // this file cont\
ains no errors ains no errors other than the #error which are there to see if line numbering for errors is correct
#error e1
float f\ float f\
oo; // same as 'float foo;' oo; // same as 'float foo;'
#error e2
#define MAIN void main() \ #define MAIN void main() \
{ \ { \
gl_Position = vec4(foo); \ gl_Position = vec4(foo); \
} }
#error e3
MAIN MAIN
...@@ -14,13 +14,13 @@ int OE = 0777777777777777777777; // ERROR ...@@ -14,13 +14,13 @@ int OE = 0777777777777777777777; // ERROR
int HE = 0x1234567890ABCDEF0; // ERROR int HE = 0x1234567890ABCDEF0; // ERROR
// 1023 character fraction // 1023 character fraction
float F = 1.012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012; float F = 1.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;
// 1024 character value // 1024 character value
float G = 1.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890; float G = 1.01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678890;
// 1027 character fraction // 1025 character fraction
float E3 = 1.01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234; float E3 = 1.012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012;
void main() void main()
{ {
......
...@@ -150,7 +150,6 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command> ...@@ -150,7 +150,6 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="glslang\MachineIndependent\Constant.cpp" /> <ClCompile Include="glslang\MachineIndependent\Constant.cpp" />
<ClCompile Include="glslang\MachineIndependent\gen_glslang.cpp" />
<ClCompile Include="glslang\MachineIndependent\glslang_tab.cpp" /> <ClCompile Include="glslang\MachineIndependent\glslang_tab.cpp" />
<ClCompile Include="glslang\MachineIndependent\InfoSink.cpp" /> <ClCompile Include="glslang\MachineIndependent\InfoSink.cpp" />
<ClCompile Include="glslang\MachineIndependent\Initialize.cpp" /> <ClCompile Include="glslang\MachineIndependent\Initialize.cpp" />
...@@ -192,7 +191,6 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command> ...@@ -192,7 +191,6 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command>
<ClInclude Include="glslang\MachineIndependent\RemoveTree.h" /> <ClInclude Include="glslang\MachineIndependent\RemoveTree.h" />
<ClInclude Include="glslang\MachineIndependent\localintermediate.h" /> <ClInclude Include="glslang\MachineIndependent\localintermediate.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\atom.h" /> <ClInclude Include="glslang\MachineIndependent\preprocessor\atom.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\compile.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\cpp.h" /> <ClInclude Include="glslang\MachineIndependent\preprocessor\cpp.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\memory.h" /> <ClInclude Include="glslang\MachineIndependent\preprocessor\memory.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\parser.h" /> <ClInclude Include="glslang\MachineIndependent\preprocessor\parser.h" />
...@@ -206,6 +204,7 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command> ...@@ -206,6 +204,7 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command>
<ClInclude Include="glslang\Include\ConstantUnion.h" /> <ClInclude Include="glslang\Include\ConstantUnion.h" />
<ClInclude Include="glslang\Include\InfoSink.h" /> <ClInclude Include="glslang\Include\InfoSink.h" />
<ClInclude Include="glslang\MachineIndependent\Scan.h" /> <ClInclude Include="glslang\MachineIndependent\Scan.h" />
<ClInclude Include="glslang\MachineIndependent\ScanContext.h" />
<ClInclude Include="glslang\MachineIndependent\Versions.h" /> <ClInclude Include="glslang\MachineIndependent\Versions.h" />
<ClInclude Include="OGLCompilersDLL\InitializeDll.h" /> <ClInclude Include="OGLCompilersDLL\InitializeDll.h" />
<ClInclude Include="glslang\Include\InitializeGlobals.h" /> <ClInclude Include="glslang\Include\InitializeGlobals.h" />
...@@ -238,23 +237,6 @@ cd %(RootDir)%(Directory) ...@@ -238,23 +237,6 @@ cd %(RootDir)%(Directory)
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(RootDir)%(Directory)%(Filename)_tab.cpp;%(Outputs)</Outputs> <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(RootDir)%(Directory)%(Filename)_tab.cpp;%(Outputs)</Outputs>
</CustomBuild> </CustomBuild>
</ItemGroup> </ItemGroup>
<ItemGroup>
<CustomBuild Include="glslang\MachineIndependent\glslang.l">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">cd %(RootDir)%(Directory)
%(RootDir)%(Directory)..\..\tools\flex.exe glslang.l
</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Executing flex on glslang.l</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(RootDir)%(Directory)gen_glslang.cpp</Outputs>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(RootDir)%(Directory)glslang_tab.cpp.h</AdditionalInputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">cd %(RootDir)%(Directory)
%(RootDir)%(Directory)..\..\tools\flex.exe glslang.l
</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Executing flex on glslang.l</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(RootDir)%(Directory)gen_glslang.cpp</Outputs>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(RootDir)%(Directory)glslang_tab.cpp.h</AdditionalInputs>
</CustomBuild>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
......
...@@ -97,9 +97,6 @@ ...@@ -97,9 +97,6 @@
<ClCompile Include="glslang\OSDependent\Linux\ossource.cpp"> <ClCompile Include="glslang\OSDependent\Linux\ossource.cpp">
<Filter>OSDependent\Linux</Filter> <Filter>OSDependent\Linux</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="glslang\MachineIndependent\gen_glslang.cpp">
<Filter>Machine Independent\Generated Source</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\glslang_tab.cpp"> <ClCompile Include="glslang\MachineIndependent\glslang_tab.cpp">
<Filter>Machine Independent\Generated Source</Filter> <Filter>Machine Independent\Generated Source</Filter>
</ClCompile> </ClCompile>
...@@ -135,9 +132,6 @@ ...@@ -135,9 +132,6 @@
<ClInclude Include="glslang\MachineIndependent\preprocessor\atom.h"> <ClInclude Include="glslang\MachineIndependent\preprocessor\atom.h">
<Filter>Machine Independent\CPP</Filter> <Filter>Machine Independent\CPP</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\compile.h">
<Filter>Machine Independent\CPP</Filter>
</ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\cpp.h"> <ClInclude Include="glslang\MachineIndependent\preprocessor\cpp.h">
<Filter>Machine Independent\CPP</Filter> <Filter>Machine Independent\CPP</Filter>
</ClInclude> </ClInclude>
...@@ -222,13 +216,13 @@ ...@@ -222,13 +216,13 @@
<ClInclude Include="glslang\MachineIndependent\Scan.h"> <ClInclude Include="glslang\MachineIndependent\Scan.h">
<Filter>Machine Independent</Filter> <Filter>Machine Independent</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="glslang\MachineIndependent\ScanContext.h">
<Filter>Machine Independent</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="glslang\MachineIndependent\glslang.y"> <CustomBuild Include="glslang\MachineIndependent\glslang.y">
<Filter>Machine Independent</Filter> <Filter>Machine Independent</Filter>
</CustomBuild> </CustomBuild>
<CustomBuild Include="glslang\MachineIndependent\glslang.l">
<Filter>Machine Independent</Filter>
</CustomBuild>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -66,8 +66,6 @@ ...@@ -66,8 +66,6 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
typedef int TSourceLoc;
#include "PoolAlloc.h" #include "PoolAlloc.h"
// //
...@@ -162,25 +160,10 @@ inline const TString String(const int i, const int base = 10) ...@@ -162,25 +160,10 @@ inline const TString String(const int i, const int base = 10)
return text; return text;
} }
const unsigned int SourceLocLineMask = 0xffff; struct TSourceLoc {
const unsigned int SourceLocStringShift = 16; int string;
int line;
__inline TPersistString FormatSourceLoc(const TSourceLoc loc) };
{
const int maxSize = 64;
char locText[maxSize];
int string = loc >> SourceLocStringShift;
int line = loc & SourceLocLineMask;
if (line)
snprintf(locText, maxSize, "%d:%d", string, line);
else
snprintf(locText, maxSize, "%d:? ", string);
return TPersistString(locText);
}
typedef TMap<TString, TString> TPragmaTable; typedef TMap<TString, TString> TPragmaTable;
typedef TMap<TString, TString>::tAllocator TPragmaTableAllocator; typedef TMap<TString, TString>::tAllocator TPragmaTableAllocator;
......
...@@ -94,7 +94,10 @@ public: ...@@ -94,7 +94,10 @@ public:
} }
} }
void location(TSourceLoc loc) { void location(TSourceLoc loc) {
append(FormatSourceLoc(loc).c_str()); const int maxSize = 24;
char locText[maxSize];
snprintf(locText, maxSize, "%d:%d", loc.string, loc.line);
append(locText);
append(": "); append(": ");
} }
void message(TPrefixType message, const char* s) { void message(TPrefixType message, const char* s) {
......
...@@ -142,11 +142,11 @@ struct TSampler { ...@@ -142,11 +142,11 @@ struct TSampler {
// Need to have association of line numbers to types in a list for building structs. // Need to have association of line numbers to types in a list for building structs.
// //
class TType; class TType;
struct TTypeLine { struct TTypeLoc {
TType* type; TType* type;
int line; TSourceLoc loc;
}; };
typedef TVector<TTypeLine> TTypeList; typedef TVector<TTypeLoc> TTypeList;
inline TTypeList* NewPoolTTypeList() inline TTypeList* NewPoolTTypeList()
{ {
...@@ -347,9 +347,9 @@ public: ...@@ -347,9 +347,9 @@ public:
int matrixRows : 4; int matrixRows : 4;
TArraySizes arraySizes; TArraySizes arraySizes;
const TType* userDef; const TType* userDef;
int line; TSourceLoc loc;
void initType(int ln = 0) void initType(TSourceLoc l)
{ {
basicType = EbtVoid; basicType = EbtVoid;
vectorSize = 1; vectorSize = 1;
...@@ -357,7 +357,7 @@ public: ...@@ -357,7 +357,7 @@ public:
matrixCols = 0; matrixCols = 0;
arraySizes = 0; arraySizes = 0;
userDef = 0; userDef = 0;
line = ln; loc = l;
} }
void initQualifiers(bool global = false) void initQualifiers(bool global = false)
...@@ -367,9 +367,9 @@ public: ...@@ -367,9 +367,9 @@ public:
qualifier.storage = EvqGlobal; qualifier.storage = EvqGlobal;
} }
void init(int line = 0, bool global = false) void init(TSourceLoc loc, bool global = false)
{ {
initType(line); initType(loc);
sampler.clear(); sampler.clear();
initQualifiers(global); initQualifiers(global);
} }
...@@ -479,10 +479,10 @@ public: ...@@ -479,10 +479,10 @@ public:
// create the new structure here // create the new structure here
structure = NewPoolTTypeList(); structure = NewPoolTTypeList();
for (unsigned int i = 0; i < copyOf.structure->size(); ++i) { for (unsigned int i = 0; i < copyOf.structure->size(); ++i) {
TTypeLine typeLine; TTypeLoc typeLoc;
typeLine.line = (*copyOf.structure)[i].line; typeLoc.loc = (*copyOf.structure)[i].loc;
typeLine.type = (*copyOf.structure)[i].type->clone(remapper); typeLoc.type = (*copyOf.structure)[i].type->clone(remapper);
structure->push_back(typeLine); structure->push_back(typeLoc);
} }
} else { } else {
structure = iter->second; structure = iter->second;
......
...@@ -320,9 +320,9 @@ class TIntermNode { ...@@ -320,9 +320,9 @@ class TIntermNode {
public: public:
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
TIntermNode() : line(0) {} TIntermNode() { loc.line = 0; loc.string = 0; }
virtual TSourceLoc getLine() const { return line; } virtual TSourceLoc getLoc() const { return loc; }
virtual void setLine(TSourceLoc l) { line = l; } virtual void setLoc(TSourceLoc l) { loc = l; }
virtual void traverse(TIntermTraverser*) = 0; virtual void traverse(TIntermTraverser*) = 0;
virtual TIntermTyped* getAsTyped() { return 0; } virtual TIntermTyped* getAsTyped() { return 0; }
virtual TIntermConstantUnion* getAsConstantUnion() { return 0; } virtual TIntermConstantUnion* getAsConstantUnion() { return 0; }
...@@ -336,7 +336,7 @@ public: ...@@ -336,7 +336,7 @@ public:
virtual TIntermBranch* getAsBranchNode() { return 0; } virtual TIntermBranch* getAsBranchNode() { return 0; }
virtual ~TIntermNode() { } virtual ~TIntermNode() { }
protected: protected:
TSourceLoc line; TSourceLoc loc;
}; };
// //
......
...@@ -195,7 +195,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -195,7 +195,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
newConstArray[i].setUConst(unionArray[i].getUConst() / rightUnionArray[i].getUConst()); newConstArray[i].setUConst(unionArray[i].getUConst() / rightUnionArray[i].getUConst());
break; break;
default: default:
infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"/\"", getLine()); infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"/\"", getLoc());
return 0; return 0;
} }
} }
...@@ -352,13 +352,13 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -352,13 +352,13 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
break; break;
default: default:
infoSink.info.message(EPrefixInternalError, "Invalid operator for constant folding", getLine()); infoSink.info.message(EPrefixInternalError, "Invalid operator for constant folding", getLoc());
return 0; return 0;
} }
TIntermConstantUnion *newNode = new TIntermConstantUnion(newConstArray, returnType); TIntermConstantUnion *newNode = new TIntermConstantUnion(newConstArray, returnType);
newNode->setLine(getLine()); newNode->setLoc(getLoc());
return newNode; return newNode;
} }
...@@ -416,7 +416,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType, ...@@ -416,7 +416,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType,
case EbtInt: newConstArray[i].setIConst(-unionArray[i].getIConst()); break; case EbtInt: newConstArray[i].setIConst(-unionArray[i].getIConst()); break;
case EbtUint: newConstArray[i].setUConst(static_cast<unsigned int>(-static_cast<int>(unionArray[i].getUConst()))); break; case EbtUint: newConstArray[i].setUConst(static_cast<unsigned int>(-static_cast<int>(unionArray[i].getUConst()))); break;
default: default:
infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", getLine()); infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", getLoc());
return 0; return 0;
} }
break; break;
...@@ -425,7 +425,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType, ...@@ -425,7 +425,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType,
switch (getType().getBasicType()) { switch (getType().getBasicType()) {
case EbtBool: newConstArray[i].setBConst(!unionArray[i].getBConst()); break; case EbtBool: newConstArray[i].setBConst(!unionArray[i].getBConst()); break;
default: default:
infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", getLine()); infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", getLoc());
return 0; return 0;
} }
break; break;
...@@ -570,14 +570,14 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType, ...@@ -570,14 +570,14 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType,
case EOpAll: case EOpAll:
default: default:
infoSink.info.message(EPrefixInternalError, "missing operator for unary constant folding", getLine()); infoSink.info.message(EPrefixInternalError, "missing operator for unary constant folding", getLoc());
return 0; return 0;
} }
} }
TIntermConstantUnion *newNode = new TIntermConstantUnion(newConstArray, returnType); TIntermConstantUnion *newNode = new TIntermConstantUnion(newConstArray, returnType);
newNode->getTypePointer()->getQualifier().storage = EvqConst; newNode->getTypePointer()->getQualifier().storage = EvqConst;
newNode->setLine(getLine()); newNode->setLoc(getLoc());
return newNode; return newNode;
} }
...@@ -667,7 +667,7 @@ TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode) ...@@ -667,7 +667,7 @@ TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode)
case EOpReflect: case EOpReflect:
case EOpRefract: case EOpRefract:
case EOpOuterProduct: case EOpOuterProduct:
infoSink.info.message(EPrefixInternalError, "constant folding operation not implemented", aggrNode->getLine()); infoSink.info.message(EPrefixInternalError, "constant folding operation not implemented", aggrNode->getLoc());
return aggrNode; return aggrNode;
default: default:
...@@ -676,7 +676,7 @@ TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode) ...@@ -676,7 +676,7 @@ TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode)
TIntermConstantUnion *newNode = new TIntermConstantUnion(newConstArray, aggrNode->getType()); TIntermConstantUnion *newNode = new TIntermConstantUnion(newConstArray, aggrNode->getType());
newNode->getTypePointer()->getQualifier().storage = EvqConst; newNode->getTypePointer()->getQualifier().storage = EvqConst;
newNode->setLine(aggrNode->getLine()); newNode->setLoc(aggrNode->getLoc());
return newNode; return newNode;
} }
...@@ -705,12 +705,12 @@ TIntermTyped* TIntermediate::foldConstructor(TIntermAggregate* aggrNode) ...@@ -705,12 +705,12 @@ TIntermTyped* TIntermediate::foldConstructor(TIntermAggregate* aggrNode)
constUnion* unionArray = new constUnion[aggrNode->getType().getObjectSize()]; constUnion* unionArray = new constUnion[aggrNode->getType().getObjectSize()];
if (aggrNode->getSequence().size() == 1) if (aggrNode->getSequence().size() == 1)
returnVal = parseConstTree(aggrNode->getLine(), aggrNode, unionArray, aggrNode->getOp(), aggrNode->getType(), true); returnVal = parseConstTree(aggrNode->getLoc(), aggrNode, unionArray, aggrNode->getOp(), aggrNode->getType(), true);
else else
returnVal = parseConstTree(aggrNode->getLine(), aggrNode, unionArray, aggrNode->getOp(), aggrNode->getType()); returnVal = parseConstTree(aggrNode->getLoc(), aggrNode, unionArray, aggrNode->getOp(), aggrNode->getType());
if (returnVal) if (returnVal)
return aggrNode; return aggrNode;
return addConstantUnion(unionArray, aggrNode->getType(), aggrNode->getLine()); return addConstantUnion(unionArray, aggrNode->getType(), aggrNode->getLoc());
} }
...@@ -70,7 +70,5 @@ protected: ...@@ -70,7 +70,5 @@ protected:
void IdentifyBuiltIns(int version, EProfile profile, EShLanguage, TSymbolTable&); void IdentifyBuiltIns(int version, EProfile profile, EShLanguage, TSymbolTable&);
void IdentifyBuiltIns(int version, EProfile profile, EShLanguage, TSymbolTable&, const TBuiltInResource &resources); void IdentifyBuiltIns(int version, EProfile profile, EShLanguage, TSymbolTable&, const TBuiltInResource &resources);
extern "C" int InitPreprocessor(void);
extern "C" int FinalizePreprocessor(void);
#endif // _INITIALIZE_INCLUDED_ #endif // _INITIALIZE_INCLUDED_
...@@ -105,7 +105,7 @@ protected: ...@@ -105,7 +105,7 @@ protected:
int currentChar; int currentChar;
}; };
// The location of these is still pending a grand design for going to a singular // TODO: The location of these is still pending a grand design for going to a singular
// scanner for version finding, preprocessing, and tokenizing: // scanner for version finding, preprocessing, and tokenizing:
void ConsumeWhiteSpace(TInputScanner& input, bool& foundNonSpaceTab); void ConsumeWhiteSpace(TInputScanner& input, bool& foundNonSpaceTab);
bool ConsumeComment(TInputScanner& input); bool ConsumeComment(TInputScanner& input);
......
//
//Copyright (C) 2013 LunarG, Inc.
//
//All rights reserved.
//
//Redistribution and use in source and binary forms, with or without
//modification, are permitted provided that the following conditions
//are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
//POSSIBILITY OF SUCH DAMAGE.
//
//
// This holds context specific to the GLSL scanner, which
// sits between the preprocessor scanner and parser.
//
#include "ParseHelper.h"
namespace glslang {
class TParserToken;
class TPpToken;
class TScanContext {
public:
explicit TScanContext(TParseContext& pc) : parseContext(pc), afterType(false), field(false) { }
virtual ~TScanContext() { }
static void fillInKeywordMap();
int tokenize(TParserToken&);
protected:
int tokenizeIdentifier();
int identifierOrType();
int reservedWord();
int identifierOrReserved(bool reserved);
int es30ReservedFromGLSL(int version);
int nonreservedKeyword(int esVersion, int nonEsVersion);
int precisionKeyword();
int matNxM();
int dMat();
int firstGenerationImage();
int secondGenerationImage();
TParseContext& parseContext;
bool afterType; // true if we've recognized a type, so can only be looking for an identifier
bool field; // true if we're on a field, right after a '.'
TSourceLoc loc;
TParserToken* parserToken;
TPpToken* ppToken;
const char* tokenText;
int keyword;
};
};
...@@ -44,10 +44,15 @@ ...@@ -44,10 +44,15 @@
#include "SymbolTable.h" #include "SymbolTable.h"
#include "ParseHelper.h" #include "ParseHelper.h"
#include "Scan.h" #include "Scan.h"
#include "ScanContext.h"
#include "../Include/ShHandle.h" #include "../Include/ShHandle.h"
#include "InitializeDll.h" #include "InitializeDll.h"
extern "C" {
#include "preprocessor/preprocess.h"
}
#define SH_EXPORTING #define SH_EXPORTING
#include "../Public/ShaderLang.h" #include "../Public/ShaderLang.h"
#include "Initialize.h" #include "Initialize.h"
...@@ -99,8 +104,9 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil ...@@ -99,8 +104,9 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil
symbolTable = &symbolTables[language]; symbolTable = &symbolTables[language];
TParseContext parseContext(*symbolTable, intermediate, true, version, profile, language, infoSink); TParseContext parseContext(*symbolTable, intermediate, true, version, profile, language, infoSink);
ThreadLocalParseContext() = &parseContext; ThreadLocalParseContext() = &parseContext;
glslang::TScanContext scanContext(parseContext);
parseContext.scanContext = &scanContext;
assert(symbolTable->isEmpty() || symbolTable->atSharedBuiltInLevel()); assert(symbolTable->isEmpty() || symbolTable->atSharedBuiltInLevel());
...@@ -123,8 +129,6 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil ...@@ -123,8 +129,6 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil
return false; return false;
} }
ResetFlex();
for (TBuiltInStrings::iterator i = BuiltInStrings[parseContext.language].begin(); for (TBuiltInStrings::iterator i = BuiltInStrings[parseContext.language].begin();
i != BuiltInStrings[parseContext.language].end(); ++i) { i != BuiltInStrings[parseContext.language].end(); ++i) {
const char* builtInShaders[1]; const char* builtInShaders[1];
...@@ -132,7 +136,7 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil ...@@ -132,7 +136,7 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil
builtInShaders[0] = (*i).c_str(); builtInShaders[0] = (*i).c_str();
builtInLengths[0] = (int) (*i).size(); builtInLengths[0] = (int) (*i).size();
if (PaParseStrings(const_cast<char**>(builtInShaders), builtInLengths, 1, parseContext, 0) != 0) { if (! parseContext.parseShaderStrings(const_cast<char**>(builtInShaders), builtInLengths, 1) != 0) {
infoSink.info.message(EPrefixInternalError, "Unable to parse built-ins"); infoSink.info.message(EPrefixInternalError, "Unable to parse built-ins");
printf("Unable to parse built-ins\n"); printf("Unable to parse built-ins\n");
...@@ -271,6 +275,8 @@ int ShInitialize() ...@@ -271,6 +275,8 @@ int ShInitialize()
PerProcessGPA = new TPoolAllocator(true); PerProcessGPA = new TPoolAllocator(true);
} }
glslang::TScanContext::fillInKeywordMap();
return true; return true;
} }
...@@ -411,19 +417,24 @@ int ShCompile( ...@@ -411,19 +417,24 @@ int ShCompile(
AddContextSpecificSymbols(resources, compiler->infoSink, &symbolTable, version, profile, compiler->getLanguage()); AddContextSpecificSymbols(resources, compiler->infoSink, &symbolTable, version, profile, compiler->getLanguage());
TParseContext parseContext(symbolTable, intermediate, false, version, profile, compiler->getLanguage(), compiler->infoSink, forwardCompatible, messages); TParseContext parseContext(symbolTable, intermediate, false, version, profile, compiler->getLanguage(), compiler->infoSink, forwardCompatible, messages);
glslang::TScanContext scanContext(parseContext);
parseContext.scanContext = &scanContext;
TSourceLoc beginning;
beginning.line = 1;
beginning.string = 0;
if (! goodProfile) if (! goodProfile)
parseContext.error(1, "incorrect", "#version", ""); parseContext.error(beginning, "incorrect", "#version", "");
parseContext.initializeExtensionBehavior(); parseContext.initializeExtensionBehavior();
if (versionStatementMissing) if (versionStatementMissing)
parseContext.warn(1, "statement missing: use #version on first line of shader", "#version", ""); parseContext.warn(beginning, "statement missing: use #version on first line of shader", "#version", "");
else if (profile == EEsProfile && version >= 300 && versionNotFirst) else if (profile == EEsProfile && version >= 300 && versionNotFirst)
parseContext.error(1, "statement must appear first in ESSL shader; before comments or newlines", "#version", ""); parseContext.error(beginning, "statement must appear first in ESSL shader; before comments or newlines", "#version", "");
ThreadLocalParseContext() = &parseContext; ThreadLocalParseContext() = &parseContext;
ResetFlex();
InitPreprocessor(); InitPreprocessor();
// //
...@@ -440,8 +451,8 @@ int ShCompile( ...@@ -440,8 +451,8 @@ int ShCompile(
if (parseContext.insertBuiltInArrayAtGlobalLevel()) if (parseContext.insertBuiltInArrayAtGlobalLevel())
success = false; success = false;
int ret = PaParseStrings(const_cast<char**>(shaderStrings), lengths, numStrings, parseContext, parseContext.getPreamble()); bool ret = parseContext.parseShaderStrings(const_cast<char**>(shaderStrings), lengths, numStrings);
if (ret) if (! ret)
success = false; success = false;
intermediate.addSymbolLinkageNodes(parseContext.treeRoot, parseContext.linkage, parseContext.language, symbolTable); intermediate.addSymbolLinkageNodes(parseContext.treeRoot, parseContext.linkage, parseContext.language, symbolTable);
......
...@@ -64,10 +64,10 @@ const char* ProfileName[EProfileCount] = { ...@@ -64,10 +64,10 @@ const char* ProfileName[EProfileCount] = {
// which subset allows the feature. If the current profile is not present, // which subset allows the feature. If the current profile is not present,
// give an error message. // give an error message.
// //
void TParseContext::requireProfile(int line, EProfileMask profileMask, const char *featureDesc) void TParseContext::requireProfile(TSourceLoc loc, EProfileMask profileMask, const char *featureDesc)
{ {
if (((1 << profile) & profileMask) == 0) if (((1 << profile) & profileMask) == 0)
error(line, "not supported with this profile:", featureDesc, ProfileName[profile]); error(loc, "not supported with this profile:", featureDesc, ProfileName[profile]);
} }
// //
...@@ -75,10 +75,10 @@ void TParseContext::requireProfile(int line, EProfileMask profileMask, const cha ...@@ -75,10 +75,10 @@ void TParseContext::requireProfile(int line, EProfileMask profileMask, const cha
// which subset allows the feature. If the current stage is not present, // which subset allows the feature. If the current stage is not present,
// give an error message. // give an error message.
// //
void TParseContext::requireStage(int line, EShLanguageMask languageMask, const char *featureDesc) void TParseContext::requireStage(TSourceLoc loc, EShLanguageMask languageMask, const char *featureDesc)
{ {
if (((1 << language) & languageMask) == 0) if (((1 << language) & languageMask) == 0)
error(line, "not supported in this stage:", featureDesc, StageName[language]); error(loc, "not supported in this stage:", featureDesc, StageName[language]);
} }
// //
...@@ -88,7 +88,7 @@ void TParseContext::requireStage(int line, EShLanguageMask languageMask, const c ...@@ -88,7 +88,7 @@ void TParseContext::requireStage(int line, EShLanguageMask languageMask, const c
// //
// one that takes multiple extensions // one that takes multiple extensions
void TParseContext::profileRequires(int line, EProfile callingProfile, int minVersion, int numExtensions, const char* extensions[], const char *featureDesc) void TParseContext::profileRequires(TSourceLoc loc, EProfile callingProfile, int minVersion, int numExtensions, const char* extensions[], const char *featureDesc)
{ {
if (profile == callingProfile) { if (profile == callingProfile) {
bool okay = false; bool okay = false;
...@@ -98,7 +98,7 @@ void TParseContext::profileRequires(int line, EProfile callingProfile, int minVe ...@@ -98,7 +98,7 @@ void TParseContext::profileRequires(int line, EProfile callingProfile, int minVe
TBehavior behavior = extensionBehavior[extensions[i]]; TBehavior behavior = extensionBehavior[extensions[i]];
switch (behavior) { switch (behavior) {
case EBhWarn: case EBhWarn:
infoSink.info.message(EPrefixWarning, ("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str(), line); infoSink.info.message(EPrefixWarning, ("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str(), loc);
// fall through // fall through
case EBhRequire: case EBhRequire:
case EBhEnable: case EBhEnable:
...@@ -109,29 +109,29 @@ void TParseContext::profileRequires(int line, EProfile callingProfile, int minVe ...@@ -109,29 +109,29 @@ void TParseContext::profileRequires(int line, EProfile callingProfile, int minVe
} }
if (! okay) if (! okay)
error(line, "not supported for this version or the enabled extensions", featureDesc, ""); error(loc, "not supported for this version or the enabled extensions", featureDesc, "");
} }
} }
// one that takes a single extension // one that takes a single extension
void TParseContext::profileRequires(int line, EProfile callingProfile, int minVersion, const char* extension, const char *featureDesc) void TParseContext::profileRequires(TSourceLoc loc, EProfile callingProfile, int minVersion, const char* extension, const char *featureDesc)
{ {
profileRequires(line, callingProfile, minVersion, extension ? 1 : 0, &extension, featureDesc); profileRequires(loc, callingProfile, minVersion, extension ? 1 : 0, &extension, featureDesc);
} }
// //
// Within a profile, see if a feature is deprecated and error or warn based on whether // Within a profile, see if a feature is deprecated and error or warn based on whether
// a future compatibility context is being use. // a future compatibility context is being use.
// //
void TParseContext::checkDeprecated(int line, EProfile callingProfile, int depVersion, const char *featureDesc) void TParseContext::checkDeprecated(TSourceLoc loc, EProfile callingProfile, int depVersion, const char *featureDesc)
{ {
if (profile == callingProfile) { if (profile == callingProfile) {
if (version >= depVersion) { if (version >= depVersion) {
if (forwardCompatible) if (forwardCompatible)
error(line, "deprecated, may be removed in future release", featureDesc, ""); error(loc, "deprecated, may be removed in future release", featureDesc, "");
else if (! (messages & EShMsgSuppressWarnings)) else if (! (messages & EShMsgSuppressWarnings))
infoSink.info.message(EPrefixWarning, (TString(featureDesc) + " deprecated in version " + infoSink.info.message(EPrefixWarning, (TString(featureDesc) + " deprecated in version " +
String(depVersion) + "; may be removed in future release").c_str(), line); String(depVersion) + "; may be removed in future release").c_str(), loc);
} }
} }
} }
...@@ -140,27 +140,27 @@ void TParseContext::checkDeprecated(int line, EProfile callingProfile, int depVe ...@@ -140,27 +140,27 @@ void TParseContext::checkDeprecated(int line, EProfile callingProfile, int depVe
// Within a profile, see if a feature has now been removed and if so, give an error. // Within a profile, see if a feature has now been removed and if so, give an error.
// The version argument is the first version no longer having the feature. // The version argument is the first version no longer having the feature.
// //
void TParseContext::requireNotRemoved(int line, EProfile callingProfile, int removedVersion, const char *featureDesc) void TParseContext::requireNotRemoved(TSourceLoc loc, EProfile callingProfile, int removedVersion, const char *featureDesc)
{ {
if (profile == callingProfile) { if (profile == callingProfile) {
if (version >= removedVersion) { if (version >= removedVersion) {
const int maxSize = 60; const int maxSize = 60;
char buf[maxSize]; char buf[maxSize];
snprintf(buf, maxSize, "%s profile; removed in version %d", ProfileName[profile], removedVersion); snprintf(buf, maxSize, "%s profile; removed in version %d", ProfileName[profile], removedVersion);
error(line, "no longer supported in", featureDesc, buf); error(loc, "no longer supported in", featureDesc, buf);
} }
} }
} }
void TParseContext::fullIntegerCheck(int line, const char* op) void TParseContext::fullIntegerCheck(TSourceLoc loc, const char* op)
{ {
profileRequires(line, ENoProfile, 130, 0, op); profileRequires(loc, ENoProfile, 130, 0, op);
profileRequires(line, EEsProfile, 300, 0, op); profileRequires(loc, EEsProfile, 300, 0, op);
} }
void TParseContext::doubleCheck(int line, const char* op) void TParseContext::doubleCheck(TSourceLoc loc, const char* op)
{ {
requireProfile(line, (EProfileMask)(ECoreProfileMask | ECompatibilityProfileMask), op); requireProfile(loc, (EProfileMask)(ECoreProfileMask | ECompatibilityProfileMask), op);
profileRequires(line, ECoreProfile, 400, 0, op); profileRequires(loc, ECoreProfile, 400, 0, op);
profileRequires(line, ECompatibilityProfile, 400, 0, op); profileRequires(loc, ECompatibilityProfile, 400, 0, op);
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -63,7 +63,11 @@ void OutputTreeText(TInfoSink& infoSink, TIntermNode* node, const int depth) ...@@ -63,7 +63,11 @@ void OutputTreeText(TInfoSink& infoSink, TIntermNode* node, const int depth)
{ {
int i; int i;
infoSink.debug << FormatSourceLoc(node->getLine()); infoSink.debug << node->getLoc().string << ":";
if (node->getLoc().line)
infoSink.debug << node->getLoc().line;
else
infoSink.debug << "? ";
for (i = 0; i < depth; ++i) for (i = 0; i < depth; ++i)
infoSink.debug << " "; infoSink.debug << " ";
...@@ -445,7 +449,7 @@ void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it) ...@@ -445,7 +449,7 @@ void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
} }
break; break;
default: default:
out.info.message(EPrefixInternalError, "Unknown constant", node->getLine()); out.info.message(EPrefixInternalError, "Unknown constant", node->getLoc());
break; break;
} }
} }
......
...@@ -62,7 +62,9 @@ public: ...@@ -62,7 +62,9 @@ public:
TIntermTyped* addUnaryMath(TOperator, TIntermNode* child, TSourceLoc); TIntermTyped* addUnaryMath(TOperator, TIntermNode* child, TSourceLoc);
TIntermTyped* addBuiltInFunctionCall(TOperator, bool unary, TIntermNode*, const TType& returnType); TIntermTyped* addBuiltInFunctionCall(TOperator, bool unary, TIntermNode*, const TType& returnType);
bool canImplicitlyPromote(TBasicType from, TBasicType to); bool canImplicitlyPromote(TBasicType from, TBasicType to);
TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right);
TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right, TSourceLoc); TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right, TSourceLoc);
TIntermAggregate* makeAggregate(TIntermNode* node);
TIntermAggregate* makeAggregate(TIntermNode* node, TSourceLoc); TIntermAggregate* makeAggregate(TIntermNode* node, TSourceLoc);
TIntermTyped* setAggregateOperator(TIntermNode*, TOperator, const TType& type, TSourceLoc); TIntermTyped* setAggregateOperator(TIntermNode*, TOperator, const TType& type, TSourceLoc);
bool areAllChildConst(TIntermAggregate* aggrNode); bool areAllChildConst(TIntermAggregate* aggrNode);
......
...@@ -69,7 +69,7 @@ public: ...@@ -69,7 +69,7 @@ public:
void ParseSymbol(TIntermSymbol* node, TIntermTraverser* it) void ParseSymbol(TIntermSymbol* node, TIntermTraverser* it)
{ {
TConstTraverser* oit = static_cast<TConstTraverser*>(it); TConstTraverser* oit = static_cast<TConstTraverser*>(it);
oit->infoSink.info.message(EPrefixInternalError, "Symbol Node found in constant constructor", node->getLine()); oit->infoSink.info.message(EPrefixInternalError, "Symbol Node found in constant constructor", node->getLoc());
return; return;
} }
...@@ -84,13 +84,13 @@ bool ParseBinary(bool /* preVisit */, TIntermBinary* node, TIntermTraverser* it) ...@@ -84,13 +84,13 @@ bool ParseBinary(bool /* preVisit */, TIntermBinary* node, TIntermTraverser* it)
const int maxSize = GlslangMaxTypeLength + 50; const int maxSize = GlslangMaxTypeLength + 50;
char buf[maxSize]; char buf[maxSize];
snprintf(buf, maxSize, "'constructor' : assigning non-constant to %s", oit->type.getCompleteString().c_str()); snprintf(buf, maxSize, "'constructor' : assigning non-constant to %s", oit->type.getCompleteString().c_str());
oit->infoSink.info.message(EPrefixError, buf, node->getLine()); oit->infoSink.info.message(EPrefixError, buf, node->getLoc());
oit->error = true; oit->error = true;
return false; return false;
} }
oit->infoSink.info.message(EPrefixInternalError, "Binary Node found in constant constructor", node->getLine()); oit->infoSink.info.message(EPrefixInternalError, "Binary Node found in constant constructor", node->getLoc());
return false; return false;
} }
...@@ -102,7 +102,7 @@ bool ParseUnary(bool /* preVisit */, TIntermUnary* node, TIntermTraverser* it) ...@@ -102,7 +102,7 @@ bool ParseUnary(bool /* preVisit */, TIntermUnary* node, TIntermTraverser* it)
const int maxSize = GlslangMaxTypeLength + 50; const int maxSize = GlslangMaxTypeLength + 50;
char buf[maxSize]; char buf[maxSize];
snprintf(buf, maxSize, "'constructor' : assigning non-constant to '%s'", oit->type.getCompleteString().c_str()); snprintf(buf, maxSize, "'constructor' : assigning non-constant to '%s'", oit->type.getCompleteString().c_str());
oit->infoSink.info.message(EPrefixError, buf, node->getLine()); oit->infoSink.info.message(EPrefixError, buf, node->getLoc());
oit->error = true; oit->error = true;
return false; return false;
...@@ -116,7 +116,7 @@ bool ParseAggregate(bool /* preVisit */, TIntermAggregate* node, TIntermTraverse ...@@ -116,7 +116,7 @@ bool ParseAggregate(bool /* preVisit */, TIntermAggregate* node, TIntermTraverse
const int maxSize = GlslangMaxTypeLength + 50; const int maxSize = GlslangMaxTypeLength + 50;
char buf[maxSize]; char buf[maxSize];
snprintf(buf, maxSize, "'constructor' : assigning non-constant to '%s'", oit->type.getCompleteString().c_str()); snprintf(buf, maxSize, "'constructor' : assigning non-constant to '%s'", oit->type.getCompleteString().c_str());
oit->infoSink.info.message(EPrefixError, buf, node->getLine()); oit->infoSink.info.message(EPrefixError, buf, node->getLoc());
oit->error = true; oit->error = true;
return false; return false;
...@@ -165,7 +165,7 @@ bool ParseAggregate(bool /* preVisit */, TIntermAggregate* node, TIntermTraverse ...@@ -165,7 +165,7 @@ bool ParseAggregate(bool /* preVisit */, TIntermAggregate* node, TIntermTraverse
bool ParseSelection(bool /* preVisit */, TIntermSelection* node, TIntermTraverser* it) bool ParseSelection(bool /* preVisit */, TIntermSelection* node, TIntermTraverser* it)
{ {
TConstTraverser* oit = static_cast<TConstTraverser*>(it); TConstTraverser* oit = static_cast<TConstTraverser*>(it);
oit->infoSink.info.message(EPrefixInternalError, "Selection Node found in constant constructor", node->getLine()); oit->infoSink.info.message(EPrefixInternalError, "Selection Node found in constant constructor", node->getLoc());
oit->error = true; oit->error = true;
return false; return false;
} }
...@@ -235,7 +235,7 @@ void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it) ...@@ -235,7 +235,7 @@ void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
bool ParseLoop(bool /* preVisit */, TIntermLoop* node, TIntermTraverser* it) bool ParseLoop(bool /* preVisit */, TIntermLoop* node, TIntermTraverser* it)
{ {
TConstTraverser* oit = static_cast<TConstTraverser*>(it); TConstTraverser* oit = static_cast<TConstTraverser*>(it);
oit->infoSink.info.message(EPrefixInternalError, "Loop Node found in constant constructor", node->getLine()); oit->infoSink.info.message(EPrefixInternalError, "Loop Node found in constant constructor", node->getLoc());
oit->error = true; oit->error = true;
return false; return false;
...@@ -244,7 +244,7 @@ bool ParseLoop(bool /* preVisit */, TIntermLoop* node, TIntermTraverser* it) ...@@ -244,7 +244,7 @@ bool ParseLoop(bool /* preVisit */, TIntermLoop* node, TIntermTraverser* it)
bool ParseBranch(bool /* previsit*/, TIntermBranch* node, TIntermTraverser* it) bool ParseBranch(bool /* previsit*/, TIntermBranch* node, TIntermTraverser* it)
{ {
TConstTraverser* oit = static_cast<TConstTraverser*>(it); TConstTraverser* oit = static_cast<TConstTraverser*>(it);
oit->infoSink.info.message(EPrefixInternalError, "Branch Node found in constant constructor", node->getLine()); oit->infoSink.info.message(EPrefixInternalError, "Branch Node found in constant constructor", node->getLoc());
oit->error = true; oit->error = true;
return false; return false;
......
...@@ -107,29 +107,20 @@ static const struct { ...@@ -107,29 +107,20 @@ static const struct {
{ CPP_ADD_ASSIGN, "+=" }, { CPP_ADD_ASSIGN, "+=" },
{ CPP_DIV_ASSIGN, "/=" }, { CPP_DIV_ASSIGN, "/=" },
{ CPP_MUL_ASSIGN, "*=" }, { CPP_MUL_ASSIGN, "*=" },
{ CPP_RIGHT_BRACKET, ":>" },
{ CPP_EQ_OP, "==" }, { CPP_EQ_OP, "==" },
{ CPP_XOR_OP, "^^" }, { CPP_XOR_OP, "^^" },
{ CPP_XOR_ASSIGN, "^=" }, { CPP_XOR_ASSIGN, "^=" },
{ CPP_FLOATCONSTANT, "<float-const>" },
{ CPP_GE_OP, ">=" }, { CPP_GE_OP, ">=" },
{ CPP_RIGHT_OP, ">>" }, { CPP_RIGHT_OP, ">>" },
{ CPP_RIGHT_ASSIGN, ">>=" }, { CPP_RIGHT_ASSIGN, ">>="},
{ CPP_IDENTIFIER, "<ident>" },
{ CPP_INTCONSTANT, "<int-const>" },
{ CPP_LE_OP, "<=" }, { CPP_LE_OP, "<=" },
{ CPP_LEFT_OP, "<<" }, { CPP_LEFT_OP, "<<" },
{ CPP_LEFT_ASSIGN, "<<=" }, { CPP_LEFT_ASSIGN, "<<="},
{ CPP_LEFT_BRACKET, "<:" },
{ CPP_LEFT_BRACE, "<%" },
{ CPP_DEC_OP, "--" }, { CPP_DEC_OP, "--" },
{ CPP_RIGHT_BRACE, "%>" },
{ CPP_NE_OP, "!=" }, { CPP_NE_OP, "!=" },
{ CPP_OR_OP, "||" }, { CPP_OR_OP, "||" },
{ CPP_OR_ASSIGN, "|=" }, { CPP_OR_ASSIGN, "|=" },
{ CPP_INC_OP, "++" }, { CPP_INC_OP, "++" },
{ CPP_STRCONSTANT, "<string-const>" },
{ CPP_TYPEIDENTIFIER, "<type-ident>" },
}; };
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
...@@ -672,7 +663,7 @@ int InitAtomTable(AtomTable *atable, int htsize) ...@@ -672,7 +663,7 @@ int InitAtomTable(AtomTable *atable, int htsize)
// Initialize lower part of atom table to "<undefined>" atom: // Initialize lower part of atom table to "<undefined>" atom:
AddAtomFixed(atable, "<undefined>", 0); AddAtomFixed(atable, "<undefined>", 0);
for (ii = 0; ii < FIRST_USER_TOKEN_SY; ii++) for (ii = 0; ii < CPP_FIRST_USER_TOKEN_SY; ii++)
atable->amap[ii] = atable->amap[0]; atable->amap[ii] = atable->amap[0];
// Add single character tokens to the atom table: // Add single character tokens to the atom table:
...@@ -697,7 +688,7 @@ int InitAtomTable(AtomTable *atable, int htsize) ...@@ -697,7 +688,7 @@ int InitAtomTable(AtomTable *atable, int htsize)
// Add error symbol if running in error mode: // Add error symbol if running in error mode:
if (cpp->options.ErrorMode) if (cpp->options.ErrorMode)
AddAtomFixed(atable, "error", ERROR_SY); AddAtomFixed(atable, "error", CPP_ERROR_SY);
AddAtom(atable, "<*** end fixed atoms ***>"); AddAtom(atable, "<*** end fixed atoms ***>");
......
//
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
//All rights reserved.
//
//Redistribution and use in source and binary forms, with or without
//modification, are permitted provided that the following conditions
//are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
//POSSIBILITY OF SUCH DAMAGE.
//
/****************************************************************************\
Copyright (c) 2002, NVIDIA Corporation.
NVIDIA Corporation("NVIDIA") supplies this software to you in
consideration of your agreement to the following terms, and your use,
installation, modification or redistribution of this NVIDIA software
constitutes acceptance of these terms. If you do not agree with these
terms, please do not use, install, modify or redistribute this NVIDIA
software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, NVIDIA grants you a personal, non-exclusive
license, under NVIDIA's copyrights in this original NVIDIA software (the
"NVIDIA Software"), to use, reproduce, modify and redistribute the
NVIDIA Software, with or without modifications, in source and/or binary
forms; provided that if you redistribute the NVIDIA Software, you must
retain the copyright notice of NVIDIA, this notice and the following
text and disclaimers in all such redistributions of the NVIDIA Software.
Neither the name, trademarks, service marks nor logos of NVIDIA
Corporation may be used to endorse or promote products derived from the
NVIDIA Software without specific prior written permission from NVIDIA.
Except as expressly stated in this notice, no other rights or licenses
express or implied, are granted by NVIDIA herein, including but not
limited to any patent rights that may be infringed by your derivative
works or by other works in which the NVIDIA Software may be
incorporated. No hardware is licensed hereunder.
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
PRODUCTS.
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
//
// compile.h
//
#if !defined(__COMPILE_H)
#define __COMPILE_H 1
int InitCPPStruct(void);
typedef struct Options_Rec{
const char *profileString;
int ErrorMode;
int Quiet;
// Debug The Compiler options:
int DumpAtomTable;
} Options;
struct CPPStruct_Rec {
// Public members
SourceLoc *pLastSourceLoc; // Set at the start of each statement by the tree walkers
Options options; // Compile options and parameters
// Private members
SourceLoc lastSourceLoc;
// Scanner data:
SourceLoc *tokenLoc; // Source location of most recent token seen by the scanner
int mostRecentToken; // Most recent token seen by the scanner
InputSrc *currentInput;
int previous_token;
int notAVersionToken; // used to make sure that #version is the first token seen in the file, if present
void *pC; // storing the parseContext of the compile object in cpp.
// Private members:
SourceLoc ltokenLoc;
int ifdepth; //current #if-#else-#endif nesting in the cpp.c file (pre-processor)
int elsedepth[64]; //Keep a track of #if depth..Max allowed is 64.
int elsetracker; //#if-#else and #endif constructs...Counter.
const char *ErrMsg;
int CompileError; //Indicate compile error when #error, #else,#elif mismatch.
//
// Globals used to communicate between PaParseStrings() and yy_input()and
// also across the files.(gen_glslang.cpp and scanner.c)
//
int PaWhichStr; // which string we're parsing
int* PaStrLen; // array of lengths of the PaArgv strings
int PaArgc; // count of strings in the array
char** PaArgv; // our array of strings to parse
unsigned int tokensBeforeEOF : 1;
};
#endif // !defined(__COMPILE_H)
...@@ -630,7 +630,8 @@ static int CPPerror(yystypepp * yylvalpp) ...@@ -630,7 +630,8 @@ static int CPPerror(yystypepp * yylvalpp)
const char *message; const char *message;
while (token != '\n') { while (token != '\n') {
if (token == CPP_FLOATCONSTANT || token == CPP_INTCONSTANT){ if (token == CPP_INTCONSTANT || token == CPP_UINTCONSTANT ||
token == CPP_FLOATCONSTANT || token == CPP_DOUBLECONSTANT) {
StoreStr(yylvalpp->symbol_name); StoreStr(yylvalpp->symbol_name);
}else if(token == CPP_IDENTIFIER || token == CPP_STRCONSTANT){ }else if(token == CPP_IDENTIFIER || token == CPP_STRCONSTANT){
StoreStr(GetStringOfAtom(atable, yylvalpp->sc_ident)); StoreStr(GetStringOfAtom(atable, yylvalpp->sc_ident));
...@@ -681,11 +682,9 @@ static int CPPpragma(yystypepp * yylvalpp) ...@@ -681,11 +682,9 @@ static int CPPpragma(yystypepp * yylvalpp)
strcpy(allTokens[tokenCount++], SrcStr); strcpy(allTokens[tokenCount++], SrcStr);
break; break;
case CPP_INTCONSTANT: case CPP_INTCONSTANT:
SrcStr = yylvalpp->symbol_name; case CPP_UINTCONSTANT:
allTokens[tokenCount] = (char*)malloc(strlen(SrcStr) + 1);
strcpy(allTokens[tokenCount++], SrcStr);
break;
case CPP_FLOATCONSTANT: case CPP_FLOATCONSTANT:
case CPP_DOUBLECONSTANT:
SrcStr = yylvalpp->symbol_name; SrcStr = yylvalpp->symbol_name;
allTokens[tokenCount] = (char*)malloc(strlen(SrcStr) + 1); allTokens[tokenCount] = (char*)malloc(strlen(SrcStr) + 1);
strcpy(allTokens[tokenCount++], SrcStr); strcpy(allTokens[tokenCount++], SrcStr);
...@@ -715,41 +714,35 @@ static int CPPpragma(yystypepp * yylvalpp) ...@@ -715,41 +714,35 @@ static int CPPpragma(yystypepp * yylvalpp)
return token; return token;
} // CPPpragma } // CPPpragma
// This is just for error checking: the version and profile are decided before preprocessing starts
static int CPPversion(yystypepp * yylvalpp) static int CPPversion(yystypepp * yylvalpp)
{ {
int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
if (cpp->notAVersionToken == 1) if (cpp->notAVersionToken == 1)
ShPpErrorToInfoLog("#version must occur before any other statement in the program"); ShPpErrorToInfoLog("#version must occur before any other statement in the program");
if(token=='\n'){ if (token == '\n'){
DecLineNumber(); DecLineNumber();
ShPpErrorToInfoLog("#version"); ShPpErrorToInfoLog("#version");
IncLineNumber(); IncLineNumber();
return token; return token;
} }
if (token != CPP_INTCONSTANT) if (token != CPP_INTCONSTANT)
ShPpErrorToInfoLog("#version"); ShPpErrorToInfoLog("#version");
yylvalpp->sc_int=atoi(yylvalpp->symbol_name); yylvalpp->sc_int = atoi(yylvalpp->symbol_name);
SetVersion(yylvalpp->sc_int);
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
if (token == '\n') { if (token == '\n')
SetProfile(ENoProfile);
return token; return token;
}
else { else {
if (yylvalpp->sc_ident == coreAtom) if (yylvalpp->sc_ident != coreAtom &&
SetProfile(ECoreProfile); yylvalpp->sc_ident != compatibilityAtom &&
else if (yylvalpp->sc_ident == compatibilityAtom) yylvalpp->sc_ident != esAtom)
SetProfile(ECompatibilityProfile);
else if (yylvalpp->sc_ident == esAtom)
SetProfile(EEsProfile);
else
ShPpErrorToInfoLog("#version profile name"); ShPpErrorToInfoLog("#version profile name");
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
...@@ -1025,7 +1018,7 @@ int MacroExpand(int atom, yystypepp* yylvalpp, int expandUndef) ...@@ -1025,7 +1018,7 @@ int MacroExpand(int atom, yystypepp* yylvalpp, int expandUndef)
} }
if (atom == __VERSION__Atom) { if (atom == __VERSION__Atom) {
yylvalpp->sc_int = GetVersion(cpp->pC); yylvalpp->sc_int = GetShaderVersion(cpp->pC);
sprintf(yylvalpp->symbol_name, "%d", yylvalpp->sc_int); sprintf(yylvalpp->symbol_name, "%d", yylvalpp->sc_int);
UngetToken(CPP_INTCONSTANT, yylvalpp); UngetToken(CPP_INTCONSTANT, yylvalpp);
......
...@@ -116,8 +116,7 @@ int GetLineNumber(void); // Get the current String Number. ...@@ -116,8 +116,7 @@ int GetLineNumber(void); // Get the current String Number.
int GetStringNumber(void); // Get the current String Number. int GetStringNumber(void); // Get the current String Number.
const char* GetStrfromTStr(void); // Convert TString to String. const char* GetStrfromTStr(void); // Convert TString to String.
void SetVersion(int); void SetVersion(int);
void SetProfile(EProfile); int GetShaderVersion(void*);
int GetVersion(void*);
void updateExtensionBehavior(const char* extName, const char* behavior); void updateExtensionBehavior(const char* extName, const char* behavior);
int FreeCPP(void); int FreeCPP(void);
......
...@@ -86,10 +86,8 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -86,10 +86,8 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
CPPStruct *cpp = NULL; CPPStruct *cpp = NULL;
static int refCount = 0; static int refCount = 0;
int InitPreprocessor(void);
int ResetPreprocessor(void); int ResetPreprocessor(void);
int FreeCPPStruct(void); int FreeCPPStruct(void);
int FinalizePreprocessor(void);
/* /*
* InitCPPStruct() - Initilaize the CPP structure. * InitCPPStruct() - Initilaize the CPP structure.
......
...@@ -75,20 +75,9 @@ TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF ...@@ -75,20 +75,9 @@ TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/ \****************************************************************************/
#ifndef BISON_PARSER_H #ifndef PARSER_H
# define BISON_PARSER_H # define PARSER_H
#ifndef yystypepp
typedef struct {
int sc_int;
float sc_fval;
double sc_dval;
int sc_ident;
char symbol_name[MAX_SYMBOL_NAME_LEN+1];
} yystypepp;
# define YYSTYPE_IS_TRIVIAL 1
#endif
# define CPP_AND_OP 257 # define CPP_AND_OP 257
# define CPP_SUB_ASSIGN 259 # define CPP_SUB_ASSIGN 259
# define CPP_MOD_ASSIGN 260 # define CPP_MOD_ASSIGN 260
...@@ -97,7 +86,7 @@ typedef struct { ...@@ -97,7 +86,7 @@ typedef struct {
# define CPP_MUL_ASSIGN 263 # define CPP_MUL_ASSIGN 263
# define CPP_EQ_OP 264 # define CPP_EQ_OP 264
# define CPP_XOR_OP 265 # define CPP_XOR_OP 265
# define ERROR_SY 266 # define CPP_ERROR_SY 266
# define CPP_FLOATCONSTANT 267 # define CPP_FLOATCONSTANT 267
# define CPP_GE_OP 268 # define CPP_GE_OP 268
# define CPP_RIGHT_OP 269 # define CPP_RIGHT_OP 269
...@@ -111,9 +100,6 @@ typedef struct { ...@@ -111,9 +100,6 @@ typedef struct {
# define CPP_INC_OP 277 # define CPP_INC_OP 277
# define CPP_STRCONSTANT 278 # define CPP_STRCONSTANT 278
# define CPP_TYPEIDENTIFIER 279 # define CPP_TYPEIDENTIFIER 279
# define FIRST_USER_TOKEN_SY 289
# define CPP_RIGHT_ASSIGN 280 # define CPP_RIGHT_ASSIGN 280
# define CPP_LEFT_ASSIGN 281 # define CPP_LEFT_ASSIGN 281
# define CPP_AND_ASSIGN 282 # define CPP_AND_ASSIGN 282
...@@ -123,5 +109,8 @@ typedef struct { ...@@ -123,5 +109,8 @@ typedef struct {
# define CPP_RIGHT_BRACKET 286 # define CPP_RIGHT_BRACKET 286
# define CPP_LEFT_BRACE 287 # define CPP_LEFT_BRACE 287
# define CPP_RIGHT_BRACE 288 # define CPP_RIGHT_BRACE 288
# define CPP_UINTCONSTANT 289
# define CPP_DOUBLECONSTANT 290
# define CPP_FIRST_USER_TOKEN_SY 291
#endif /* not BISON_PARSER_H */ #endif /* not PARSER_H */
...@@ -75,10 +75,84 @@ TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF ...@@ -75,10 +75,84 @@ TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/ \****************************************************************************/
#include "slglobals.h" #ifndef PREPROCESS_H
#define PREPROCESS_H
typedef struct SourceLoc_Rec {
int file;
int line;
} SourceLoc;
typedef struct Options_Rec {
const char *profileString;
int ErrorMode;
int Quiet;
// Debug The Compiler options:
int DumpAtomTable;
} Options;
#define MAX_TOKEN_LENGTH 1024
typedef struct {
int ppToken;
int sc_int;
double sc_dval;
int sc_ident;
char symbol_name[MAX_TOKEN_LENGTH+1];
} yystypepp;
typedef struct InputSrc {
struct InputSrc *prev;
int (*scan)(struct InputSrc *, yystypepp *);
int (*getch)(struct InputSrc *, yystypepp *);
void (*ungetch)(struct InputSrc *, int, yystypepp *);
int name; /* atom */
int line;
} InputSrc;
typedef struct CPPStruct {
// Public members
SourceLoc *pLastSourceLoc; // Set at the start of each statement by the tree walkers
Options options; // Compile options and parameters
// Private members
SourceLoc lastSourceLoc;
// Scanner data:
SourceLoc *tokenLoc; // Source location of most recent token seen by the scanner
int mostRecentToken; // Most recent token seen by the scanner
InputSrc *currentInput;
int previous_token;
int notAVersionToken; // used to make sure that #version is the first token seen in the file, if present
void *pC; // storing the parseContext of the compile object in cpp.
// Private members:
SourceLoc ltokenLoc;
int ifdepth; //current #if-#else-#endif nesting in the cpp.c file (pre-processor)
int elsedepth[64]; //Keep a track of #if depth..Max allowed is 64.
int elsetracker; //#if-#else and #endif constructs...Counter.
const char *ErrMsg;
int CompileError; //Indicate compile error when #error, #else,#elif mismatch.
//
// Globals used to communicate between parseStrings() and yy_input()and
// also across the files.(gen_glslang.cpp and scanner.c)
//
int PaWhichStr; // which string we're parsing
int* PaStrLen; // array of lengths of the PaArgv strings
int PaArgc; // count of strings in the array
char** PaArgv; // our array of strings to parse
unsigned int tokensBeforeEOF : 1;
} CPPStruct;
extern CPPStruct *cpp; extern CPPStruct *cpp;
int InitCPPStruct(void);
int InitScanner(CPPStruct *cpp); int InitPreprocessor(void);
int InitAtomTable(AtomTable *atable, int htsize); int FinalizePreprocessor(void);
int ScanFromString(char *s); int ScanFromString(char *s);
char* GetStringOfAtom(AtomTable *atable, int atom); const char* PpTokenize(yystypepp*);
#endif
...@@ -81,9 +81,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -81,9 +81,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#if !defined(__SCANNER_H) #if !defined(__SCANNER_H)
#define __SCANNER_H 1 #define __SCANNER_H 1
#define MAX_SYMBOL_NAME_LEN 1025 #include "preprocess.h"
#define MAX_STRING_LEN 1025
#include "parser.h" #include "parser.h"
// Not really atom table stuff but needed first... // Not really atom table stuff but needed first...
...@@ -91,23 +89,8 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -91,23 +89,8 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
extern "C" { extern "C" {
#endif #endif
typedef struct SourceLoc_Rec {
unsigned short file, line;
} SourceLoc;
int yyparse (void); int yyparse (void);
int yylex_CPP(char* buf, int maxSize);
typedef struct InputSrc {
struct InputSrc *prev;
int (*scan)(struct InputSrc *, yystypepp *);
int (*getch)(struct InputSrc *, yystypepp *);
void (*ungetch)(struct InputSrc *, int, yystypepp *);
int name; /* atom */
int line;
} InputSrc;
int InitScanner(CPPStruct *cpp); // Intialise the cpp scanner. int InitScanner(CPPStruct *cpp); // Intialise the cpp scanner.
int ScanFromString(char *); // Start scanning the input from the string mentioned. int ScanFromString(char *); // Start scanning the input from the string mentioned.
int check_EOF(int); // check if we hit a EOF abruptly int check_EOF(int); // check if we hit a EOF abruptly
......
...@@ -81,7 +81,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -81,7 +81,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#if !defined(__SLGLOBALS_H) #if !defined(__SLGLOBALS_H)
#define __SLGLOBALS_H 1 #define __SLGLOBALS_H 1
typedef struct CPPStruct_Rec CPPStruct; #include "preprocess.h"
// TODO: threading: Multi-threading note: The existence of this global makes // TODO: threading: Multi-threading note: The existence of this global makes
// this preprocessing single-threaded only. // this preprocessing single-threaded only.
...@@ -101,7 +101,6 @@ extern CPPStruct *cpp; ...@@ -101,7 +101,6 @@ extern CPPStruct *cpp;
#include "cpp.h" #include "cpp.h"
#include "tokens.h" #include "tokens.h"
#include "symbols.h" #include "symbols.h"
#include "compile.h"
#if !defined(NO_PARSER) #if !defined(NO_PARSER)
#include "parser.h" #include "parser.h"
#endif #endif
......
...@@ -257,8 +257,10 @@ void RecordToken(TokenStream *pTok, int token, yystypepp * yylvalpp) ...@@ -257,8 +257,10 @@ void RecordToken(TokenStream *pTok, int token, yystypepp * yylvalpp)
lAddByte(pTok, (unsigned char) *s++); lAddByte(pTok, (unsigned char) *s++);
lAddByte(pTok, 0); lAddByte(pTok, 0);
break; break;
case CPP_FLOATCONSTANT:
case CPP_INTCONSTANT: case CPP_INTCONSTANT:
case CPP_UINTCONSTANT:
case CPP_FLOATCONSTANT:
case CPP_DOUBLECONSTANT:
str = yylvalpp->symbol_name; str = yylvalpp->symbol_name;
while (*str){ while (*str){
lAddByte(pTok, (unsigned char) *str); lAddByte(pTok, (unsigned char) *str);
...@@ -293,8 +295,9 @@ void RewindTokenStream(TokenStream *pTok) ...@@ -293,8 +295,9 @@ void RewindTokenStream(TokenStream *pTok)
int ReadToken(TokenStream *pTok, yystypepp * yylvalpp) int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
{ {
char symbol_name[MAX_SYMBOL_NAME_LEN + 1]; //TODO: PP: why is this different than byte_scan
char string_val[MAX_STRING_LEN + 1];
char tokenText[MAX_TOKEN_LENGTH + 1];
int ltoken, len; int ltoken, len;
char ch; char ch;
...@@ -312,8 +315,8 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp) ...@@ -312,8 +315,8 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
(ch >= '0' && ch <= '9') || (ch >= '0' && ch <= '9') ||
ch == '_') ch == '_')
{ {
if (len < MAX_SYMBOL_NAME_LEN) { if (len < MAX_TOKEN_LENGTH) {
symbol_name[len] = ch; tokenText[len] = ch;
len++; len++;
ch = lReadByte(pTok); ch = lReadByte(pTok);
} else { } else {
...@@ -321,30 +324,31 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp) ...@@ -321,30 +324,31 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
break; break;
} }
} }
symbol_name[len] = '\0'; tokenText[len] = '\0';
assert(ch == '\0'); assert(ch == '\0');
yylvalpp->sc_ident = LookUpAddString(atable, symbol_name); yylvalpp->sc_ident = LookUpAddString(atable, tokenText);
return CPP_IDENTIFIER; return CPP_IDENTIFIER;
break; break;
case CPP_STRCONSTANT: case CPP_STRCONSTANT:
len = 0; len = 0;
while ((ch = lReadByte(pTok)) != 0) { while ((ch = lReadByte(pTok)) != 0) {
if (len < MAX_STRING_LEN) if (len < MAX_TOKEN_LENGTH)
string_val[len++] = ch; tokenText[len++] = ch;
else else
break; break;
} }
string_val[len] = 0; tokenText[len] = 0;
yylvalpp->sc_ident = LookUpAddString(atable, string_val); yylvalpp->sc_ident = LookUpAddString(atable, tokenText);
break; break;
case CPP_FLOATCONSTANT: case CPP_FLOATCONSTANT:
case CPP_DOUBLECONSTANT:
len = 0; len = 0;
ch = lReadByte(pTok); ch = lReadByte(pTok);
while ((ch >= '0' && ch <= '9')||(ch=='e'||ch=='E'||ch=='.')||(ch=='+'||ch=='-')) while ((ch >= '0' && ch <= '9') || ch=='e' || ch=='E' || ch=='.' || ch=='+' || ch=='-' || ch=='l' || ch=='L' || ch=='f'|| ch=='F')
{ {
if (len < MAX_SYMBOL_NAME_LEN) { if (len < MAX_TOKEN_LENGTH) {
symbol_name[len] = ch; tokenText[len] = ch;
len++; len++;
ch = lReadByte(pTok); ch = lReadByte(pTok);
} else { } else {
...@@ -352,18 +356,19 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp) ...@@ -352,18 +356,19 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
break; break;
} }
} }
symbol_name[len] = '\0'; tokenText[len] = '\0';
assert(ch == '\0'); assert(ch == '\0');
strcpy(yylvalpp->symbol_name,symbol_name); strcpy(yylvalpp->symbol_name, tokenText);
yylvalpp->sc_fval=(float)atof(yylvalpp->symbol_name); yylvalpp->sc_dval = atof(yylvalpp->symbol_name);
break; break;
case CPP_INTCONSTANT: case CPP_INTCONSTANT:
case CPP_UINTCONSTANT:
len = 0; len = 0;
ch = lReadByte(pTok); ch = lReadByte(pTok);
while ((ch >= '0' && ch <= '9')) while ((ch >= '0' && ch <= '9') || ch == 'u' || ch == 'U')
{ {
if (len < MAX_SYMBOL_NAME_LEN) { if (len < MAX_TOKEN_LENGTH) {
symbol_name[len] = ch; tokenText[len] = ch;
len++; len++;
ch = lReadByte(pTok); ch = lReadByte(pTok);
} else { } else {
...@@ -371,10 +376,10 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp) ...@@ -371,10 +376,10 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
break; break;
} }
} }
symbol_name[len] = '\0'; tokenText[len] = '\0';
assert(ch == '\0'); assert(ch == '\0');
strcpy(yylvalpp->symbol_name,symbol_name); strcpy(yylvalpp->symbol_name,tokenText);
yylvalpp->sc_int=atoi(yylvalpp->symbol_name); yylvalpp->sc_int = atoi(yylvalpp->symbol_name);
break; break;
case '(': case '(':
yylvalpp->sc_int = lReadByte(pTok); yylvalpp->sc_int = lReadByte(pTok);
...@@ -456,7 +461,7 @@ void UngetToken(int token, yystypepp * yylvalpp) { ...@@ -456,7 +461,7 @@ void UngetToken(int token, yystypepp * yylvalpp) {
void DumpTokenStream(FILE *fp, TokenStream *s, yystypepp * yylvalpp) { void DumpTokenStream(FILE *fp, TokenStream *s, yystypepp * yylvalpp) {
int token; int token;
const int maxSize = MAX_SYMBOL_NAME_LEN + 5; const int maxSize = MAX_TOKEN_LENGTH + 5;
char str[100]; char str[100];
if (fp == 0) fp = stdout; if (fp == 0) fp = stdout;
...@@ -471,10 +476,12 @@ void DumpTokenStream(FILE *fp, TokenStream *s, yystypepp * yylvalpp) { ...@@ -471,10 +476,12 @@ void DumpTokenStream(FILE *fp, TokenStream *s, yystypepp * yylvalpp) {
snprintf(str, maxSize, "\"%s\"", GetAtomString(atable, yylvalpp->sc_ident)); snprintf(str, maxSize, "\"%s\"", GetAtomString(atable, yylvalpp->sc_ident));
break; break;
case CPP_FLOATCONSTANT: case CPP_FLOATCONSTANT:
//printf("%g9.6 ", yylvalpp->sc_fval); case CPP_DOUBLECONSTANT:
printf("%g9.6 ", yylvalpp->sc_dval);
break; break;
case CPP_INTCONSTANT: case CPP_INTCONSTANT:
//printf("%d ", yylvalpp->sc_int); case CPP_UINTCONSTANT:
printf("%d ", yylvalpp->sc_int);
break; break;
default: default:
if (token >= 127) if (token >= 127)
......
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