From eb7010d292effbabd3303fdd6ff9591af6fecc51 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Sat, 12 Feb 2011 04:04:51 +0000 Subject: [PATCH] Now avoiding structure assignment since it seems to cause problems on blackfin processors. Urk! git-svn-id: http://picoc.googlecode.com/svn/trunk@515 21eae674-98b7-11dd-bd71-f92a316d2d60 --- expression.c | 20 ++++++++++++-------- lex.c | 2 +- parse.c | 6 ++++++ picoc.h | 1 + type.c | 14 ++++++++------ variable.c | 4 ++-- 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/expression.c b/expression.c index de8ec06..e14338f 100644 --- a/expression.c +++ b/expression.c @@ -992,8 +992,11 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) debugf("ExpressionParse():\n"); do { - struct ParseState PreState = *Parser; - enum LexToken Token = LexGetToken(Parser, &LexValue, TRUE); + struct ParseState PreState; + enum LexToken Token; + + ParserCopy(&PreState, Parser); + Token = LexGetToken(Parser, &LexValue, TRUE); if ( ( ( (int)Token > TokenComma && (int)Token <= (int)TokenOpenBracket) || (Token == TokenCloseBracket && BracketPrecedence != 0)) && (Token != TokenColon || TernaryDepth > 0) ) @@ -1057,7 +1060,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) if (BracketPrecedence == 0) { /* assume this bracket is after the end of the expression */ - *Parser = PreState; + ParserCopy(Parser, &PreState); Done = TRUE; } else @@ -1131,9 +1134,10 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) if (VariableValue->Typ->Base == TypeMacro) { /* evaluate a macro as a kind of simple subroutine */ - struct ParseState MacroParser = VariableValue->Val->MacroDef.Body; + struct ParseState MacroParser; struct Value *MacroResult; + ParserCopy(&MacroParser, &VariableValue->Val->MacroDef.Body); if (VariableValue->Val->MacroDef.NumParams != 0) ProgramFail(&MacroParser, "macro arguments missing"); @@ -1173,7 +1177,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) ProgramFail(Parser, "type not expected here"); PrefixState = FALSE; - *Parser = PreState; + ParserCopy(Parser, &PreState); TypeParse(Parser, &Typ, &Identifier); TypeValue = VariableAllocValueFromType(Parser, &TypeType, FALSE, NULL, FALSE); TypeValue->Val->Typ = Typ; @@ -1182,7 +1186,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) else { /* it isn't a token from an expression */ - *Parser = PreState; + ParserCopy(Parser, &PreState); Done = TRUE; } @@ -1286,7 +1290,7 @@ void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack if (MDef->Body.Pos == NULL) ProgramFail(Parser, "'%s' is undefined", MacroName); - memcpy((void *)&MacroParser, (void *)&MDef->Body, sizeof(struct ParseState)); + ParserCopy(&MacroParser, &MDef->Body); VariableStackFrameAdd(Parser, 0); TopStackFrame->NumParams = ArgCount; TopStackFrame->ReturnValue = ReturnValue; @@ -1387,7 +1391,7 @@ void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionSta if (FuncValue->Val->FuncDef.Body.Pos == NULL) ProgramFail(Parser, "'%s' is undefined", FuncName); - memcpy((void *)&FuncParser, (void *)&FuncValue->Val->FuncDef.Body, sizeof(struct ParseState)); + ParserCopy(&FuncParser, &FuncValue->Val->FuncDef.Body); VariableStackFrameAdd(Parser, FuncValue->Val->FuncDef.Intrinsic ? FuncValue->Val->FuncDef.NumParams : 0); TopStackFrame->NumParams = ArgCount; TopStackFrame->ReturnValue = ReturnValue; diff --git a/lex.c b/lex.c index 4ea5e18..0bceefd 100644 --- a/lex.c +++ b/lex.c @@ -769,7 +769,7 @@ void LexHashIf(struct ParseState *Parser) if (SavedValue->Typ->Base != TypeMacro) ProgramFail(Parser, "value expected"); - MacroParser = SavedValue->Val->MacroDef.Body; + ParserCopy(&MacroParser, &SavedValue->Val->MacroDef.Body); Token = LexGetRawToken(&MacroParser, &IdentValue, TRUE); } diff --git a/parse.c b/parse.c index 9d04a88..93fff49 100644 --- a/parse.c +++ b/parse.c @@ -325,6 +325,12 @@ void ParseMacroDefinition(struct ParseState *Parser) ProgramFail(Parser, "'%s' is already defined", MacroNameStr); } +/* copy the entire parser state */ +void ParserCopy(struct ParseState *To, struct ParseState *From) +{ + memcpy((void *)To, (void *)From, sizeof(*To)); +} + /* copy where we're at in the parsing */ void ParserCopyPos(struct ParseState *To, struct ParseState *From) { diff --git a/picoc.h b/picoc.h index cb93385..d67cb41 100644 --- a/picoc.h +++ b/picoc.h @@ -346,6 +346,7 @@ void Parse(const char *FileName, const char *Source, int SourceLen, int RunIt, i void ParseInteractive(); void ParseCleanup(); void ParserCopyPos(struct ParseState *To, struct ParseState *From); +void ParserCopy(struct ParseState *To, struct ParseState *From); /* expression.c */ int ExpressionParse(struct ParseState *Parser, struct Value **Result); diff --git a/type.c b/type.c index cbd46f7..19508ef 100644 --- a/type.c +++ b/type.c @@ -316,14 +316,16 @@ void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ) /* parse a type - just the basic type */ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ) { - struct ParseState Before = *Parser; + struct ParseState Before; struct Value *LexerValue; - enum LexToken Token = LexGetToken(Parser, &LexerValue, TRUE); + enum LexToken Token; int Unsigned = FALSE; struct Value *VarValue; *Typ = NULL; /* ignore leading type qualifiers */ + ParserCopy(&Before, Parser); + Token = LexGetToken(Parser, &LexerValue, TRUE); while (Token == TokenStaticType || Token == TokenRegisterType || Token == TokenExternType) Token = LexGetToken(Parser, &LexerValue, TRUE); @@ -377,7 +379,7 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ) *Typ = VarValue->Val->Typ; break; - default: *Parser = Before; return FALSE; + default: ParserCopy(Parser, &Before); return FALSE; } return TRUE; @@ -395,7 +397,7 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s while (!Done) { - Before = *Parser; + ParserCopy(&Before, Parser); Token = LexGetToken(Parser, &LexValue, TRUE); switch (Token) { @@ -423,7 +425,7 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s Done = TRUE; break; - default: *Parser = Before; Done = TRUE; break; + default: ParserCopy(Parser, &Before); Done = TRUE; break; } } @@ -459,7 +461,7 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s break; /* XXX - finish this */ #endif - default: *Parser = Before; Done = TRUE; break; + default: ParserCopy(Parser, &Before); Done = TRUE; break; } } } diff --git a/variable.c b/variable.c index a131914..07e6241 100644 --- a/variable.c +++ b/variable.c @@ -252,7 +252,7 @@ void VariableStackFrameAdd(struct ParseState *Parser, int NumParams) if (NewFrame == NULL) ProgramFail(Parser, "out of memory"); - NewFrame->ReturnParser = *Parser; + ParserCopy(&NewFrame->ReturnParser, Parser); NewFrame->Parameter = (NumParams > 0) ? ((void *)((char *)NewFrame + sizeof(struct StackFrame))) : NULL; TableInitTable(&NewFrame->LocalTable, &NewFrame->LocalHashTable[0], LOCAL_TABLE_SIZE, FALSE); NewFrame->PreviousStackFrame = TopStackFrame; @@ -265,7 +265,7 @@ void VariableStackFramePop(struct ParseState *Parser) if (TopStackFrame == NULL) ProgramFail(Parser, "stack is empty - can't go back"); - *Parser = TopStackFrame->ReturnParser; + ParserCopy(Parser, &TopStackFrame->ReturnParser); TopStackFrame = TopStackFrame->PreviousStackFrame; HeapPopStackFrame(); }