Commit 72133242 by John Kessenich

Reframe the preprocessor as a C++ class, with instances, removing all C code,…

Reframe the preprocessor as a C++ class, with instances, removing all C code, removing all global variables. Upgrade bison version to pass a parse context on through to the preprocessor. All the basic things to make something thread safe. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@22291 e7fa87d3-cd2b-0410-9028-fcbf551c1848
parent 5f1a0b79
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include "InitializeDll.h" #include "InitializeDll.h"
#include "Include/InitializeGlobals.h" #include "Include/InitializeGlobals.h"
#include "Include/InitializeParseContext.h"
#include "Public/ShaderLang.h" #include "Public/ShaderLang.h"
...@@ -58,18 +57,13 @@ bool InitProcess() ...@@ -58,18 +57,13 @@ bool InitProcess()
return false; return false;
} }
if (! InitializePoolIndex()) {
if (!InitializePoolIndex()) {
assert(0 && "InitProcess(): Failed to initalize global pool"); assert(0 && "InitProcess(): Failed to initalize global pool");
return false; return false;
} }
if (!InitializeParseContextIndex()) {
assert(0 && "InitProcess(): Failed to initalize parse context");
return false;
}
InitThread(); InitThread();
return true; return true;
} }
...@@ -89,10 +83,7 @@ bool InitThread() ...@@ -89,10 +83,7 @@ bool InitThread()
InitializeGlobalPools(); InitializeGlobalPools();
if (!InitializeThreadParseContext()) if (! OS_SetTLSValue(ThreadInitializeIndex, (void *)1)) {
return false;
if (!OS_SetTLSValue(ThreadInitializeIndex, (void *)1)) {
assert(0 && "InitThread(): Unable to set init flag."); assert(0 && "InitThread(): Unable to set init flag.");
return false; return false;
} }
...@@ -119,8 +110,6 @@ bool DetachThread() ...@@ -119,8 +110,6 @@ bool DetachThread()
FreeGlobalPools(); FreeGlobalPools();
if (!FreeParseContext())
success = false;
} }
return success; return success;
...@@ -139,9 +128,6 @@ bool DetachProcess() ...@@ -139,9 +128,6 @@ bool DetachProcess()
FreePoolIndex(); FreePoolIndex();
if (!FreeParseContextIndex())
success = false;
OS_FreeTLSIndex(ThreadInitializeIndex); OS_FreeTLSIndex(ThreadInitializeIndex);
ThreadInitializeIndex = OS_INVALID_TLS_INDEX; ThreadInitializeIndex = OS_INVALID_TLS_INDEX;
......
...@@ -150,9 +150,18 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command> ...@@ -150,9 +150,18 @@ 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\glslang_tab.cpp" /> <ClCompile Include="glslang\MachineIndependent\glslang_tab.cpp">
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4065</DisableSpecificWarnings>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\InfoSink.cpp" /> <ClCompile Include="glslang\MachineIndependent\InfoSink.cpp" />
<ClCompile Include="glslang\MachineIndependent\Initialize.cpp" /> <ClCompile Include="glslang\MachineIndependent\Initialize.cpp" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\Pp.cpp" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\PpAtom.cpp" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\PpMemory.cpp" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\PpScanner.cpp" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\PpContext.cpp" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\PpSymbols.cpp" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\PpTokens.cpp" />
<ClCompile Include="glslang\MachineIndependent\Scan.cpp" /> <ClCompile Include="glslang\MachineIndependent\Scan.cpp" />
<ClCompile Include="glslang\MachineIndependent\Versions.cpp" /> <ClCompile Include="glslang\MachineIndependent\Versions.cpp" />
<ClCompile Include="OGLCompilersDLL\InitializeDll.cpp" /> <ClCompile Include="OGLCompilersDLL\InitializeDll.cpp" />
...@@ -166,13 +175,6 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command> ...@@ -166,13 +175,6 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command>
<ClCompile Include="glslang\MachineIndependent\SymbolTable.cpp" /> <ClCompile Include="glslang\MachineIndependent\SymbolTable.cpp" />
<ClCompile Include="glslang\MachineIndependent\intermOut.cpp" /> <ClCompile Include="glslang\MachineIndependent\intermOut.cpp" />
<ClCompile Include="glslang\MachineIndependent\parseConst.cpp" /> <ClCompile Include="glslang\MachineIndependent\parseConst.cpp" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\atom.c" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\cpp.c" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\cppstruct.c" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\memory.c" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\scanner.c" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\symbols.c" />
<ClCompile Include="glslang\MachineIndependent\preprocessor\tokens.c" />
<ClCompile Include="glslang\OSDependent\Windows\main.cpp" /> <ClCompile Include="glslang\OSDependent\Windows\main.cpp" />
<ClCompile Include="glslang\OSDependent\Windows\ossource.cpp" /> <ClCompile Include="glslang\OSDependent\Windows\ossource.cpp" />
<ClCompile Include="glslang\OSDependent\Linux\ossource.cpp"> <ClCompile Include="glslang\OSDependent\Linux\ossource.cpp">
...@@ -187,18 +189,11 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command> ...@@ -187,18 +189,11 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command>
<ClInclude Include="glslang\MachineIndependent\Initialize.h" /> <ClInclude Include="glslang\MachineIndependent\Initialize.h" />
<ClInclude Include="glslang\MachineIndependent\MMap.h" /> <ClInclude Include="glslang\MachineIndependent\MMap.h" />
<ClInclude Include="glslang\MachineIndependent\ParseHelper.h" /> <ClInclude Include="glslang\MachineIndependent\ParseHelper.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\PpContext.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\PpTokens.h" />
<ClInclude Include="glslang\MachineIndependent\QualifierAlive.h" /> <ClInclude Include="glslang\MachineIndependent\QualifierAlive.h" />
<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\cpp.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\memory.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\parser.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\preprocess.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\scanner.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\slglobals.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\symbols.h" />
<ClInclude Include="glslang\MachineIndependent\preprocessor\tokens.h" />
<ClInclude Include="glslang\Include\BaseTypes.h" /> <ClInclude Include="glslang\Include\BaseTypes.h" />
<ClInclude Include="glslang\Include\Common.h" /> <ClInclude Include="glslang\Include\Common.h" />
<ClInclude Include="glslang\Include\ConstantUnion.h" /> <ClInclude Include="glslang\Include\ConstantUnion.h" />
...@@ -208,7 +203,6 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command> ...@@ -208,7 +203,6 @@ xcopy /y $(IntDir)$(TargetName)$(TargetExt) Test</Command>
<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" />
<ClInclude Include="glslang\Include\InitializeParseContext.h" />
<ClInclude Include="glslang\Include\PoolAlloc.h" /> <ClInclude Include="glslang\Include\PoolAlloc.h" />
<ClInclude Include="glslang\Include\ResourceLimits.h" /> <ClInclude Include="glslang\Include\ResourceLimits.h" />
<ClInclude Include="glslang\Include\ShHandle.h" /> <ClInclude Include="glslang\Include\ShHandle.h" />
......
...@@ -8,9 +8,6 @@ ...@@ -8,9 +8,6 @@
<Filter Include="Machine Independent\Generated Source"> <Filter Include="Machine Independent\Generated Source">
<UniqueIdentifier>{564543b5-6302-49ab-9d24-bd6bef91274a}</UniqueIdentifier> <UniqueIdentifier>{564543b5-6302-49ab-9d24-bd6bef91274a}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Machine Independent\CPP">
<UniqueIdentifier>{5d320e20-4d64-4db1-9d8c-e7fdc234be36}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files"> <Filter Include="Header Files">
<UniqueIdentifier>{d4faa328-f693-4b77-9fcb-9629ca0d8ee8}</UniqueIdentifier> <UniqueIdentifier>{d4faa328-f693-4b77-9fcb-9629ca0d8ee8}</UniqueIdentifier>
</Filter> </Filter>
...@@ -26,6 +23,9 @@ ...@@ -26,6 +23,9 @@
<Filter Include="OSDependent\Linux"> <Filter Include="OSDependent\Linux">
<UniqueIdentifier>{0c27903f-6ef2-4725-9d9c-70f50aeaa7a1}</UniqueIdentifier> <UniqueIdentifier>{0c27903f-6ef2-4725-9d9c-70f50aeaa7a1}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Machine Independent\Preprocessor">
<UniqueIdentifier>{f25a01e9-79ce-49bf-b79a-d10de89a0fec}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="glslang\MachineIndependent\InfoSink.cpp"> <ClCompile Include="glslang\MachineIndependent\InfoSink.cpp">
...@@ -67,27 +67,6 @@ ...@@ -67,27 +67,6 @@
<ClCompile Include="glslang\MachineIndependent\parseConst.cpp"> <ClCompile Include="glslang\MachineIndependent\parseConst.cpp">
<Filter>Machine Independent</Filter> <Filter>Machine Independent</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\atom.c">
<Filter>Machine Independent\CPP</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\cpp.c">
<Filter>Machine Independent\CPP</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\cppstruct.c">
<Filter>Machine Independent\CPP</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\memory.c">
<Filter>Machine Independent\CPP</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\scanner.c">
<Filter>Machine Independent\CPP</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\symbols.c">
<Filter>Machine Independent\CPP</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\tokens.c">
<Filter>Machine Independent\CPP</Filter>
</ClCompile>
<ClCompile Include="glslang\OSDependent\Windows\main.cpp"> <ClCompile Include="glslang\OSDependent\Windows\main.cpp">
<Filter>OSDependent\Windows</Filter> <Filter>OSDependent\Windows</Filter>
</ClCompile> </ClCompile>
...@@ -109,6 +88,27 @@ ...@@ -109,6 +88,27 @@
<ClCompile Include="glslang\MachineIndependent\Scan.cpp"> <ClCompile Include="glslang\MachineIndependent\Scan.cpp">
<Filter>Machine Independent</Filter> <Filter>Machine Independent</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\Pp.cpp">
<Filter>Machine Independent\Preprocessor</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\PpAtom.cpp">
<Filter>Machine Independent\Preprocessor</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\PpMemory.cpp">
<Filter>Machine Independent\Preprocessor</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\PpScanner.cpp">
<Filter>Machine Independent\Preprocessor</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\PpSymbols.cpp">
<Filter>Machine Independent\Preprocessor</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\PpTokens.cpp">
<Filter>Machine Independent\Preprocessor</Filter>
</ClCompile>
<ClCompile Include="glslang\MachineIndependent\preprocessor\PpContext.cpp">
<Filter>Machine Independent\Preprocessor</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="glslang\MachineIndependent\Initialize.h"> <ClInclude Include="glslang\MachineIndependent\Initialize.h">
...@@ -129,33 +129,6 @@ ...@@ -129,33 +129,6 @@
<ClInclude Include="glslang\MachineIndependent\localintermediate.h"> <ClInclude Include="glslang\MachineIndependent\localintermediate.h">
<Filter>Machine Independent</Filter> <Filter>Machine Independent</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\atom.h">
<Filter>Machine Independent\CPP</Filter>
</ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\cpp.h">
<Filter>Machine Independent\CPP</Filter>
</ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\memory.h">
<Filter>Machine Independent\CPP</Filter>
</ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\parser.h">
<Filter>Machine Independent\CPP</Filter>
</ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\preprocess.h">
<Filter>Machine Independent\CPP</Filter>
</ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\scanner.h">
<Filter>Machine Independent\CPP</Filter>
</ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\slglobals.h">
<Filter>Machine Independent\CPP</Filter>
</ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\symbols.h">
<Filter>Machine Independent\CPP</Filter>
</ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\tokens.h">
<Filter>Machine Independent\CPP</Filter>
</ClInclude>
<ClInclude Include="glslang\Include\BaseTypes.h"> <ClInclude Include="glslang\Include\BaseTypes.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
...@@ -174,9 +147,6 @@ ...@@ -174,9 +147,6 @@
<ClInclude Include="glslang\Include\InitializeGlobals.h"> <ClInclude Include="glslang\Include\InitializeGlobals.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="glslang\Include\InitializeParseContext.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="glslang\Include\PoolAlloc.h"> <ClInclude Include="glslang\Include\PoolAlloc.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
...@@ -219,6 +189,12 @@ ...@@ -219,6 +189,12 @@
<ClInclude Include="glslang\MachineIndependent\ScanContext.h"> <ClInclude Include="glslang\MachineIndependent\ScanContext.h">
<Filter>Machine Independent</Filter> <Filter>Machine Independent</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\PpContext.h">
<Filter>Machine Independent\Preprocessor</Filter>
</ClInclude>
<ClInclude Include="glslang\MachineIndependent\preprocessor\PpTokens.h">
<Filter>Machine Independent\Preprocessor</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="glslang\MachineIndependent\glslang.y"> <CustomBuild Include="glslang\MachineIndependent\glslang.y">
......
//
//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.
//
#ifndef __INITIALIZE_PARSE_CONTEXT_INCLUDED_
#define __INITIALIZE_PARSE_CONTEXT_INCLUDED_
#include "osinclude.h"
bool InitializeParseContextIndex();
bool InitializeThreadParseContext();
bool FreeParseContext();
bool FreeParseContextIndex();
#endif // __INITIALIZE_PARSE_CONTEXT_INCLUDED_
...@@ -13,7 +13,7 @@ OBJECTS= Initialize.o IntermTraverse.o \ ...@@ -13,7 +13,7 @@ OBJECTS= Initialize.o IntermTraverse.o \
RemoveTree.o ShaderLang.o intermOut.o parseConst.o SymbolTable.o \ RemoveTree.o ShaderLang.o intermOut.o parseConst.o SymbolTable.o \
InfoSink.o Versions.o Constant.o Scan.o InfoSink.o Versions.o Constant.o Scan.o
SRCS= gen_glslang.cpp gen_glslang_tab.cpp Initialize.cpp IntermTraverse.cpp \ SRCS= gen_glslang_tab.cpp Initialize.cpp IntermTraverse.cpp \
Intermediate.cpp ParseHelper.cpp PoolAlloc.cp QualifierAlive.cpp \ Intermediate.cpp ParseHelper.cpp PoolAlloc.cp QualifierAlive.cpp \
RemoveTree.cpp ShaderLang.cpp SymbolTable.cpp intermOut.cpp \ RemoveTree.cpp ShaderLang.cpp SymbolTable.cpp intermOut.cpp \
parseConst.cpp InfoSink.cpp Versions.cpp Constant.cpp Scan.cpp parseConst.cpp InfoSink.cpp Versions.cpp Constant.cpp Scan.cpp
...@@ -24,21 +24,13 @@ default: all ...@@ -24,21 +24,13 @@ default: all
all: $(SHAREDOBJECT) all: $(SHAREDOBJECT)
$(SHAREDOBJECT): gen_glslang.o gen_glslang_tab.o $(OBJECTS) \ $(SHAREDOBJECT): gen_glslang_tab.o $(OBJECTS) \
$(LIBPREPROCESSOR) $(LIBCODEGEN) $(LIBOSDEPENDENT) $(LIBINITIALISATION) $(LIBPREPROCESSOR) $(LIBCODEGEN) $(LIBOSDEPENDENT) $(LIBINITIALISATION)
$(CC) -fPIC -shared -o $@ -rdynamic -Wl,-whole-archive $(OBJECTS) $(LIBPREPROCESSOR) $(LIBCODEGEN) $(LIBOSDEPENDENT) $(LIBINITIALISATION) gen_glslang.o gen_glslang_tab.o -Wl,-no-whole-archive $(CC) -fPIC -shared -o $@ -rdynamic -Wl,-whole-archive $(OBJECTS) $(LIBPREPROCESSOR) $(LIBCODEGEN) $(LIBOSDEPENDENT) $(LIBINITIALISATION) gen_glslang_tab.o -Wl,-no-whole-archive
gen_glslang.o : gen_glslang.cpp glslang_tab.h
$(CC) -fPIC -c $(INCLUDE) gen_glslang.cpp -o $@
gen_glslang_tab.o : gen_glslang_tab.cpp gen_glslang_tab.o : gen_glslang_tab.cpp
$(CC) -fPIC -c $(INCLUDE) gen_glslang_tab.cpp -o $@ $(CC) -fPIC -c $(INCLUDE) gen_glslang_tab.cpp -o $@
gen_glslang.cpp: glslang.l
@echo Generating gen_glslang.cpp
@dos2unix glslang.l
flex glslang.l
gen_glslang_tab.cpp glslang_tab.h: glslang.y gen_glslang_tab.cpp glslang_tab.h: glslang.y
@echo Generating gen_glslang_tab.cpp @echo Generating gen_glslang_tab.cpp
@dos2unix glslang.y @dos2unix glslang.y
...@@ -72,7 +64,7 @@ depend: ...@@ -72,7 +64,7 @@ depend:
# #
.PHONY : clean .PHONY : clean
clean : clean :
$(RM) *.o *.a gen_glslang_tab.cpp glslang_tab.cpp glslang_tab.cpp.h gen_glslang.cpp glslang_tab.h glslang.output $(RM) *.o *.a gen_glslang_tab.cpp glslang_tab.cpp glslang_tab.cpp.h glslang_tab.h glslang.output
$(RM) ./lib/*.so $(RM) ./lib/*.so
cd $(INCPREPROCESSOR); make clean cd $(INCPREPROCESSOR); make clean
cd $(INCCODEGEN); make clean cd $(INCCODEGEN); make clean
...@@ -81,19 +73,6 @@ clean : ...@@ -81,19 +73,6 @@ clean :
# DO NOT DELETE # DO NOT DELETE
gen_glslang.o: ParseHelper.h ../Include/ShHandle.h
gen_glslang.o: ../Public/ShaderLang.h ../Include/InfoSink.h
gen_glslang.o: ../Include/Common.h ../Include/PoolAlloc.h SymbolTable.h
gen_glslang.o: ../Include/Common.h ../Include/intermediate.h
gen_glslang.o: ../Include/Types.h ../Include/BaseTypes.h
gen_glslang.o: ../Include/ConstantUnion.h ../Include/InfoSink.h
gen_glslang.o: localintermediate.h ../Include/intermediate.h
gen_glslang.o: ../Public/ShaderLang.h glslang_tab.h ./unistd.h
gen_glslang.o: ./preprocessor/preprocess.h ./preprocessor/slglobals.h
gen_glslang.o: ./preprocessor/memory.h ./preprocessor/atom.h
gen_glslang.o: ./preprocessor/scanner.h ./preprocessor/parser.h
gen_glslang.o: ./preprocessor/cpp.h ./preprocessor/tokens.h
gen_glslang.o: ./preprocessor/symbols.h ./preprocessor/compile.h
gen_glslang_tab.o: SymbolTable.h ../Include/Common.h gen_glslang_tab.o: SymbolTable.h ../Include/Common.h
gen_glslang_tab.o: ../Include/intermediate.h ../Include/Common.h gen_glslang_tab.o: ../Include/intermediate.h ../Include/Common.h
gen_glslang_tab.o: ../Include/PoolAlloc.h ../Include/Types.h gen_glslang_tab.o: ../Include/PoolAlloc.h ../Include/Types.h
...@@ -126,10 +105,15 @@ ParseHelper.o: ../Include/Common.h ../Include/intermediate.h ...@@ -126,10 +105,15 @@ ParseHelper.o: ../Include/Common.h ../Include/intermediate.h
ParseHelper.o: ../Include/Types.h ../Include/BaseTypes.h ParseHelper.o: ../Include/Types.h ../Include/BaseTypes.h
ParseHelper.o: ../Include/ConstantUnion.h ../Include/InfoSink.h ParseHelper.o: ../Include/ConstantUnion.h ../Include/InfoSink.h
ParseHelper.o: localintermediate.h ../Include/intermediate.h ParseHelper.o: localintermediate.h ../Include/intermediate.h
ParseHelper.o: ../Public/ShaderLang.h ../Include/InitializeParseContext.h ParseHelper.o: ../Public/ShaderLang.h
ParseHelper.o: ../OSDependent/Linux/osinclude.h ParseHelper.o: ../OSDependent/Linux/osinclude.h
ParseHelper.o: ../Include/InitializeGlobals.h ../Include/PoolAlloc.h ParseHelper.o: ../Include/InitializeGlobals.h ../Include/PoolAlloc.h
QualifierAlive.o: ../Include/intermediate.h QualifierAlive.o: ../Include/intermediate.h
Scan.o: Scan.h
Scan.o: ParseHelper.h SymbolTable.h
Scan.o: glslang_tab.cpp.h
Scan.o: ../Include/Types.h
Scan.o: ScanContext.h preprocessor/PpContext.h preprocessor/PpTokens.h
RemoveTree.o: ../Include/intermediate.h RemoveTree.h RemoveTree.o: ../Include/intermediate.h RemoveTree.h
ShaderLang.o: SymbolTable.h ../Include/Common.h ../Include/intermediate.h ShaderLang.o: SymbolTable.h ../Include/Common.h ../Include/intermediate.h
ShaderLang.o: ../Include/Common.h ../Include/PoolAlloc.h ../Include/Types.h ShaderLang.o: ../Include/Common.h ../Include/PoolAlloc.h ../Include/Types.h
...@@ -161,4 +145,3 @@ parseConst.o: ../Public/ShaderLang.h ...@@ -161,4 +145,3 @@ parseConst.o: ../Public/ShaderLang.h
InfoSink.o: ../Include/InfoSink.h InfoSink.o: ../Include/InfoSink.h
Versions.o: ParseHelper.h Versions.h ../Include/ShHandle.h SymbolTable.h localintermediate.h Versions.o: ParseHelper.h Versions.h ../Include/ShHandle.h SymbolTable.h localintermediate.h
Constant.o: localintermediate.h ../Include/intermediate.h ../Public/ShaderLang.h SymbolTable.h Versions.h Constant.o: localintermediate.h ../Include/intermediate.h ../Public/ShaderLang.h SymbolTable.h Versions.h
Scan.o: Scan.h Versions.h
...@@ -55,6 +55,8 @@ struct TPragma { ...@@ -55,6 +55,8 @@ struct TPragma {
TPragmaTable pragmaTable; TPragmaTable pragmaTable;
}; };
class TPpContext;
namespace glslang { namespace glslang {
class TScanContext; class TScanContext;
}; };
...@@ -63,10 +65,13 @@ namespace glslang { ...@@ -63,10 +65,13 @@ namespace glslang {
// The following are extra variables needed during parsing, grouped together so // The following are extra variables needed during parsing, grouped together so
// they can be passed to the parser without needing a global. // they can be passed to the parser without needing a global.
// //
struct TParseContext { class TParseContext {
public:
TParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins, int version, EProfile, EShLanguage, TInfoSink&, TParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins, int version, EProfile, EShLanguage, TInfoSink&,
bool forwardCompatible = false, EShMessages messages = EShMsgDefault); bool forwardCompatible = false, EShMessages messages = EShMsgDefault);
glslang::TScanContext *scanContext;
glslang::TScanContext* scanContext;
TPpContext* ppContext;
TIntermediate& intermediate; // to hold and build a parse tree TIntermediate& intermediate; // to hold and build a parse tree
TSymbolTable& symbolTable; // symbol table that goes with the current language, version, and profile TSymbolTable& symbolTable; // symbol table that goes with the current language, version, and profile
TInfoSink& infoSink; TInfoSink& infoSink;
...@@ -92,8 +97,9 @@ struct TParseContext { ...@@ -92,8 +97,9 @@ struct TParseContext {
TPrecisionQualifier defaultPrecision[EbtNumTypes]; TPrecisionQualifier defaultPrecision[EbtNumTypes];
static const int maxSamplerIndex = EsdNumDims * (EbtNumTypes * (2 * 2)); // see computeSamplerTypeIndex() static const int maxSamplerIndex = EsdNumDims * (EbtNumTypes * (2 * 2)); // see computeSamplerTypeIndex()
TPrecisionQualifier defaultSamplerPrecision[maxSamplerIndex]; TPrecisionQualifier defaultSamplerPrecision[maxSamplerIndex];
TString HashErrMsg;
bool afterEOF; bool afterEOF;
bool tokensBeforeEOF;
TSourceLoc currentLoc;
const TString* blockName; const TString* blockName;
TQualifier globalUniformDefaults; TQualifier globalUniformDefaults;
TQualifier globalInputDefaults; TQualifier globalInputDefaults;
...@@ -102,7 +108,12 @@ struct TParseContext { ...@@ -102,7 +108,12 @@ struct TParseContext {
void initializeExtensionBehavior(); void initializeExtensionBehavior();
const char* getPreamble(); const char* getPreamble();
bool parseShaderStrings(char* strings[], int strLen[], int numStrings); bool parseShaderStrings(TPpContext&, char* strings[], int strLen[], int numStrings);
void parserError(const char *s);
void handlePragma(const char **tokens, int numTokens);
TBehavior getExtensionBehavior(const char* behavior);
void updateExtensionBehavior(const char* extName, const char* behavior);
void C_DECL error(TSourceLoc, const char *szReason, const char *szToken, void C_DECL error(TSourceLoc, const char *szReason, const char *szToken,
const char *szExtraInfoFormat, ...); const char *szExtraInfoFormat, ...);
...@@ -183,13 +194,4 @@ struct TParseContext { ...@@ -183,13 +194,4 @@ struct TParseContext {
void doubleCheck(TSourceLoc, const char* op); void doubleCheck(TSourceLoc, const char* op);
}; };
typedef TParseContext* TParseContextPointer;
TParseContextPointer& ThreadLocalParseContext();
// TODO: threading:
typedef struct TThreadParseContextRec
{
TParseContext *lpGlobalParseContext;
} TThreadParseContext;
#endif // _PARSER_HELPER_INCLUDED_ #endif // _PARSER_HELPER_INCLUDED_
...@@ -42,7 +42,7 @@ OS_TLSIndex PoolIndex; ...@@ -42,7 +42,7 @@ OS_TLSIndex PoolIndex;
void InitializeGlobalPools() void InitializeGlobalPools()
{ {
TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex)); TThreadGlobalPools* globalPools = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));
if (globalPools) if (globalPools)
return; return;
......
...@@ -48,10 +48,8 @@ ...@@ -48,10 +48,8 @@
#include "ScanContext.h" #include "ScanContext.h"
// preprocessor includes // preprocessor includes
extern "C" { #include "preprocessor/PpContext.h"
#include "preprocessor/parser.h" #include "preprocessor/PpTokens.h"
#include "preprocessor/preprocess.h"
}
namespace glslang { namespace glslang {
...@@ -236,12 +234,6 @@ bool ScanVersion(TInputScanner& input, int& version, EProfile& profile) ...@@ -236,12 +234,6 @@ bool ScanVersion(TInputScanner& input, int& version, EProfile& profile)
namespace glslang { namespace glslang {
// This gets filled in by the preprocessor scanner.
class TPpToken{
public:
yystypepp lexer;
};
// Fill this in when doing glslang-level scanning, to hand back to the parser. // Fill this in when doing glslang-level scanning, to hand back to the parser.
class TParserToken { class TParserToken {
public: public:
...@@ -257,7 +249,7 @@ int yylex(YYSTYPE* glslangTokenDesc, TParseContext& parseContext) ...@@ -257,7 +249,7 @@ int yylex(YYSTYPE* glslangTokenDesc, TParseContext& parseContext)
{ {
glslang::TParserToken token(*glslangTokenDesc); glslang::TParserToken token(*glslangTokenDesc);
return parseContext.scanContext->tokenize(token); return parseContext.scanContext->tokenize(parseContext.ppContext, token);
} }
namespace { namespace {
...@@ -487,17 +479,15 @@ void TScanContext::fillInKeywordMap() ...@@ -487,17 +479,15 @@ void TScanContext::fillInKeywordMap()
ReservedSet->insert("using"); ReservedSet->insert("using");
} }
int TScanContext::tokenize(TParserToken& token) int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
{ {
parserToken = &token; parserToken = &token;
TPpToken ppTokenStorage; TPpToken ppToken;
ppToken = &ppTokenStorage; tokenText = pp->tokenize(&ppToken);
tokenText = PpTokenize(&ppToken->lexer);
loc.string = cpp->tokenLoc->file; loc = ppToken.loc;
loc.line = cpp->tokenLoc->line;
parserToken->sType.lex.loc = loc; parserToken->sType.lex.loc = loc;
switch (ppToken->lexer.ppToken) { switch (ppToken.ppToken) {
case ';': afterType = false; return SEMICOLON; case ';': afterType = false; return SEMICOLON;
case ',': afterType = false; return COMMA; case ',': afterType = false; return COMMA;
case ':': return COLON; case ':': return COLON;
...@@ -545,10 +535,10 @@ int TScanContext::tokenize(TParserToken& token) ...@@ -545,10 +535,10 @@ int TScanContext::tokenize(TParserToken& token)
case CPP_OR_ASSIGN: return OR_ASSIGN; case CPP_OR_ASSIGN: return OR_ASSIGN;
case CPP_XOR_ASSIGN: return XOR_ASSIGN; case CPP_XOR_ASSIGN: return XOR_ASSIGN;
case CPP_INTCONSTANT: parserToken->sType.lex.i = ppToken->lexer.sc_int; return INTCONSTANT; case CPP_INTCONSTANT: parserToken->sType.lex.i = ppToken.ival; return INTCONSTANT;
case CPP_UINTCONSTANT: parserToken->sType.lex.i = ppToken->lexer.sc_int; return UINTCONSTANT; case CPP_UINTCONSTANT: parserToken->sType.lex.i = ppToken.ival; return UINTCONSTANT;
case CPP_FLOATCONSTANT: parserToken->sType.lex.d = ppToken->lexer.sc_dval; return FLOATCONSTANT; case CPP_FLOATCONSTANT: parserToken->sType.lex.d = ppToken.dval; return FLOATCONSTANT;
case CPP_DOUBLECONSTANT: parserToken->sType.lex.d = ppToken->lexer.sc_dval; return DOUBLECONSTANT; case CPP_DOUBLECONSTANT: parserToken->sType.lex.d = ppToken.dval; return DOUBLECONSTANT;
case CPP_IDENTIFIER: return tokenizeIdentifier(); case CPP_IDENTIFIER: return tokenizeIdentifier();
case EOF: return 0; case EOF: return 0;
...@@ -896,7 +886,7 @@ int TScanContext::identifierOrType() ...@@ -896,7 +886,7 @@ int TScanContext::identifierOrType()
int TScanContext::reservedWord() int TScanContext::reservedWord()
{ {
ThreadLocalParseContext()->error(loc, "Reserved word.", tokenText, "", ""); parseContext.error(loc, "Reserved word.", tokenText, "", "");
return 0; return 0;
} }
......
...@@ -40,10 +40,12 @@ ...@@ -40,10 +40,12 @@
#include "ParseHelper.h" #include "ParseHelper.h"
class TPpContext;
class TPpToken;
namespace glslang { namespace glslang {
class TParserToken; class TParserToken;
class TPpToken;
class TScanContext { class TScanContext {
public: public:
...@@ -51,7 +53,7 @@ public: ...@@ -51,7 +53,7 @@ public:
virtual ~TScanContext() { } virtual ~TScanContext() { }
static void fillInKeywordMap(); static void fillInKeywordMap();
int tokenize(TParserToken&); int tokenize(TPpContext*, TParserToken&);
protected: protected:
int tokenizeIdentifier(); int tokenizeIdentifier();
......
...@@ -49,9 +49,7 @@ ...@@ -49,9 +49,7 @@
#include "../Include/ShHandle.h" #include "../Include/ShHandle.h"
#include "InitializeDll.h" #include "InitializeDll.h"
extern "C" { #include "preprocessor/PpContext.h"
#include "preprocessor/preprocess.h"
}
#define SH_EXPORTING #define SH_EXPORTING
#include "../Public/ShaderLang.h" #include "../Public/ShaderLang.h"
...@@ -87,7 +85,6 @@ const int VersionCount = 12; ...@@ -87,7 +85,6 @@ const int VersionCount = 12;
// Each has a different set of built-ins, and we want to preserve that from // Each has a different set of built-ins, and we want to preserve that from
// compile to compile. // compile to compile.
// //
// TODO: quality: thread safety: ensure the built-in symbol table levels are read only.
TSymbolTable* SharedSymbolTables[VersionCount][EProfileCount][EShLangCount] = {}; TSymbolTable* SharedSymbolTables[VersionCount][EProfileCount][EShLangCount] = {};
TPoolAllocator* PerProcessGPA = 0; TPoolAllocator* PerProcessGPA = 0;
...@@ -104,9 +101,10 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil ...@@ -104,9 +101,10 @@ 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; TPpContext ppContext(parseContext);
glslang::TScanContext scanContext(parseContext); glslang::TScanContext scanContext(parseContext);
parseContext.scanContext = &scanContext; parseContext.scanContext = &scanContext;
parseContext.ppContext = &ppContext;
assert(symbolTable->isEmpty() || symbolTable->atSharedBuiltInLevel()); assert(symbolTable->isEmpty() || symbolTable->atSharedBuiltInLevel());
...@@ -121,14 +119,6 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil ...@@ -121,14 +119,6 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil
symbolTable->push(); symbolTable->push();
//Initialize the Preprocessor
int ret = InitPreprocessor();
if (ret) {
infoSink.info.message(EPrefixInternalError, "Unable to intialize the Preprocessor");
return false;
}
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];
...@@ -136,14 +126,13 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil ...@@ -136,14 +126,13 @@ 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 (! parseContext.parseShaderStrings(const_cast<char**>(builtInShaders), builtInLengths, 1) != 0) { if (! parseContext.parseShaderStrings(ppContext, 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");
return false; return false;
} }
} }
FinalizePreprocessor();
if (resources) { if (resources) {
IdentifyBuiltIns(version, profile, parseContext.language, *symbolTable, *resources); IdentifyBuiltIns(version, profile, parseContext.language, *symbolTable, *resources);
...@@ -418,7 +407,9 @@ int ShCompile( ...@@ -418,7 +407,9 @@ int ShCompile(
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); glslang::TScanContext scanContext(parseContext);
TPpContext ppContext(parseContext);
parseContext.scanContext = &scanContext; parseContext.scanContext = &scanContext;
parseContext.ppContext = &ppContext;
TSourceLoc beginning; TSourceLoc beginning;
beginning.line = 1; beginning.line = 1;
...@@ -433,10 +424,6 @@ int ShCompile( ...@@ -433,10 +424,6 @@ int ShCompile(
else if (profile == EEsProfile && version >= 300 && versionNotFirst) else if (profile == EEsProfile && version >= 300 && versionNotFirst)
parseContext.error(beginning, "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;
InitPreprocessor();
// //
// Parse the application's shaders. All the following symbol table // Parse the application's shaders. All the following symbol table
// work will be throw-away, so push a new allocation scope that can // work will be throw-away, so push a new allocation scope that can
...@@ -451,7 +438,7 @@ int ShCompile( ...@@ -451,7 +438,7 @@ int ShCompile(
if (parseContext.insertBuiltInArrayAtGlobalLevel()) if (parseContext.insertBuiltInArrayAtGlobalLevel())
success = false; success = false;
bool ret = parseContext.parseShaderStrings(const_cast<char**>(shaderStrings), lengths, numStrings); bool ret = parseContext.parseShaderStrings(ppContext, 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);
...@@ -490,7 +477,6 @@ int ShCompile( ...@@ -490,7 +477,6 @@ int ShCompile(
while (! symbolTable.atSharedBuiltInLevel()) while (! symbolTable.atSharedBuiltInLevel())
symbolTable.pop(0); symbolTable.pop(0);
FinalizePreprocessor();
// //
// Throw away all the temporary memory used by the compilation process. // Throw away all the temporary memory used by the compilation process.
// //
......
...@@ -59,20 +59,6 @@ Jutta Degener, 1995 ...@@ -59,20 +59,6 @@ Jutta Degener, 1995
#include "ParseHelper.h" #include "ParseHelper.h"
#include "../Public/ShaderLang.h" #include "../Public/ShaderLang.h"
#ifdef _WIN32
#define YYPARSE_PARAM parseContext
#define YYPARSE_PARAM_DECL TParseContext&
#define YY_DECL int yylex(YYSTYPE* pyylval, TParseContext& parseContext)
#define YYLEX_PARAM parseContext
#else
#define YYPARSE_PARAM parseContextLocal
#define parseContext (*((TParseContext*)(parseContextLocal)))
#define YY_DECL int yylex(YYSTYPE* pyylval, void* parseContextLocal)
#define YYLEX_PARAM (void*)(parseContextLocal)
#endif
extern void yyerror(const char*);
%} %}
%union { %union {
...@@ -109,13 +95,18 @@ extern void yyerror(const char*); ...@@ -109,13 +95,18 @@ extern void yyerror(const char*);
} }
%{ %{
#ifndef _WIN32
extern int yylex(YYSTYPE*, void*); #define YYPARSE_PARAM voidParseContext
#endif #define parseContext (*(TParseContext*)voidParseContext)
#define YYLEX_PARAM parseContext
#define yyerror(msg) parseContext.parserError(msg)
extern int yylex(YYSTYPE*, TParseContext&);
%} %}
%pure_parser /* Just in case is called from multiple threads */ %pure_parser // enable thread safety
%expect 1 /* One shift reduce conflict because of if | else */ %expect 1 // One shift reduce conflict because of if | else
%token <lex> ATTRIBUTE VARYING %token <lex> ATTRIBUTE VARYING
%token <lex> CONST BOOL FLOAT DOUBLE INT UINT %token <lex> CONST BOOL FLOAT DOUBLE INT UINT
......
...@@ -3,9 +3,10 @@ CC = gcc ...@@ -3,9 +3,10 @@ CC = gcc
CPPFLAGS=$(DEFINE) $(INCLUDE) -fPIC CPPFLAGS=$(DEFINE) $(INCLUDE) -fPIC
OBJECTS = atom.o cpp.o cppstruct.o memory.o scanner.o symbols.o tokens.o OBJECTS = PpAtom.o PpScanner.o PpTokens.o Pp.o PpContext.o PpMemory.o PpSymbols.o
AR=ar AR=ar
SRCS=scanner.c atom.c memory.c tokens. cpp.c cppstruct.c symbols.c SRCS = PpAtom.cpp PpScanner.cpp PpTokens.cpp Pp.cpp PpContext.cpp PpMemory.cpp PpSymbols.cpp
default: all default: all
all : libPreprocessor.a all : libPreprocessor.a
...@@ -28,14 +29,10 @@ depend: ...@@ -28,14 +29,10 @@ depend:
# DO NOT DELETE # DO NOT DELETE
scanner.o: slglobals.h memory.h atom.h scanner.h parser.h cpp.h tokens.h PpAtom.o: PpContext.h PpToken.h
scanner.o: symbols.h compile.h PpScanner.o: PpContext.h PpToken.h
atom.o: slglobals.h memory.h atom.h scanner.h parser.h cpp.h tokens.h PpTokens.o: PpContext.h PpToken.h
atom.o: symbols.h compile.h Pp.o: PpContext.h PpToken.h
memory.o: memory.h PpContext.o: PpContext.h PpToken.h
cpp.o: slglobals.h memory.h atom.h scanner.h parser.h cpp.h tokens.h PpMemory.o: PpContext.h PpToken.h
cpp.o: symbols.h compile.h PpSymbols.o: PpContext.h PpToken.h
cppstruct.o: slglobals.h memory.h atom.h scanner.h parser.h cpp.h tokens.h
cppstruct.o: symbols.h compile.h
symbols.o: slglobals.h memory.h atom.h scanner.h parser.h cpp.h tokens.h
symbols.o: symbols.h compile.h
// //
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd. //Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
//Copyright (C) 2013 LunarG, Inc.
//All rights reserved. //All rights reserved.
// //
//Redistribution and use in source and binary forms, with or without //Redistribution and use in source and binary forms, with or without
...@@ -74,23 +75,52 @@ NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, ...@@ -74,23 +75,52 @@ NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF 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.
\****************************************************************************/ \****************************************************************************/
//
// atom.h
//
#if !defined(__ATOM_H) #include <stdio.h>
#define __ATOM_H 1 #include <stdlib.h>
#include "PpContext.h"
TPpContext::TPpContext(TParseContext& pc) :
parseContext(pc), preamble(0), strings(0), notAVersionToken(false),
ScopeList(0), CurrentScope(0), GlobalScope(0)
{
InitAtomTable(&atomTable, 0);
InitScanner(this);
ifdepth = 0;
for (elsetracker = 0; elsetracker < maxIfNesting; elsetracker++)
elsedepth[elsetracker] = 0;
elsetracker = 0;
}
typedef struct AtomTable_Rec AtomTable; TPpContext::~TPpContext()
{
delete [] preamble;
FreeAtomTable(&atomTable);
FreeScanner();
}
extern AtomTable *atable; void TPpContext::setPreamble(const char* p, int l)
{
if (p && l > 0) {
// preAmble could be a hard-coded string; make writable copy
// TODO: efficiency PP: make it not need writable strings
preambleLength = l;
preamble = new char[preambleLength + 1];
memcpy(preamble, p, preambleLength + 1); // TODO: PP: assuming nul-terminated strings
ScanFromString(preamble);
currentString = -1;
}
}
int InitAtomTable(AtomTable *atable, int htsize); void TPpContext::setShaderStrings(char* s[], int l[], int n)
void FreeAtomTable(AtomTable *atable); {
int AddAtom(AtomTable *atable, const char *s); strings = s;
void PrintAtomTable(AtomTable *atable); lengths = l;
int LookUpAddString(AtomTable *atable, const char *s); numStrings = n;
const char *GetAtomString(AtomTable *atable, int atom); if (! preamble) {
int GetReversedAtom(AtomTable *atable, int atom); ScanFromString(strings[0]);
char* GetStringOfAtom(AtomTable *atable, int atom); currentString = 0;
#endif // !defined(__ATOM_H) }
}
// //
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd. //Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
//Copyright (C) 2013 LunarG, Inc.
//All rights reserved. //All rights reserved.
// //
//Redistribution and use in source and binary forms, with or without //Redistribution and use in source and binary forms, with or without
...@@ -80,7 +81,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -80,7 +81,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include "memory.h" #include "PpContext.h"
// default alignment and chunksize, if called with 0 arguments // default alignment and chunksize, if called with 0 arguments
#define CHUNKSIZE (64*1024) #define CHUNKSIZE (64*1024)
...@@ -96,28 +97,28 @@ struct chunk { ...@@ -96,28 +97,28 @@ struct chunk {
struct cleanup { struct cleanup {
struct cleanup *next; struct cleanup *next;
void (*fn)(void *); void (*fn)(void *, void *);
void *arg; void *arg1;
void *arg2;
}; };
struct MemoryPool_rec { TPpContext::MemoryPool* TPpContext::mem_CreatePool(size_t chunksize, unsigned int align)
struct chunk *next;
uintptr_t free, end;
size_t chunksize;
uintptr_t alignmask;
struct cleanup *cleanup;
};
MemoryPool *mem_CreatePool(size_t chunksize, unsigned int align)
{ {
MemoryPool *pool; MemoryPool *pool;
if (align == 0) align = ALIGN; if (align == 0)
if (chunksize == 0) chunksize = CHUNKSIZE; align = ALIGN;
if (align & (align-1)) return 0; if (chunksize == 0)
if (chunksize < sizeof(MemoryPool)) return 0; chunksize = CHUNKSIZE;
if (chunksize & (align-1)) return 0; if (align & (align-1))
if (!(pool = (MemoryPool*)malloc(chunksize))) return 0; return 0;
if (chunksize < sizeof(MemoryPool))
return 0;
if (chunksize & (align-1))
return 0;
if (!(pool = (MemoryPool*)malloc(chunksize)))
return 0;
pool->next = 0; pool->next = 0;
pool->chunksize = chunksize; pool->chunksize = chunksize;
pool->alignmask = (uintptr_t)(align)-1; pool->alignmask = (uintptr_t)(align)-1;
...@@ -127,13 +128,13 @@ MemoryPool *mem_CreatePool(size_t chunksize, unsigned int align) ...@@ -127,13 +128,13 @@ MemoryPool *mem_CreatePool(size_t chunksize, unsigned int align)
return pool; return pool;
} }
void mem_FreePool(MemoryPool *pool) void TPpContext::mem_FreePool(MemoryPool *pool)
{ {
struct cleanup *cleanup; struct cleanup *cleanup;
struct chunk *p, *next; struct chunk *p, *next;
for (cleanup = pool->cleanup; cleanup; cleanup = cleanup->next) { for (cleanup = pool->cleanup; cleanup; cleanup = cleanup->next) {
cleanup->fn(cleanup->arg); cleanup->fn(cleanup->arg1, cleanup->arg2);
} }
for (p = (struct chunk *)pool; p; p = next) { for (p = (struct chunk *)pool; p; p = next) {
next = p->next; next = p->next;
...@@ -141,7 +142,7 @@ void mem_FreePool(MemoryPool *pool) ...@@ -141,7 +142,7 @@ void mem_FreePool(MemoryPool *pool)
} }
} }
void *mem_Alloc(MemoryPool *pool, size_t size) void* TPpContext::mem_Alloc(MemoryPool *pool, size_t size)
{ {
struct chunk *ch; struct chunk *ch;
void *rv = (void *)pool->free; void *rv = (void *)pool->free;
...@@ -149,8 +150,7 @@ void *mem_Alloc(MemoryPool *pool, size_t size) ...@@ -149,8 +150,7 @@ void *mem_Alloc(MemoryPool *pool, size_t size)
if (size <= 0) size = pool->alignmask; if (size <= 0) size = pool->alignmask;
pool->free += size; pool->free += size;
if (pool->free > pool->end || pool->free < (uintptr_t)rv) { if (pool->free > pool->end || pool->free < (uintptr_t)rv) {
size_t minreq = (size + sizeof(struct chunk) + pool->alignmask) size_t minreq = (size + sizeof(struct chunk) + pool->alignmask) & ~pool->alignmask;
& ~pool->alignmask;
pool->free = (uintptr_t)rv; pool->free = (uintptr_t)rv;
if (minreq >= pool->chunksize) { if (minreq >= pool->chunksize) {
// request size is too big for the chunksize, so allocate it as // request size is too big for the chunksize, so allocate it as
...@@ -170,7 +170,8 @@ void *mem_Alloc(MemoryPool *pool, size_t size) ...@@ -170,7 +170,8 @@ void *mem_Alloc(MemoryPool *pool, size_t size)
return rv; return rv;
} }
int mem_AddCleanup(MemoryPool *pool, void (*fn)(void *), void *arg) { int TPpContext::mem_AddCleanup(MemoryPool *pool, void (*fn)(void *, void*), void* arg1, void* arg2)
{
struct cleanup *cleanup; struct cleanup *cleanup;
pool->free = (pool->free + sizeof(void *) - 1) & ~(sizeof(void *)-1); pool->free = (pool->free + sizeof(void *) - 1) & ~(sizeof(void *)-1);
...@@ -178,7 +179,8 @@ int mem_AddCleanup(MemoryPool *pool, void (*fn)(void *), void *arg) { ...@@ -178,7 +179,8 @@ int mem_AddCleanup(MemoryPool *pool, void (*fn)(void *), void *arg) {
if (!cleanup) return -1; if (!cleanup) return -1;
cleanup->next = pool->cleanup; cleanup->next = pool->cleanup;
cleanup->fn = fn; cleanup->fn = fn;
cleanup->arg = arg; cleanup->arg1 = arg1;
cleanup->arg2 = arg2;
pool->cleanup = cleanup; pool->cleanup = cleanup;
return 0; return 0;
} }
// //
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd. //Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
//Copyright (C) 2013 LunarG, Inc.
//All rights reserved. //All rights reserved.
// //
//Redistribution and use in source and binary forms, with or without //Redistribution and use in source and binary forms, with or without
...@@ -83,32 +84,29 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -83,32 +84,29 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "slglobals.h" #include "PpContext.h"
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// Symbol Table Variables: /////////////////////////////////// /////////////////////////////////// Symbol Table Variables: ///////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
Scope *ScopeList = NULL; static void unlinkScope(void *_scope, void* scopeList)
Scope *CurrentScope = NULL; {
Scope *GlobalScope = NULL; TPpContext::Scope *scope = (TPpContext::Scope*)_scope;
static void unlinkScope(void *_scope) {
Scope *scope = (Scope*)_scope;
if (scope->next) if (scope->next)
scope->next->prev = scope->prev; scope->next->prev = scope->prev;
if (scope->prev) if (scope->prev)
scope->prev->next = scope->next; scope->prev->next = scope->next;
else else
ScopeList = scope->next; *(TPpContext::Scope**)scopeList = scope->next;
} }
/* /*
* NewScope() * NewScope()
* *
*/ */
Scope *NewScopeInPool(MemoryPool *pool) TPpContext::Scope* TPpContext::NewScopeInPool(MemoryPool *pool)
{ {
Scope *lScope; Scope *lScope;
...@@ -117,7 +115,7 @@ Scope *NewScopeInPool(MemoryPool *pool) ...@@ -117,7 +115,7 @@ Scope *NewScopeInPool(MemoryPool *pool)
lScope->parent = NULL; lScope->parent = NULL;
lScope->funScope = NULL; lScope->funScope = NULL;
lScope->symbols = NULL; lScope->symbols = NULL;
lScope->level = 0; lScope->level = 0;
lScope->programs = NULL; lScope->programs = NULL;
...@@ -125,16 +123,17 @@ Scope *NewScopeInPool(MemoryPool *pool) ...@@ -125,16 +123,17 @@ Scope *NewScopeInPool(MemoryPool *pool)
ScopeList->prev = lScope; ScopeList->prev = lScope;
lScope->prev = 0; lScope->prev = 0;
ScopeList = lScope; ScopeList = lScope;
mem_AddCleanup(pool, unlinkScope, lScope); mem_AddCleanup(pool, unlinkScope, lScope, &ScopeList);
return lScope; return lScope;
} // NewScope } // NewScope
/* /*
* PushScope() * PushScope()
* *
*/ */
void PushScope(Scope *fScope) void TPpContext::PushScope(Scope *fScope)
{ {
Scope *lScope; Scope *lScope;
...@@ -143,9 +142,9 @@ void PushScope(Scope *fScope) ...@@ -143,9 +142,9 @@ void PushScope(Scope *fScope)
if (fScope->level == 1) { if (fScope->level == 1) {
if (!GlobalScope) { if (!GlobalScope) {
/* HACK - CTD -- if GlobalScope==NULL and level==1, we're /* HACK - CTD -- if GlobalScope==NULL and level==1, we're
* defining a function in the superglobal scope. Things * defining a function in the superglobal scope. Things
* will break if we leave the level as 1, so we arbitrarily * will break if we leave the level as 1, so we arbitrarily
* set it to 2 */ * set it to 2 */
fScope->level = 2; fScope->level = 2;
} }
} }
...@@ -163,11 +162,11 @@ void PushScope(Scope *fScope) ...@@ -163,11 +162,11 @@ void PushScope(Scope *fScope)
} // PushScope } // PushScope
/* /*
* PopScope() * PopScope()
* *
*/ */
Scope *PopScope(void) TPpContext::Scope* TPpContext::PopScope(void)
{ {
Scope *lScope; Scope *lScope;
...@@ -178,11 +177,11 @@ Scope *PopScope(void) ...@@ -178,11 +177,11 @@ Scope *PopScope(void)
} // PopScope } // PopScope
/* /*
* NewSymbol() - Allocate a new symbol node; * NewSymbol() - Allocate a new symbol node;
* *
*/ */
Symbol *NewSymbol(SourceLoc *loc, Scope *fScope, int name, symbolkind kind) TPpContext::Symbol* TPpContext::NewSymbol(TSourceLoc *loc, Scope *fScope, int name, symbolkind kind)
{ {
Symbol *lSymb; Symbol *lSymb;
char *pch; char *pch;
...@@ -195,7 +194,7 @@ Symbol *NewSymbol(SourceLoc *loc, Scope *fScope, int name, symbolkind kind) ...@@ -195,7 +194,7 @@ Symbol *NewSymbol(SourceLoc *loc, Scope *fScope, int name, symbolkind kind)
lSymb->name = name; lSymb->name = name;
lSymb->loc = *loc; lSymb->loc = *loc;
lSymb->kind = kind; lSymb->kind = kind;
// Clear union area: // Clear union area:
pch = (char *) &lSymb->details; pch = (char *) &lSymb->details;
...@@ -205,13 +204,13 @@ Symbol *NewSymbol(SourceLoc *loc, Scope *fScope, int name, symbolkind kind) ...@@ -205,13 +204,13 @@ Symbol *NewSymbol(SourceLoc *loc, Scope *fScope, int name, symbolkind kind)
} // NewSymbol } // NewSymbol
/* /*
* lAddToTree() - Using a binary tree is not a good idea for basic atom values because they * lAddToTree() - Using a binary tree is not a good idea for basic atom values because they
* are generated in order. We'll fix this later (by reversing the bit pattern). * are generated in order. We'll fix this later (by reversing the bit pattern).
*/ */
static void lAddToTree(Symbol **fSymbols, Symbol *fSymb) void TPpContext::lAddToTree(Symbol **fSymbols, Symbol *fSymb, AtomTable *atable)
{ {
Symbol *lSymb; TPpContext::Symbol *lSymb;
int lrev, frev; int lrev, frev;
lSymb = *fSymbols; lSymb = *fSymbols;
...@@ -220,7 +219,7 @@ static void lAddToTree(Symbol **fSymbols, Symbol *fSymb) ...@@ -220,7 +219,7 @@ static void lAddToTree(Symbol **fSymbols, Symbol *fSymb)
while (lSymb) { while (lSymb) {
lrev = GetReversedAtom(atable, lSymb->name); lrev = GetReversedAtom(atable, lSymb->name);
if (lrev == frev) { if (lrev == frev) {
ShPpErrorToInfoLog("GetAtomString(atable, fSymb->name)"); printf("GetAtomString(atable, fSymb->name)");
break; break;
} else { } else {
if (lrev > frev) { if (lrev > frev) {
...@@ -247,18 +246,18 @@ static void lAddToTree(Symbol **fSymbols, Symbol *fSymb) ...@@ -247,18 +246,18 @@ static void lAddToTree(Symbol **fSymbols, Symbol *fSymb)
/* /*
* AddSymbol() - Add a variable, type, or function name to a scope. * AddSymbol() - Add a variable, type, or function name to a scope.
* *
*/ */
Symbol *AddSymbol(SourceLoc *loc, Scope *fScope, int atom, symbolkind kind) TPpContext::Symbol* TPpContext::AddSymbol(TSourceLoc *loc, Scope *fScope, int atom, symbolkind kind)
{ {
Symbol *lSymb; Symbol *lSymb;
if (!fScope) if (!fScope)
fScope = CurrentScope; fScope = CurrentScope;
lSymb = NewSymbol(loc, fScope, atom, kind); lSymb = NewSymbol(loc, fScope, atom, kind);
lAddToTree(&fScope->symbols, lSymb); lAddToTree(&fScope->symbols, lSymb, &atomTable);
return lSymb; return lSymb;
} // AddSymbol } // AddSymbol
...@@ -268,21 +267,21 @@ Symbol *AddSymbol(SourceLoc *loc, Scope *fScope, int atom, symbolkind kind) ...@@ -268,21 +267,21 @@ Symbol *AddSymbol(SourceLoc *loc, Scope *fScope, int atom, symbolkind kind)
/*********************************************************************************************/ /*********************************************************************************************/
/* /*
* LookUpLocalSymbol() * LookUpLocalSymbol()
* *
*/ */
Symbol *LookUpLocalSymbol(Scope *fScope, int atom) TPpContext::Symbol* TPpContext::LookUpLocalSymbol(Scope *fScope, int atom)
{ {
Symbol *lSymb; Symbol *lSymb;
int rname, ratom; int rname, ratom;
ratom = GetReversedAtom(atable, atom); ratom = GetReversedAtom(&atomTable, atom);
if (!fScope) if (!fScope)
fScope = CurrentScope; fScope = CurrentScope;
lSymb = fScope->symbols; lSymb = fScope->symbols;
while (lSymb) { while (lSymb) {
rname = GetReversedAtom(atable, lSymb->name); rname = GetReversedAtom(&atomTable, lSymb->name);
if (rname == ratom) { if (rname == ratom) {
return lSymb; return lSymb;
} else { } else {
...@@ -297,11 +296,11 @@ Symbol *LookUpLocalSymbol(Scope *fScope, int atom) ...@@ -297,11 +296,11 @@ Symbol *LookUpLocalSymbol(Scope *fScope, int atom)
} // LookUpLocalSymbol } // LookUpLocalSymbol
/* /*
* LookUpSymbol() * LookUpSymbol()
* *
*/ */
Symbol *LookUpSymbol(Scope *fScope, int atom) TPpContext::Symbol* TPpContext::LookUpSymbol(Scope *fScope, int atom)
{ {
Symbol *lSymb; Symbol *lSymb;
......
...@@ -74,16 +74,44 @@ NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, ...@@ -74,16 +74,44 @@ NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF 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 __MEMORY_H
#define __MEMORY_H
typedef struct MemoryPool_rec MemoryPool; #ifndef PARSER_H
#define PARSER_H
#define CPP_AND_OP 257
#define CPP_SUB_ASSIGN 259
#define CPP_MOD_ASSIGN 260
#define CPP_ADD_ASSIGN 261
#define CPP_DIV_ASSIGN 262
#define CPP_MUL_ASSIGN 263
#define CPP_EQ_OP 264
#define CPP_XOR_OP 265
#define CPP_ERROR_SY 266
#define CPP_FLOATCONSTANT 267
#define CPP_GE_OP 268
#define CPP_RIGHT_OP 269
#define CPP_IDENTIFIER 270
#define CPP_INTCONSTANT 271
#define CPP_LE_OP 272
#define CPP_LEFT_OP 273
#define CPP_DEC_OP 274
#define CPP_NE_OP 275
#define CPP_OR_OP 276
#define CPP_INC_OP 277
#define CPP_STRCONSTANT 278
#define CPP_TYPEIDENTIFIER 279
#define CPP_RIGHT_ASSIGN 280
#define CPP_LEFT_ASSIGN 281
#define CPP_AND_ASSIGN 282
#define CPP_OR_ASSIGN 283
#define CPP_XOR_ASSIGN 284
#define CPP_LEFT_BRACKET 285
#define CPP_RIGHT_BRACKET 286
#define CPP_LEFT_BRACE 287
#define CPP_RIGHT_BRACE 288
#define CPP_UINTCONSTANT 289
#define CPP_DOUBLECONSTANT 290
extern MemoryPool *mem_CreatePool(size_t chunksize, unsigned align); #define CPP_FIRST_USER_TOKEN_SY 291
extern void mem_FreePool(MemoryPool *);
extern void *mem_Alloc(MemoryPool *p, size_t size);
extern void *mem_Realloc(MemoryPool *p, void *old, size_t oldsize, size_t newsize);
extern int mem_AddCleanup(MemoryPool *p, void (*fn)(void *), void *arg);
#endif /* __MEMORY_H */ #endif /* not PARSER_H */
//
//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.
\****************************************************************************/
//
// cpp.h
//
#if !defined(__CPP_H)
#define __CPP_H 1
#include "parser.h"
#include "tokens.h"
#include "Versions.h"
typedef struct MacroSymbol {
int argc;
int *args;
TokenStream *body;
unsigned busy:1;
unsigned undef:1;
} MacroSymbol;
int InitCPP(void);
int FinalCPP(void);
int readCPPline(yystypepp * yylvalpp);
int MacroExpand(int atom, yystypepp * yylvalpp, int expandUndef);
#ifdef __cplusplus
extern "C" {
#endif
void ShPpDebugLogMsg(const char *msg); // Prints information into debug log
void ShPpErrorToInfoLog(const char*); // Store cpp Err Msg into Sh.Info.Log
void ShPpWarningToInfoLog(const char *msg); // Prints warning messages into info log
int ShPpMacrosMustBeDefinedError();
void HandlePragma(const char**, int numTokens); // #pragma directive container.
void ResetTString(void); // #error Message as TString.
void StoreStr(const char*); // Store the TString in Parse Context.
void SetLineNumber(int); // Set line number.
void SetStringNumber(int); // Set string number.
int GetLineNumber(void); // Get the current String Number.
int GetStringNumber(void); // Get the current String Number.
const char* GetStrfromTStr(void); // Convert TString to String.
void SetVersion(int);
int GetShaderVersion(void*);
void updateExtensionBehavior(const char* extName, const char* behavior);
int FreeCPP(void);
#ifdef __cplusplus
}
#endif
#endif // !(defined(__CPP_H)
//
//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.
\****************************************************************************/
//
// cppstruct.c
//
#include <stdio.h>
#include <stdlib.h>
#include "slglobals.h"
CPPStruct *cpp = NULL;
static int refCount = 0;
int ResetPreprocessor(void);
int FreeCPPStruct(void);
/*
* InitCPPStruct() - Initilaize the CPP structure.
*
*/
int InitCPPStruct(void)
{
int len;
char *p;
cpp = (CPPStruct *) malloc(sizeof(CPPStruct));
if (cpp == NULL)
return 0;
refCount++;
// Initialize public members:
cpp->pLastSourceLoc = &cpp->lastSourceLoc;
p = (char *) &cpp->options;
len = sizeof(cpp->options);
while (--len >= 0)
p[len] = 0;
ResetPreprocessor();
return 1;
} // InitCPPStruct
int ResetPreprocessor(void)
{
// Initialize private members:
cpp->lastSourceLoc.file = 0;
cpp->lastSourceLoc.line = 0;
cpp->pC=0;
cpp->CompileError=0;
cpp->ifdepth=0;
for(cpp->elsetracker=0; cpp->elsetracker<64; cpp->elsetracker++)
cpp->elsedepth[cpp->elsetracker]=0;
cpp->elsetracker=0;
cpp->tokensBeforeEOF = 0;
return 1;
}
//Intializing the Preprocessor.
int InitPreprocessor(void)
{
# define CPP_STUFF true
# ifdef CPP_STUFF
FreeCPPStruct();
InitCPPStruct();
cpp->options.Quiet = 1;
cpp->options.profileString = "generic";
if (!InitAtomTable(atable, 0))
return 1;
if (!InitScanner(cpp))
return 1;
# endif
return 0;
}
//FreeCPPStruct() - Free the CPP structure.
int FreeCPPStruct(void)
{
if (refCount)
{
free(cpp);
refCount--;
}
return 1;
}
//Finalizing the Preprocessor.
int FinalizePreprocessor(void)
{
# define CPP_STUFF true
# ifdef CPP_STUFF
FreeAtomTable(atable);
FreeCPPStruct();
FreeScanner();
# endif
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// End of cppstruct.c //////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
//
//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.
\****************************************************************************/
#ifndef PARSER_H
# define PARSER_H
# define CPP_AND_OP 257
# define CPP_SUB_ASSIGN 259
# define CPP_MOD_ASSIGN 260
# define CPP_ADD_ASSIGN 261
# define CPP_DIV_ASSIGN 262
# define CPP_MUL_ASSIGN 263
# define CPP_EQ_OP 264
# define CPP_XOR_OP 265
# define CPP_ERROR_SY 266
# define CPP_FLOATCONSTANT 267
# define CPP_GE_OP 268
# define CPP_RIGHT_OP 269
# define CPP_IDENTIFIER 270
# define CPP_INTCONSTANT 271
# define CPP_LE_OP 272
# define CPP_LEFT_OP 273
# define CPP_DEC_OP 274
# define CPP_NE_OP 275
# define CPP_OR_OP 276
# define CPP_INC_OP 277
# define CPP_STRCONSTANT 278
# define CPP_TYPEIDENTIFIER 279
# define CPP_RIGHT_ASSIGN 280
# define CPP_LEFT_ASSIGN 281
# define CPP_AND_ASSIGN 282
# define CPP_OR_ASSIGN 283
# define CPP_XOR_ASSIGN 284
# define CPP_LEFT_BRACKET 285
# define CPP_RIGHT_BRACKET 286
# define CPP_LEFT_BRACE 287
# define CPP_RIGHT_BRACE 288
# define CPP_UINTCONSTANT 289
# define CPP_DOUBLECONSTANT 290
# define CPP_FIRST_USER_TOKEN_SY 291
#endif /* not PARSER_H */
//
//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.
\****************************************************************************/
#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;
int InitPreprocessor(void);
int FinalizePreprocessor(void);
int ScanFromString(char *s);
const char* PpTokenize(yystypepp*);
#endif
//
//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.
\****************************************************************************/
//
// scanner.h
//
#if !defined(__SCANNER_H)
#define __SCANNER_H 1
#include "preprocess.h"
#include "parser.h"
// Not really atom table stuff but needed first...
#ifdef __cplusplus
extern "C" {
#endif
int yyparse (void);
int InitScanner(CPPStruct *cpp); // Intialise the cpp scanner.
int ScanFromString(char *); // Start scanning the input from the string mentioned.
int check_EOF(int); // check if we hit a EOF abruptly
void ShPpErrorToInfoLog(const char *); // sticking the msg,line into the Shader's.Info.log
void SetLineNumber(int);
void SetStringNumber(int);
void IncLineNumber(void);
void DecLineNumber(void);
int FreeScanner(void); // Free the cpp scanner
#ifdef __cplusplus
}
#endif
#endif // !(defined(__SCANNER_H)
//
//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.
\****************************************************************************/
//
// slglobals.h
//
#if !defined(__SLGLOBALS_H)
#define __SLGLOBALS_H 1
#include "preprocess.h"
// TODO: threading: Multi-threading note: The existence of this global makes
// this preprocessing single-threaded only.
extern CPPStruct *cpp;
#undef CPPC_DEBUG_THE_COMPILER
#if defined(_DEBUG)
#define CPPC_DEBUG_THE_COMPILER 1
#endif
#undef CPPC_ENABLE_TOOLS
#define CPPC_ENABLE_TOOLS 1
#include "memory.h"
#include "atom.h"
#include "scanner.h"
#include "cpp.h"
#include "tokens.h"
#include "symbols.h"
#if !defined(NO_PARSER)
#include "parser.h"
#endif
#if !defined(NULL)
#define NULL 0
#endif
#endif // !(defined(__SLGLOBALS_H)
//
//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.
\****************************************************************************/
//
// symbols.h
//
#if !defined(__SYMBOLS_H)
#define __SYMBOLS_H 1
#include "memory.h"
typedef enum symbolkind {
MACRO_S
} symbolkind;
// Typedefs for things defined here in "symbols.h":
typedef struct Scope_Rec Scope;
typedef struct Symbol_Rec Symbol;
typedef struct SymbolList_Rec {
struct SymbolList_Rec *next;
Symbol *symb;
} SymbolList;
struct Scope_Rec {
Scope *next, *prev; // doubly-linked list of all scopes
Scope *parent;
Scope *funScope; // Points to base scope of enclosing function
MemoryPool *pool; // pool used for allocation in this scope
Symbol *symbols;
int level; // 0 = super globals, 1 = globals, etc.
// Only used at global scope (level 1):
SymbolList *programs; // List of programs for this compilation.
};
// Symbol table is a simple binary tree.
#include "cpp.h" // to get MacroSymbol def
struct Symbol_Rec {
Symbol *left, *right;
Symbol *next;
int name; // Name atom
SourceLoc loc;
symbolkind kind;
union {
MacroSymbol mac;
} details;
};
extern Scope *CurrentScope;
extern Scope *GlobalScope;
extern Scope *ScopeList;
Scope *NewScopeInPool(MemoryPool *);
#define NewScope() NewScopeInPool(CurrentScope->pool)
void PushScope(Scope *fScope);
Scope *PopScope(void);
Symbol *NewSymbol(SourceLoc *loc, Scope *fScope, int name, symbolkind kind);
Symbol *AddSymbol(SourceLoc *loc, Scope *fScope, int atom, symbolkind kind);
Symbol *LookUpLocalSymbol(Scope *fScope, int atom);
Symbol *LookUpSymbol(Scope *fScope, int atom);
#endif // !defined(__SYMBOLS_H)
//
//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.
\****************************************************************************/
//
// tokens.h
//
#if !defined(__TOKENS_H)
#define __TOKENS_H 1
#include "parser.h"
#define EOF_SY (-1)
typedef struct TokenBlock_Rec TokenBlock;
typedef struct TokenStream_Rec {
struct TokenStream_Rec *next;
char *name;
TokenBlock *head;
TokenBlock *current;
} TokenStream;
struct TokenBlock_Rec {
TokenBlock *next;
int current;
int count;
int max;
unsigned char *data;
};
extern TokenStream stdlib_cpp_stream;
TokenStream *NewTokenStream(const char *name, MemoryPool *pool);
void DeleteTokenStream(TokenStream *pTok);
void RecordToken(TokenStream *pTok, int token, yystypepp * yylvalpp);
void RewindTokenStream(TokenStream *pTok);
int ReadToken(TokenStream *pTok, yystypepp * yylvalpp);
int ReadFromTokenStream(TokenStream *pTok, int name, int (*final)(CPPStruct *));
void UngetToken(int, yystypepp * yylvalpp);
#if defined(CPPC_ENABLE_TOOLS)
void DumpTokenStream(FILE *, TokenStream *, yystypepp * yylvalpp);
#endif // defined(CPPC_ENABLE_TOOLS)
#endif // !defined(__TOKENS_H)
No preview for this file type
extern int timeclock;
int yyerror; /* Yyerror and yycost are set by guards. */
int yycost; /* If yyerror is set to a nonzero value by a */
/* guard, the reduction with which the guard */
/* is associated is not performed, and the */
/* error recovery mechanism is invoked. */
/* Yycost indicates the cost of performing */
/* the reduction given the attributes of the */
/* symbols. */
/* YYMAXDEPTH indicates the size of the parser's state and value */
/* stacks. */
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 500
#endif
/* YYMAXRULES must be at least as large as the number of rules that */
/* could be placed in the rule queue. That number could be determined */
/* from the grammar and the size of the stack, but, as yet, it is not. */
#ifndef YYMAXRULES
#define YYMAXRULES 100
#endif
#ifndef YYMAXBACKUP
#define YYMAXBACKUP 100
#endif
short yyss[YYMAXDEPTH]; /* the state stack */
YYSTYPE yyvs[YYMAXDEPTH]; /* the semantic value stack */
YYLTYPE yyls[YYMAXDEPTH]; /* the location stack */
short yyrq[YYMAXRULES]; /* the rule queue */
int yychar; /* the lookahead symbol */
YYSTYPE yylval; /* the semantic value of the */
/* lookahead symbol */
YYSTYPE yytval; /* the semantic value for the state */
/* at the top of the state stack. */
YYSTYPE yyval; /* the variable used to return */
/* semantic values from the action */
/* routines */
YYLTYPE yylloc; /* location data for the lookahead */
/* symbol */
YYLTYPE yytloc; /* location data for the state at the */
/* top of the state stack */
int yynunlexed;
short yyunchar[YYMAXBACKUP];
YYSTYPE yyunval[YYMAXBACKUP];
YYLTYPE yyunloc[YYMAXBACKUP];
short *yygssp; /* a pointer to the top of the state */
/* stack; only set during error */
/* recovery. */
YYSTYPE *yygvsp; /* a pointer to the top of the value */
/* stack; only set during error */
/* recovery. */
YYLTYPE *yyglsp; /* a pointer to the top of the */
/* location stack; only set during */
/* error recovery. */
/* Yyget is an interface between the parser and the lexical analyzer. */
/* It is costly to provide such an interface, but it avoids requiring */
/* the lexical analyzer to be able to back up the scan. */
yyget()
{
if (yynunlexed > 0)
{
yynunlexed--;
yychar = yyunchar[yynunlexed];
yylval = yyunval[yynunlexed];
yylloc = yyunloc[yynunlexed];
}
else if (yychar <= 0)
yychar = 0;
else
{
yychar = yylex();
if (yychar < 0)
yychar = 0;
else yychar = YYTRANSLATE(yychar);
}
}
yyunlex(chr, val, loc)
int chr;
YYSTYPE val;
YYLTYPE loc;
{
yyunchar[yynunlexed] = chr;
yyunval[yynunlexed] = val;
yyunloc[yynunlexed] = loc;
yynunlexed++;
}
yyrestore(first, last)
register short *first;
register short *last;
{
register short *ssp;
register short *rp;
register int symbol;
register int state;
register int tvalsaved;
ssp = yygssp;
yyunlex(yychar, yylval, yylloc);
tvalsaved = 0;
while (first != last)
{
symbol = yystos[*ssp];
if (symbol < YYNTBASE)
{
yyunlex(symbol, yytval, yytloc);
tvalsaved = 1;
ssp--;
}
ssp--;
if (first == yyrq)
first = yyrq + YYMAXRULES;
first--;
for (rp = yyrhs + yyprhs[*first]; symbol = *rp; rp++)
{
if (symbol < YYNTBASE)
state = yytable[yypact[*ssp] + symbol];
else
{
state = yypgoto[symbol - YYNTBASE] + *ssp;
if (state >= 0 && state <= YYLAST && yycheck[state] == *ssp)
state = yytable[state];
else
state = yydefgoto[symbol - YYNTBASE];
}
*++ssp = state;
}
}
if ( ! tvalsaved && ssp > yyss)
{
yyunlex(yystos[*ssp], yytval, yytloc);
ssp--;
}
yygssp = ssp;
}
int
yyparse()
{
register int yystate;
register int yyn;
register short *yyssp;
register short *yyrq0;
register short *yyptr;
register YYSTYPE *yyvsp;
int yylen;
YYLTYPE *yylsp;
short *yyrq1;
short *yyrq2;
yystate = 0;
yyssp = yyss - 1;
yyvsp = yyvs - 1;
yylsp = yyls - 1;
yyrq0 = yyrq;
yyrq1 = yyrq0;
yyrq2 = yyrq0;
yychar = yylex();
if (yychar < 0)
yychar = 0;
else yychar = YYTRANSLATE(yychar);
yynewstate:
if (yyssp >= yyss + YYMAXDEPTH - 1)
{
yyabort("Parser Stack Overflow");
YYABORT;
}
*++yyssp = yystate;
yyresume:
yyn = yypact[yystate];
if (yyn == YYFLAG)
goto yydefault;
yyn += yychar;
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar)
goto yydefault;
yyn = yytable[yyn];
if (yyn < 0)
{
yyn = -yyn;
goto yyreduce;
}
else if (yyn == 0)
goto yyerrlab;
yystate = yyn;
yyptr = yyrq2;
while (yyptr != yyrq1)
{
yyn = *yyptr++;
yylen = yyr2[yyn];
yyvsp -= yylen;
yylsp -= yylen;
yyguard(yyn, yyvsp, yylsp);
if (yyerror)
goto yysemerr;
yyaction(yyn, yyvsp, yylsp);
*++yyvsp = yyval;
yylsp++;
if (yylen == 0)
{
yylsp->timestamp = timeclock;
yylsp->first_line = yytloc.first_line;
yylsp->first_column = yytloc.first_column;
yylsp->last_line = (yylsp-1)->last_line;
yylsp->last_column = (yylsp-1)->last_column;
yylsp->text = 0;
}
else
{
yylsp->last_line = (yylsp+yylen-1)->last_line;
yylsp->last_column = (yylsp+yylen-1)->last_column;
}
if (yyptr == yyrq + YYMAXRULES)
yyptr = yyrq;
}
if (yystate == YYFINAL)
YYACCEPT;
yyrq2 = yyptr;
yyrq1 = yyrq0;
*++yyvsp = yytval;
*++yylsp = yytloc;
yytval = yylval;
yytloc = yylloc;
yyget();
goto yynewstate;
yydefault:
yyn = yydefact[yystate];
if (yyn == 0)
goto yyerrlab;
yyreduce:
*yyrq0++ = yyn;
if (yyrq0 == yyrq + YYMAXRULES)
yyrq0 = yyrq;
if (yyrq0 == yyrq2)
{
yyabort("Parser Rule Queue Overflow");
YYABORT;
}
yyssp -= yyr2[yyn];
yyn = yyr1[yyn];
yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
yystate = yytable[yystate];
else
yystate = yydefgoto[yyn - YYNTBASE];
goto yynewstate;
yysemerr:
*--yyptr = yyn;
yyrq2 = yyptr;
yyvsp += yyr2[yyn];
yyerrlab:
yygssp = yyssp;
yygvsp = yyvsp;
yyglsp = yylsp;
yyrestore(yyrq0, yyrq2);
yyrecover();
yystate = *yygssp;
yyssp = yygssp;
yyvsp = yygvsp;
yyrq0 = yyrq;
yyrq1 = yyrq0;
yyrq2 = yyrq0;
goto yyresume;
}
$
## Copyright (C) 2002, 2005-2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
dist_pkgdata_DATA = README bison.m4 \
c-like.m4 \
c-skel.m4 c.m4 yacc.c glr.c \
c++-skel.m4 c++.m4 location.cc lalr1.cc glr.cc stack.hh \
java-skel.m4 java.m4 lalr1.java
m4sugardir = $(pkgdatadir)/m4sugar
dist_m4sugar_DATA = m4sugar/m4sugar.m4 m4sugar/foreach.m4
xsltdir = $(pkgdatadir)/xslt
dist_xslt_DATA = \
xslt/bison.xsl \
xslt/xml2dot.xsl \
xslt/xml2text.xsl \
xslt/xml2xhtml.xsl
-*- outline -*-
This directory contains data needed by Bison.
* Skeletons
Bison skeletons: the general shapes of the different parser kinds,
that are specialized for specific grammars by the bison program.
Currently, the supported skeletons are:
- yacc.c
It used to be named bison.simple: it corresponds to C Yacc
compatible LALR(1) parsers.
- lalr1.cc
Produces a C++ parser class.
- lalr1.java
Produces a Java parser class.
- glr.c
A Generalized LR C parser based on Bison's LALR(1) tables.
- glr.cc
A Generalized LR C++ parser. Actually a C++ wrapper around glr.c.
These skeletons are the only ones supported by the Bison team.
Because the interface between skeletons and the bison program is not
finished, *we are not bound to it*. In particular, Bison is not
mature enough for us to consider that ``foreign skeletons'' are
supported.
* m4sugar
This directory contains M4sugar, sort of an extended library for M4,
which is used by Bison to instantiate the skeletons.
* xslt
This directory contains XSLT programs that transform Bison's XML output
into various formats.
- bison.xsl
A library of routines used by the other XSLT programs.
- xml2dot.xsl
Conversion into GraphViz's dot format.
- xml2text.xsl
Conversion into text.
- xml2xhtml.xsl
Conversion into XHTML.
-----
Copyright (C) 2002, 2008-2012 Free Software Foundation, Inc.
This file is part of GNU Bison.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-*- Autoconf -*-
# C++ skeleton dispatching for Bison.
# Copyright (C) 2006-2007, 2009-2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
b4_glr_if( [m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.cc]])])
b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.cc]])])
m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[lalr1.cc]])
m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"])
m4_include(b4_used_skeleton)
-*- Autoconf -*-
# C++ skeleton for Bison
# Copyright (C) 2002-2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
m4_include(b4_pkgdatadir/[c.m4])
## ---------------- ##
## Default values. ##
## ---------------- ##
# Default parser class name.
b4_percent_define_default([[parser_class_name]], [[parser]])
# Don't do that so that we remember whether we're using a user
# request, or the default value.
#
# b4_percent_define_default([[api.location.type]], [[location]])
b4_percent_define_default([[filename_type]], [[std::string]])
b4_percent_define_default([[namespace]], m4_defn([b4_prefix]))
b4_percent_define_default([[global_tokens_and_yystype]], [[false]])
b4_percent_define_default([[define_location_comparison]],
[m4_if(b4_percent_define_get([[filename_type]]),
[std::string], [[true]], [[false]])])
## ----------- ##
## Namespace. ##
## ----------- ##
m4_define([b4_namespace_ref], [b4_percent_define_get([[namespace]])])
# Don't permit an empty b4_namespace_ref. Any `::parser::foo' appended to it
# would compile as an absolute reference with `parser' in the global namespace.
# b4_namespace_open would open an anonymous namespace and thus establish
# internal linkage. This would compile. However, it's cryptic, and internal
# linkage for the parser would be specified in all translation units that
# include the header, which is always generated. If we ever need to permit
# internal linkage somehow, surely we can find a cleaner approach.
m4_if(m4_bregexp(b4_namespace_ref, [^[ ]*$]), [-1], [],
[b4_complain_at(b4_percent_define_get_loc([[namespace]]),
[[namespace reference is empty]])])
# Instead of assuming the C++ compiler will do it, Bison should reject any
# invalid b4_namepsace_ref that would be converted to a valid
# b4_namespace_open. The problem is that Bison doesn't always output
# b4_namespace_ref to uncommented code but should reserve the ability to do so
# in future releases without risking breaking any existing user grammars.
# Specifically, don't allow empty names as b4_namespace_open would just convert
# those into anonymous namespaces, and that might tempt some users.
m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*::]), [-1], [],
[b4_complain_at(b4_percent_define_get_loc([[namespace]]),
[[namespace reference has consecutive "::"]])])
m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*$]), [-1], [],
[b4_complain_at(b4_percent_define_get_loc([[namespace]]),
[[namespace reference has a trailing "::"]])])
m4_define([b4_namespace_open],
[b4_user_code([b4_percent_define_get_syncline([[namespace]])
[namespace ]m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref),
[^\(.\)[ ]*::], [\1])),
[::], [ { namespace ])[ {]])])
m4_define([b4_namespace_close],
[b4_user_code([b4_percent_define_get_syncline([[namespace]])
m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]),
[^\(.\)[ ]*\(::\)?\([^][:]\|:[^:]\)*],
[\1])),
[::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])])
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
# -----------------------------------------------------
# Output the definition of the tokens as enums.
m4_define([b4_token_enums],
[/* Tokens. */
enum yytokentype {
m4_map_sep([ b4_token_enum], [,
],
[$@])
};
])
## ----------------- ##
## Semantic Values. ##
## ----------------- ##
# b4_lhs_value([TYPE])
# --------------------
# Expansion of $<TYPE>$.
m4_define([b4_lhs_value],
[(yyval[]m4_ifval([$1], [.$1]))])
# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
# --------------------------------------
# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
# symbols on RHS.
m4_define([b4_rhs_value],
[(yysemantic_stack_@{($1) - ($2)@}m4_ifval([$3], [.$3]))])
# b4_lhs_location()
# -----------------
# Expansion of @$.
m4_define([b4_lhs_location],
[(yyloc)])
# b4_rhs_location(RULE-LENGTH, NUM)
# ---------------------------------
# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
# on RHS.
m4_define([b4_rhs_location],
[(yylocation_stack_@{($1) - ($2)@})])
# b4_parse_param_decl
# -------------------
# Extra formal arguments of the constructor.
# Change the parameter names from "foo" into "foo_yyarg", so that
# there is no collision bw the user chosen attribute name, and the
# argument name in the constructor.
m4_define([b4_parse_param_decl],
[m4_ifset([b4_parse_param],
[m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])])
m4_define([b4_parse_param_decl_1],
[$1_yyarg])
# b4_parse_param_cons
# -------------------
# Extra initialisations of the constructor.
m4_define([b4_parse_param_cons],
[m4_ifset([b4_parse_param],
[
b4_cc_constructor_calls(b4_parse_param)])])
m4_define([b4_cc_constructor_calls],
[m4_map_sep([b4_cc_constructor_call], [,
], [$@])])
m4_define([b4_cc_constructor_call],
[$2 ($2_yyarg)])
# b4_parse_param_vars
# -------------------
# Extra instance variables.
m4_define([b4_parse_param_vars],
[m4_ifset([b4_parse_param],
[
/* User arguments. */
b4_cc_var_decls(b4_parse_param)])])
m4_define([b4_cc_var_decls],
[m4_map_sep([b4_cc_var_decl], [
], [$@])])
m4_define([b4_cc_var_decl],
[ $1;])
## ---------##
## Values. ##
## ---------##
# b4_yylloc_default_define
# ------------------------
# Define YYLLOC_DEFAULT.
m4_define([b4_yylloc_default_define],
[[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */
# ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).begin = YYRHSLOC (Rhs, 1).begin; \
(Current).end = YYRHSLOC (Rhs, N).end; \
} \
else \
{ \
(Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
} \
while (/*CONSTCOND*/ false)
# endif
]])
-*- Autoconf -*-
# Common code for C-like languages (C, C++, Java, etc.)
# Copyright (C) 2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# b4_dollar_dollar_(VALUE, FIELD, DEFAULT-FIELD)
# ----------------------------------------------
# If FIELD (or DEFAULT-FIELD) is non-null, return "VALUE.FIELD",
# otherwise just VALUE. Be sure to pass "(VALUE)" is VALUE is a
# pointer.
m4_define([b4_dollar_dollar_],
[m4_if([$2], [[]],
[m4_ifval([$3], [($1.$3)],
[$1])],
[($1.$2)])])
# b4_dollar_pushdef(VALUE-POINTER, DEFAULT-FIELD, LOCATION)
# b4_dollar_popdef
# ---------------------------------------------------------
# Define b4_dollar_dollar for VALUE and DEFAULT-FIELD,
# and b4_at_dollar for LOCATION.
m4_define([b4_dollar_pushdef],
[m4_pushdef([b4_dollar_dollar],
[b4_dollar_dollar_([$1], m4_dquote($][1), [$2])])dnl
m4_pushdef([b4_at_dollar], [$3])dnl
])
m4_define([b4_dollar_popdef],
[m4_popdef([b4_at_dollar])dnl
m4_popdef([b4_dollar_dollar])dnl
])
-*- Autoconf -*-
# C skeleton dispatching for Bison.
# Copyright (C) 2006-2007, 2009-2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
b4_glr_if( [m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.c]])])
b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.c]])])
m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[yacc.c]])
m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"])
m4_include(b4_used_skeleton)
This diff is collapsed. Click to expand it.
-*- Autoconf -*-
# Java skeleton dispatching for Bison.
# Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
b4_glr_if( [b4_complain([%%glr-parser not supported for Java])])
b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for Java])])
m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[lalr1.java]])
m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"])
m4_include(b4_used_skeleton)
-*- Autoconf -*-
# Java language support for Bison
# Copyright (C) 2007-2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
m4_include(b4_pkgdatadir/[c-like.m4])
# b4_comment(TEXT)
# ----------------
m4_define([b4_comment], [/* m4_bpatsubst([$1], [
], [
]) */])
# b4_list2(LIST1, LIST2)
# --------------------------
# Join two lists with a comma if necessary.
m4_define([b4_list2],
[$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2])
# b4_percent_define_get3(DEF, PRE, POST, NOT)
# -------------------------------------------
# Expand to the value of DEF surrounded by PRE and POST if it's %define'ed,
# otherwise NOT.
m4_define([b4_percent_define_get3],
[m4_ifval(m4_quote(b4_percent_define_get([$1])),
[$2[]b4_percent_define_get([$1])[]$3], [$4])])
# b4_flag_value(BOOLEAN-FLAG)
# ---------------------------
m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])])
# b4_public_if(TRUE, FALSE)
# -------------------------
b4_percent_define_default([[public]], [[false]])
m4_define([b4_public_if],
[b4_percent_define_flag_if([public], [$1], [$2])])
# b4_abstract_if(TRUE, FALSE)
# ---------------------------
b4_percent_define_default([[abstract]], [[false]])
m4_define([b4_abstract_if],
[b4_percent_define_flag_if([abstract], [$1], [$2])])
# b4_final_if(TRUE, FALSE)
# ---------------------------
b4_percent_define_default([[final]], [[false]])
m4_define([b4_final_if],
[b4_percent_define_flag_if([final], [$1], [$2])])
# b4_strictfp_if(TRUE, FALSE)
# ---------------------------
b4_percent_define_default([[strictfp]], [[false]])
m4_define([b4_strictfp_if],
[b4_percent_define_flag_if([strictfp], [$1], [$2])])
# b4_lexer_if(TRUE, FALSE)
# ------------------------
m4_define([b4_lexer_if],
[b4_percent_code_ifdef([[lexer]], [$1], [$2])])
# b4_identification
# -----------------
m4_define([b4_identification],
[ /** Version number for the Bison executable that generated this parser. */
public static final String bisonVersion = "b4_version";
/** Name of the skeleton that generated this parser. */
public static final String bisonSkeleton = b4_skeleton;
])
## ------------ ##
## Data types. ##
## ------------ ##
# b4_int_type(MIN, MAX)
# ---------------------
# Return the smallest int type able to handle numbers ranging from
# MIN to MAX (included).
m4_define([b4_int_type],
[m4_if(b4_ints_in($@, [-128], [127]), [1], [byte],
b4_ints_in($@, [-32768], [32767]), [1], [short],
[int])])
# b4_int_type_for(NAME)
# ---------------------
# Return the smallest int type able to handle numbers ranging from
# `NAME_min' to `NAME_max' (included).
m4_define([b4_int_type_for],
[b4_int_type($1_min, $1_max)])
# b4_null
# -------
m4_define([b4_null], [null])
## ------------------------- ##
## Assigning token numbers. ##
## ------------------------- ##
# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
# ---------------------------------------
# Output the definition of this token as an enum.
m4_define([b4_token_enum],
[ /** Token number, to be returned by the scanner. */
public static final int $1 = $2;
])
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
# -----------------------------------------------------
# Output the definition of the tokens (if there are) as enums.
m4_define([b4_token_enums],
[m4_if([$#$1], [1], [],
[/* Tokens. */
m4_map([b4_token_enum], [$@])])
])
# b4-case(ID, CODE)
# -----------------
# We need to fool Java's stupid unreachable code detection.
m4_define([b4_case], [ case $1:
if (yyn == $1)
$2;
break;
])
## ---------------- ##
## Default values. ##
## ---------------- ##
m4_define([b4_yystype], [b4_percent_define_get([[stype]])])
b4_percent_define_default([[stype]], [[Object]])
# %name-prefix
m4_define_default([b4_prefix], [[YY]])
b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])
m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])])
b4_percent_define_default([[lex_throws]], [[java.io.IOException]])
m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
b4_percent_define_default([[throws]], [])
m4_define([b4_throws], [b4_percent_define_get([[throws]])])
b4_percent_define_default([[api.location.type]], [Location])
m4_define([b4_location_type], [b4_percent_define_get([[api.location.type]])])
b4_percent_define_default([[api.position.type]], [Position])
m4_define([b4_position_type], [b4_percent_define_get([[api.position.type]])])
## ----------------- ##
## Semantic Values. ##
## ----------------- ##
# b4_lhs_value([TYPE])
# --------------------
# Expansion of $<TYPE>$.
m4_define([b4_lhs_value], [yyval])
# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
# --------------------------------------
# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
# symbols on RHS.
#
# In this simple implementation, %token and %type have class names
# between the angle brackets.
m4_define([b4_rhs_value],
[(m4_ifval($3, [($3)])[](yystack.valueAt ($1-($2))))])
# b4_lhs_location()
# -----------------
# Expansion of @$.
m4_define([b4_lhs_location],
[(yyloc)])
# b4_rhs_location(RULE-LENGTH, NUM)
# ---------------------------------
# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
# on RHS.
m4_define([b4_rhs_location],
[yystack.locationAt ($1-($2))])
# b4_lex_param
# b4_parse_param
# --------------
# If defined, b4_lex_param arrives double quoted, but below we prefer
# it to be single quoted. Same for b4_parse_param.
# TODO: should be in bison.m4
m4_define_default([b4_lex_param], [[]])
m4_define([b4_lex_param], b4_lex_param)
m4_define([b4_parse_param], b4_parse_param)
# b4_lex_param_decl
# -------------------
# Extra formal arguments of the constructor.
m4_define([b4_lex_param_decl],
[m4_ifset([b4_lex_param],
[b4_remove_comma([$1],
b4_param_decls(b4_lex_param))],
[$1])])
m4_define([b4_param_decls],
[m4_map([b4_param_decl], [$@])])
m4_define([b4_param_decl], [, $1])
m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)])
# b4_parse_param_decl
# -------------------
# Extra formal arguments of the constructor.
m4_define([b4_parse_param_decl],
[m4_ifset([b4_parse_param],
[b4_remove_comma([$1],
b4_param_decls(b4_parse_param))],
[$1])])
# b4_lex_param_call
# -------------------
# Delegating the lexer parameters to the lexer constructor.
m4_define([b4_lex_param_call],
[m4_ifset([b4_lex_param],
[b4_remove_comma([$1],
b4_param_calls(b4_lex_param))],
[$1])])
m4_define([b4_param_calls],
[m4_map([b4_param_call], [$@])])
m4_define([b4_param_call], [, $2])
# b4_parse_param_cons
# -------------------
# Extra initialisations of the constructor.
m4_define([b4_parse_param_cons],
[m4_ifset([b4_parse_param],
[b4_constructor_calls(b4_parse_param)])])
m4_define([b4_constructor_calls],
[m4_map([b4_constructor_call], [$@])])
m4_define([b4_constructor_call],
[this.$2 = $2;
])
# b4_parse_param_vars
# -------------------
# Extra instance variables.
m4_define([b4_parse_param_vars],
[m4_ifset([b4_parse_param],
[
/* User arguments. */
b4_var_decls(b4_parse_param)])])
m4_define([b4_var_decls],
[m4_map_sep([b4_var_decl], [
], [$@])])
m4_define([b4_var_decl],
[ protected final $1;])
# b4_maybe_throws(THROWS)
# -----------------------
# Expand to either an empty string or "throws THROWS".
m4_define([b4_maybe_throws],
[m4_ifval($1, [throws $1])])
# C++ skeleton for Bison
# Copyright (C) 2002-2007, 2009-2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
b4_output_begin([b4_dir_prefix[]position.hh])
b4_copyright([Positions for Bison parsers in C++],
[2002-2007, 2009-2012])[
/**
** \file ]b4_dir_prefix[position.hh
** Define the ]b4_namespace_ref[::position class.
*/
]b4_cpp_guard_open([b4_dir_prefix[]position.hh])[
# include <algorithm> // std::max
# include <iostream>
# include <string>
]b4_null_define[
]b4_namespace_open[
/// Abstract a position.
class position
{
public:
]m4_ifdef([b4_location_constructors], [[
/// Construct a position.
explicit position (]b4_percent_define_get([[filename_type]])[* f = YY_NULL,
unsigned int l = ]b4_location_initial_line[u,
unsigned int c = ]b4_location_initial_column[u)
: filename (f)
, line (l)
, column (c)
{
}
]])[
/// Initialization.
void initialize (]b4_percent_define_get([[filename_type]])[* fn = YY_NULL,
unsigned int l = ]b4_location_initial_line[u,
unsigned int c = ]b4_location_initial_column[u)
{
filename = fn;
line = l;
column = c;
}
/** \name Line and Column related manipulators
** \{ */
/// (line related) Advance to the COUNT next lines.
void lines (int count = 1)
{
column = ]b4_location_initial_column[u;
line += count;
}
/// (column related) Advance to the COUNT next columns.
void columns (int count = 1)
{
column = std::max (]b4_location_initial_column[u, column + count);
}
/** \} */
/// File name to which this position refers.
]b4_percent_define_get([[filename_type]])[* filename;
/// Current line number.
unsigned int line;
/// Current column number.
unsigned int column;
};
/// Add and assign a position.
inline position&
operator+= (position& res, const int width)
{
res.columns (width);
return res;
}
/// Add two position objects.
inline const position
operator+ (const position& begin, const int width)
{
position res = begin;
return res += width;
}
/// Add and assign a position.
inline position&
operator-= (position& res, const int width)
{
return res += -width;
}
/// Add two position objects.
inline const position
operator- (const position& begin, const int width)
{
return begin + -width;
}
]b4_percent_define_flag_if([[define_location_comparison]], [[
/// Compare two position objects.
inline bool
operator== (const position& pos1, const position& pos2)
{
return (pos1.line == pos2.line
&& pos1.column == pos2.column
&& (pos1.filename == pos2.filename
|| (pos1.filename && pos2.filename
&& *pos1.filename == *pos2.filename)));
}
/// Compare two position objects.
inline bool
operator!= (const position& pos1, const position& pos2)
{
return !(pos1 == pos2);
}
]])[
/** \brief Intercept output stream redirection.
** \param ostr the destination output stream
** \param pos a reference to the position to redirect
*/
template <typename YYChar>
inline std::basic_ostream<YYChar>&
operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
{
if (pos.filename)
ostr << *pos.filename << ':';
return ostr << pos.line << '.' << pos.column;
}
]b4_namespace_close[
]b4_cpp_guard_close([b4_dir_prefix[]position.hh])
b4_output_end()
b4_output_begin([b4_dir_prefix[]location.hh])
b4_copyright([Locations for Bison parsers in C++],
[2002-2007, 2009-2012])[
/**
** \file ]b4_dir_prefix[location.hh
** Define the ]b4_namespace_ref[::location class.
*/
]b4_cpp_guard_open([b4_dir_prefix[]location.hh])[
# include "position.hh"
]b4_namespace_open[
/// Abstract a location.
class location
{
public:
]m4_ifdef([b4_location_constructors], [
/// Construct a location from \a b to \a e.
location (const position& b, const position& e)
: begin (b)
, end (e)
{
}
/// Construct a 0-width location in \a p.
explicit location (const position& p = position ())
: begin (p)
, end (p)
{
}
/// Construct a 0-width location in \a f, \a l, \a c.
explicit location (]b4_percent_define_get([[filename_type]])[* f,
unsigned int l = ]b4_location_initial_line[u,
unsigned int c = ]b4_location_initial_column[u)
: begin (f, l, c)
, end (f, l, c)
{
}
])[
/// Initialization.
void initialize (]b4_percent_define_get([[filename_type]])[* f = YY_NULL,
unsigned int l = ]b4_location_initial_line[u,
unsigned int c = ]b4_location_initial_column[u)
{
begin.initialize (f, l, c);
end = begin;
}
/** \name Line and Column related manipulators
** \{ */
public:
/// Reset initial location to final location.
void step ()
{
begin = end;
}
/// Extend the current location to the COUNT next columns.
void columns (unsigned int count = 1)
{
end += count;
}
/// Extend the current location to the COUNT next lines.
void lines (unsigned int count = 1)
{
end.lines (count);
}
/** \} */
public:
/// Beginning of the located region.
position begin;
/// End of the located region.
position end;
};
/// Join two location objects to create a location.
inline const location operator+ (const location& begin, const location& end)
{
location res = begin;
res.end = end.end;
return res;
}
/// Add two location objects.
inline const location operator+ (const location& begin, unsigned int width)
{
location res = begin;
res.columns (width);
return res;
}
/// Add and assign a location.
inline location& operator+= (location& res, unsigned int width)
{
res.columns (width);
return res;
}
]b4_percent_define_flag_if([[define_location_comparison]], [[
/// Compare two location objects.
inline bool
operator== (const location& loc1, const location& loc2)
{
return loc1.begin == loc2.begin && loc1.end == loc2.end;
}
/// Compare two location objects.
inline bool
operator!= (const location& loc1, const location& loc2)
{
return !(loc1 == loc2);
}
]])[
/** \brief Intercept output stream redirection.
** \param ostr the destination output stream
** \param loc a reference to the location to redirect
**
** Avoid duplicate information.
*/
template <typename YYChar>
inline std::basic_ostream<YYChar>&
operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
{
position last = loc.end - 1;
ostr << loc.begin;
if (last.filename
&& (!loc.begin.filename
|| *loc.begin.filename != *last.filename))
ostr << '-' << last;
else if (loc.begin.line != last.line)
ostr << '-' << last.line << '.' << last.column;
else if (loc.begin.column != last.column)
ostr << '-' << last.column;
return ostr;
}
]b4_namespace_close[
]b4_cpp_guard_close([b4_dir_prefix[]location.hh])
b4_output_end()
This source diff could not be displayed because it is too large. You can view the blob instead.
# C++ skeleton for Bison
# Copyright (C) 2002-2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
m4_pushdef([b4_copyright_years],
[2002-2012])
b4_output_begin([b4_dir_prefix[]stack.hh])
b4_copyright([Stack handling for Bison parsers in C++],
[2002-2012])[
/**
** \file ]b4_dir_prefix[stack.hh
** Define the ]b4_namespace_ref[::stack class.
*/
]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[
# include <deque>
]b4_namespace_open[
template <class T, class S = std::deque<T> >
class stack
{
public:
// Hide our reversed order.
typedef typename S::reverse_iterator iterator;
typedef typename S::const_reverse_iterator const_iterator;
stack () : seq_ ()
{
}
stack (unsigned int n) : seq_ (n)
{
}
inline
T&
operator [] (unsigned int i)
{
return seq_[i];
}
inline
const T&
operator [] (unsigned int i) const
{
return seq_[i];
}
inline
void
push (const T& t)
{
seq_.push_front (t);
}
inline
void
pop (unsigned int n = 1)
{
for (; n; --n)
seq_.pop_front ();
}
inline
unsigned int
height () const
{
return seq_.size ();
}
inline const_iterator begin () const { return seq_.rbegin (); }
inline const_iterator end () const { return seq_.rend (); }
private:
S seq_;
};
/// Present a slice of the top of a stack.
template <class T, class S = stack<T> >
class slice
{
public:
slice (const S& stack, unsigned int range)
: stack_ (stack)
, range_ (range)
{
}
inline
const T&
operator [] (unsigned int i) const
{
return stack_[range_ - i];
}
private:
const S& stack_;
unsigned int range_;
};
]b4_namespace_close[
]b4_cpp_guard_close([b4_dir_prefix[]stack.hh])
b4_output_end()
m4_popdef([b4_copyright_years])
<?xml version="1.0" encoding="UTF-8"?>
<!--
bison.xsl - common templates for Bison XSLT.
Copyright (C) 2007-2012 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bison="http://www.gnu.org/software/bison/">
<xsl:key
name="bison:symbolByName"
match="/bison-xml-report/grammar/nonterminals/nonterminal"
use="@name"
/>
<xsl:key
name="bison:symbolByName"
match="/bison-xml-report/grammar/terminals/terminal"
use="@name"
/>
<xsl:key
name="bison:ruleByNumber"
match="/bison-xml-report/grammar/rules/rule"
use="@number"
/>
<xsl:key
name="bison:ruleByLhs"
match="/bison-xml-report/grammar/rules/rule[
@usefulness != 'useless-in-grammar']"
use="lhs"
/>
<xsl:key
name="bison:ruleByRhs"
match="/bison-xml-report/grammar/rules/rule[
@usefulness != 'useless-in-grammar']"
use="rhs/symbol"
/>
<!-- For the specified state, output: #sr-conflicts,#rr-conflicts -->
<xsl:template match="state" mode="bison:count-conflicts">
<xsl:variable name="transitions" select="actions/transitions"/>
<xsl:variable name="reductions" select="actions/reductions"/>
<xsl:variable
name="terminals"
select="
$transitions/transition[@type='shift']/@symbol
| $reductions/reduction/@symbol
"
/>
<xsl:variable name="conflict-data">
<xsl:for-each select="$terminals">
<xsl:variable name="name" select="."/>
<xsl:if test="generate-id($terminals[. = $name][1]) = generate-id(.)">
<xsl:variable
name="shift-count"
select="count($transitions/transition[@symbol=$name])"
/>
<xsl:variable
name="reduce-count"
select="count($reductions/reduction[@symbol=$name])"
/>
<xsl:if test="$shift-count > 0 and $reduce-count > 0">
<xsl:text>s</xsl:text>
</xsl:if>
<xsl:if test="$reduce-count > 1">
<xsl:text>r</xsl:text>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="string-length(translate($conflict-data, 'r', ''))"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="string-length(translate($conflict-data, 's', ''))"/>
</xsl:template>
<xsl:template name="space">
<xsl:param name="repeat">0</xsl:param>
<xsl:param name="fill" select="' '"/>
<xsl:if test="number($repeat) &gt;= 1">
<xsl:call-template name="space">
<xsl:with-param name="repeat" select="$repeat - 1"/>
<xsl:with-param name="fill" select="$fill"/>
</xsl:call-template>
<xsl:value-of select="$fill"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
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