mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-09 20:10:06 +00:00
Fix a preprocessor memory leak by cleaning up some preprocessor memory management.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@24125 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
43e43ce77a
commit
e1dba1b59f
@ -1,7 +1,8 @@
|
||||
ERROR: 0:46: 'xyxwx' : illegal vector field selection
|
||||
ERROR: 0:46: 'xyxwx' : illegal vector field selection
|
||||
ERROR: 0:51: '' : missing #endif
|
||||
ERROR: 3 compilation errors. No code generated.
|
||||
ERROR: 0:66: '#define' : Macro redefined; different substitutions: BIG
|
||||
ERROR: 0:79: '' : missing #endif
|
||||
ERROR: 4 compilation errors. No code generated.
|
||||
|
||||
ERROR: node is still EOpNull!
|
||||
0:4 Sequence
|
||||
@ -65,4 +66,6 @@ ERROR: node is still EOpNull!
|
||||
0:47 3.000000
|
||||
0:? Linker Objects
|
||||
0:? 'sum' (highp float)
|
||||
0:? 'gl_VertexID' (gl_VertexId highp int)
|
||||
0:? 'gl_InstanceID' (gl_InstanceId highp int)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#version 300 es
|
||||
#define ON1
|
||||
#define ON2
|
||||
|
||||
float sum = 0.0;
|
||||
|
||||
void main()
|
||||
@ -47,5 +47,33 @@ float foo()
|
||||
return ADD(gl_Position.y, 3.0)
|
||||
}
|
||||
|
||||
#define BIG aonetuhanoethuanoenaoethu snaoetuhs onethausoentuas hnoethaueohnatuoeh santuoehsantouhe snathoensuta hsnoethuasntoe hsnuathoesnuathoenstuh nsoethantseuh toae ua \
|
||||
antoeh uantheount oentahoent uahnsoethasnutoehansteuo santhu sneoathu snoethasnut oesanthoesna thusenotha nsthasunoeth ausntehsunathoensuathoesnta uhnsoetha usntoeh uanhs unosethu \
|
||||
antoehunatoehu natoehua oentha neotuhan toehu natoehu ntahoe nutah eu natoheunathoen uasoenuasoent asntoehsan tuosnthnu aohenuath eontha untoh eunth unth anth unth nth nth nt \
|
||||
a ntoehanu tunth nsont uhansoethausn oehsanthnt heauo eanthuo sh nahnoethansu tohe sanuthoe snathuoesntha snuothe anthusonehtasuntoeh asnuthonsa teauhntoeha onetuha nth \
|
||||
anoethuan toentauh noethauntohe anuthoe nathu noethaun oethanuthoe nathuoe ntahu enotha unetha ntuhenaothu enotahun eotha ntoehu aoehuntha enotuh aonethau noethu anoethuna toheua \
|
||||
ontehanutoe hnuathoena aoteha aonetuha
|
||||
|
||||
// identical
|
||||
#define BIG aonetuhanoethuanoenaoethu snaoetuhs onethausoentuas hnoethaueohnatuoeh santuoehsantouhe snathoensuta hsnoethuasntoe hsnuathoesnuathoenstuh nsoethantseuh toae ua \
|
||||
antoeh uantheount oentahoent uahnsoethasnutoehansteuo santhu sneoathu snoethasnut oesanthoesna thusenotha nsthasunoeth ausntehsunathoensuathoesnta uhnsoetha usntoeh uanhs unosethu \
|
||||
antoehunatoehu natoehua oentha neotuhan toehu natoehu ntahoe nutah eu natoheunathoen uasoenuasoent asntoehsan tuosnthnu aohenuath eontha untoh eunth unth anth unth nth nth nt \
|
||||
a ntoehanu tunth nsont uhansoethausn oehsanthnt heauo eanthuo sh nahnoethansu tohe sanuthoe snathuoesntha snuothe anthusonehtasuntoeh asnuthonsa teauhntoeha onetuha nth \
|
||||
anoethuan toentauh noethauntohe anuthoe nathu noethaun oethanuthoe nathuoe ntahu enotha unetha ntuhenaothu enotahun eotha ntoehu aoehuntha enotuh aonethau noethu anoethuna toheua \
|
||||
ontehanutoe hnuathoena aoteha aonetuha
|
||||
|
||||
// ERROR, one character different
|
||||
#define BIG aonetuhanoethuanoenaoethu snaoetuhs onethausoentuas hnoethaueohnatuoeh santuoehsantouhe snathoensuta hsnoethuasntoe hsnuathoesnuathoenstuh nsoethantseuh toae ua \
|
||||
antoeh uantheount oentahoent uahnsoethasnutoehansteuo santhu sneoathu snoethasnut oesanthoesna thusenotha nsthasunoeth ausntehsunathoensuathoesnta uhnsoetha usntoeh uanhs unosethu \
|
||||
antoehunatoehu natoehua oentha neotuhan toehu natoehu ntahoe nutah eu natoheunathoen uasoenuasoent asntoehsan tuosnthnu aohenuath eontha untoh eunth unth anth unth nth nth nt \
|
||||
a ntoehanu tunth nsont uhansoethasn oehsanthnt heauo eanthuo sh nahnoethansu tohe sanuthoe snathuoesntha snuothe anthusonehtasuntoeh asnuthonsa teauhntoeha onetuha nth \
|
||||
anoethuan toentauh noethauntohe anuthoe nathu noethaun oethanuthoe nathuoe ntahu enotha unetha ntuhenaothu enotahun eotha ntoehu aoehuntha enotuh aonethau noethu anoethuna toheua \
|
||||
ontehanutoe hnuathoena aoteha aonetuha
|
||||
|
||||
#define BIGARGS1(aonthanotehu, bonthanotehu, conthanotehu, donthanotehu, eonthanotehu, fonthanotehu, gonthanotehu, honthanotehu, ionthanotehu, jonthanotehu, konthanotehu) jonthanotehu
|
||||
#define BIGARGS2(aonthanotehu, bonthanotehu, conthanotehu, donthanotehu, eonthanotehu, fonthanotehu, gonthanotehu, honthanotehu, ionthanotehu, jonthanotehu, konthanotehu) jonthanotehu
|
||||
#define BIGARGS3(aonthanotehu, bonthanotehu, conthanotehu, donthanotehu, eonthanotehu, fonthanotehu, gonthanotehu, honthanotehu, ionthanotehu, jonthanotehu, konthanotehu) jonthanotehu
|
||||
#define BIGARGS4(aonthanotehu, bonthanotehu, conthanotehu, donthanotehu, eonthanotehu, fonthanotehu, gonthanotehu, honthanotehu, ionthanotehu, jonthanotehu, konthanotehu) jonthanotehu
|
||||
|
||||
#if 0
|
||||
// ERROR, EOF
|
@ -90,10 +90,6 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "PpContext.h"
|
||||
#include "PpTokens.h"
|
||||
|
||||
/* Don't use memory.c's replacements, as we clean up properly here */
|
||||
#undef malloc
|
||||
#undef free
|
||||
|
||||
namespace glslang {
|
||||
|
||||
int TPpContext::InitCPP()
|
||||
@ -129,19 +125,11 @@ int TPpContext::InitCPP()
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TPpContext::FinalCPP()
|
||||
{
|
||||
mem_FreePool(pool);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TPpContext::CPPdefine(TPpToken* ppToken)
|
||||
{
|
||||
int token, atom, args[maxMacroArgs], argc;
|
||||
MacroSymbol mac;
|
||||
Symbol *symb;
|
||||
memset(&mac, 0, sizeof(mac));
|
||||
token = currentInput->scan(this, currentInput, ppToken);
|
||||
if (token != CPP_IDENTIFIER) {
|
||||
parseContext.error(ppToken->loc, "must be followed by macro name", "#define", "");
|
||||
@ -194,7 +182,7 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
||||
token = currentInput->scan(this, currentInput, ppToken);
|
||||
}
|
||||
TSourceLoc defineLoc = ppToken->loc; // because ppToken is going to go to the next line before we report errors
|
||||
mac.body = NewTokenStream(pool);
|
||||
mac.body = new TokenStream;
|
||||
while (token != '\n') {
|
||||
if (token == '\\') {
|
||||
parseContext.lineContinuationCheck(ppToken->loc);
|
||||
@ -243,6 +231,7 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
||||
} else {
|
||||
symb = AddSymbol(atom);
|
||||
}
|
||||
delete symb->mac.body;
|
||||
symb->mac = mac;
|
||||
|
||||
return '\n';
|
||||
@ -857,17 +846,12 @@ int TPpContext::readCPPline(TPpToken * ppToken)
|
||||
return token;
|
||||
}
|
||||
|
||||
void TPpContext::FreeMacro(MacroSymbol *s) {
|
||||
DeleteTokenStream(s->body);
|
||||
}
|
||||
|
||||
int eof_scan(TPpContext*, TPpContext::InputSrc* in, TPpToken* ppToken) { return -1; }
|
||||
void noop(TPpContext*, TPpContext::InputSrc* in, int ch, TPpToken* ppToken) { }
|
||||
|
||||
void TPpContext::PushEofSrc()
|
||||
{
|
||||
InputSrc *in = (InputSrc*)malloc(sizeof(InputSrc));
|
||||
memset(in, 0, sizeof(InputSrc));
|
||||
InputSrc *in = new InputSrc;
|
||||
in->scan = eof_scan;
|
||||
in->getch = eof_scan;
|
||||
in->ungetch = noop;
|
||||
@ -880,7 +864,7 @@ void TPpContext::PopEofSrc()
|
||||
if (currentInput->scan == eof_scan) {
|
||||
InputSrc *in = currentInput;
|
||||
currentInput = in->prev;
|
||||
free(in);
|
||||
delete in;
|
||||
}
|
||||
}
|
||||
|
||||
@ -896,7 +880,7 @@ TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream *a, TPpToken *
|
||||
} while (token != EOF);
|
||||
if (token == EOF)
|
||||
return a;
|
||||
n = NewTokenStream(0);
|
||||
n = new TokenStream;
|
||||
PushEofSrc();
|
||||
ReadFromTokenStream(a, 0, 0);
|
||||
while ((token = currentInput->scan(this, currentInput, ppToken)) > 0) {
|
||||
@ -905,7 +889,7 @@ TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream *a, TPpToken *
|
||||
RecordToken(n, token, ppToken);
|
||||
}
|
||||
PopEofSrc();
|
||||
DeleteTokenStream(a);
|
||||
delete a;
|
||||
|
||||
return n;
|
||||
}
|
||||
@ -917,9 +901,9 @@ TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream *a, TPpToken *
|
||||
/*
|
||||
** return the next token for a macro expansion, handling macro args
|
||||
*/
|
||||
int TPpContext::macro_scan(TPpContext* pp, TPpContext::InputSrc* inInput, TPpToken* ppToken)
|
||||
int TPpContext::macro_scan(TPpContext* pp, InputSrc* inInput, TPpToken* ppToken)
|
||||
{
|
||||
TPpContext::MacroInputSrc* in = (TPpContext::MacroInputSrc*)inInput;
|
||||
MacroInputSrc* in = (TPpContext::MacroInputSrc*)inInput;
|
||||
|
||||
int i;
|
||||
int token;
|
||||
@ -942,13 +926,8 @@ int TPpContext::macro_scan(TPpContext* pp, TPpContext::InputSrc* inInput, TPpTok
|
||||
return token;
|
||||
|
||||
in->mac->busy = 0;
|
||||
pp->currentInput = in->base.prev;
|
||||
if (in->args) {
|
||||
for (i=in->mac->argc-1; i>=0; i--)
|
||||
pp->DeleteTokenStream(in->args[i]);
|
||||
free(in->args);
|
||||
}
|
||||
free(in);
|
||||
pp->currentInput = in->prev;
|
||||
delete in;
|
||||
|
||||
return pp->currentInput->scan(pp, pp->currentInput, ppToken);
|
||||
}
|
||||
@ -962,8 +941,8 @@ int TPpContext::zero_scan(TPpContext* pp, InputSrc *inInput, TPpToken* ppToken)
|
||||
ppToken->ival = 0;
|
||||
|
||||
// pop input
|
||||
pp->currentInput = in->base.prev;
|
||||
free(in);
|
||||
pp->currentInput = in->prev;
|
||||
delete in;
|
||||
|
||||
return CPP_INTCONSTANT;
|
||||
}
|
||||
@ -1015,19 +994,18 @@ int TPpContext::MacroExpand(int atom, TPpToken* ppToken, int expandUndef)
|
||||
if ((! sym || sym->mac.undef) && ! expandUndef)
|
||||
return 0;
|
||||
|
||||
in = (MacroInputSrc*)malloc(sizeof(*in));
|
||||
memset(in, 0, sizeof(*in));
|
||||
in = new MacroInputSrc;
|
||||
|
||||
if ((! sym || sym->mac.undef) && expandUndef) {
|
||||
// push input
|
||||
in->base.scan = zero_scan;
|
||||
in->base.prev = currentInput;
|
||||
currentInput = &in->base;
|
||||
in->scan = zero_scan;
|
||||
in->prev = currentInput;
|
||||
currentInput = in;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
in->base.scan = macro_scan;
|
||||
in->scan = macro_scan;
|
||||
in->mac = &sym->mac;
|
||||
if (sym->mac.args) {
|
||||
token = currentInput->scan(this, currentInput, ppToken);
|
||||
@ -1037,9 +1015,9 @@ int TPpContext::MacroExpand(int atom, TPpToken* ppToken, int expandUndef)
|
||||
|
||||
return 0;
|
||||
}
|
||||
in->args = (TokenStream**)malloc(in->mac->argc * sizeof(TokenStream *));
|
||||
in->args.resize(in->mac->argc);
|
||||
for (i = 0; i < in->mac->argc; i++)
|
||||
in->args[i] = NewTokenStream(0);
|
||||
in->args[i] = new TokenStream;
|
||||
i = 0;
|
||||
j = 0;
|
||||
do {
|
||||
@ -1086,16 +1064,15 @@ int TPpContext::MacroExpand(int atom, TPpToken* ppToken, int expandUndef)
|
||||
}
|
||||
parseContext.error(ppToken->loc, "Too many args in Macro", "preprocessor", GetAtomString(atom));
|
||||
}
|
||||
for (i = 0; i<in->mac->argc; i++) {
|
||||
for (i = 0; i < in->mac->argc; i++)
|
||||
in->args[i] = PrescanMacroArg(in->args[i], ppToken);
|
||||
}
|
||||
}
|
||||
|
||||
/*retain the input source*/
|
||||
in->base.prev = currentInput;
|
||||
in->prev = currentInput;
|
||||
sym->mac.busy = 1;
|
||||
RewindTokenStream(sym->mac.body);
|
||||
currentInput = &in->base;
|
||||
currentInput = in;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -90,10 +90,6 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "PpContext.h"
|
||||
#include "PpTokens.h"
|
||||
|
||||
#undef malloc
|
||||
#undef realloc
|
||||
#undef free
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace glslang;
|
||||
|
@ -97,20 +97,21 @@ TPpContext::TPpContext(TParseContext& pc) :
|
||||
|
||||
TPpContext::~TPpContext()
|
||||
{
|
||||
FinalCPP();
|
||||
for (TSymbolMap::iterator it = symbols.begin(); it != symbols.end(); ++it)
|
||||
delete it->second->mac.body;
|
||||
mem_FreePool(pool);
|
||||
delete [] preamble;
|
||||
}
|
||||
|
||||
void TPpContext::setInput(TInputScanner& input, bool versionWillBeError)
|
||||
{
|
||||
StringInputSrc *in = (StringInputSrc *)malloc(sizeof(StringInputSrc));
|
||||
memset(in, 0, sizeof(StringInputSrc));
|
||||
StringInputSrc* in = new StringInputSrc;
|
||||
in->input = &input;
|
||||
in->base.scan = sourceScan;
|
||||
in->base.getch = (int (*)(TPpContext*, InputSrc *, TPpToken *))sourceGetCh;
|
||||
in->base.ungetch = (void (*)(TPpContext*, InputSrc *, int, TPpToken *))sourceUngetCh;
|
||||
in->base.prev = currentInput;
|
||||
currentInput = &in->base;
|
||||
in->scan = sourceScan;
|
||||
in->getch = (int (*)(TPpContext*, InputSrc *, TPpToken *))sourceGetCh;
|
||||
in->ungetch = (void (*)(TPpContext*, InputSrc *, int, TPpToken *))sourceUngetCh;
|
||||
in->prev = currentInput;
|
||||
currentInput = in;
|
||||
errorOnVersion = versionWillBeError;
|
||||
}
|
||||
|
||||
|
@ -126,24 +126,17 @@ public:
|
||||
|
||||
// TODO: preprocessor simplification: this should be a base class, not a set of function pointers
|
||||
struct InputSrc {
|
||||
InputSrc() : prev(0), scan(0), getch(0), ungetch(0) { }
|
||||
struct InputSrc *prev;
|
||||
int (*scan)(TPpContext*, struct InputSrc *, TPpToken *);
|
||||
int (*getch)(TPpContext*, struct InputSrc *, TPpToken *);
|
||||
void (*ungetch)(TPpContext*, struct InputSrc *, int, TPpToken *);
|
||||
};
|
||||
|
||||
struct TokenBlock {
|
||||
TokenBlock *next;
|
||||
int current;
|
||||
int count;
|
||||
int max;
|
||||
unsigned char *data;
|
||||
};
|
||||
|
||||
struct TokenStream {
|
||||
TokenStream *next;
|
||||
TokenBlock *head;
|
||||
TokenBlock *current;
|
||||
TokenStream() : current(0) { }
|
||||
TVector<unsigned char> data;
|
||||
size_t current;
|
||||
};
|
||||
|
||||
struct MemoryPool {
|
||||
@ -159,6 +152,7 @@ public:
|
||||
//
|
||||
|
||||
struct MacroSymbol {
|
||||
MacroSymbol() : argc(0), args(0), body(0), busy(0), undef(0) { }
|
||||
int argc;
|
||||
int *args;
|
||||
TokenStream *body;
|
||||
@ -201,10 +195,15 @@ protected:
|
||||
int elsetracker; // #if-#else and #endif constructs...Counter.
|
||||
const char *ErrMsg;
|
||||
|
||||
struct MacroInputSrc {
|
||||
InputSrc base;
|
||||
struct MacroInputSrc : public InputSrc {
|
||||
MacroInputSrc() : mac(0) { }
|
||||
virtual ~MacroInputSrc()
|
||||
{
|
||||
for (size_t i = 0; i < args.size(); ++i)
|
||||
delete args[i];
|
||||
}
|
||||
MacroSymbol *mac;
|
||||
TokenStream **args;
|
||||
TVector<TokenStream*> args;
|
||||
};
|
||||
|
||||
InputSrc *currentInput;
|
||||
@ -241,7 +240,6 @@ protected:
|
||||
TSourceLoc ifloc; /* outermost #if */
|
||||
|
||||
int InitCPP();
|
||||
int FinalCPP();
|
||||
int CPPdefine(TPpToken * ppToken);
|
||||
int CPPundef(TPpToken * ppToken);
|
||||
int CPPelse(int matchelse, TPpToken * ppToken);
|
||||
@ -255,7 +253,6 @@ protected:
|
||||
int CPPversion(TPpToken * ppToken);
|
||||
int CPPextension(TPpToken * ppToken);
|
||||
int readCPPline(TPpToken * ppToken);
|
||||
void FreeMacro(MacroSymbol *s);
|
||||
void PushEofSrc();
|
||||
void PopEofSrc();
|
||||
TokenStream* PrescanMacroArg(TokenStream *a, TPpToken * ppToken);
|
||||
@ -273,24 +270,19 @@ protected:
|
||||
//
|
||||
// From PpTokens.cpp
|
||||
//
|
||||
TPpContext::TokenBlock* lNewBlock(TokenStream *fTok, MemoryPool *pool);
|
||||
void lAddByte(TokenStream *fTok, unsigned char fVal);
|
||||
int lReadByte(TokenStream *pTok);
|
||||
TokenStream *NewTokenStream(MemoryPool *pool);
|
||||
void DeleteTokenStream(TokenStream *pTok);
|
||||
void RecordToken(TokenStream* pTok, int token, TPpToken* ppToken);
|
||||
void RewindTokenStream(TokenStream *pTok);
|
||||
int ReadToken(TokenStream* pTok, TPpToken* ppToken);
|
||||
int ReadFromTokenStream(TokenStream *ts, int name, int (*final)(TPpContext *));
|
||||
void UngetToken(int token, TPpToken* ppToken);
|
||||
struct TokenInputSrc {
|
||||
InputSrc base;
|
||||
struct TokenInputSrc : public InputSrc {
|
||||
TokenStream *tokens;
|
||||
int (*final)(TPpContext *);
|
||||
};
|
||||
static int scan_token(TPpContext*, TokenInputSrc *in, TPpToken * ppToken);
|
||||
struct UngotToken {
|
||||
InputSrc base;
|
||||
struct UngotToken : public InputSrc {
|
||||
int token;
|
||||
TPpToken lval;
|
||||
};
|
||||
@ -299,8 +291,7 @@ protected:
|
||||
//
|
||||
// From PpScanner.cpp
|
||||
//
|
||||
struct StringInputSrc {
|
||||
InputSrc base;
|
||||
struct StringInputSrc : public InputSrc {
|
||||
TInputScanner* input;
|
||||
};
|
||||
int InitScanner(TPpContext *cpp);
|
||||
|
@ -87,10 +87,6 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#define CHUNKSIZE (64*1024)
|
||||
#define ALIGN 8
|
||||
|
||||
// we need to call the `real' malloc and free, not our replacements
|
||||
#undef malloc
|
||||
#undef free
|
||||
|
||||
namespace glslang {
|
||||
|
||||
struct chunk {
|
||||
|
@ -110,7 +110,7 @@ int TPpContext::sourceGetCh(TPpContext* pp, StringInputSrc *in)
|
||||
int ch = in->input->get();
|
||||
|
||||
if (ch == EOF)
|
||||
free(in);
|
||||
delete in;
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
@ -96,36 +96,9 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
namespace glslang {
|
||||
|
||||
TPpContext::TokenBlock* TPpContext::lNewBlock(TokenStream *fTok, MemoryPool *pool)
|
||||
{
|
||||
TokenBlock *lBlock;
|
||||
|
||||
if (!pool)
|
||||
lBlock = (TokenBlock *) malloc(sizeof(TokenBlock) + 256);
|
||||
else
|
||||
lBlock = (TokenBlock *) mem_Alloc(pool, sizeof(TokenBlock) + 256);
|
||||
lBlock->count = 0;
|
||||
lBlock->current = 0;
|
||||
lBlock->data = (unsigned char *) lBlock + sizeof(TokenBlock);
|
||||
lBlock->max = 256;
|
||||
lBlock->next = NULL;
|
||||
if (fTok->head) {
|
||||
fTok->current->next = lBlock;
|
||||
} else {
|
||||
fTok->head = lBlock;
|
||||
}
|
||||
fTok->current = lBlock;
|
||||
|
||||
return lBlock;
|
||||
}
|
||||
|
||||
void TPpContext::lAddByte(TokenStream *fTok, unsigned char fVal)
|
||||
{
|
||||
TokenBlock *lBlock;
|
||||
lBlock = fTok->current;
|
||||
if (lBlock->count >= lBlock->max)
|
||||
lBlock = lNewBlock(fTok, 0);
|
||||
lBlock->data[lBlock->count++] = fVal;
|
||||
fTok->data.push_back(fVal);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -133,54 +106,10 @@ void TPpContext::lAddByte(TokenStream *fTok, unsigned char fVal)
|
||||
*/
|
||||
int TPpContext::lReadByte(TokenStream *pTok)
|
||||
{
|
||||
TokenBlock *lBlock;
|
||||
int lval = -1;
|
||||
|
||||
lBlock = pTok->current;
|
||||
if (lBlock) {
|
||||
if (lBlock->current >= lBlock->count) {
|
||||
lBlock = lBlock->next;
|
||||
if (lBlock)
|
||||
lBlock->current = 0;
|
||||
pTok->current = lBlock;
|
||||
}
|
||||
if (lBlock)
|
||||
lval = lBlock->data[lBlock->current++];
|
||||
}
|
||||
return lval;
|
||||
}
|
||||
|
||||
//
|
||||
// Make a token stream (used for reprocessing macros).
|
||||
//
|
||||
TPpContext::TokenStream* TPpContext::NewTokenStream(MemoryPool *pool)
|
||||
{
|
||||
TokenStream *pTok;
|
||||
|
||||
if (!pool)
|
||||
pTok = (TokenStream *) malloc(sizeof(TokenStream));
|
||||
if (pTok->current < pTok->data.size())
|
||||
return pTok->data[pTok->current++];
|
||||
else
|
||||
pTok = (TokenStream*)mem_Alloc(pool, sizeof(TokenStream));
|
||||
pTok->next = NULL;
|
||||
pTok->head = NULL;
|
||||
pTok->current = NULL;
|
||||
lNewBlock(pTok, pool);
|
||||
return pTok;
|
||||
}
|
||||
|
||||
void TPpContext::DeleteTokenStream(TokenStream *pTok)
|
||||
{
|
||||
TokenBlock *pBlock, *nBlock;
|
||||
|
||||
if (pTok) {
|
||||
pBlock = pTok->head;
|
||||
while (pBlock) {
|
||||
nBlock = pBlock->next;
|
||||
free(pBlock);
|
||||
pBlock = nBlock;
|
||||
}
|
||||
free(pTok);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -227,10 +156,12 @@ void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken* ppToken)
|
||||
*/
|
||||
void TPpContext::RewindTokenStream(TokenStream *pTok)
|
||||
{
|
||||
if (pTok->head) {
|
||||
pTok->current = pTok->head;
|
||||
pTok->current->current = 0;
|
||||
}
|
||||
pTok->current = 0;
|
||||
|
||||
//if (pTok->head) {
|
||||
// pTok->current = pTok->head;
|
||||
// pTok->current->current = 0;
|
||||
//}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -306,9 +237,9 @@ int TPpContext::scan_token(TPpContext* pp, TokenInputSrc *in, TPpToken * ppToken
|
||||
if (token > 0)
|
||||
return token;
|
||||
|
||||
pp->currentInput = in->base.prev;
|
||||
pp->currentInput = in->prev;
|
||||
final = in->final;
|
||||
free(in);
|
||||
delete in;
|
||||
if (final && !final(pp))
|
||||
return -1;
|
||||
|
||||
@ -317,14 +248,13 @@ int TPpContext::scan_token(TPpContext* pp, TokenInputSrc *in, TPpToken * ppToken
|
||||
|
||||
int TPpContext::ReadFromTokenStream(TokenStream *ts, int name, int (*final)(TPpContext *))
|
||||
{
|
||||
TokenInputSrc *in = (TokenInputSrc *) malloc(sizeof(TokenInputSrc));
|
||||
memset(in, 0, sizeof(TokenInputSrc));
|
||||
in->base.prev = currentInput;
|
||||
in->base.scan = (int (*)(TPpContext*, InputSrc*, TPpToken*))scan_token;
|
||||
TokenInputSrc* in = new TokenInputSrc;
|
||||
in->prev = currentInput;
|
||||
in->scan = (int (*)(TPpContext*, InputSrc*, TPpToken*))scan_token;
|
||||
in->tokens = ts;
|
||||
in->final = final;
|
||||
RewindTokenStream(ts);
|
||||
currentInput = &in->base;
|
||||
currentInput = in;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -333,20 +263,20 @@ int TPpContext::reget_token(TPpContext* pp, UngotToken *t, TPpToken * ppToken)
|
||||
{
|
||||
int token = t->token;
|
||||
*ppToken = t->lval;
|
||||
pp->currentInput = t->base.prev;
|
||||
free(t);
|
||||
pp->currentInput = t->prev;
|
||||
delete t;
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
void TPpContext::UngetToken(int token, TPpToken* ppToken)
|
||||
{
|
||||
UngotToken *t = (UngotToken *) malloc(sizeof(UngotToken));
|
||||
memset(t, 0, sizeof(UngotToken));
|
||||
UngotToken *t = new UngotToken;
|
||||
t->token = token;
|
||||
t->lval = *ppToken;
|
||||
t->base.scan = (int(*)(TPpContext*, struct InputSrc *, TPpToken *))reget_token;
|
||||
t->base.prev = currentInput;
|
||||
currentInput = &t->base;
|
||||
t->scan = (int(*)(TPpContext*, struct InputSrc *, TPpToken *))reget_token;
|
||||
t->prev = currentInput;
|
||||
currentInput = t;
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
|
Loading…
Reference in New Issue
Block a user