From 61174fb11537e0068fd8ac1f5b845137cdb7fedc Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Sat, 4 Apr 2009 03:11:12 +0000 Subject: [PATCH] Interactive mode error handling fixed for surveyor. All surveyor warnings fixed. git-svn-id: http://picoc.googlecode.com/svn/trunk@216 21eae674-98b7-11dd-bd71-f92a316d2d60 --- clibrary.c | 2 +- expression.c | 6 +++--- heap.c | 2 +- lex.c | 8 ++++---- parse.c | 2 +- picoc.c | 8 +++----- platform.h | 3 +++ platform_surveyor.c | 9 +++++---- table.c | 8 ++++---- type.c | 2 +- variable.c | 2 +- 11 files changed, 27 insertions(+), 25 deletions(-) diff --git a/clibrary.c b/clibrary.c index e585184..61b0f64 100644 --- a/clibrary.c +++ b/clibrary.c @@ -13,7 +13,7 @@ void LibraryInit(struct Table *GlobalTable, const char *LibraryName, struct Libr for (Count = 0; (*FuncList)[Count].Prototype != NULL; Count++) { - Tokens = LexAnalyse(IntrinsicName, (*FuncList)[Count].Prototype, strlen((*FuncList)[Count].Prototype), NULL); + Tokens = LexAnalyse(IntrinsicName, (*FuncList)[Count].Prototype, strlen((char *)(*FuncList)[Count].Prototype), NULL); LexInitParser(&Parser, Tokens, IntrinsicName, Count+1, TRUE); TypeParse(&Parser, &ReturnType, &Identifier); NewValue = ParseFunctionDefinition(&Parser, ReturnType, Identifier, TRUE); diff --git a/expression.c b/expression.c index c0d664e..4cc245b 100644 --- a/expression.c +++ b/expression.c @@ -274,7 +274,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) ProgramFail(Parser, "can't assign incompatible types"); if (TotalValue->Typ->Base != TypeArray) - memcpy(TotalValue->Val, CurrentValue->Val, TotalValue->Typ->Sizeof); + memcpy((void *)TotalValue->Val, (void *)CurrentValue->Val, TotalValue->Typ->Sizeof); else { /* array assignment */ if (TotalValue->Val->Array.Size != CurrentValue->Val->Array.Size) @@ -407,7 +407,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) case TokenAmpersand: IntResult = IntX & IntY; break; case TokenArithmeticOr: IntResult = IntX | IntY; break; case TokenArithmeticExor: IntResult = IntX ^ IntY; break; - default: break; + default: IntResult = 0; break; } TotalValue = ParsePushInt(Parser, IntResult); } @@ -954,7 +954,7 @@ void ExpressionParseFunctionCall(struct ParseState *Parser, struct Value **Resul { struct Value *FuncValue; struct Value *Param; - struct Value **ParamArray; + struct Value **ParamArray = NULL; int ArgCount; enum LexToken Token = LexGetToken(Parser, NULL, TRUE); /* open bracket */ diff --git a/heap.c b/heap.c index cd197b9..a9b1035 100644 --- a/heap.c +++ b/heap.c @@ -164,7 +164,7 @@ void *HeapAlloc(int Size) NewMem->Size = AllocSize; } - memset(&NewMem->NextFree, '\0', AllocSize-sizeof(NewMem->Size)); + memset((void *)&NewMem->NextFree, '\0', AllocSize-sizeof(NewMem->Size)); #ifdef DEBUG_HEAP printf(" = %lx\n", (unsigned long)&NewMem->NextFree); #endif diff --git a/lex.c b/lex.c index 6df74fc..32cd116 100644 --- a/lex.c +++ b/lex.c @@ -429,7 +429,7 @@ void *LexTokenise(struct LexState *Lexer, int *TokenLen) ValueSize = LexTokenSize(Token); if (ValueSize > 0) { /* store a value as well */ - memcpy(TokenPos, GotValue->Val, ValueSize); + memcpy(TokenPos, (void *)GotValue->Val, ValueSize); TokenPos += ValueSize; MemUsed += ValueSize; } @@ -567,7 +567,7 @@ enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int I default: break; } - memcpy(LexValue.Val, Parser->Pos+1, ValueSize); + memcpy((void *)LexValue.Val, (void *)Parser->Pos+1, ValueSize); LexValue.ValOnHeap = FALSE; LexValue.ValOnStack = FALSE; LexValue.IsLValue = FALSE; @@ -617,7 +617,7 @@ void *LexCopyTokens(struct ParseState *StartParser, struct ParseState *EndParser { /* non-interactive mode - copy the tokens */ MemSize = EndParser->Pos - StartParser->Pos; NewTokens = VariableAlloc(StartParser, MemSize + 1, TRUE); - memcpy(NewTokens, StartParser->Pos, MemSize); + memcpy(NewTokens, (void *)StartParser->Pos, MemSize); } else { /* we're in interactive mode - add up line by line */ @@ -628,7 +628,7 @@ void *LexCopyTokens(struct ParseState *StartParser, struct ParseState *EndParser { /* all on a single line */ MemSize = EndParser->Pos - StartParser->Pos; NewTokens = VariableAlloc(StartParser, MemSize + 1, TRUE); - memcpy(NewTokens, StartParser->Pos, MemSize); + memcpy(NewTokens, (void *)StartParser->Pos, MemSize); } else { /* it's spread across multiple lines */ diff --git a/parse.c b/parse.c index 6a253c7..a7e6696 100644 --- a/parse.c +++ b/parse.c @@ -464,7 +464,7 @@ int ParseStatement(struct ParseState *Parser) // XXX - make assignment a separate function // XXX - also arrays need cleverer assignment - memcpy(TopStackFrame->ReturnValue->Val, CValue->Val, TypeSizeValue(CValue)); + memcpy((void *)TopStackFrame->ReturnValue->Val, (void *)CValue->Val, TypeSizeValue(CValue)); Parser->Mode = RunModeReturn; } else diff --git a/picoc.c b/picoc.c index dd9cec8..867ef67 100644 --- a/picoc.c +++ b/picoc.c @@ -54,8 +54,6 @@ int main(int argc, char **argv) } #else # ifdef SURVEYOR_HOST -int errjmp[41]; - int picoc(char *SourceStr) { int ix; @@ -68,9 +66,9 @@ int picoc(char *SourceStr) printf("%s\n\r", SourceStr); // display program source printf("=====================\n"); } - errjmp[40] = 0; - setjmp(errjmp); - if (errjmp[40]) { + ExitBuf[40] = 0; + PlatformSetExitPoint(); + if (ExitBuf[40]) { printf("leaving picoC\n\r"); Cleanup(); return 1; diff --git a/platform.h b/platform.h index 1d12aa1..b91b550 100644 --- a/platform.h +++ b/platform.h @@ -70,6 +70,9 @@ extern jmp_buf ExitBuf; # define INTERACTIVE_PROMPT_LINE "- " # endif # endif + +extern int ExitBuf[]; + #endif #endif /* PLATFORM_H */ diff --git a/platform_surveyor.c b/platform_surveyor.c index e5c7796..8a1f487 100644 --- a/platform_surveyor.c +++ b/platform_surveyor.c @@ -43,12 +43,13 @@ int PlatformGetCharacter() return getch(); } -/* exit the program */ -extern int errjmp[]; +/* mark where to end the program for platforms which require this */ +int ExitBuf[41]; +/* exit the program */ void PlatformExit() { - errjmp[40] = 1; - longjmp(errjmp, 1); + ExitBuf[40] = 1; + longjmp(ExitBuf, 1); } diff --git a/table.c b/table.c index ac368a6..49ce48c 100644 --- a/table.c +++ b/table.c @@ -35,7 +35,7 @@ void TableInitTable(struct Table *Tbl, struct TableEntry **HashTable, int Size, Tbl->Size = Size; Tbl->OnHeap = OnHeap; Tbl->HashTable = HashTable; - memset(HashTable, '\0', sizeof(struct TableEntry *) * Size); + memset((void *)HashTable, '\0', sizeof(struct TableEntry *) * Size); } /* check a hash table entry for a key */ @@ -114,7 +114,7 @@ static struct TableEntry *TableSearchIdentifier(struct Table *Tbl, const char *K for (Entry = Tbl->HashTable[HashValue]; Entry != NULL; Entry = Entry->Next) { - if (strncmp(&Entry->p.Key[0], Key, Len) == 0 && Entry->p.Key[Len] == '\0') + if (strncmp(&Entry->p.Key[0], (char *)Key, Len) == 0 && Entry->p.Key[Len] == '\0') return Entry; /* found */ } @@ -136,7 +136,7 @@ char *TableSetIdentifier(struct Table *Tbl, const char *Ident, int IdentLen) if (NewEntry == NULL) ProgramFail(NULL, "out of memory"); - strncpy((char *)&NewEntry->p.Key[0], Ident, IdentLen); + strncpy((char *)&NewEntry->p.Key[0], (char *)Ident, IdentLen); NewEntry->p.Key[IdentLen] = '\0'; NewEntry->Next = Tbl->HashTable[AddAt]; Tbl->HashTable[AddAt] = NewEntry; @@ -152,7 +152,7 @@ char *TableStrRegister2(const char *Str, int Len) char *TableStrRegister(const char *Str) { - return TableStrRegister2(Str, strlen(Str)); + return TableStrRegister2(Str, strlen((char *)Str)); } /* free all the strings */ diff --git a/type.c b/type.c index 51f3309..24b3443 100644 --- a/type.c +++ b/type.c @@ -237,7 +237,7 @@ void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ) LexGetToken(Parser, NULL, TRUE); (*Typ)->Members = &GlobalTable; - memset(&InitValue, '\0', sizeof(struct Value)); + memset((void *)&InitValue, '\0', sizeof(struct Value)); InitValue.Typ = &IntType; InitValue.Val = (union AnyValue *)&EnumValue; do { diff --git a/variable.c b/variable.c index 78b639c..8490003 100644 --- a/variable.c +++ b/variable.c @@ -120,7 +120,7 @@ struct Value *VariableAllocValueAndCopy(struct ParseState *Parser, struct Value int CopySize = TypeSizeValue(FromValue); struct Value *NewValue = VariableAllocValueAndData(Parser, CopySize, FromValue->IsLValue, FromValue->LValueFrom, OnHeap); NewValue->Typ = FromValue->Typ; - memcpy(NewValue->Val, FromValue->Val, CopySize); + memcpy((void *)NewValue->Val, (void *)FromValue->Val, CopySize); return NewValue; }