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
This commit is contained in:
parent
5f1a0b7998
commit
7213324259
59 changed files with 18949 additions and 4503 deletions
|
|
@ -3,9 +3,10 @@ CC = gcc
|
|||
|
||||
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
|
||||
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
|
||||
all : libPreprocessor.a
|
||||
|
|
@ -28,14 +29,10 @@ depend:
|
|||
|
||||
# DO NOT DELETE
|
||||
|
||||
scanner.o: slglobals.h memory.h atom.h scanner.h parser.h cpp.h tokens.h
|
||||
scanner.o: symbols.h compile.h
|
||||
atom.o: slglobals.h memory.h atom.h scanner.h parser.h cpp.h tokens.h
|
||||
atom.o: symbols.h compile.h
|
||||
memory.o: memory.h
|
||||
cpp.o: slglobals.h memory.h atom.h scanner.h parser.h cpp.h tokens.h
|
||||
cpp.o: symbols.h compile.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
|
||||
PpAtom.o: PpContext.h PpToken.h
|
||||
PpScanner.o: PpContext.h PpToken.h
|
||||
PpTokens.o: PpContext.h PpToken.h
|
||||
Pp.o: PpContext.h PpToken.h
|
||||
PpContext.o: PpContext.h PpToken.h
|
||||
PpMemory.o: PpContext.h PpToken.h
|
||||
PpSymbols.o: PpContext.h PpToken.h
|
||||
|
|
|
|||
1076
glslang/MachineIndependent/preprocessor/Pp.cpp
Normal file
1076
glslang/MachineIndependent/preprocessor/Pp.cpp
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,6 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//Copyright (C) 2013 LunarG, Inc.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -86,7 +87,8 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "slglobals.h"
|
||||
#include "PpContext.h"
|
||||
#include "PpTokens.h"
|
||||
|
||||
#undef malloc
|
||||
#undef realloc
|
||||
|
|
@ -129,18 +131,12 @@ static const struct {
|
|||
|
||||
#define INIT_STRING_TABLE_SIZE 16384
|
||||
|
||||
typedef struct StringTable_Rec {
|
||||
char *strings;
|
||||
int nextFree;
|
||||
int size;
|
||||
} StringTable;
|
||||
|
||||
/*
|
||||
* InitStringTable() - Initialize the string table.
|
||||
*
|
||||
*/
|
||||
* InitStringTable() - Initialize the string table.
|
||||
*
|
||||
*/
|
||||
|
||||
static int InitStringTable(StringTable *stable)
|
||||
int InitStringTable(TPpContext::StringTable *stable)
|
||||
{
|
||||
stable->strings = (char *) malloc(INIT_STRING_TABLE_SIZE);
|
||||
if (!stable->strings)
|
||||
|
|
@ -152,11 +148,11 @@ static int InitStringTable(StringTable *stable)
|
|||
} // InitStringTable
|
||||
|
||||
/*
|
||||
* FreeStringTable() - Free the string table.
|
||||
*
|
||||
*/
|
||||
* FreeStringTable() - Free the string table.
|
||||
*
|
||||
*/
|
||||
|
||||
static void FreeStringTable(StringTable *stable)
|
||||
void FreeStringTable(TPpContext::StringTable *stable)
|
||||
{
|
||||
if (stable->strings)
|
||||
free(stable->strings);
|
||||
|
|
@ -166,9 +162,9 @@ static void FreeStringTable(StringTable *stable)
|
|||
} // FreeStringTable
|
||||
|
||||
/*
|
||||
* HashString() - Hash a string with the base hash function.
|
||||
*
|
||||
*/
|
||||
* HashString() - Hash a string with the base hash function.
|
||||
*
|
||||
*/
|
||||
|
||||
static int HashString(const char *s)
|
||||
{
|
||||
|
|
@ -182,9 +178,9 @@ static int HashString(const char *s)
|
|||
} // HashString
|
||||
|
||||
/*
|
||||
* HashString2() - Hash a string with the incrimenting hash function.
|
||||
*
|
||||
*/
|
||||
* HashString2() - Hash a string with the incrimenting hash function.
|
||||
*
|
||||
*/
|
||||
|
||||
static int HashString2(const char *s)
|
||||
{
|
||||
|
|
@ -198,11 +194,11 @@ static int HashString2(const char *s)
|
|||
} // HashString2
|
||||
|
||||
/*
|
||||
* AddString() - Add a string to a string table. Return it's offset.
|
||||
*
|
||||
*/
|
||||
* AddString() - Add a string to a string table. Return it's offset.
|
||||
*
|
||||
*/
|
||||
|
||||
static int AddString(StringTable *stable, const char *s)
|
||||
static int AddString(TPpContext::StringTable *stable, const char *s)
|
||||
{
|
||||
int len, loc;
|
||||
char *str;
|
||||
|
|
@ -226,31 +222,18 @@ static int AddString(StringTable *stable, const char *s)
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define INIT_HASH_TABLE_SIZE 2047
|
||||
#define HASH_TABLE_MAX_COLLISIONS 3
|
||||
|
||||
typedef struct HashEntry_Rec {
|
||||
int index; // String table offset of string representation
|
||||
int value; // Atom (symbol) value
|
||||
} HashEntry;
|
||||
|
||||
typedef struct HashTable_Rec {
|
||||
HashEntry *entry;
|
||||
int size;
|
||||
int entries;
|
||||
int counts[HASH_TABLE_MAX_COLLISIONS + 1];
|
||||
} HashTable;
|
||||
|
||||
/*
|
||||
* InitHashTable() - Initialize the hash table.
|
||||
*
|
||||
*/
|
||||
* InitHashTable() - Initialize the hash table.
|
||||
*
|
||||
*/
|
||||
|
||||
static int InitHashTable(HashTable *htable, int fsize)
|
||||
static int InitHashTable(TPpContext::HashTable *htable, int fsize)
|
||||
{
|
||||
int ii;
|
||||
|
||||
htable->entry = (HashEntry *) malloc(sizeof(HashEntry)*fsize);
|
||||
if (!htable->entry)
|
||||
htable->entry = (TPpContext::HashEntry *) malloc(sizeof(TPpContext::HashEntry)*fsize);
|
||||
if (! htable->entry)
|
||||
return 0;
|
||||
htable->size = fsize;
|
||||
for (ii = 0; ii < fsize; ii++) {
|
||||
|
|
@ -258,17 +241,17 @@ static int InitHashTable(HashTable *htable, int fsize)
|
|||
htable->entry[ii].value = 0;
|
||||
}
|
||||
htable->entries = 0;
|
||||
for (ii = 0; ii <= HASH_TABLE_MAX_COLLISIONS; ii++)
|
||||
for (ii = 0; ii <= TPpContext::hashTableMaxCollisions; ii++)
|
||||
htable->counts[ii] = 0;
|
||||
return 1;
|
||||
} // InitHashTable
|
||||
|
||||
/*
|
||||
* FreeHashTable() - Free the hash table.
|
||||
*
|
||||
*/
|
||||
* FreeHashTable() - Free the hash table.
|
||||
*
|
||||
*/
|
||||
|
||||
static void FreeHashTable(HashTable *htable)
|
||||
static void FreeHashTable(TPpContext::HashTable *htable)
|
||||
{
|
||||
if (htable->entry)
|
||||
free(htable->entry);
|
||||
|
|
@ -278,11 +261,11 @@ static void FreeHashTable(HashTable *htable)
|
|||
} // FreeHashTable
|
||||
|
||||
/*
|
||||
* Empty() - See if a hash table entry is empty.
|
||||
*
|
||||
*/
|
||||
* Empty() - See if a hash table entry is empty.
|
||||
*
|
||||
*/
|
||||
|
||||
static int Empty(HashTable *htable, int hashloc)
|
||||
static int Empty(TPpContext::HashTable *htable, int hashloc)
|
||||
{
|
||||
assert(hashloc >= 0 && hashloc < htable->size);
|
||||
if (htable->entry[hashloc].index == 0) {
|
||||
|
|
@ -293,11 +276,11 @@ static int Empty(HashTable *htable, int hashloc)
|
|||
} // Empty
|
||||
|
||||
/*
|
||||
* Match() - See if a hash table entry is matches a string.
|
||||
*
|
||||
*/
|
||||
* Match() - See if a hash table entry is matches a string.
|
||||
*
|
||||
*/
|
||||
|
||||
static int Match(HashTable *htable, StringTable *stable, const char *s, int hashloc)
|
||||
static int Match(TPpContext::HashTable *htable, TPpContext::StringTable *stable, const char *s, int hashloc)
|
||||
{
|
||||
int strloc;
|
||||
|
||||
|
|
@ -315,34 +298,12 @@ static int Match(HashTable *htable, StringTable *stable, const char *s, int hash
|
|||
|
||||
#define INIT_ATOM_TABLE_SIZE 1024
|
||||
|
||||
|
||||
struct AtomTable_Rec {
|
||||
StringTable stable; // String table.
|
||||
HashTable htable; // Hashes string to atom number and token value. Multiple strings can
|
||||
// have the same token value but each unique string is a unique atom.
|
||||
int *amap; // Maps atom value to offset in string table. Atoms all map to unique
|
||||
// strings except for some undefined values in the lower, fixed part
|
||||
// of the atom table that map to "<undefined>". The lowest 256 atoms
|
||||
// correspond to single character ASCII values except for alphanumeric
|
||||
// characters and '_', which can be other tokens. Next come the
|
||||
// language tokens with their atom values equal to the token value.
|
||||
// Then come predefined atoms, followed by user specified identifiers.
|
||||
int *arev; // Reversed atom for symbol table use.
|
||||
int nextFree;
|
||||
int size;
|
||||
};
|
||||
|
||||
static AtomTable latable = { { 0 } };
|
||||
AtomTable *atable = &latable;
|
||||
|
||||
static int AddAtomFixed(AtomTable *atable, const char *s, int atom);
|
||||
|
||||
/*
|
||||
* GrowAtomTable() - Grow the atom table to at least "size" if it's smaller.
|
||||
*
|
||||
*/
|
||||
* GrowAtomTable() - Grow the atom table to at least "size" if it's smaller.
|
||||
*
|
||||
*/
|
||||
|
||||
static int GrowAtomTable(AtomTable *atable, int size)
|
||||
int GrowAtomTable(TPpContext::AtomTable *atable, int size)
|
||||
{
|
||||
int *newmap, *newrev;
|
||||
|
||||
|
|
@ -373,9 +334,9 @@ static int GrowAtomTable(AtomTable *atable, int size)
|
|||
} // GrowAtomTable
|
||||
|
||||
/*
|
||||
* lReverse() - Reverse the bottom 20 bits of a 32 bit int.
|
||||
*
|
||||
*/
|
||||
* lReverse() - Reverse the bottom 20 bits of a 32 bit int.
|
||||
*
|
||||
*/
|
||||
|
||||
static int lReverse(int fval)
|
||||
{
|
||||
|
|
@ -398,11 +359,11 @@ static int lReverse(int fval)
|
|||
} // lReverse
|
||||
|
||||
/*
|
||||
* AllocateAtom() - Allocate a new atom. Associated with the "undefined" value of -1.
|
||||
*
|
||||
*/
|
||||
* AllocateAtom() - Allocate a new atom. Associated with the "undefined" value of -1.
|
||||
*
|
||||
*/
|
||||
|
||||
static int AllocateAtom(AtomTable *atable)
|
||||
int AllocateAtom(TPpContext::AtomTable *atable)
|
||||
{
|
||||
if (atable->nextFree >= atable->size)
|
||||
GrowAtomTable(atable, atable->nextFree*2);
|
||||
|
|
@ -413,26 +374,26 @@ static int AllocateAtom(AtomTable *atable)
|
|||
} // AllocateAtom
|
||||
|
||||
/*
|
||||
* SetAtomValue() - Allocate a new atom associated with "hashindex".
|
||||
*
|
||||
*/
|
||||
* SetAtomValue() - Allocate a new atom associated with "hashindex".
|
||||
*
|
||||
*/
|
||||
|
||||
static void SetAtomValue(AtomTable *atable, int atomnumber, int hashindex)
|
||||
void SetAtomValue(TPpContext::AtomTable *atable, int atomnumber, int hashindex)
|
||||
{
|
||||
atable->amap[atomnumber] = atable->htable.entry[hashindex].index;
|
||||
atable->htable.entry[hashindex].value = atomnumber;
|
||||
} // SetAtomValue
|
||||
|
||||
/*
|
||||
* FindHashLoc() - Find the hash location for this string. Return -1 it hash table is full.
|
||||
*
|
||||
*/
|
||||
* FindHashLoc() - Find the hash location for this string. Return -1 it hash table is full.
|
||||
*
|
||||
*/
|
||||
|
||||
static int FindHashLoc(AtomTable *atable, const char *s)
|
||||
int FindHashLoc(TPpContext::AtomTable *atable, const char *s)
|
||||
{
|
||||
int hashloc, hashdelta, count;
|
||||
int FoundEmptySlot = 0;
|
||||
int collision[HASH_TABLE_MAX_COLLISIONS + 1];
|
||||
int collision[TPpContext::hashTableMaxCollisions + 1];
|
||||
|
||||
hashloc = HashString(s) % atable->htable.size;
|
||||
if (!Empty(&atable->htable, hashloc)) {
|
||||
|
|
@ -441,7 +402,7 @@ static int FindHashLoc(AtomTable *atable, const char *s)
|
|||
collision[0] = hashloc;
|
||||
hashdelta = HashString2(s);
|
||||
count = 0;
|
||||
while (count < HASH_TABLE_MAX_COLLISIONS) {
|
||||
while (count < TPpContext::hashTableMaxCollisions) {
|
||||
hashloc = ((hashloc + hashdelta) & 0x7fffffff) % atable->htable.size;
|
||||
if (!Empty(&atable->htable, hashloc)) {
|
||||
if (Match(&atable->htable, &atable->stable, s, hashloc)) {
|
||||
|
|
@ -455,22 +416,20 @@ static int FindHashLoc(AtomTable *atable, const char *s)
|
|||
collision[count] = hashloc;
|
||||
}
|
||||
|
||||
if (!FoundEmptySlot) {
|
||||
if (cpp->options.DumpAtomTable) {
|
||||
if (! FoundEmptySlot) {
|
||||
#ifdef DUMP_TABLE
|
||||
{
|
||||
int ii;
|
||||
char str[200];
|
||||
sprintf(str, "*** Hash failed with more than %d collisions. Must increase hash table size. ***",
|
||||
HASH_TABLE_MAX_COLLISIONS);
|
||||
ShPpErrorToInfoLog(str);
|
||||
|
||||
sprintf(str, "*** New string \"%s\", hash=%04x, delta=%04x", s, collision[0], hashdelta);
|
||||
ShPpErrorToInfoLog(str);
|
||||
for (ii = 0; ii <= HASH_TABLE_MAX_COLLISIONS; ii++) {
|
||||
sprintf(str, "*** Collides on try %d at hash entry %04x with \"%s\"",
|
||||
ii + 1, collision[ii], GetAtomString(atable, atable->htable.entry[collision[ii]].value));
|
||||
ShPpErrorToInfoLog(str);
|
||||
printf(str, "*** Hash failed with more than %d collisions. Must increase hash table size. ***",
|
||||
hashTableMaxCollisions);
|
||||
printf(str, "*** New string \"%s\", hash=%04x, delta=%04x", s, collision[0], hashdelta);
|
||||
for (ii = 0; ii <= hashTableMaxCollisions; ii++) {
|
||||
printf(str, "*** Collides on try %d at hash entry %04x with \"%s\"",
|
||||
ii + 1, collision[ii], GetAtomString(atable, atable->htable.entry[collision[ii]].value));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
} else {
|
||||
atable->htable.counts[count]++;
|
||||
|
|
@ -480,11 +439,11 @@ static int FindHashLoc(AtomTable *atable, const char *s)
|
|||
} // FindHashLoc
|
||||
|
||||
/*
|
||||
* IncreaseHashTableSize()
|
||||
*
|
||||
*/
|
||||
* IncreaseHashTableSize()
|
||||
*
|
||||
*/
|
||||
|
||||
static int IncreaseHashTableSize(AtomTable *atable)
|
||||
int TPpContext::IncreaseHashTableSize(AtomTable *atable)
|
||||
{
|
||||
int ii, strloc, oldhashloc, value, size;
|
||||
AtomTable oldtable;
|
||||
|
|
@ -494,7 +453,7 @@ static int IncreaseHashTableSize(AtomTable *atable)
|
|||
|
||||
oldtable = *atable;
|
||||
size = oldtable.htable.size*2 + 1;
|
||||
if (!InitAtomTable(atable, size))
|
||||
if (! InitAtomTable(atable, size))
|
||||
return 0;
|
||||
|
||||
// Add all the existing values to the new atom table preserving their atom values:
|
||||
|
|
@ -508,15 +467,16 @@ static int IncreaseHashTableSize(AtomTable *atable)
|
|||
AddAtomFixed(atable, s, value);
|
||||
}
|
||||
FreeAtomTable(&oldtable);
|
||||
|
||||
return 1;
|
||||
} // IncreaseHashTableSize
|
||||
|
||||
/*
|
||||
* LookUpAddStringHash() - Lookup a string in the hash table. If it's not there, add it and
|
||||
* initialize the atom value in the hash table to 0. Return the hash table index.
|
||||
*/
|
||||
* LookUpAddStringHash() - Lookup a string in the hash table. If it's not there, add it and
|
||||
* initialize the atom value in the hash table to 0. Return the hash table index.
|
||||
*/
|
||||
|
||||
static int LookUpAddStringHash(AtomTable *atable, const char *s)
|
||||
int TPpContext::LookUpAddStringHash(AtomTable *atable, const char *s)
|
||||
{
|
||||
int hashloc, strloc;
|
||||
|
||||
|
|
@ -537,12 +497,12 @@ static int LookUpAddStringHash(AtomTable *atable, const char *s)
|
|||
} // LookUpAddStringHash
|
||||
|
||||
/*
|
||||
* LookUpAddString() - Lookup a string in the hash table. If it's not there, add it and
|
||||
* initialize the atom value in the hash table to the next atom number.
|
||||
* Return the atom value of string.
|
||||
*/
|
||||
* LookUpAddString() - Lookup a string in the hash table. If it's not there, add it and
|
||||
* initialize the atom value in the hash table to the next atom number.
|
||||
* Return the atom value of string.
|
||||
*/
|
||||
|
||||
int LookUpAddString(AtomTable *atable, const char *s)
|
||||
int TPpContext::LookUpAddString(AtomTable *atable, const char *s)
|
||||
{
|
||||
int hashindex, atom;
|
||||
|
||||
|
|
@ -556,11 +516,11 @@ int LookUpAddString(AtomTable *atable, const char *s)
|
|||
} // LookUpAddString
|
||||
|
||||
/*
|
||||
* GetAtomString()
|
||||
*
|
||||
*/
|
||||
* GetAtomString()
|
||||
*
|
||||
*/
|
||||
|
||||
const char *GetAtomString(AtomTable *atable, int atom)
|
||||
const char *TPpContext::GetAtomString(AtomTable *atable, int atom)
|
||||
{
|
||||
int soffset;
|
||||
|
||||
|
|
@ -585,38 +545,35 @@ const char *GetAtomString(AtomTable *atable, int atom)
|
|||
} // GetAtomString
|
||||
|
||||
/*
|
||||
* GetReversedAtom()
|
||||
*
|
||||
*/
|
||||
* GetReversedAtom()
|
||||
*
|
||||
*/
|
||||
|
||||
int GetReversedAtom(AtomTable *atable, int atom)
|
||||
int TPpContext::GetReversedAtom(TPpContext::AtomTable *atable, int atom)
|
||||
{
|
||||
if (atom > 0 && atom < atable->nextFree) {
|
||||
if (atom > 0 && atom < atable->nextFree)
|
||||
return atable->arev[atom];
|
||||
} else {
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
} // GetReversedAtom
|
||||
|
||||
/*
|
||||
* AddAtom() - Add a string to the atom, hash and string tables if it isn't already there.
|
||||
* Return it's atom index.
|
||||
*/
|
||||
* AddAtom() - Add a string to the atom, hash and string tables if it isn't already there.
|
||||
* Return it's atom index.
|
||||
*/
|
||||
|
||||
int AddAtom(AtomTable *atable, const char *s)
|
||||
int TPpContext::AddAtom(TPpContext::AtomTable *atable, const char *s)
|
||||
{
|
||||
int atom;
|
||||
|
||||
atom = LookUpAddString(atable, s);
|
||||
int atom = LookUpAddString(atable, s);
|
||||
return atom;
|
||||
} // AddAtom
|
||||
|
||||
/*
|
||||
* AddAtomFixed() - Add an atom to the hash and string tables if it isn't already there.
|
||||
* Assign it the atom value of "atom".
|
||||
*/
|
||||
* AddAtomFixed() - Add an atom to the hash and string tables if it isn't already there.
|
||||
* Assign it the atom value of "atom".
|
||||
*/
|
||||
|
||||
static int AddAtomFixed(AtomTable *atable, const char *s, int atom)
|
||||
int TPpContext::AddAtomFixed(AtomTable *atable, const char *s, int atom)
|
||||
{
|
||||
int hashindex, lsize;
|
||||
|
||||
|
|
@ -639,23 +596,24 @@ static int AddAtomFixed(AtomTable *atable, const char *s, int atom)
|
|||
} // AddAtomFixed
|
||||
|
||||
/*
|
||||
* InitAtomTable() - Initialize the atom table.
|
||||
*
|
||||
*/
|
||||
* InitAtomTable() - Initialize the atom table.
|
||||
*
|
||||
*/
|
||||
|
||||
int InitAtomTable(AtomTable *atable, int htsize)
|
||||
int TPpContext::InitAtomTable(AtomTable *atable, int htsize)
|
||||
{
|
||||
int ii;
|
||||
|
||||
htsize = htsize <= 0 ? INIT_HASH_TABLE_SIZE : htsize;
|
||||
if (!InitStringTable(&atable->stable))
|
||||
if (! InitStringTable(&atable->stable))
|
||||
return 0;
|
||||
if (!InitHashTable(&atable->htable, htsize))
|
||||
if (! InitHashTable(&atable->htable, htsize))
|
||||
return 0;
|
||||
|
||||
atable->nextFree = 0;
|
||||
atable->amap = NULL;
|
||||
atable->size = 0;
|
||||
atable->arev = 0;
|
||||
GrowAtomTable(atable, INIT_ATOM_TABLE_SIZE);
|
||||
if (!atable->amap)
|
||||
return 0;
|
||||
|
|
@ -669,7 +627,7 @@ int InitAtomTable(AtomTable *atable, int htsize)
|
|||
// Add single character tokens to the atom table:
|
||||
|
||||
{
|
||||
const char *s = "~!%^&*()-+=|,.<>/?;:[]{}#";
|
||||
const char *s = "~!%^&*()-+=|,.<>/?;:[]{}#";
|
||||
char t[2];
|
||||
|
||||
t[1] = '\0';
|
||||
|
|
@ -685,11 +643,6 @@ int InitAtomTable(AtomTable *atable, int htsize)
|
|||
for (ii = 0; ii < sizeof(tokens)/sizeof(tokens[0]); ii++)
|
||||
AddAtomFixed(atable, tokens[ii].str, tokens[ii].val);
|
||||
|
||||
// Add error symbol if running in error mode:
|
||||
|
||||
if (cpp->options.ErrorMode)
|
||||
AddAtomFixed(atable, "error", CPP_ERROR_SY);
|
||||
|
||||
AddAtom(atable, "<*** end fixed atoms ***>");
|
||||
|
||||
return 1;
|
||||
|
|
@ -700,48 +653,45 @@ int InitAtomTable(AtomTable *atable, int htsize)
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* PrintAtomTable()
|
||||
*
|
||||
*/
|
||||
* PrintAtomTable()
|
||||
*
|
||||
*/
|
||||
|
||||
void PrintAtomTable(AtomTable *atable)
|
||||
void TPpContext::PrintAtomTable(AtomTable *atable)
|
||||
{
|
||||
int ii;
|
||||
char str[200];
|
||||
|
||||
for (ii = 0; ii < atable->nextFree; ii++) {
|
||||
sprintf(str, "%d: \"%s\"", ii, &atable->stable.strings[atable->amap[ii]]);
|
||||
ShPpDebugLogMsg(str);
|
||||
printf(str, "%d: \"%s\"", ii, &atable->stable.strings[atable->amap[ii]]);
|
||||
}
|
||||
sprintf(str, "Hash table: size=%d, entries=%d, collisions=",
|
||||
atable->htable.size, atable->htable.entries);
|
||||
ShPpDebugLogMsg(str);
|
||||
for (ii = 0; ii < HASH_TABLE_MAX_COLLISIONS; ii++) {
|
||||
sprintf(str, " %d", atable->htable.counts[ii]);
|
||||
ShPpDebugLogMsg(str);
|
||||
printf(str, "Hash table: size=%d, entries=%d, collisions=",
|
||||
atable->htable.size, atable->htable.entries);
|
||||
for (ii = 0; ii < hashTableMaxCollisions; ii++) {
|
||||
printf(str, " %d", atable->htable.counts[ii]);
|
||||
}
|
||||
|
||||
} // PrintAtomTable
|
||||
|
||||
|
||||
/*
|
||||
* GetStringOfAtom()
|
||||
*
|
||||
*/
|
||||
* GetStringOfAtom()
|
||||
*
|
||||
*/
|
||||
|
||||
char* GetStringOfAtom(AtomTable *atable, int atom)
|
||||
char* TPpContext::GetStringOfAtom(AtomTable *atable, int atom)
|
||||
{
|
||||
char* chr_str;
|
||||
chr_str=&atable->stable.strings[atable->amap[atom]];
|
||||
return chr_str;
|
||||
char* chr_str;
|
||||
chr_str=&atable->stable.strings[atable->amap[atom]];
|
||||
return chr_str;
|
||||
} // GetStringOfAtom
|
||||
|
||||
/*
|
||||
* FreeAtomTable() - Free the atom table and associated memory
|
||||
*
|
||||
*/
|
||||
* FreeAtomTable() - Free the atom table and associated memory
|
||||
*
|
||||
*/
|
||||
|
||||
void FreeAtomTable(AtomTable *atable)
|
||||
void TPpContext::FreeAtomTable(AtomTable *atable)
|
||||
{
|
||||
FreeStringTable(&atable->stable);
|
||||
FreeHashTable(&atable->htable);
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//Copyright (C) 2013 LunarG, Inc.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -74,36 +75,52 @@ 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "preprocess.h"
|
||||
#include "parser.h"
|
||||
#include "PpContext.h"
|
||||
|
||||
// Not really atom table stuff but needed first...
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
TPpContext::TPpContext(TParseContext& pc) :
|
||||
parseContext(pc), preamble(0), strings(0), notAVersionToken(false),
|
||||
ScopeList(0), CurrentScope(0), GlobalScope(0)
|
||||
{
|
||||
InitAtomTable(&atomTable, 0);
|
||||
InitScanner(this);
|
||||
|
||||
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
|
||||
ifdepth = 0;
|
||||
for (elsetracker = 0; elsetracker < maxIfNesting; elsetracker++)
|
||||
elsedepth[elsetracker] = 0;
|
||||
elsetracker = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // !(defined(__SCANNER_H)
|
||||
TPpContext::~TPpContext()
|
||||
{
|
||||
delete [] preamble;
|
||||
FreeAtomTable(&atomTable);
|
||||
FreeScanner();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void TPpContext::setShaderStrings(char* s[], int l[], int n)
|
||||
{
|
||||
strings = s;
|
||||
lengths = l;
|
||||
numStrings = n;
|
||||
if (! preamble) {
|
||||
ScanFromString(strings[0]);
|
||||
currentString = 0;
|
||||
}
|
||||
}
|
||||
389
glslang/MachineIndependent/preprocessor/PpContext.h
Normal file
389
glslang/MachineIndependent/preprocessor/PpContext.h
Normal file
|
|
@ -0,0 +1,389 @@
|
|||
//
|
||||
//Copyright (C) 2013 LunarG, Inc.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
/****************************************************************************\
|
||||
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 PPCONTEXT_H
|
||||
#define PPCONTEXT_H
|
||||
|
||||
#include "../ParseHelper.h"
|
||||
|
||||
class TPpToken {
|
||||
public:
|
||||
static const int maxTokenLength = 1024;
|
||||
|
||||
TSourceLoc loc;
|
||||
int ppToken;
|
||||
int ival;
|
||||
double dval;
|
||||
int atom;
|
||||
char name[maxTokenLength+1];
|
||||
};
|
||||
|
||||
// This class is the result of turning a huge pile of C code communicating through globals
|
||||
// into a class. This was done to allowing instancing to attain thread safety.
|
||||
// Don't expect too much in terms of OO design.
|
||||
class TPpContext {
|
||||
public:
|
||||
TPpContext(TParseContext&);
|
||||
virtual ~TPpContext();
|
||||
|
||||
void setPreamble(const char* preamble, int length);
|
||||
void setShaderStrings(char* strings[], int lengths[], int numStrings);
|
||||
|
||||
const char* tokenize(TPpToken* yylvalpp);
|
||||
|
||||
struct InputSrc {
|
||||
struct InputSrc *prev;
|
||||
int (*scan)(TPpContext*, struct InputSrc *, TPpToken *);
|
||||
int (*getch)(TPpContext*, struct InputSrc *, TPpToken *);
|
||||
void (*ungetch)(TPpContext*, struct InputSrc *, int, TPpToken *);
|
||||
int name; /* atom */
|
||||
int line;
|
||||
};
|
||||
|
||||
struct TokenBlock {
|
||||
TokenBlock *next;
|
||||
int current;
|
||||
int count;
|
||||
int max;
|
||||
unsigned char *data;
|
||||
};
|
||||
|
||||
struct TokenStream {
|
||||
TokenStream *next;
|
||||
char *name;
|
||||
TokenBlock *head;
|
||||
TokenBlock *current;
|
||||
};
|
||||
|
||||
struct MemoryPool {
|
||||
struct chunk *next;
|
||||
uintptr_t free, end;
|
||||
size_t chunksize;
|
||||
uintptr_t alignmask;
|
||||
struct cleanup *cleanup;
|
||||
};
|
||||
|
||||
//
|
||||
// From PpAtom.cpp
|
||||
//
|
||||
struct StringTable {
|
||||
char *strings;
|
||||
int nextFree;
|
||||
int size;
|
||||
};
|
||||
typedef struct HashEntry_Rec {
|
||||
int index; // String table offset of string representation
|
||||
int value; // Atom (symbol) value
|
||||
} HashEntry;
|
||||
|
||||
static const int hashTableMaxCollisions = 3;
|
||||
|
||||
typedef struct HashTable_Rec {
|
||||
HashEntry *entry;
|
||||
int size;
|
||||
int entries;
|
||||
int counts[hashTableMaxCollisions + 1];
|
||||
} HashTable;
|
||||
struct AtomTable {
|
||||
StringTable stable; // String table.
|
||||
HashTable htable; // Hashes string to atom number and token value. Multiple strings can
|
||||
// have the same token value but each unique string is a unique atom.
|
||||
int *amap; // Maps atom value to offset in string table. Atoms all map to unique
|
||||
// strings except for some undefined values in the lower, fixed part
|
||||
// of the atom table that map to "<undefined>". The lowest 256 atoms
|
||||
// correspond to single character ASCII values except for alphanumeric
|
||||
// characters and '_', which can be other tokens. Next come the
|
||||
// language tokens with their atom values equal to the token value.
|
||||
// Then come predefined atoms, followed by user specified identifiers.
|
||||
int *arev; // Reversed atom for symbol table use.
|
||||
int nextFree;
|
||||
int size;
|
||||
};
|
||||
|
||||
struct MacroSymbol {
|
||||
int argc;
|
||||
int *args;
|
||||
TokenStream *body;
|
||||
unsigned busy:1;
|
||||
unsigned undef:1;
|
||||
};
|
||||
|
||||
typedef enum symbolkind {
|
||||
MACRO_S
|
||||
} symbolkind;
|
||||
|
||||
struct Symbol {
|
||||
Symbol *left, *right;
|
||||
Symbol *next;
|
||||
int name; // Name atom
|
||||
TSourceLoc loc;
|
||||
symbolkind kind;
|
||||
union {
|
||||
MacroSymbol mac;
|
||||
} details;
|
||||
};
|
||||
|
||||
typedef struct SymbolList {
|
||||
struct SymbolList_Rec *next;
|
||||
Symbol *symb;
|
||||
};
|
||||
|
||||
struct Scope {
|
||||
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.
|
||||
};
|
||||
|
||||
protected:
|
||||
char* preamble; // string to parse, all before line 1 of string 0, it is 0 if no preamble
|
||||
int preambleLength;
|
||||
char** strings; // official strings of shader, starting a string 0 line 1
|
||||
int* lengths;
|
||||
int numStrings; // how many official strings there are
|
||||
int currentString; // which string we're currently parsing (-1 for preamble)
|
||||
|
||||
// Scanner data:
|
||||
int mostRecentToken; // Most recent token seen by the scanner
|
||||
int previous_token;
|
||||
bool notAVersionToken; // used to make sure that #version is the first token seen in the file, if present
|
||||
TParseContext& parseContext;
|
||||
|
||||
static const int maxMacroArgs = 64;
|
||||
static const int maxIfNesting = 64;
|
||||
|
||||
int ifdepth; // current #if-#else-#endif nesting in the cpp.c file (pre-processor)
|
||||
int elsedepth[maxIfNesting]; // Keep a track of #if depth..Max allowed is 64.
|
||||
int elsetracker; // #if-#else and #endif constructs...Counter.
|
||||
const char *ErrMsg;
|
||||
|
||||
typedef struct MacroInputSrc {
|
||||
InputSrc base;
|
||||
MacroSymbol *mac;
|
||||
TokenStream **args;
|
||||
} MacroInputSrc;
|
||||
|
||||
InputSrc *currentInput;
|
||||
|
||||
//
|
||||
// from Pp.cpp
|
||||
//
|
||||
int bindAtom;
|
||||
int constAtom;
|
||||
int defaultAtom;
|
||||
int defineAtom;
|
||||
int definedAtom;
|
||||
int elseAtom;
|
||||
int elifAtom;
|
||||
int endifAtom;
|
||||
int ifAtom;
|
||||
int ifdefAtom;
|
||||
int ifndefAtom;
|
||||
int includeAtom;
|
||||
int lineAtom;
|
||||
int pragmaAtom;
|
||||
int texunitAtom;
|
||||
int undefAtom;
|
||||
int errorAtom;
|
||||
int __LINE__Atom;
|
||||
int __FILE__Atom;
|
||||
int __VERSION__Atom;
|
||||
int versionAtom;
|
||||
int coreAtom;
|
||||
int compatibilityAtom;
|
||||
int esAtom;
|
||||
int extensionAtom;
|
||||
Scope *macros;
|
||||
TSourceLoc ifloc; /* outermost #if */
|
||||
|
||||
int InitCPP();
|
||||
int FreeCPP();
|
||||
int FinalCPP();
|
||||
int CPPdefine(TPpToken * yylvalpp);
|
||||
int CPPundef(TPpToken * yylvalpp);
|
||||
int CPPelse(int matchelse, TPpToken * yylvalpp);
|
||||
int eval(int token, int prec, int *res, int *err, TPpToken * yylvalpp);
|
||||
int CPPif (TPpToken * yylvalpp);
|
||||
int CPPifdef(int defined, TPpToken * yylvalpp);
|
||||
int CPPline(TPpToken * yylvalpp);
|
||||
int CPPerror(TPpToken * yylvalpp);
|
||||
int CPPpragma(TPpToken * yylvalpp);
|
||||
int CPPversion(TPpToken * yylvalpp);
|
||||
int CPPextension(TPpToken * yylvalpp);
|
||||
int readCPPline(TPpToken * yylvalpp);
|
||||
void FreeMacro(MacroSymbol *s);
|
||||
void PushEofSrc();
|
||||
void PopEofSrc();
|
||||
TokenStream* PrescanMacroArg(TokenStream *a, TPpToken * yylvalpp);
|
||||
static int macro_scan(TPpContext* pp, InputSrc *inInput, TPpToken * yylvalpp);
|
||||
static int zero_scan(TPpContext* pp, InputSrc *inInput, TPpToken * yylvalpp);
|
||||
int MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef);
|
||||
int ChkCorrectElseNesting();
|
||||
|
||||
//
|
||||
// from PpSymbols.cpp
|
||||
//
|
||||
Scope *ScopeList;
|
||||
Scope *CurrentScope;
|
||||
Scope *GlobalScope;
|
||||
|
||||
Scope *NewScopeInPool(MemoryPool *pool);
|
||||
void PushScope(Scope *fScope);
|
||||
Scope *PopScope(void);
|
||||
Symbol *NewSymbol(TSourceLoc *loc, Scope *fScope, int name, symbolkind kind);
|
||||
void lAddToTree(Symbol **fSymbols, Symbol *fSymb, AtomTable *atable);
|
||||
Symbol *AddSymbol(TSourceLoc *loc, Scope *fScope, int atom, symbolkind kind);
|
||||
Symbol *LookUpLocalSymbol(Scope *fScope, int atom);
|
||||
Symbol *LookUpSymbol(Scope *fScope, int atom);
|
||||
|
||||
//
|
||||
// From PpTokens.cpp
|
||||
//
|
||||
char* idstr(const char *fstr, MemoryPool *pool);
|
||||
TPpContext::TokenBlock* lNewBlock(TokenStream *fTok, MemoryPool *pool);
|
||||
void lAddByte(TokenStream *fTok, unsigned char fVal);
|
||||
int lReadByte(TokenStream *pTok);
|
||||
TokenStream *NewTokenStream(const char *name, MemoryPool *pool);
|
||||
void DeleteTokenStream(TokenStream *pTok);
|
||||
void RecordToken(TokenStream *pTok, int token, TPpToken * yylvalpp);
|
||||
void RewindTokenStream(TokenStream *pTok);
|
||||
int ReadToken(TokenStream *pTok, TPpToken * yylvalpp);
|
||||
int ReadFromTokenStream(TokenStream *ts, int name, int (*final)(TPpContext *));
|
||||
void UngetToken(int token, TPpToken * yylvalpp);
|
||||
void DumpTokenStream(FILE *fp, TokenStream *s, TPpToken * yylvalpp);
|
||||
struct TokenInputSrc {
|
||||
InputSrc base;
|
||||
TokenStream *tokens;
|
||||
int (*final)(TPpContext *);
|
||||
};
|
||||
static int scan_token(TPpContext*, TokenInputSrc *in, TPpToken * yylvalpp);
|
||||
struct UngotToken {
|
||||
InputSrc base;
|
||||
int token;
|
||||
TPpToken lval;
|
||||
};
|
||||
static int reget_token(TPpContext *, UngotToken *t, TPpToken * yylvalpp);
|
||||
|
||||
//
|
||||
// From PpScanner.cpp
|
||||
//
|
||||
struct StringInputSrc {
|
||||
InputSrc base;
|
||||
char *p;
|
||||
};
|
||||
int InitScanner(TPpContext *cpp);
|
||||
int FreeScanner(void);
|
||||
static int str_getch(TPpContext*, StringInputSrc *in);
|
||||
static void str_ungetch(TPpContext*, StringInputSrc *in, int ch, TPpToken *type);
|
||||
int ScanFromString(char *s);
|
||||
int check_EOF(int token);
|
||||
int lFloatConst(char *str, int len, int ch, TPpToken * yylvalpp);
|
||||
static int byte_scan(TPpContext*, InputSrc *in, TPpToken * yylvalpp);
|
||||
|
||||
//
|
||||
// From PpAtom.cpp
|
||||
//
|
||||
AtomTable atomTable;
|
||||
int InitAtomTable(AtomTable *atable, int htsize);
|
||||
void FreeAtomTable(AtomTable *atable);
|
||||
int AddAtom(AtomTable *atable, const char *s);
|
||||
int AddAtomFixed(AtomTable *atable, const char *s, int atom);
|
||||
void PrintAtomTable(AtomTable *atable);
|
||||
int IncreaseHashTableSize(TPpContext::AtomTable *atable);
|
||||
int LookUpAddStringHash(AtomTable *atable, const char *s);
|
||||
int LookUpAddString(AtomTable *atable, const char *s);
|
||||
const char *GetAtomString(AtomTable *atable, int atom);
|
||||
int GetReversedAtom(AtomTable *atable, int atom);
|
||||
char* GetStringOfAtom(AtomTable *atable, int atom);
|
||||
|
||||
//
|
||||
// From PpMemory.cpp
|
||||
//
|
||||
MemoryPool *mem_CreatePool(size_t chunksize, unsigned align);
|
||||
void mem_FreePool(MemoryPool *);
|
||||
void *mem_Alloc(MemoryPool *p, size_t size);
|
||||
int mem_AddCleanup(MemoryPool *p, void (*fn)(void *, void*), void *arg1, void* arg2);
|
||||
};
|
||||
|
||||
#endif // PPCONTEXT_H
|
||||
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//Copyright (C) 2013 LunarG, Inc.
|
||||
//All rights reserved.
|
||||
//
|
||||
//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.
|
|||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "memory.h"
|
||||
#include "PpContext.h"
|
||||
|
||||
// default alignment and chunksize, if called with 0 arguments
|
||||
#define CHUNKSIZE (64*1024)
|
||||
|
|
@ -96,28 +97,28 @@ struct chunk {
|
|||
|
||||
struct cleanup {
|
||||
struct cleanup *next;
|
||||
void (*fn)(void *);
|
||||
void *arg;
|
||||
void (*fn)(void *, void *);
|
||||
void *arg1;
|
||||
void *arg2;
|
||||
};
|
||||
|
||||
struct MemoryPool_rec {
|
||||
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)
|
||||
TPpContext::MemoryPool* TPpContext::mem_CreatePool(size_t chunksize, unsigned int align)
|
||||
{
|
||||
MemoryPool *pool;
|
||||
|
||||
if (align == 0) align = ALIGN;
|
||||
if (chunksize == 0) chunksize = CHUNKSIZE;
|
||||
if (align & (align-1)) return 0;
|
||||
if (chunksize < sizeof(MemoryPool)) return 0;
|
||||
if (chunksize & (align-1)) return 0;
|
||||
if (!(pool = (MemoryPool*)malloc(chunksize))) return 0;
|
||||
if (align == 0)
|
||||
align = ALIGN;
|
||||
if (chunksize == 0)
|
||||
chunksize = CHUNKSIZE;
|
||||
if (align & (align-1))
|
||||
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->chunksize = chunksize;
|
||||
pool->alignmask = (uintptr_t)(align)-1;
|
||||
|
|
@ -127,13 +128,13 @@ MemoryPool *mem_CreatePool(size_t chunksize, unsigned int align)
|
|||
return pool;
|
||||
}
|
||||
|
||||
void mem_FreePool(MemoryPool *pool)
|
||||
void TPpContext::mem_FreePool(MemoryPool *pool)
|
||||
{
|
||||
struct cleanup *cleanup;
|
||||
struct chunk *p, *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) {
|
||||
next = p->next;
|
||||
|
|
@ -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;
|
||||
void *rv = (void *)pool->free;
|
||||
|
|
@ -149,8 +150,7 @@ void *mem_Alloc(MemoryPool *pool, size_t size)
|
|||
if (size <= 0) size = pool->alignmask;
|
||||
pool->free += size;
|
||||
if (pool->free > pool->end || pool->free < (uintptr_t)rv) {
|
||||
size_t minreq = (size + sizeof(struct chunk) + pool->alignmask)
|
||||
& ~pool->alignmask;
|
||||
size_t minreq = (size + sizeof(struct chunk) + pool->alignmask) & ~pool->alignmask;
|
||||
pool->free = (uintptr_t)rv;
|
||||
if (minreq >= pool->chunksize) {
|
||||
// request size is too big for the chunksize, so allocate it as
|
||||
|
|
@ -170,7 +170,8 @@ void *mem_Alloc(MemoryPool *pool, size_t size)
|
|||
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;
|
||||
|
||||
pool->free = (pool->free + sizeof(void *) - 1) & ~(sizeof(void *)-1);
|
||||
|
|
@ -178,7 +179,8 @@ int mem_AddCleanup(MemoryPool *pool, void (*fn)(void *), void *arg) {
|
|||
if (!cleanup) return -1;
|
||||
cleanup->next = pool->cleanup;
|
||||
cleanup->fn = fn;
|
||||
cleanup->arg = arg;
|
||||
cleanup->arg1 = arg1;
|
||||
cleanup->arg2 = arg2;
|
||||
pool->cleanup = cleanup;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//Copyright (C) 2013 LunarG, Inc.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -86,140 +87,104 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <string.h>
|
||||
|
||||
#if 0
|
||||
#include <ieeefp.h>
|
||||
#else
|
||||
#define isinff(x) (((*(int *)&(x) & 0x7f800000L)==0x7f800000L) && \
|
||||
((*(int *)&(x) & 0x007fffffL)==0000000000L))
|
||||
#include <ieeefp.h>
|
||||
#else
|
||||
#define isinff(x) (((*(int *)&(x) & 0x7f800000L)==0x7f800000L) && \
|
||||
((*(int *)&(x) & 0x007fffffL)==0000000000L))
|
||||
#endif
|
||||
|
||||
#include "slglobals.h"
|
||||
#include "PpContext.h"
|
||||
#include "PpTokens.h"
|
||||
|
||||
|
||||
typedef struct StringInputSrc {
|
||||
InputSrc base;
|
||||
char *p;
|
||||
} StringInputSrc;
|
||||
|
||||
static int eof_scan(InputSrc *is, yystypepp * yylvalpp)
|
||||
static int eof_scan(TPpContext*, TPpContext::InputSrc*, TPpToken*)
|
||||
{
|
||||
return EOF;
|
||||
} // eof_scan
|
||||
|
||||
static void noop(InputSrc *in, int ch, yystypepp * yylvalpp) {}
|
||||
static void noop(TPpContext*, TPpContext::InputSrc *in, int ch, TPpToken * yylvalpp) {}
|
||||
static TPpContext::InputSrc eof_inputsrc = { 0, &eof_scan, &eof_scan, &noop };
|
||||
|
||||
static InputSrc eof_inputsrc = { 0, &eof_scan, &eof_scan, &noop };
|
||||
|
||||
static int byte_scan(InputSrc *, yystypepp * yylvalpp);
|
||||
|
||||
#define EOL_SY '\n'
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define DBG_BREAKPOINT() __asm int 3
|
||||
#elif defined(_M_AMD64)
|
||||
#define DBG_BREAKPOINT() assert(!"Dbg_Breakpoint");
|
||||
#else
|
||||
#define DBG_BREAKPOINT()
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && !defined(_M_AMD64)
|
||||
__int64 RDTSC ( void ) {
|
||||
|
||||
__int64 v;
|
||||
|
||||
__asm __emit 0x0f
|
||||
__asm __emit 0x31
|
||||
__asm mov dword ptr v, eax
|
||||
__asm mov dword ptr v+4, edx
|
||||
|
||||
return v;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int InitScanner(CPPStruct *cpp)
|
||||
int TPpContext::InitScanner(TPpContext *cpp)
|
||||
{
|
||||
// Add various atoms needed by the CPP line scanner:
|
||||
if (!InitCPP())
|
||||
return 0;
|
||||
|
||||
cpp->mostRecentToken = 0;
|
||||
cpp->tokenLoc = &cpp->ltokenLoc;
|
||||
|
||||
cpp->ltokenLoc.file = 0;
|
||||
cpp->ltokenLoc.line = 0;
|
||||
|
||||
cpp->currentInput = &eof_inputsrc;
|
||||
cpp->previous_token = '\n';
|
||||
cpp->notAVersionToken = 0;
|
||||
mostRecentToken = 0;
|
||||
currentInput = &eof_inputsrc;
|
||||
previous_token = '\n';
|
||||
notAVersionToken = false;
|
||||
|
||||
return 1;
|
||||
} // InitScanner
|
||||
|
||||
int FreeScanner(void)
|
||||
int TPpContext::FreeScanner(void)
|
||||
{
|
||||
return (FreeCPP());
|
||||
}
|
||||
|
||||
/*
|
||||
* str_getch()
|
||||
* takes care of reading from multiple strings.
|
||||
* returns the next-char from the input stream.
|
||||
* returns EOF when the complete shader is parsed.
|
||||
*/
|
||||
static int str_getch(StringInputSrc *in)
|
||||
* str_getch()
|
||||
* takes care of reading from multiple strings.
|
||||
* returns the next-char from the input stream.
|
||||
* returns EOF when the complete shader is parsed.
|
||||
*/
|
||||
int TPpContext::str_getch(TPpContext* pp, StringInputSrc *in)
|
||||
{
|
||||
for(;;) {
|
||||
if (*in->p) {
|
||||
if (*in->p == '\n') {
|
||||
in->base.line++;
|
||||
IncLineNumber();
|
||||
}
|
||||
return *in->p++;
|
||||
}
|
||||
if (cpp->PaWhichStr < 0) {
|
||||
// we only parsed the built-in pre-amble; start with clean slate for user code
|
||||
cpp->notAVersionToken = 0;
|
||||
}
|
||||
if (++(cpp->PaWhichStr) < cpp->PaArgc) {
|
||||
free(in);
|
||||
SetStringNumber(cpp->PaWhichStr);
|
||||
SetLineNumber(1);
|
||||
ScanFromString(cpp->PaArgv[cpp->PaWhichStr]);
|
||||
in=(StringInputSrc*)cpp->currentInput;
|
||||
continue;
|
||||
} else {
|
||||
cpp->currentInput = in->base.prev;
|
||||
cpp->PaWhichStr=0;
|
||||
free(in);
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
for(;;) {
|
||||
if (*in->p) {
|
||||
if (*in->p == '\n') {
|
||||
in->base.line++;
|
||||
++pp->parseContext.currentLoc.line;
|
||||
}
|
||||
return *in->p++;
|
||||
}
|
||||
if (pp->currentString < 0) {
|
||||
// we only parsed the built-in pre-amble; start with clean slate for user code
|
||||
pp->notAVersionToken = false;
|
||||
}
|
||||
if (++(pp->currentString) < pp->numStrings) {
|
||||
free(in);
|
||||
pp->parseContext.currentLoc.string = pp->currentString;
|
||||
pp->parseContext.currentLoc.line = 1;
|
||||
pp->ScanFromString(pp->strings[pp->currentString]);
|
||||
in=(StringInputSrc*)pp->currentInput;
|
||||
continue;
|
||||
} else {
|
||||
pp->currentInput = in->base.prev;
|
||||
pp->currentString = 0;
|
||||
free(in);
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
} // str_getch
|
||||
|
||||
static void str_ungetch(StringInputSrc *in, int ch, yystypepp *type) {
|
||||
void TPpContext::str_ungetch(TPpContext* pp, StringInputSrc *in, int ch, TPpToken *type)
|
||||
{
|
||||
if (in->p[-1] == ch)in->p--;
|
||||
else {
|
||||
*(in->p)='\0'; //this would take care of shifting to the previous string.
|
||||
cpp->PaWhichStr--;
|
||||
}
|
||||
if (ch == '\n') {
|
||||
else {
|
||||
*(in->p)='\0'; //this would take care of shifting to the previous string.
|
||||
pp->currentString--;
|
||||
pp->parseContext.currentLoc.string = pp->currentString;
|
||||
}
|
||||
if (ch == '\n') {
|
||||
in->base.line--;
|
||||
DecLineNumber();
|
||||
--pp->parseContext.currentLoc.line;
|
||||
}
|
||||
} // str_ungetch
|
||||
|
||||
int ScanFromString(char *s)
|
||||
int TPpContext::ScanFromString(char *s)
|
||||
{
|
||||
|
||||
StringInputSrc *in = (StringInputSrc *)malloc(sizeof(StringInputSrc));
|
||||
|
||||
StringInputSrc *in = (StringInputSrc *)malloc(sizeof(StringInputSrc));
|
||||
memset(in, 0, sizeof(StringInputSrc));
|
||||
in->p = s;
|
||||
in->p = s;
|
||||
in->base.line = 1;
|
||||
in->base.scan = byte_scan;
|
||||
in->base.getch = (int (*)(InputSrc *, yystypepp *))str_getch;
|
||||
in->base.ungetch = (void (*)(InputSrc *, int, yystypepp *))str_ungetch;
|
||||
in->base.prev = cpp->currentInput;
|
||||
cpp->currentInput = &in->base;
|
||||
in->base.getch = (int (*)(TPpContext*, InputSrc *, TPpToken *))str_getch;
|
||||
in->base.ungetch = (void (*)(TPpContext*, InputSrc *, int, TPpToken *))str_ungetch;
|
||||
in->base.prev = currentInput;
|
||||
currentInput = &in->base;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -230,36 +195,36 @@ int ScanFromString(char *s)
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* lFloatConst() - Scan a single- or double-precision floating point constant. Assumes that the scanner
|
||||
* has seen at least one digit, followed by either a decimal '.' or the
|
||||
* letter 'e'.
|
||||
*/
|
||||
* lFloatConst() - Scan a single- or double-precision floating point constant. Assumes that the scanner
|
||||
* has seen at least one digit, followed by either a decimal '.' or the
|
||||
* letter 'e'.
|
||||
*/
|
||||
|
||||
static int lFloatConst(char *str, int len, int ch, yystypepp * yylvalpp)
|
||||
int TPpContext::lFloatConst(char *str, int len, int ch, TPpToken * yylvalpp)
|
||||
{
|
||||
int HasDecimal, declen, exp, ExpSign;
|
||||
int str_len;
|
||||
int isDouble = 0;
|
||||
|
||||
|
||||
HasDecimal = 0;
|
||||
declen = 0;
|
||||
exp = 0;
|
||||
|
||||
|
||||
str_len=len;
|
||||
if (ch == '.') {
|
||||
str[len++]=ch;
|
||||
str[len++]=ch;
|
||||
HasDecimal = 1;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = currentInput->getch(this, currentInput, yylvalpp);
|
||||
while (ch >= '0' && ch <= '9') {
|
||||
if (len < MAX_TOKEN_LENGTH) {
|
||||
if (len < TPpToken::maxTokenLength) {
|
||||
declen++;
|
||||
if (len > 0 || ch != '0') {
|
||||
str[len] = ch;
|
||||
len++;str_len++;
|
||||
}
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = currentInput->getch(this, currentInput, yylvalpp);
|
||||
} else {
|
||||
ShPpErrorToInfoLog("floating-point literal too long");
|
||||
parseContext.error(yylvalpp->loc,"float literal too long", "", "");
|
||||
len = 1,str_len=1;
|
||||
}
|
||||
}
|
||||
|
|
@ -268,74 +233,74 @@ static int lFloatConst(char *str, int len, int ch, yystypepp * yylvalpp)
|
|||
// Exponent:
|
||||
|
||||
if (ch == 'e' || ch == 'E') {
|
||||
if (len >= MAX_TOKEN_LENGTH) {
|
||||
ShPpErrorToInfoLog("floating-point literal too long");
|
||||
if (len >= TPpToken::maxTokenLength) {
|
||||
parseContext.error(yylvalpp->loc,"float literal too long", "", "");
|
||||
len = 1,str_len=1;
|
||||
} else {
|
||||
ExpSign = 1;
|
||||
str[len++]=ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
str[len++]=ch;
|
||||
ch = currentInput->getch(this, currentInput, yylvalpp);
|
||||
if (ch == '+') {
|
||||
str[len++]=ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = currentInput->getch(this, currentInput, yylvalpp);
|
||||
} else if (ch == '-') {
|
||||
ExpSign = -1;
|
||||
str[len++]=ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
str[len++]=ch;
|
||||
ch = currentInput->getch(this, currentInput, yylvalpp);
|
||||
}
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
while (ch >= '0' && ch <= '9') {
|
||||
if (len < MAX_TOKEN_LENGTH) {
|
||||
if (len < TPpToken::maxTokenLength) {
|
||||
exp = exp*10 + ch - '0';
|
||||
str[len++]=ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
str[len++]=ch;
|
||||
ch = currentInput->getch(this, currentInput, yylvalpp);
|
||||
} else {
|
||||
ShPpErrorToInfoLog("floating-point literal too long");
|
||||
parseContext.error(yylvalpp->loc,"float literal too long", "", "");
|
||||
len = 1,str_len=1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ShPpErrorToInfoLog("bad character in exponent");
|
||||
parseContext.error(yylvalpp->loc,"bad character in float exponent", "", "");
|
||||
}
|
||||
exp *= ExpSign;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (len == 0) {
|
||||
yylvalpp->sc_dval = 0.0;
|
||||
strcpy(str, "0.0");
|
||||
yylvalpp->dval = 0.0;
|
||||
strcpy(str, "0.0");
|
||||
} else {
|
||||
if (ch == 'l' || ch == 'L') {
|
||||
int ch2 = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
int ch2 = currentInput->getch(this, currentInput, yylvalpp);
|
||||
if (ch2 != 'f' && ch2 != 'F') {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch2, yylvalpp);
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
currentInput->ungetch(this, currentInput, ch2, yylvalpp);
|
||||
currentInput->ungetch(this, currentInput, ch, yylvalpp);
|
||||
} else {
|
||||
if (len < MAX_TOKEN_LENGTH) {
|
||||
if (len < TPpToken::maxTokenLength) {
|
||||
str[len++] = ch;
|
||||
str[len++] = ch2;
|
||||
isDouble = 1;
|
||||
} else {
|
||||
ShPpErrorToInfoLog("floating-point literal too long");
|
||||
parseContext.error(yylvalpp->loc,"float literal too long", "", "");
|
||||
len = 1,str_len=1;
|
||||
}
|
||||
}
|
||||
} else if (ch == 'f' || ch == 'F') {
|
||||
if (len < MAX_TOKEN_LENGTH)
|
||||
if (len < TPpToken::maxTokenLength)
|
||||
str[len++] = ch;
|
||||
else {
|
||||
ShPpErrorToInfoLog("floating-point literal too long");
|
||||
parseContext.error(yylvalpp->loc,"float literal too long", "", "");
|
||||
len = 1,str_len=1;
|
||||
}
|
||||
} else
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
currentInput->ungetch(this, currentInput, ch, yylvalpp);
|
||||
|
||||
str[len]='\0';
|
||||
|
||||
yylvalpp->sc_dval = strtod(str, 0);
|
||||
|
||||
yylvalpp->dval = strtod(str, 0);
|
||||
}
|
||||
// Suffix:
|
||||
strcpy(yylvalpp->symbol_name, str);
|
||||
strcpy(yylvalpp->name, str);
|
||||
|
||||
if (isDouble)
|
||||
return CPP_DOUBLECONSTANT;
|
||||
|
|
@ -346,32 +311,31 @@ static int lFloatConst(char *str, int len, int ch, yystypepp * yylvalpp)
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////// Normal Scanner //////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
||||
|
||||
int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
|
||||
{
|
||||
char tokenText[MAX_TOKEN_LENGTH + 1];
|
||||
char tokenText[TPpToken::maxTokenLength + 1];
|
||||
int AlreadyComplained = 0;
|
||||
int len, ch, ii;
|
||||
unsigned ival = 0;
|
||||
|
||||
for (;;) {
|
||||
yylvalpp->sc_int = 0;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
|
||||
yylvalpp->ival = 0;
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
|
||||
while (ch == ' ' || ch == '\t' || ch == '\r') {
|
||||
yylvalpp->sc_int = 1;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
yylvalpp->ival = 1;
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
}
|
||||
|
||||
cpp->ltokenLoc.file = cpp->currentInput->name;
|
||||
cpp->ltokenLoc.line = cpp->currentInput->line;
|
||||
|
||||
yylvalpp->loc = pp->parseContext.currentLoc;
|
||||
len = 0;
|
||||
switch (ch) {
|
||||
default:
|
||||
return ch; // Single character token
|
||||
return ch; // Single character token
|
||||
case EOF:
|
||||
return EOF;
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E':
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E':
|
||||
case 'F': case 'G': case 'H': case 'I': case 'J':
|
||||
case 'K': case 'L': case 'M': case 'N': case 'O':
|
||||
case 'P': case 'Q': case 'R': case 'S': case 'T':
|
||||
|
|
@ -386,43 +350,43 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
|||
do {
|
||||
if (ch == '\\') {
|
||||
// escaped character
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '\r' || ch == '\n') {
|
||||
int nextch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
int nextch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '\r' && nextch == '\n')
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
else
|
||||
ch = nextch;
|
||||
} else
|
||||
ShPpErrorToInfoLog("can only escape newlines");
|
||||
} else if (len < MAX_TOKEN_LENGTH) {
|
||||
pp->parseContext.error(yylvalpp->loc,"can only escape newlines", "\\", "");
|
||||
} else if (len < TPpToken::maxTokenLength) {
|
||||
tokenText[len++] = ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
} else {
|
||||
if (! AlreadyComplained) {
|
||||
ShPpErrorToInfoLog("name too long");
|
||||
pp->parseContext.error(yylvalpp->loc,"name too long", "", "");
|
||||
AlreadyComplained = 1;
|
||||
}
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
}
|
||||
} while ((ch >= 'a' && ch <= 'z') ||
|
||||
(ch >= 'A' && ch <= 'Z') ||
|
||||
(ch >= '0' && ch <= '9') ||
|
||||
ch == '_' ||
|
||||
ch == '\\');
|
||||
(ch >= 'A' && ch <= 'Z') ||
|
||||
(ch >= '0' && ch <= '9') ||
|
||||
ch == '_' ||
|
||||
ch == '\\');
|
||||
|
||||
tokenText[len] = '\0';
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
yylvalpp->sc_ident = LookUpAddString(atable, tokenText);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
yylvalpp->atom = pp->LookUpAddString(&pp->atomTable, tokenText);
|
||||
|
||||
return CPP_IDENTIFIER;
|
||||
case '0':
|
||||
yylvalpp->symbol_name[len++] = ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
yylvalpp->name[len++] = ch;
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == 'x' || ch == 'X') {
|
||||
int uint = 0;
|
||||
yylvalpp->symbol_name[len++] = ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
yylvalpp->name[len++] = ch;
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if ((ch >= '0' && ch <= '9') ||
|
||||
(ch >= 'A' && ch <= 'F') ||
|
||||
(ch >= 'a' && ch <= 'f'))
|
||||
|
|
@ -430,7 +394,7 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
|||
ival = 0;
|
||||
do {
|
||||
if (ival <= 0x0fffffff) {
|
||||
yylvalpp->symbol_name[len++] = ch;
|
||||
yylvalpp->name[len++] = ch;
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
ii = ch - '0';
|
||||
} else if (ch >= 'A' && ch <= 'F') {
|
||||
|
|
@ -438,30 +402,30 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
|||
} else if (ch >= 'a' && ch <= 'f') {
|
||||
ii = ch - 'a' + 10;
|
||||
} else
|
||||
ShPpErrorToInfoLog("bad digit in hexidecimal literal");
|
||||
pp->parseContext.error(yylvalpp->loc,"bad digit in hexidecimal literal", "", "");
|
||||
ival = (ival << 4) | ii;
|
||||
} else {
|
||||
if (! AlreadyComplained) {
|
||||
ShPpErrorToInfoLog("hexidecimal literal too big");
|
||||
pp->parseContext.error(yylvalpp->loc,"hexidecimal literal too big literal", "", "");
|
||||
AlreadyComplained = 1;
|
||||
}
|
||||
ival = 0xffffffff;
|
||||
}
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
} while ((ch >= '0' && ch <= '9') ||
|
||||
(ch >= 'A' && ch <= 'F') ||
|
||||
(ch >= 'a' && ch <= 'f'));
|
||||
(ch >= 'A' && ch <= 'F') ||
|
||||
(ch >= 'a' && ch <= 'f'));
|
||||
} else {
|
||||
ShPpErrorToInfoLog("bad digit in hexidecimal literal");
|
||||
pp->parseContext.error(yylvalpp->loc,"bad digit in hexidecimal literal", "", "");
|
||||
}
|
||||
if (ch == 'u' || ch == 'U') {
|
||||
if (len < MAX_TOKEN_LENGTH)
|
||||
yylvalpp->symbol_name[len++] = ch;
|
||||
if (len < TPpToken::maxTokenLength)
|
||||
yylvalpp->name[len++] = ch;
|
||||
uint = 1;
|
||||
} else
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
yylvalpp->symbol_name[len] = '\0';
|
||||
yylvalpp->sc_int = (int)ival;
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
yylvalpp->name[len] = '\0';
|
||||
yylvalpp->ival = (int)ival;
|
||||
|
||||
if (uint)
|
||||
return CPP_UINTCONSTANT;
|
||||
|
|
@ -472,79 +436,79 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
|||
ival = 0;
|
||||
do {
|
||||
if (ival <= 0x1fffffff) {
|
||||
yylvalpp->symbol_name[len++] = ch;
|
||||
yylvalpp->name[len++] = ch;
|
||||
ii = ch - '0';
|
||||
ival = (ival << 3) | ii;
|
||||
} else {
|
||||
if (!AlreadyComplained) {
|
||||
ShPpErrorToInfoLog("octal literal too big");
|
||||
pp->parseContext.error(yylvalpp->loc,"octal literal too big", "", "");
|
||||
AlreadyComplained = 1;
|
||||
}
|
||||
ival = 0xffffffff;
|
||||
}
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
} while (ch >= '0' && ch <= '7');
|
||||
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E' || ch == 'F' || ch == 'l' || ch == 'L')
|
||||
return lFloatConst(yylvalpp->symbol_name, len, ch, yylvalpp);
|
||||
return pp->lFloatConst(yylvalpp->name, len, ch, yylvalpp);
|
||||
else if (ch == 'u' || ch == 'U') {
|
||||
if (len < MAX_TOKEN_LENGTH)
|
||||
yylvalpp->symbol_name[len++] = ch;
|
||||
if (len < TPpToken::maxTokenLength)
|
||||
yylvalpp->name[len++] = ch;
|
||||
uint = 1;
|
||||
} else
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
yylvalpp->symbol_name[len] = '\0';
|
||||
yylvalpp->sc_int = (int)ival;
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
yylvalpp->name[len] = '\0';
|
||||
yylvalpp->ival = (int)ival;
|
||||
|
||||
if (uint)
|
||||
return CPP_UINTCONSTANT;
|
||||
else
|
||||
return CPP_INTCONSTANT;
|
||||
} else {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
ch = '0';
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
ch = '0';
|
||||
}
|
||||
// Fall through...
|
||||
case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
do {
|
||||
if (len < MAX_TOKEN_LENGTH) {
|
||||
if (len < TPpToken::maxTokenLength) {
|
||||
if (len > 0 || ch != '0') {
|
||||
yylvalpp->symbol_name[len] = ch;
|
||||
yylvalpp->name[len] = ch;
|
||||
len++;
|
||||
}
|
||||
} else {
|
||||
if (! AlreadyComplained) {
|
||||
ShPpErrorToInfoLog("integer literal too long");
|
||||
pp->parseContext.error(yylvalpp->loc,"numeric literal too long", "", "");
|
||||
AlreadyComplained = 1;
|
||||
}
|
||||
}
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
} while (ch >= '0' && ch <= '9');
|
||||
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E' || ch == 'F' || ch == 'l' || ch == 'L') {
|
||||
return lFloatConst(yylvalpp->symbol_name, len, ch, yylvalpp);
|
||||
return pp->lFloatConst(yylvalpp->name, len, ch, yylvalpp);
|
||||
} else {
|
||||
// Finish handling signed and unsigned integers
|
||||
int numericLen = len;
|
||||
int uint = 0;
|
||||
if (ch == 'u' || ch == 'U') {
|
||||
if (len < MAX_TOKEN_LENGTH)
|
||||
yylvalpp->symbol_name[len++] = ch;
|
||||
if (len < TPpToken::maxTokenLength)
|
||||
yylvalpp->name[len++] = ch;
|
||||
uint = 1;
|
||||
} else
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
|
||||
yylvalpp->symbol_name[len] = '\0';
|
||||
yylvalpp->name[len] = '\0';
|
||||
ival = 0;
|
||||
for (ii = 0; ii < numericLen; ii++) {
|
||||
ch = yylvalpp->symbol_name[ii] - '0';
|
||||
ch = yylvalpp->name[ii] - '0';
|
||||
if ((ival > 429496729) || (ival == 429496729 && ch >= 6)) {
|
||||
ShPpErrorToInfoLog("integral literal too big");
|
||||
pp->parseContext.error(yylvalpp->loc,"numeric literal too big", "", "");
|
||||
ival = -1;
|
||||
break;
|
||||
} else
|
||||
ival = ival * 10 + ch;
|
||||
}
|
||||
yylvalpp->sc_int = (int)ival;
|
||||
yylvalpp->ival = (int)ival;
|
||||
|
||||
if (uint)
|
||||
return CPP_UINTCONSTANT;
|
||||
|
|
@ -553,112 +517,112 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
|||
}
|
||||
break;
|
||||
case '-':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '-') {
|
||||
return CPP_DEC_OP;
|
||||
} else if (ch == '=') {
|
||||
return CPP_SUB_ASSIGN;
|
||||
} else {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '-';
|
||||
}
|
||||
case '+':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '+') {
|
||||
return CPP_INC_OP;
|
||||
} else if (ch == '=') {
|
||||
return CPP_ADD_ASSIGN;
|
||||
} else {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '+';
|
||||
}
|
||||
case '*':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '=') {
|
||||
return CPP_MUL_ASSIGN;
|
||||
} else {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '*';
|
||||
}
|
||||
case '%':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '=') {
|
||||
return CPP_MOD_ASSIGN;
|
||||
} else if (ch == '>'){
|
||||
return CPP_RIGHT_BRACE;
|
||||
} else {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '%';
|
||||
}
|
||||
case ':':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '>') {
|
||||
return CPP_RIGHT_BRACKET;
|
||||
} else {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return ':';
|
||||
}
|
||||
case '^':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '^') {
|
||||
return CPP_XOR_OP;
|
||||
} else {
|
||||
if (ch == '=')
|
||||
return CPP_XOR_ASSIGN;
|
||||
else{
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
return '^';
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '^';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
case '=':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '=') {
|
||||
return CPP_EQ_OP;
|
||||
} else {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '=';
|
||||
}
|
||||
case '!':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '=') {
|
||||
return CPP_NE_OP;
|
||||
} else {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '!';
|
||||
}
|
||||
case '|':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '|') {
|
||||
return CPP_OR_OP;
|
||||
} else {
|
||||
if (ch == '=')
|
||||
return CPP_OR_ASSIGN;
|
||||
else{
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
return '|';
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '|';
|
||||
}
|
||||
}
|
||||
case '&':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '&') {
|
||||
return CPP_AND_OP;
|
||||
} else {
|
||||
if (ch == '=')
|
||||
return CPP_AND_ASSIGN;
|
||||
else{
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
return '&';
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '&';
|
||||
}
|
||||
}
|
||||
case '<':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '<') {
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
if(ch == '=')
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '=')
|
||||
return CPP_LEFT_ASSIGN;
|
||||
else{
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return CPP_LEFT_OP;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -670,159 +634,161 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
|||
else if (ch == ':')
|
||||
return CPP_LEFT_BRACKET;
|
||||
else{
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '<';
|
||||
}
|
||||
}
|
||||
}
|
||||
case '>':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '>') {
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
if(ch == '=')
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '=')
|
||||
return CPP_RIGHT_ASSIGN;
|
||||
else{
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return CPP_RIGHT_OP;
|
||||
}
|
||||
} else {
|
||||
if (ch == '=') {
|
||||
return CPP_GE_OP;
|
||||
} else {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '>';
|
||||
}
|
||||
}
|
||||
case '.':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
return lFloatConst(yylvalpp->symbol_name, 0, '.', yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return pp->lFloatConst(yylvalpp->name, 0, '.', yylvalpp);
|
||||
} else {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '.';
|
||||
}
|
||||
case '/':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '/') {
|
||||
do {
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '\\') {
|
||||
// allow an escaped newline, otherwise escapes in comments are meaningless
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '\r' || ch == '\n') {
|
||||
int nextch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
int nextch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '\r' && nextch == '\n')
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
else
|
||||
ch = nextch;
|
||||
}
|
||||
}
|
||||
} while (ch != '\n' && ch != EOF);
|
||||
if (ch == EOF)
|
||||
return -1;
|
||||
return EOF;
|
||||
return '\n';
|
||||
} else if (ch == '*') {
|
||||
int nlcount = 0;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
do {
|
||||
while (ch != '*') {
|
||||
if (ch == '\n') nlcount++;
|
||||
if (ch == '\n')
|
||||
nlcount++;
|
||||
if (ch == EOF) {
|
||||
ShPpErrorToInfoLog("EOF in comment");
|
||||
return -1;
|
||||
pp->parseContext.error(yylvalpp->loc,"EOF in comment", "comment", "");
|
||||
|
||||
return EOF;
|
||||
}
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
}
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == EOF) {
|
||||
ShPpErrorToInfoLog("EOF in comment");
|
||||
return -1;
|
||||
pp->parseContext.error(yylvalpp->loc,"EOF in comment", "comment", "");
|
||||
|
||||
return EOF;
|
||||
}
|
||||
} while (ch != '/');
|
||||
if (nlcount) {
|
||||
if (nlcount)
|
||||
return '\n';
|
||||
}
|
||||
// Go try it again...
|
||||
} else if (ch == '=') {
|
||||
return CPP_DIV_ASSIGN;
|
||||
} else {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
|
||||
return '/';
|
||||
}
|
||||
break;
|
||||
case '"':
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
while (ch != '"' && ch != '\n' && ch != EOF) {
|
||||
if (ch == '\\') {
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
if (ch == '\n' || ch == EOF) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (len < MAX_TOKEN_LENGTH) {
|
||||
if (len < TPpToken::maxTokenLength) {
|
||||
tokenText[len] = ch;
|
||||
len++;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
|
||||
} else
|
||||
break;
|
||||
};
|
||||
tokenText[len] = '\0';
|
||||
if (ch == '"') {
|
||||
yylvalpp->sc_ident = LookUpAddString(atable, tokenText);
|
||||
yylvalpp->atom = pp->LookUpAddString(&pp->atomTable, tokenText);
|
||||
return CPP_STRCONSTANT;
|
||||
} else {
|
||||
ShPpErrorToInfoLog("end of line in string");
|
||||
pp->parseContext.error(yylvalpp->loc,"end of line in string", "string", "");
|
||||
return CPP_ERROR_SY;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // byte_scan
|
||||
|
||||
const char* PpTokenize(yystypepp* yylvalpp)
|
||||
const char* TPpContext::tokenize(TPpToken* yylvalpp)
|
||||
{
|
||||
int token = '\n';
|
||||
int token = '\n';
|
||||
|
||||
for(;;) {
|
||||
|
||||
char* tokenString = 0;
|
||||
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||
token = currentInput->scan(this, currentInput, yylvalpp);
|
||||
yylvalpp->ppToken = token;
|
||||
if (check_EOF(token))
|
||||
return 0;
|
||||
if (token == '#') {
|
||||
if (cpp->previous_token == '\n'|| cpp->previous_token == 0) {
|
||||
if (previous_token == '\n' || previous_token == 0) {
|
||||
token = readCPPline(yylvalpp);
|
||||
if(check_EOF(token))
|
||||
if (check_EOF(token))
|
||||
return 0;
|
||||
continue;
|
||||
} else {
|
||||
ShPpErrorToInfoLog("preprocessor directive cannot be preceded by another token");
|
||||
parseContext.error(yylvalpp->loc,"preprocessor directive cannot be preceded by another token", "#", "");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
cpp->previous_token = token;
|
||||
previous_token = token;
|
||||
|
||||
if (token == '\n')
|
||||
continue;
|
||||
|
||||
cpp->notAVersionToken = 1;
|
||||
notAVersionToken = true;
|
||||
|
||||
// expand macros
|
||||
if (token == CPP_IDENTIFIER && MacroExpand(yylvalpp->sc_ident, yylvalpp, 0) == 1)
|
||||
if (token == CPP_IDENTIFIER && MacroExpand(yylvalpp->atom, yylvalpp, 0) == 1)
|
||||
continue;
|
||||
|
||||
if (token == CPP_IDENTIFIER)
|
||||
tokenString = GetStringOfAtom(atable, yylvalpp->sc_ident);
|
||||
tokenString = GetStringOfAtom(&atomTable, yylvalpp->atom);
|
||||
else if (token == CPP_INTCONSTANT || token == CPP_UINTCONSTANT ||
|
||||
token == CPP_FLOATCONSTANT || token == CPP_DOUBLECONSTANT)
|
||||
tokenString = yylvalpp->symbol_name;
|
||||
tokenString = yylvalpp->name;
|
||||
else
|
||||
tokenString = GetStringOfAtom(atable, token);
|
||||
tokenString = GetStringOfAtom(&atomTable, token);
|
||||
|
||||
if (tokenString) {
|
||||
if (tokenString[0] != 0)
|
||||
cpp->tokensBeforeEOF = 1;
|
||||
parseContext.tokensBeforeEOF = 1;
|
||||
|
||||
return tokenString;
|
||||
}
|
||||
|
|
@ -832,16 +798,14 @@ const char* PpTokenize(yystypepp* yylvalpp)
|
|||
} // PpTokenize
|
||||
|
||||
//Checks if the token just read is EOF or not.
|
||||
int check_EOF(int token)
|
||||
int TPpContext::check_EOF(int token)
|
||||
{
|
||||
if(token==-1){
|
||||
if(cpp->ifdepth >0){
|
||||
ShPpErrorToInfoLog("missing #endif");
|
||||
cpp->CompileError=1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
if (token == EOF) {
|
||||
if (ifdepth > 0)
|
||||
parseContext.error(parseContext.currentLoc, "missing #endif", "#if", "");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//Copyright (C) 2013 LunarG, Inc.
|
||||
//All rights reserved.
|
||||
//
|
||||
//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.
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "slglobals.h"
|
||||
#include "PpContext.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////// Symbol Table Variables: ///////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Scope *ScopeList = NULL;
|
||||
Scope *CurrentScope = NULL;
|
||||
Scope *GlobalScope = NULL;
|
||||
|
||||
static void unlinkScope(void *_scope) {
|
||||
Scope *scope = (Scope*)_scope;
|
||||
static void unlinkScope(void *_scope, void* scopeList)
|
||||
{
|
||||
TPpContext::Scope *scope = (TPpContext::Scope*)_scope;
|
||||
|
||||
if (scope->next)
|
||||
scope->next->prev = scope->prev;
|
||||
if (scope->prev)
|
||||
scope->prev->next = scope->next;
|
||||
else
|
||||
ScopeList = scope->next;
|
||||
*(TPpContext::Scope**)scopeList = scope->next;
|
||||
}
|
||||
|
||||
/*
|
||||
* NewScope()
|
||||
*
|
||||
*/
|
||||
Scope *NewScopeInPool(MemoryPool *pool)
|
||||
* NewScope()
|
||||
*
|
||||
*/
|
||||
TPpContext::Scope* TPpContext::NewScopeInPool(MemoryPool *pool)
|
||||
{
|
||||
Scope *lScope;
|
||||
|
||||
|
|
@ -117,7 +115,7 @@ Scope *NewScopeInPool(MemoryPool *pool)
|
|||
lScope->parent = NULL;
|
||||
lScope->funScope = NULL;
|
||||
lScope->symbols = NULL;
|
||||
|
||||
|
||||
lScope->level = 0;
|
||||
|
||||
lScope->programs = NULL;
|
||||
|
|
@ -125,16 +123,17 @@ Scope *NewScopeInPool(MemoryPool *pool)
|
|||
ScopeList->prev = lScope;
|
||||
lScope->prev = 0;
|
||||
ScopeList = lScope;
|
||||
mem_AddCleanup(pool, unlinkScope, lScope);
|
||||
mem_AddCleanup(pool, unlinkScope, lScope, &ScopeList);
|
||||
|
||||
return lScope;
|
||||
} // NewScope
|
||||
|
||||
/*
|
||||
* PushScope()
|
||||
*
|
||||
*/
|
||||
* PushScope()
|
||||
*
|
||||
*/
|
||||
|
||||
void PushScope(Scope *fScope)
|
||||
void TPpContext::PushScope(Scope *fScope)
|
||||
{
|
||||
Scope *lScope;
|
||||
|
||||
|
|
@ -143,9 +142,9 @@ void PushScope(Scope *fScope)
|
|||
if (fScope->level == 1) {
|
||||
if (!GlobalScope) {
|
||||
/* HACK - CTD -- if GlobalScope==NULL and level==1, we're
|
||||
* defining a function in the superglobal scope. Things
|
||||
* will break if we leave the level as 1, so we arbitrarily
|
||||
* set it to 2 */
|
||||
* defining a function in the superglobal scope. Things
|
||||
* will break if we leave the level as 1, so we arbitrarily
|
||||
* set it to 2 */
|
||||
fScope->level = 2;
|
||||
}
|
||||
}
|
||||
|
|
@ -163,11 +162,11 @@ void PushScope(Scope *fScope)
|
|||
} // PushScope
|
||||
|
||||
/*
|
||||
* PopScope()
|
||||
*
|
||||
*/
|
||||
* PopScope()
|
||||
*
|
||||
*/
|
||||
|
||||
Scope *PopScope(void)
|
||||
TPpContext::Scope* TPpContext::PopScope(void)
|
||||
{
|
||||
Scope *lScope;
|
||||
|
||||
|
|
@ -178,11 +177,11 @@ Scope *PopScope(void)
|
|||
} // 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;
|
||||
char *pch;
|
||||
|
|
@ -195,7 +194,7 @@ Symbol *NewSymbol(SourceLoc *loc, Scope *fScope, int name, symbolkind kind)
|
|||
lSymb->name = name;
|
||||
lSymb->loc = *loc;
|
||||
lSymb->kind = kind;
|
||||
|
||||
|
||||
// Clear union area:
|
||||
|
||||
pch = (char *) &lSymb->details;
|
||||
|
|
@ -205,13 +204,13 @@ Symbol *NewSymbol(SourceLoc *loc, Scope *fScope, int name, symbolkind kind)
|
|||
} // NewSymbol
|
||||
|
||||
/*
|
||||
* 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).
|
||||
*/
|
||||
* 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).
|
||||
*/
|
||||
|
||||
static void lAddToTree(Symbol **fSymbols, Symbol *fSymb)
|
||||
void TPpContext::lAddToTree(Symbol **fSymbols, Symbol *fSymb, AtomTable *atable)
|
||||
{
|
||||
Symbol *lSymb;
|
||||
TPpContext::Symbol *lSymb;
|
||||
int lrev, frev;
|
||||
|
||||
lSymb = *fSymbols;
|
||||
|
|
@ -220,7 +219,7 @@ static void lAddToTree(Symbol **fSymbols, Symbol *fSymb)
|
|||
while (lSymb) {
|
||||
lrev = GetReversedAtom(atable, lSymb->name);
|
||||
if (lrev == frev) {
|
||||
ShPpErrorToInfoLog("GetAtomString(atable, fSymb->name)");
|
||||
printf("GetAtomString(atable, fSymb->name)");
|
||||
break;
|
||||
} else {
|
||||
if (lrev > frev) {
|
||||
|
|
@ -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;
|
||||
|
||||
if (!fScope)
|
||||
fScope = CurrentScope;
|
||||
lSymb = NewSymbol(loc, fScope, atom, kind);
|
||||
lAddToTree(&fScope->symbols, lSymb);
|
||||
lAddToTree(&fScope->symbols, lSymb, &atomTable);
|
||||
return lSymb;
|
||||
} // AddSymbol
|
||||
|
||||
|
|
@ -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;
|
||||
int rname, ratom;
|
||||
|
||||
ratom = GetReversedAtom(atable, atom);
|
||||
ratom = GetReversedAtom(&atomTable, atom);
|
||||
if (!fScope)
|
||||
fScope = CurrentScope;
|
||||
lSymb = fScope->symbols;
|
||||
while (lSymb) {
|
||||
rname = GetReversedAtom(atable, lSymb->name);
|
||||
rname = GetReversedAtom(&atomTable, lSymb->name);
|
||||
if (rname == ratom) {
|
||||
return lSymb;
|
||||
} else {
|
||||
|
|
@ -297,11 +296,11 @@ Symbol *LookUpLocalSymbol(Scope *fScope, int atom)
|
|||
} // LookUpLocalSymbol
|
||||
|
||||
/*
|
||||
* LookUpSymbol()
|
||||
*
|
||||
*/
|
||||
* LookUpSymbol()
|
||||
*
|
||||
*/
|
||||
|
||||
Symbol *LookUpSymbol(Scope *fScope, int atom)
|
||||
TPpContext::Symbol* TPpContext::LookUpSymbol(Scope *fScope, int atom)
|
||||
{
|
||||
Symbol *lSymb;
|
||||
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//Copyright (C) 2013 LunarG, Inc.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -78,8 +79,8 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
// tokens.c
|
||||
//
|
||||
#ifdef _WIN32
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define snprintf sprintf_s
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define snprintf sprintf_s
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
|
@ -88,20 +89,21 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "slglobals.h"
|
||||
#include "PpContext.h"
|
||||
#include "PpTokens.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////// Preprocessor and Token Recorder and Playback: ////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* idstr()
|
||||
* Copy a string to a malloc'ed block and convert it into something suitable
|
||||
* for an ID
|
||||
*
|
||||
*/
|
||||
* idstr()
|
||||
* Copy a string to a malloc'ed block and convert it into something suitable
|
||||
* for an ID
|
||||
*
|
||||
*/
|
||||
|
||||
static char *idstr(const char *fstr, MemoryPool *pool)
|
||||
char* TPpContext::idstr(const char *fstr, MemoryPool *pool)
|
||||
{
|
||||
size_t len;
|
||||
char *str, *t;
|
||||
|
|
@ -112,7 +114,7 @@ static char *idstr(const char *fstr, MemoryPool *pool)
|
|||
str = (char *) malloc(len + 1);
|
||||
else
|
||||
str = (char *) mem_Alloc(pool, len + 1);
|
||||
|
||||
|
||||
for (f=fstr, t=str; *f; f++) {
|
||||
if (isalnum(*f)) *t++ = *f;
|
||||
else if (*f == '.' || *f == '/') *t++ = '_';
|
||||
|
|
@ -123,11 +125,11 @@ static char *idstr(const char *fstr, MemoryPool *pool)
|
|||
|
||||
|
||||
/*
|
||||
* lNewBlock()
|
||||
*
|
||||
*/
|
||||
* lNewBlock()
|
||||
*
|
||||
*/
|
||||
|
||||
static TokenBlock *lNewBlock(TokenStream *fTok, MemoryPool *pool)
|
||||
TPpContext::TokenBlock* TPpContext::lNewBlock(TokenStream *fTok, MemoryPool *pool)
|
||||
{
|
||||
TokenBlock *lBlock;
|
||||
|
||||
|
|
@ -146,15 +148,16 @@ static TokenBlock *lNewBlock(TokenStream *fTok, MemoryPool *pool)
|
|||
fTok->head = lBlock;
|
||||
}
|
||||
fTok->current = lBlock;
|
||||
|
||||
return lBlock;
|
||||
} // lNewBlock
|
||||
|
||||
/*
|
||||
* lAddByte()
|
||||
*
|
||||
*/
|
||||
* lAddByte()
|
||||
*
|
||||
*/
|
||||
|
||||
static void lAddByte(TokenStream *fTok, unsigned char fVal)
|
||||
void TPpContext::lAddByte(TokenStream *fTok, unsigned char fVal)
|
||||
{
|
||||
TokenBlock *lBlock;
|
||||
lBlock = fTok->current;
|
||||
|
|
@ -164,13 +167,12 @@ static void lAddByte(TokenStream *fTok, unsigned char fVal)
|
|||
} // lAddByte
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* lReadByte() - Get the next byte from a stream.
|
||||
*
|
||||
*/
|
||||
* lReadByte() - Get the next byte from a stream.
|
||||
*
|
||||
*/
|
||||
|
||||
static int lReadByte(TokenStream *pTok)
|
||||
int TPpContext::lReadByte(TokenStream *pTok)
|
||||
{
|
||||
TokenBlock *lBlock;
|
||||
int lval = -1;
|
||||
|
|
@ -192,11 +194,11 @@ static int lReadByte(TokenStream *pTok)
|
|||
/////////////////////////////////////// Global Functions://////////////////////////////////////
|
||||
|
||||
/*
|
||||
* NewTokenStream()
|
||||
*
|
||||
*/
|
||||
* NewTokenStream()
|
||||
*
|
||||
*/
|
||||
|
||||
TokenStream *NewTokenStream(const char *name, MemoryPool *pool)
|
||||
TPpContext::TokenStream* TPpContext::NewTokenStream(const char *name, MemoryPool *pool)
|
||||
{
|
||||
TokenStream *pTok;
|
||||
|
||||
|
|
@ -213,11 +215,11 @@ TokenStream *NewTokenStream(const char *name, MemoryPool *pool)
|
|||
} // NewTokenStream
|
||||
|
||||
/*
|
||||
* DeleteTokenStream()
|
||||
*
|
||||
*/
|
||||
* DeleteTokenStream()
|
||||
*
|
||||
*/
|
||||
|
||||
void DeleteTokenStream(TokenStream *pTok)
|
||||
void TPpContext::DeleteTokenStream(TokenStream *pTok)
|
||||
{
|
||||
TokenBlock *pBlock, *nBlock;
|
||||
|
||||
|
|
@ -235,11 +237,11 @@ void DeleteTokenStream(TokenStream *pTok)
|
|||
} // DeleteTokenStream
|
||||
|
||||
/*
|
||||
* RecordToken() - Add a token to the end of a list for later playback or printout.
|
||||
*
|
||||
*/
|
||||
* RecordToken() - Add a token to the end of a list for later playback or printout.
|
||||
*
|
||||
*/
|
||||
|
||||
void RecordToken(TokenStream *pTok, int token, yystypepp * yylvalpp)
|
||||
void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken * yylvalpp)
|
||||
{
|
||||
const char *s;
|
||||
char *str = NULL;
|
||||
|
|
@ -252,7 +254,7 @@ void RecordToken(TokenStream *pTok, int token, yystypepp * yylvalpp)
|
|||
case CPP_IDENTIFIER:
|
||||
case CPP_TYPEIDENTIFIER:
|
||||
case CPP_STRCONSTANT:
|
||||
s = GetAtomString(atable, yylvalpp->sc_ident);
|
||||
s = GetAtomString(&atomTable, yylvalpp->atom);
|
||||
while (*s)
|
||||
lAddByte(pTok, (unsigned char) *s++);
|
||||
lAddByte(pTok, 0);
|
||||
|
|
@ -261,26 +263,26 @@ void RecordToken(TokenStream *pTok, int token, yystypepp * yylvalpp)
|
|||
case CPP_UINTCONSTANT:
|
||||
case CPP_FLOATCONSTANT:
|
||||
case CPP_DOUBLECONSTANT:
|
||||
str = yylvalpp->symbol_name;
|
||||
while (*str){
|
||||
str = yylvalpp->name;
|
||||
while (*str){
|
||||
lAddByte(pTok, (unsigned char) *str);
|
||||
str++;
|
||||
}
|
||||
lAddByte(pTok, 0);
|
||||
break;
|
||||
}
|
||||
lAddByte(pTok, 0);
|
||||
break;
|
||||
case '(':
|
||||
lAddByte(pTok, (unsigned char)(yylvalpp->sc_int ? 1 : 0));
|
||||
lAddByte(pTok, (unsigned char)(yylvalpp->ival ? 1 : 0));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} // RecordToken
|
||||
|
||||
/*
|
||||
* RewindTokenStream() - Reset a token stream in preperation for reading.
|
||||
*
|
||||
*/
|
||||
* RewindTokenStream() - Reset a token stream in preperation for reading.
|
||||
*
|
||||
*/
|
||||
|
||||
void RewindTokenStream(TokenStream *pTok)
|
||||
void TPpContext::RewindTokenStream(TokenStream *pTok)
|
||||
{
|
||||
if (pTok->head) {
|
||||
pTok->current = pTok->head;
|
||||
|
|
@ -289,19 +291,20 @@ void RewindTokenStream(TokenStream *pTok)
|
|||
} // RewindTokenStream
|
||||
|
||||
/*
|
||||
* ReadToken() - Read the next token from a stream.
|
||||
*
|
||||
*/
|
||||
* ReadToken() - Read the next token from a stream.
|
||||
*
|
||||
*/
|
||||
|
||||
int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
|
||||
int TPpContext::ReadToken(TokenStream *pTok, TPpToken * yylvalpp)
|
||||
{
|
||||
//TODO: PP: why is this different than byte_scan
|
||||
|
||||
char tokenText[MAX_TOKEN_LENGTH + 1];
|
||||
char tokenText[TPpToken::maxTokenLength + 1];
|
||||
int ltoken, len;
|
||||
char ch;
|
||||
|
||||
ltoken = lReadByte(pTok);
|
||||
yylvalpp->loc = parseContext.currentLoc;
|
||||
if (ltoken >= 0) {
|
||||
if (ltoken > 127)
|
||||
ltoken += 128;
|
||||
|
|
@ -311,35 +314,35 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
|
|||
len = 0;
|
||||
ch = lReadByte(pTok);
|
||||
while ((ch >= 'a' && ch <= 'z') ||
|
||||
(ch >= 'A' && ch <= 'Z') ||
|
||||
(ch >= '0' && ch <= '9') ||
|
||||
ch == '_')
|
||||
(ch >= 'A' && ch <= 'Z') ||
|
||||
(ch >= '0' && ch <= '9') ||
|
||||
ch == '_')
|
||||
{
|
||||
if (len < MAX_TOKEN_LENGTH) {
|
||||
if (len < TPpToken::maxTokenLength) {
|
||||
tokenText[len] = ch;
|
||||
len++;
|
||||
ch = lReadByte(pTok);
|
||||
} else {
|
||||
ShPpErrorToInfoLog("token too long");
|
||||
parseContext.error(yylvalpp->loc,"name too long", "", "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
tokenText[len] = '\0';
|
||||
assert(ch == '\0');
|
||||
yylvalpp->sc_ident = LookUpAddString(atable, tokenText);
|
||||
yylvalpp->atom = LookUpAddString(&atomTable, tokenText);
|
||||
return CPP_IDENTIFIER;
|
||||
break;
|
||||
case CPP_STRCONSTANT:
|
||||
len = 0;
|
||||
while ((ch = lReadByte(pTok)) != 0) {
|
||||
if (len < MAX_TOKEN_LENGTH)
|
||||
if (len < TPpToken::maxTokenLength)
|
||||
tokenText[len++] = ch;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
tokenText[len] = 0;
|
||||
yylvalpp->sc_ident = LookUpAddString(atable, tokenText);
|
||||
yylvalpp->atom = LookUpAddString(&atomTable, tokenText);
|
||||
break;
|
||||
case CPP_FLOATCONSTANT:
|
||||
case CPP_DOUBLECONSTANT:
|
||||
|
|
@ -347,19 +350,19 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
|
|||
ch = lReadByte(pTok);
|
||||
while ((ch >= '0' && ch <= '9') || ch=='e' || ch=='E' || ch=='.' || ch=='+' || ch=='-' || ch=='l' || ch=='L' || ch=='f'|| ch=='F')
|
||||
{
|
||||
if (len < MAX_TOKEN_LENGTH) {
|
||||
if (len < TPpToken::maxTokenLength) {
|
||||
tokenText[len] = ch;
|
||||
len++;
|
||||
ch = lReadByte(pTok);
|
||||
} else {
|
||||
ShPpErrorToInfoLog("token too long");
|
||||
parseContext.error(yylvalpp->loc,"float literal too long", "", "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
tokenText[len] = '\0';
|
||||
assert(ch == '\0');
|
||||
strcpy(yylvalpp->symbol_name, tokenText);
|
||||
yylvalpp->sc_dval = atof(yylvalpp->symbol_name);
|
||||
strcpy(yylvalpp->name, tokenText);
|
||||
yylvalpp->dval = atof(yylvalpp->name);
|
||||
break;
|
||||
case CPP_INTCONSTANT:
|
||||
case CPP_UINTCONSTANT:
|
||||
|
|
@ -367,102 +370,94 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
|
|||
ch = lReadByte(pTok);
|
||||
while ((ch >= '0' && ch <= '9') || ch == 'u' || ch == 'U')
|
||||
{
|
||||
if (len < MAX_TOKEN_LENGTH) {
|
||||
if (len < TPpToken::maxTokenLength) {
|
||||
tokenText[len] = ch;
|
||||
len++;
|
||||
ch = lReadByte(pTok);
|
||||
} else {
|
||||
ShPpErrorToInfoLog("token too long");
|
||||
parseContext.error(yylvalpp->loc,"integer literal too long", "", "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
tokenText[len] = '\0';
|
||||
assert(ch == '\0');
|
||||
strcpy(yylvalpp->symbol_name,tokenText);
|
||||
yylvalpp->sc_int = atoi(yylvalpp->symbol_name);
|
||||
strcpy(yylvalpp->name,tokenText);
|
||||
yylvalpp->ival = atoi(yylvalpp->name);
|
||||
break;
|
||||
case '(':
|
||||
yylvalpp->sc_int = lReadByte(pTok);
|
||||
yylvalpp->ival = lReadByte(pTok);
|
||||
break;
|
||||
}
|
||||
return ltoken;
|
||||
}
|
||||
return EOF_SY;
|
||||
return EOF;
|
||||
} // ReadToken
|
||||
|
||||
typedef struct TokenInputSrc {
|
||||
InputSrc base;
|
||||
TokenStream *tokens;
|
||||
int (*final)(CPPStruct *);
|
||||
} TokenInputSrc;
|
||||
|
||||
static int scan_token(TokenInputSrc *in, yystypepp * yylvalpp)
|
||||
int TPpContext::scan_token(TPpContext* pp, TokenInputSrc *in, TPpToken * yylvalpp)
|
||||
{
|
||||
int token = ReadToken(in->tokens, yylvalpp);
|
||||
int (*final)(CPPStruct *);
|
||||
cpp->tokenLoc->file = cpp->currentInput->name;
|
||||
cpp->tokenLoc->line = cpp->currentInput->line;
|
||||
int token = pp->ReadToken(in->tokens, yylvalpp);
|
||||
int (*final)(TPpContext *);
|
||||
yylvalpp->loc.string = pp->currentInput->name;
|
||||
yylvalpp->loc.line = pp->currentInput->line;
|
||||
if (token == '\n') {
|
||||
in->base.line++;
|
||||
return token;
|
||||
}
|
||||
if (token > 0) return token;
|
||||
cpp->currentInput = in->base.prev;
|
||||
if (token > 0)
|
||||
return token;
|
||||
pp->currentInput = in->base.prev;
|
||||
final = in->final;
|
||||
free(in);
|
||||
if (final && !final(cpp)) return -1;
|
||||
return cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||
if (final && !final(pp))
|
||||
return -1;
|
||||
|
||||
return pp->currentInput->scan(pp, pp->currentInput, yylvalpp);
|
||||
}
|
||||
|
||||
int ReadFromTokenStream(TokenStream *ts, int name, int (*final)(CPPStruct *))
|
||||
int TPpContext::ReadFromTokenStream(TokenStream *ts, int name, int (*final)(TPpContext *))
|
||||
{
|
||||
TokenInputSrc *in = (TokenInputSrc *) malloc(sizeof(TokenInputSrc));
|
||||
memset(in, 0, sizeof(TokenInputSrc));
|
||||
in->base.name = name;
|
||||
in->base.prev = cpp->currentInput;
|
||||
in->base.scan = (int (*)(InputSrc *, yystypepp *))scan_token;
|
||||
in->base.prev = currentInput;
|
||||
in->base.scan = (int (*)(TPpContext*, InputSrc*, TPpToken*))scan_token;
|
||||
in->base.line = 1;
|
||||
in->tokens = ts;
|
||||
in->final = final;
|
||||
RewindTokenStream(ts);
|
||||
cpp->currentInput = &in->base;
|
||||
currentInput = &in->base;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
typedef struct UngotToken {
|
||||
InputSrc base;
|
||||
int token;
|
||||
yystypepp lval;
|
||||
} UngotToken;
|
||||
|
||||
static int reget_token(UngotToken *t, yystypepp * yylvalpp)
|
||||
int TPpContext::reget_token(TPpContext* pp, UngotToken *t, TPpToken * yylvalpp)
|
||||
{
|
||||
int token = t->token;
|
||||
*yylvalpp = t->lval;
|
||||
cpp->currentInput = t->base.prev;
|
||||
pp->currentInput = t->base.prev;
|
||||
free(t);
|
||||
return token;
|
||||
}
|
||||
|
||||
typedef int (*scanFnPtr_t)(struct InputSrc *, yystypepp *);
|
||||
typedef int (*scanFnPtr_t);
|
||||
|
||||
void UngetToken(int token, yystypepp * yylvalpp) {
|
||||
void TPpContext::UngetToken(int token, TPpToken * yylvalpp)
|
||||
{
|
||||
UngotToken *t = (UngotToken *) malloc(sizeof(UngotToken));
|
||||
memset(t, 0, sizeof(UngotToken));
|
||||
t->token = token;
|
||||
t->lval = *yylvalpp;
|
||||
t->base.scan = (scanFnPtr_t)reget_token;
|
||||
t->base.prev = cpp->currentInput;
|
||||
t->base.name = cpp->currentInput->name;
|
||||
t->base.line = cpp->currentInput->line;
|
||||
cpp->currentInput = &t->base;
|
||||
t->base.scan = (int(*)(TPpContext*, struct InputSrc *, TPpToken *))reget_token;
|
||||
t->base.prev = currentInput;
|
||||
t->base.name = currentInput->name;
|
||||
t->base.line = currentInput->line;
|
||||
currentInput = &t->base;
|
||||
}
|
||||
|
||||
|
||||
void DumpTokenStream(FILE *fp, TokenStream *s, yystypepp * yylvalpp) {
|
||||
void TPpContext::DumpTokenStream(FILE *fp, TokenStream *s, TPpToken * yylvalpp)
|
||||
{
|
||||
int token;
|
||||
const int maxSize = MAX_TOKEN_LENGTH + 5;
|
||||
char str[100];
|
||||
|
||||
if (fp == 0) fp = stdout;
|
||||
RewindTokenStream(s);
|
||||
|
|
@ -470,27 +465,26 @@ void DumpTokenStream(FILE *fp, TokenStream *s, yystypepp * yylvalpp) {
|
|||
switch (token) {
|
||||
case CPP_IDENTIFIER:
|
||||
case CPP_TYPEIDENTIFIER:
|
||||
snprintf(str, maxSize, "%s ", GetAtomString(atable, yylvalpp->sc_ident));
|
||||
printf("%s ", GetAtomString(&atomTable, yylvalpp->atom));
|
||||
break;
|
||||
case CPP_STRCONSTANT:
|
||||
snprintf(str, maxSize, "\"%s\"", GetAtomString(atable, yylvalpp->sc_ident));
|
||||
printf("\"%s\"", GetAtomString(&atomTable, yylvalpp->atom));
|
||||
break;
|
||||
case CPP_FLOATCONSTANT:
|
||||
case CPP_DOUBLECONSTANT:
|
||||
printf("%g9.6 ", yylvalpp->sc_dval);
|
||||
printf("%g9.6 ", yylvalpp->dval);
|
||||
break;
|
||||
case CPP_INTCONSTANT:
|
||||
case CPP_UINTCONSTANT:
|
||||
printf("%d ", yylvalpp->sc_int);
|
||||
printf("%d ", yylvalpp->ival);
|
||||
break;
|
||||
default:
|
||||
if (token >= 127)
|
||||
snprintf(str, maxSize, "%s ", GetAtomString(atable, token));
|
||||
printf("%s ", GetAtomString(&atomTable, token));
|
||||
else
|
||||
snprintf(str, maxSize, "%c", token);
|
||||
printf("%c", token);
|
||||
break;
|
||||
}
|
||||
ShPpDebugLogMsg(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,41 +76,42 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
\****************************************************************************/
|
||||
|
||||
#ifndef PARSER_H
|
||||
# define 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
|
||||
#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 */
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
//
|
||||
//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.
|
||||
\****************************************************************************/
|
||||
//
|
||||
// atom.h
|
||||
//
|
||||
|
||||
#if !defined(__ATOM_H)
|
||||
#define __ATOM_H 1
|
||||
|
||||
typedef struct AtomTable_Rec AtomTable;
|
||||
|
||||
extern AtomTable *atable;
|
||||
|
||||
int InitAtomTable(AtomTable *atable, int htsize);
|
||||
void FreeAtomTable(AtomTable *atable);
|
||||
int AddAtom(AtomTable *atable, const char *s);
|
||||
void PrintAtomTable(AtomTable *atable);
|
||||
int LookUpAddString(AtomTable *atable, const char *s);
|
||||
const char *GetAtomString(AtomTable *atable, int atom);
|
||||
int GetReversedAtom(AtomTable *atable, int atom);
|
||||
char* GetStringOfAtom(AtomTable *atable, int atom);
|
||||
#endif // !defined(__ATOM_H)
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,128 +0,0 @@
|
|||
//
|
||||
//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)
|
||||
|
|
@ -1,183 +0,0 @@
|
|||
//
|
||||
//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 //////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
//
|
||||
//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 __MEMORY_H
|
||||
#define __MEMORY_H
|
||||
|
||||
typedef struct MemoryPool_rec MemoryPool;
|
||||
|
||||
extern MemoryPool *mem_CreatePool(size_t chunksize, unsigned align);
|
||||
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 */
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
//
|
||||
//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
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
//
|
||||
//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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,143 +0,0 @@
|
|||
//
|
||||
//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)
|
||||
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
//
|
||||
//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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue