From 0ac0f71fc087ef90913a5dd6c4f1f8fe28636076 Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Wed, 17 Jun 2015 04:30:27 -0500 Subject: [PATCH] proper static prototypes --- expression.c | 12 ++++-------- interpreter.h | 3 +++ lex.c | 30 ++++++++++++++++++++++++++---- parse.c | 15 +++++++++++++++ picoc.c | 2 +- platform.c | 4 ++++ table.c | 13 ++++++++++--- type.c | 15 +++++++++++++++ 8 files changed, 78 insertions(+), 16 deletions(-) diff --git a/expression.c b/expression.c index b2052b5..f861990 100644 --- a/expression.c +++ b/expression.c @@ -21,8 +21,7 @@ /* local prototypes */ -enum OperatorOrder -{ +enum OperatorOrder { OrderNone, OrderPrefix, OrderInfix, @@ -30,8 +29,7 @@ enum OperatorOrder }; /* a stack of expressions we use in evaluation */ -struct ExpressionStack -{ +struct ExpressionStack { struct ExpressionStack *Next; /* the next lower item on the stack */ struct Value *Val; /* the value for this stack node */ enum LexToken Op; /* the operator */ @@ -40,8 +38,7 @@ struct ExpressionStack }; /* operator precedence definitions */ -struct OpPrecedence -{ +struct OpPrecedence { unsigned int PrefixPrecedence:4; unsigned int PostfixPrecedence:4; unsigned int InfixPrecedence:4; @@ -50,8 +47,7 @@ struct OpPrecedence /* NOTE: the order of this array must correspond exactly to the order of these tokens in enum LexToken */ -static struct OpPrecedence OperatorPrecedence[] = -{ +static struct OpPrecedence OperatorPrecedence[] = { /* TokenNone, */ {0, 0, 0, "none"}, /* TokenComma, */ {0, 0, 0, ","}, /* TokenAssign, */ {0, 0, 2, "="}, diff --git a/interpreter.h b/interpreter.h index 93cf79a..adb2cab 100644 --- a/interpreter.h +++ b/interpreter.h @@ -561,6 +561,9 @@ extern struct ValueType *TypeCreateOpaqueStruct(Picoc *pc, struct ParseState *Pa extern int TypeIsForwardDeclared(struct ParseState *Parser, struct ValueType *Typ); /* heap.c */ +#ifdef DEBUG_HEAP +extern void ShowBigList(Picoc *pc); +#endif extern void HeapInit(Picoc *pc, int StackSize); extern void HeapCleanup(Picoc *pc); extern void *HeapAllocStack(Picoc *pc, int Size); diff --git a/lex.c b/lex.c index de47778..933c887 100644 --- a/lex.c +++ b/lex.c @@ -22,15 +22,37 @@ #define MAX_CHAR_VALUE (255) /* maximum value which can be represented by a "char" data type */ +static enum LexToken LexCheckReservedWord(Picoc *pc, const char *Word); +static enum LexToken LexGetNumber(Picoc *pc, struct LexState *Lexer, struct Value *Value); +static enum LexToken LexGetWord(Picoc *pc, struct LexState *Lexer, struct Value *Value); +static unsigned char LexUnEscapeCharacterConstant(const char **From, + unsigned char FirstChar, int Base); +static unsigned char LexUnEscapeCharacter(const char **From, const char *End); +static enum LexToken LexGetStringConstant(Picoc *pc, struct LexState *Lexer, + struct Value *Value, char EndChar); +static enum LexToken LexGetCharacterConstant(Picoc *pc, struct LexState *Lexer, + struct Value *Value); +static void LexSkipComment(struct LexState *Lexer, char NextChar, + enum LexToken *ReturnToken); +static enum LexToken LexScanGetToken(Picoc *pc, struct LexState *Lexer, + struct Value **Value); +static int LexTokenSize(enum LexToken Token); +static void *LexTokenise(Picoc *pc, struct LexState *Lexer, int *TokenLen); +static enum LexToken LexGetRawToken(struct ParseState *Parser, struct Value **Value, + int IncPos); +static void LexHashIncPos(struct ParseState *Parser, int IncPos); +static void LexHashIfdef(struct ParseState *Parser, int IfNot); +static void LexHashIf(struct ParseState *Parser); +static void LexHashElse(struct ParseState *Parser); +static void LexHashEndif(struct ParseState *Parser); -struct ReservedWord -{ + +struct ReservedWord { const char *Word; enum LexToken Token; }; -static struct ReservedWord ReservedWords[] = -{ +static struct ReservedWord ReservedWords[] = { /* wrf, when optimizations are set escaping certain chars is required or they disappear */ {"\#define", TokenHashDefine}, {"\#else", TokenHashElse}, diff --git a/parse.c b/parse.c index 5816c57..3bc89d6 100644 --- a/parse.c +++ b/parse.c @@ -3,6 +3,21 @@ #include "picoc.h" #include "interpreter.h" +static enum ParseResult ParseStatementMaybeRun(struct ParseState *Parser, + int Condition, int CheckTrailingSemicolon); +static int ParseCountParams(struct ParseState *Parser); +static int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable, + int DoAssignment); +static void ParseDeclarationAssignment(struct ParseState *Parser, + struct Value *NewVariable, int DoAssignment); +static int ParseDeclaration(struct ParseState *Parser, enum LexToken Token); +static void ParseMacroDefinition(struct ParseState *Parser); +static void ParseFor(struct ParseState *Parser); +static enum RunMode ParseBlock(struct ParseState *Parser, int AbsorbOpenBrace, + int Condition); +static void ParseTypedef(struct ParseState *Parser); + + #ifdef DEBUGGER static int gEnableDebugger = true; #else diff --git a/picoc.c b/picoc.c index 04108a4..b426666 100644 --- a/picoc.c +++ b/picoc.c @@ -36,7 +36,7 @@ int main(int argc, char **argv) } if (strcmp(argv[ParamCount], "-c") == 0) { - printf("%s\n", &__LICENSE); + printf("%s\n", (char*)&__LICENSE); return 0; } diff --git a/platform.c b/platform.c index 5dd5de1..9b14461 100644 --- a/platform.c +++ b/platform.c @@ -4,6 +4,10 @@ #include "picoc.h" #include "interpreter.h" + +static void PrintSourceTextErrorLine(IOFILE *Stream, const char *FileName, + const char *SourceText, int Line, int CharacterPos); + #ifdef DEBUGGER static int gEnableDebugger = true; #else diff --git a/table.c b/table.c index b743b75..b8ef806 100644 --- a/table.c +++ b/table.c @@ -3,6 +3,13 @@ #include "interpreter.h" + +static unsigned int TableHash(const char *Key, int Len); +static struct TableEntry *TableSearch(struct Table *Tbl, const char *Key, + int *AddAt); +static struct TableEntry *TableSearchIdentifier(struct Table *Tbl, + const char *Key, int Len, int *AddAt); + /* initialise the shared string system */ void TableInit(Picoc *pc) { @@ -12,7 +19,7 @@ void TableInit(Picoc *pc) } /* hash function for strings */ -static unsigned int TableHash(const char *Key, int Len) +unsigned int TableHash(const char *Key, int Len) { unsigned int Hash = Len; int Offset; @@ -39,7 +46,7 @@ void TableInitTable(struct Table *Tbl, struct TableEntry **HashTable, int Size, } /* check a hash table entry for a key */ -static struct TableEntry *TableSearch(struct Table *Tbl, const char *Key, +struct TableEntry *TableSearch(struct Table *Tbl, const char *Key, int *AddAt) { /* shared strings have unique addresses so we don't need to hash them */ @@ -123,7 +130,7 @@ struct Value *TableDelete(Picoc *pc, struct Table *Tbl, const char *Key) } /* check a hash table entry for an identifier */ -static struct TableEntry *TableSearchIdentifier(struct Table *Tbl, +struct TableEntry *TableSearchIdentifier(struct Table *Tbl, const char *Key, int Len, int *AddAt) { int HashValue = TableHash(Key, Len) % Tbl->Size; diff --git a/type.c b/type.c index ab06eef..d41c9bd 100644 --- a/type.c +++ b/type.c @@ -3,6 +3,21 @@ #include "interpreter.h" + +static struct ValueType *TypeAdd(Picoc *pc, struct ParseState *Parser, + struct ValueType *ParentType, enum BaseType Base, int ArraySize, + const char *Identifier, int Sizeof, int AlignBytes); +static void TypeAddBaseType(Picoc *pc, struct ValueType *TypeNode, + enum BaseType Base, int Sizeof, int AlignBytes); +static void TypeCleanupNode(Picoc *pc, struct ValueType *Typ); +static void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, + int IsStruct); +static void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ); +static struct ValueType *TypeParseBack(struct ParseState *Parser, + struct ValueType *FromType); + + + /* some basic types */ static int PointerAlignBytes; static int IntAlignBytes;