proper static prototypes

This commit is contained in:
Joseph Poirier 2015-06-17 04:30:27 -05:00
parent bbcf2fdd95
commit 0ac0f71fc0
8 changed files with 78 additions and 16 deletions

View file

@ -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, "="},

View file

@ -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);

30
lex.c
View file

@ -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},

15
parse.c
View file

@ -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

View file

@ -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;
}

View file

@ -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

13
table.c
View file

@ -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;

15
type.c
View file

@ -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;