Fixed a problem with passing unnamed parameters.

Fixed a problem with file reading.

git-svn-id: http://picoc.googlecode.com/svn/trunk@30 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-01-05 05:50:04 +00:00
parent ef8969d975
commit a15cf7dd36
2 changed files with 28 additions and 24 deletions

View file

@ -92,6 +92,8 @@ void ParseParameterList(struct LexState *CallLexer, struct LexState *FuncLexer,
{ {
ParseType(FuncLexer, &Typ); ParseType(FuncLexer, &Typ);
Token = LexGetToken(FuncLexer, &Identifier); Token = LexGetToken(FuncLexer, &Identifier);
if (Token != TokenComma && Token != TokenCloseBracket)
{ /* there's an identifier */
if (Token != TokenIdentifier) if (Token != TokenIdentifier)
ProgramFail(FuncLexer, "invalid parameter"); ProgramFail(FuncLexer, "invalid parameter");
@ -107,6 +109,7 @@ void ParseParameterList(struct LexState *CallLexer, struct LexState *FuncLexer,
if (Token != TokenComma && Token != TokenCloseBracket) if (Token != TokenComma && Token != TokenCloseBracket)
ProgramFail(FuncLexer, "comma expected"); ProgramFail(FuncLexer, "comma expected");
} }
}
if (ParameterUsed == 0) if (ParameterUsed == 0)
Token = LexGetPlainToken(FuncLexer); Token = LexGetPlainToken(FuncLexer);
@ -580,9 +583,9 @@ int ParseStatement(struct LexState *Lexer, int RunIt)
LexToEndOfLine(Lexer); LexToEndOfLine(Lexer);
break; break;
case TokenBreak:
case TokenSwitch: case TokenSwitch:
case TokenCase: case TokenCase:
case TokenBreak:
case TokenReturn: case TokenReturn:
case TokenDefault: case TokenDefault:
ProgramFail(Lexer, "not implemented yet"); ProgramFail(Lexer, "not implemented yet");

19
picoc.c
View file

@ -31,10 +31,11 @@ void ProgramFail(struct LexState *Lexer, const char *Message, ...)
/* read a file into memory. this is the only function using malloc(). /* read a file into memory. this is the only function using malloc().
* do it differently for embedded devices without malloc */ * do it differently for embedded devices without malloc */
char *ReadFile(const Str *FileName) Str ReadFile(const Str *FileName)
{ {
struct stat FileInfo; struct stat FileInfo;
char *Text; char *ReadText;
Str Text;
FILE *InFile; FILE *InFile;
char CFileName[PATH_MAX]; char CFileName[PATH_MAX];
@ -43,15 +44,19 @@ char *ReadFile(const Str *FileName)
if (stat(CFileName, &FileInfo)) if (stat(CFileName, &FileInfo))
Fail("can't read file %s\n", CFileName); Fail("can't read file %s\n", CFileName);
Text = malloc(FileInfo.st_size); ReadText = malloc(FileInfo.st_size);
if (ReadText == NULL)
Fail("out of memory\n");
InFile = fopen(CFileName, "r"); InFile = fopen(CFileName, "r");
if (InFile == NULL) if (InFile == NULL)
Fail("can't read file %s\n", CFileName); Fail("can't read file %s\n", CFileName);
if (fread(Text, 1, FileInfo.st_size, InFile) != FileInfo.st_size) if (fread(ReadText, 1, FileInfo.st_size, InFile) != FileInfo.st_size)
Fail("can't read file %s\n", CFileName); Fail("can't read file %s\n", CFileName);
Text.Str = ReadText;
Text.Len = FileInfo.st_size;
fclose(InFile); fclose(InFile);
return Text; return Text;
@ -60,11 +65,7 @@ char *ReadFile(const Str *FileName)
/* read and scan a file for definitions */ /* read and scan a file for definitions */
void ScanFile(const Str *FileName) void ScanFile(const Str *FileName)
{ {
char *Source; Str SourceStr = ReadFile(FileName);
Str SourceStr;
Source = ReadFile(FileName);
StrFromC(&SourceStr, Source);
Parse(FileName, &SourceStr, TRUE); Parse(FileName, &SourceStr, TRUE);
} }