Removed free()-like function of delete().

git-svn-id: http://picoc.googlecode.com/svn/trunk@361 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-10-31 14:17:45 +00:00
parent 24ec7290ee
commit 03cf6dcc90

52
parse.c
View file

@ -44,7 +44,8 @@ struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueTyp
ParamParser = *Parser; ParamParser = *Parser;
Token = LexGetToken(Parser, NULL, TRUE); Token = LexGetToken(Parser, NULL, TRUE);
if (Token != TokenCloseBracket && Token != TokenEOF) if (Token != TokenCloseBracket && Token != TokenEOF)
{ /* count the number of parameters */ {
/* count the number of parameters */
ParamCount++; ParamCount++;
while ((Token = LexGetToken(Parser, NULL, TRUE)) != TokenCloseBracket && Token != TokenEOF) while ((Token = LexGetToken(Parser, NULL, TRUE)) != TokenCloseBracket && Token != TokenEOF)
{ {
@ -443,7 +444,8 @@ enum ParseResult ParseStatement(struct ParseState *Parser)
if (LexGetToken(Parser, NULL, FALSE) != TokenLeftBrace) if (LexGetToken(Parser, NULL, FALSE) != TokenLeftBrace)
ProgramFail(Parser, "'{' expected"); ProgramFail(Parser, "'{' expected");
{ /* new block so we can store parser state */ {
/* new block so we can store parser state */
enum RunMode OldMode = Parser->Mode; enum RunMode OldMode = Parser->Mode;
int OldSearchLabel = Parser->SearchLabel; int OldSearchLabel = Parser->SearchLabel;
Parser->Mode = RunModeCaseSearch; Parser->Mode = RunModeCaseSearch;
@ -517,39 +519,19 @@ enum ParseResult ParseStatement(struct ParseState *Parser)
case TokenDelete: case TokenDelete:
{ {
/* first try to parse this as "delete a pointer from an expression" */ /* try it as a function or variable name to delete */
struct ParseState PreExpression = *Parser; if (LexGetToken(Parser, &LexerValue, TRUE) != TokenIdentifier)
int WasPointer = FALSE; ProgramFail(Parser, "identifier expected");
if (ExpressionParse(Parser, &CValue)) if (Parser->Mode == RunModeRun)
{ /* found an expression */ {
if (Parser->Mode == RunModeRun) /* delete this variable or function */
{ CValue = TableDelete(&GlobalTable, LexerValue->Val->Identifier);
if (TopStackFrame->ReturnValue->Typ->Base == TypePointer)
{ /* this was a pointer to something - delete the object we're pointing to */ if (CValue == NULL)
/* XXX - now I'm having second thoughts about this */ ProgramFail(Parser, "'%s' is not defined", LexerValue->Val->Identifier);
WasPointer = TRUE;
} VariableFree(CValue);
VariableStackPop(Parser, CValue);
}
}
if (!WasPointer)
{ /* go back and try it as a function or variable name to delete */
*Parser = PreExpression;
if (LexGetToken(Parser, &LexerValue, TRUE) != TokenIdentifier)
ProgramFail(Parser, "identifier expected");
if (Parser->Mode == RunModeRun)
{ /* delete this variable or function */
CValue = TableDelete(&GlobalTable, LexerValue->Val->Identifier);
if (CValue == NULL)
ProgramFail(Parser, "'%s' is not defined", LexerValue->Val->Identifier);
VariableFree(CValue);
}
} }
break; break;
} }