reorder types
This commit is contained in:
parent
f26b78f29f
commit
c063462464
20
expression.c
20
expression.c
|
@ -325,11 +325,11 @@ void ExpressionStackPushLValue(struct ParseState *Parser, struct ExpressionStack
|
|||
|
||||
void ExpressionStackPushDereference(struct ParseState *Parser, struct ExpressionStack **StackTop, struct Value *DereferenceValue)
|
||||
{
|
||||
int Offset;
|
||||
int DerefIsLValue;
|
||||
struct Value *DerefVal;
|
||||
struct Value *ValueLoc;
|
||||
int Offset;
|
||||
struct ValueType *DerefType;
|
||||
int DerefIsLValue;
|
||||
void *DerefDataLoc = VariableDereferencePointer(Parser, DereferenceValue, &DerefVal, &Offset, &DerefType, &DerefIsLValue);
|
||||
if (DerefDataLoc == NULL)
|
||||
ProgramFail(Parser, "NULL pointer dereference");
|
||||
|
@ -1018,15 +1018,15 @@ void ExpressionGetStructElement(struct ParseState *Parser, struct ExpressionStac
|
|||
/* parse an expression with operator precedence */
|
||||
int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||
{
|
||||
struct Value *LexValue;
|
||||
int PrefixState = TRUE;
|
||||
int Done = FALSE;
|
||||
int BracketPrecedence = 0;
|
||||
int LocalPrecedence;
|
||||
int Precedence = 0;
|
||||
int IgnorePrecedence = DEEP_PRECEDENCE;
|
||||
struct ExpressionStack *StackTop = NULL;
|
||||
int TernaryDepth = 0;
|
||||
struct Value *LexValue;
|
||||
struct ExpressionStack *StackTop = NULL;
|
||||
|
||||
#ifdef DEBUG_EXPRESSIONS
|
||||
printf("ExpressionParse():\n");
|
||||
|
@ -1258,11 +1258,11 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
|||
/* do a parameterised macro call */
|
||||
void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack **StackTop, const char *MacroName, struct MacroDef *MDef)
|
||||
{
|
||||
int ArgCount;
|
||||
enum LexToken Token;
|
||||
struct Value *ReturnValue = NULL;
|
||||
struct Value *Param;
|
||||
struct Value **ParamArray = NULL;
|
||||
int ArgCount;
|
||||
enum LexToken Token;
|
||||
|
||||
if (Parser->Mode == RunModeRun) {
|
||||
/* create a stack frame for this macro */
|
||||
|
@ -1333,13 +1333,13 @@ void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack
|
|||
/* do a function call */
|
||||
void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionStack **StackTop, const char *FuncName, int RunIt)
|
||||
{
|
||||
int ArgCount;
|
||||
enum LexToken Token = LexGetToken(Parser, NULL, TRUE); /* open bracket */
|
||||
enum RunMode OldMode = Parser->Mode;
|
||||
struct Value *ReturnValue = NULL;
|
||||
struct Value *FuncValue = NULL;
|
||||
struct Value *Param;
|
||||
struct Value **ParamArray = NULL;
|
||||
int ArgCount;
|
||||
enum LexToken Token = LexGetToken(Parser, NULL, TRUE); /* open bracket */
|
||||
enum RunMode OldMode = Parser->Mode;
|
||||
|
||||
if (RunIt) {
|
||||
/* get the function definition */
|
||||
|
@ -1446,8 +1446,8 @@ void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionSta
|
|||
/* parse an expression */
|
||||
long ExpressionParseInt(struct ParseState *Parser)
|
||||
{
|
||||
struct Value *Val;
|
||||
long Result = 0;
|
||||
struct Value *Val;
|
||||
|
||||
if (!ExpressionParse(Parser, &Val))
|
||||
ProgramFail(Parser, "expression expected");
|
||||
|
|
20
lex.c
20
lex.c
|
@ -251,8 +251,8 @@ enum LexToken LexGetWord(Picoc *pc, struct LexState *Lexer, struct Value *Value)
|
|||
/* unescape a character from an octal character constant */
|
||||
unsigned char LexUnEscapeCharacterConstant(const char **From, const char *End, unsigned char FirstChar, int Base)
|
||||
{
|
||||
unsigned char Total = GET_BASE_DIGIT(FirstChar);
|
||||
int CCount;
|
||||
unsigned char Total = GET_BASE_DIGIT(FirstChar);
|
||||
for (CCount = 0; IS_BASE_DIGIT(**From, Base) && CCount < 2; CCount++, (*From)++)
|
||||
Total = Total * Base + GET_BASE_DIGIT(**From);
|
||||
|
||||
|
@ -489,15 +489,15 @@ int LexTokenSize(enum LexToken Token)
|
|||
/* produce tokens from the lexer and return a heap buffer with the result - used for scanning */
|
||||
void *LexTokenise(Picoc *pc, struct LexState *Lexer, int *TokenLen)
|
||||
{
|
||||
enum LexToken Token;
|
||||
void *HeapMem;
|
||||
struct Value *GotValue;
|
||||
int MemUsed = 0;
|
||||
int ValueSize;
|
||||
int ReserveSpace = (Lexer->End - Lexer->Pos) * 4 + 16;
|
||||
void *TokenSpace = HeapAllocStack(pc, ReserveSpace);
|
||||
char *TokenPos = (char *)TokenSpace;
|
||||
int LastCharacterPos = 0;
|
||||
int ReserveSpace = (Lexer->End - Lexer->Pos) * 4 + 16;
|
||||
void *HeapMem;
|
||||
void *TokenSpace = HeapAllocStack(pc, ReserveSpace);
|
||||
enum LexToken Token;
|
||||
struct Value *GotValue;
|
||||
char *TokenPos = (char*)TokenSpace;
|
||||
|
||||
if (TokenSpace == NULL)
|
||||
LexFail(pc, Lexer, "(LexTokenise TokenSpace == NULL) out of memory");
|
||||
|
@ -587,9 +587,9 @@ void LexInitParser(struct ParseState *Parser, Picoc *pc, const char *SourceText,
|
|||
/* get the next token, without pre-processing */
|
||||
enum LexToken LexGetRawToken(struct ParseState *Parser, struct Value **Value, int IncPos)
|
||||
{
|
||||
enum LexToken Token = TokenNone;
|
||||
int ValueSize;
|
||||
char *Prompt = NULL;
|
||||
enum LexToken Token = TokenNone;
|
||||
Picoc *pc = Parser->pc;
|
||||
|
||||
do {
|
||||
|
@ -707,9 +707,9 @@ void LexHashIncPos(struct ParseState *Parser, int IncPos)
|
|||
void LexHashIfdef(struct ParseState *Parser, int IfNot)
|
||||
{
|
||||
/* get symbol to check */
|
||||
int IsDefined;
|
||||
struct Value *IdentValue;
|
||||
struct Value *SavedValue;
|
||||
int IsDefined;
|
||||
enum LexToken Token = LexGetRawToken(Parser, &IdentValue, TRUE);
|
||||
|
||||
if (Token != TokenIdentifier)
|
||||
|
@ -823,8 +823,8 @@ void LexPrintToken(enum LexToken Token)
|
|||
/* get the next token given a parser state, pre-processing as we go */
|
||||
enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int IncPos)
|
||||
{
|
||||
enum LexToken Token;
|
||||
int TryNextToken;
|
||||
enum LexToken Token;
|
||||
|
||||
/* implements the pre-processor #if commands */
|
||||
do {
|
||||
|
|
24
parse.c
24
parse.c
|
@ -60,14 +60,14 @@ int ParseCountParams(struct ParseState *Parser)
|
|||
/* parse a function definition and store it for later */
|
||||
struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueType *ReturnType, char *Identifier)
|
||||
{
|
||||
struct ValueType *ParamType;
|
||||
int ParamCount = 0;
|
||||
char *ParamIdentifier;
|
||||
enum LexToken Token = TokenNone;
|
||||
struct ValueType *ParamType;
|
||||
struct ParseState ParamParser;
|
||||
struct Value *FuncValue;
|
||||
struct Value *OldFuncValue;
|
||||
struct ParseState FuncBody;
|
||||
int ParamCount = 0;
|
||||
Picoc *pc = Parser->pc;
|
||||
|
||||
if (pc->TopStackFrame != NULL)
|
||||
|
@ -287,12 +287,12 @@ void ParseDeclarationAssignment(struct ParseState *Parser, struct Value *NewVari
|
|||
/* declare a variable or function */
|
||||
int ParseDeclaration(struct ParseState *Parser, enum LexToken Token)
|
||||
{
|
||||
int IsStatic = FALSE;
|
||||
int FirstVisit = FALSE;
|
||||
char *Identifier;
|
||||
struct ValueType *BasicType;
|
||||
struct ValueType *Typ;
|
||||
struct Value *NewVariable = NULL;
|
||||
int IsStatic = FALSE;
|
||||
int FirstVisit = FALSE;
|
||||
Picoc *pc = Parser->pc;
|
||||
|
||||
TypeParseFront(Parser, &BasicType, &IsStatic);
|
||||
|
@ -334,8 +334,8 @@ int ParseDeclaration(struct ParseState *Parser, enum LexToken Token)
|
|||
/* parse a #define macro definition and store it for later */
|
||||
void ParseMacroDefinition(struct ParseState *Parser)
|
||||
{
|
||||
struct Value *MacroName;
|
||||
char *MacroNameStr;
|
||||
struct Value *MacroName;
|
||||
struct Value *ParamName;
|
||||
struct Value *MacroValue;
|
||||
|
||||
|
@ -510,9 +510,9 @@ enum RunMode ParseBlock(struct ParseState *Parser, int AbsorbOpenBrace, int Cond
|
|||
/* parse a typedef declaration */
|
||||
void ParseTypedef(struct ParseState *Parser)
|
||||
{
|
||||
char *TypeName;
|
||||
struct ValueType *Typ;
|
||||
struct ValueType **TypPtr;
|
||||
char *TypeName;
|
||||
struct Value InitValue;
|
||||
|
||||
TypeParse(Parser, &Typ, &TypeName, NULL);
|
||||
|
@ -528,12 +528,12 @@ void ParseTypedef(struct ParseState *Parser)
|
|||
/* parse a statement */
|
||||
enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemicolon)
|
||||
{
|
||||
int Condition;
|
||||
enum LexToken Token;
|
||||
struct Value *CValue;
|
||||
struct Value *LexerValue;
|
||||
struct Value *VarValue;
|
||||
int Condition;
|
||||
struct ParseState PreState;
|
||||
enum LexToken Token;
|
||||
|
||||
/* if we're debugging, check for a breakpoint */
|
||||
if (Parser->DebugMode && Parser->Mode == RunModeRun)
|
||||
|
@ -816,10 +816,10 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
|||
/* quick scan a source file for definitions */
|
||||
void PicocParse(Picoc *pc, const char *FileName, const char *Source, int SourceLen, int RunIt, int CleanupNow, int CleanupSource, int EnableDebugger)
|
||||
{
|
||||
struct ParseState Parser;
|
||||
enum ParseResult Ok;
|
||||
struct CleanupTokenNode *NewCleanupNode;
|
||||
char *RegFileName = TableStrRegister(pc, FileName);
|
||||
enum ParseResult Ok;
|
||||
struct ParseState Parser;
|
||||
struct CleanupTokenNode *NewCleanupNode;
|
||||
|
||||
void *Tokens = LexAnalyse(pc, RegFileName, Source, SourceLen, NULL);
|
||||
|
||||
|
@ -857,8 +857,8 @@ void PicocParse(Picoc *pc, const char *FileName, const char *Source, int SourceL
|
|||
/* parse interactively */
|
||||
void PicocParseInteractiveNoStartPrompt(Picoc *pc, int EnableDebugger)
|
||||
{
|
||||
struct ParseState Parser;
|
||||
enum ParseResult Ok;
|
||||
struct ParseState Parser;
|
||||
|
||||
LexInitParser(&Parser, pc, NULL, NULL, pc->StrEmpty, TRUE, EnableDebugger);
|
||||
PicocPlatformSetExitPoint(pc);
|
||||
|
|
|
@ -91,9 +91,9 @@ void PicocCallMain(Picoc *pc, int argc, char **argv)
|
|||
void PrintSourceTextErrorLine(IOFILE *Stream, const char *FileName, const char *SourceText, int Line, int CharacterPos)
|
||||
{
|
||||
int LineCount;
|
||||
int CCount;
|
||||
const char *LinePos;
|
||||
const char *CPos;
|
||||
int CCount;
|
||||
|
||||
if (SourceText != NULL) {
|
||||
/* find the source line */
|
||||
|
|
9
table.c
9
table.c
|
@ -39,8 +39,9 @@ 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, int *AddAt)
|
||||
{
|
||||
struct TableEntry *Entry;
|
||||
int HashValue = ((unsigned long)Key) % Tbl->Size; /* shared strings have unique addresses so we don't need to hash them */
|
||||
struct TableEntry *Entry;
|
||||
|
||||
for (Entry = Tbl->HashTable[HashValue]; Entry != NULL; Entry = Entry->Next) {
|
||||
if (Entry->p.v.Key == Key)
|
||||
return Entry; /* found */
|
||||
|
@ -95,8 +96,8 @@ int TableGet(struct Table *Tbl, const char *Key, struct Value **Val, const char
|
|||
/* remove an entry from the table */
|
||||
struct Value *TableDelete(Picoc *pc, struct Table *Tbl, const char *Key)
|
||||
{
|
||||
struct TableEntry **EntryPtr;
|
||||
int HashValue = ((unsigned long)Key) % Tbl->Size; /* shared strings have unique addresses so we don't need to hash them */
|
||||
struct TableEntry **EntryPtr;
|
||||
|
||||
for (EntryPtr = &Tbl->HashTable[HashValue]; *EntryPtr != NULL; EntryPtr = &(*EntryPtr)->Next) {
|
||||
if ((*EntryPtr)->p.v.Key == Key) {
|
||||
|
@ -115,8 +116,8 @@ 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, const char *Key, int Len, int *AddAt)
|
||||
{
|
||||
struct TableEntry *Entry;
|
||||
int HashValue = TableHash(Key, Len) % Tbl->Size;
|
||||
struct TableEntry *Entry;
|
||||
|
||||
for (Entry = Tbl->HashTable[HashValue]; Entry != NULL; Entry = Entry->Next) {
|
||||
if (strncmp(&Entry->p.Key[0], (char *)Key, Len) == 0 && Entry->p.Key[Len] == '\0')
|
||||
|
@ -162,9 +163,9 @@ char *TableStrRegister(Picoc *pc, const char *Str)
|
|||
/* free all the strings */
|
||||
void TableStrFree(Picoc *pc)
|
||||
{
|
||||
int Count;
|
||||
struct TableEntry *Entry;
|
||||
struct TableEntry *NextEntry;
|
||||
int Count;
|
||||
|
||||
for (Count = 0; Count < pc->StringTable.Size; Count++) {
|
||||
for (Entry = pc->StringTable.HashTable[Count]; Entry != NULL; Entry = NextEntry) {
|
||||
|
|
22
type.c
22
type.c
|
@ -172,14 +172,14 @@ void TypeCleanup(Picoc *pc)
|
|||
/* parse a struct or union declaration */
|
||||
void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, int IsStruct)
|
||||
{
|
||||
struct Value *LexValue;
|
||||
struct ValueType *MemberType;
|
||||
char *MemberIdentifier;
|
||||
char *StructIdentifier;
|
||||
struct Value *MemberValue;
|
||||
enum LexToken Token;
|
||||
int AlignBoundary;
|
||||
struct Value *MemberValue;
|
||||
Picoc *pc = Parser->pc;
|
||||
struct Value *LexValue;
|
||||
struct ValueType *MemberType;
|
||||
|
||||
Token = LexGetToken(Parser, &LexValue, FALSE);
|
||||
if (Token == TokenIdentifier) {
|
||||
|
@ -273,11 +273,11 @@ struct ValueType *TypeCreateOpaqueStruct(Picoc *pc, struct ParseState *Parser, c
|
|||
/* parse an enum declaration */
|
||||
void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ)
|
||||
{
|
||||
struct Value *LexValue;
|
||||
struct Value InitValue;
|
||||
enum LexToken Token;
|
||||
int EnumValue = 0;
|
||||
char *EnumIdentifier;
|
||||
enum LexToken Token;
|
||||
struct Value *LexValue;
|
||||
struct Value InitValue;
|
||||
Picoc *pc = Parser->pc;
|
||||
|
||||
Token = LexGetToken(Parser, &LexValue, FALSE);
|
||||
|
@ -331,12 +331,12 @@ void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ)
|
|||
/* parse a type - just the basic type */
|
||||
int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, int *IsStatic)
|
||||
{
|
||||
int Unsigned = FALSE;
|
||||
int StaticQualifier = FALSE;
|
||||
enum LexToken Token;
|
||||
struct ParseState Before;
|
||||
struct Value *LexerValue;
|
||||
enum LexToken Token;
|
||||
int Unsigned = FALSE;
|
||||
struct Value *VarValue;
|
||||
int StaticQualifier = FALSE;
|
||||
Picoc *pc = Parser->pc;
|
||||
*Typ = NULL;
|
||||
|
||||
|
@ -442,10 +442,10 @@ struct ValueType *TypeParseBack(struct ParseState *Parser, struct ValueType *Fro
|
|||
/* parse a type - the part which is repeated with each identifier in a declaration list */
|
||||
void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, struct ValueType **Typ, char **Identifier)
|
||||
{
|
||||
struct ParseState Before;
|
||||
int Done = FALSE;
|
||||
enum LexToken Token;
|
||||
struct Value *LexValue;
|
||||
int Done = FALSE;
|
||||
struct ParseState Before;
|
||||
*Typ = BasicTyp;
|
||||
*Identifier = Parser->pc->StrEmpty;
|
||||
|
||||
|
|
17
variable.c
17
variable.c
|
@ -40,9 +40,9 @@ void VariableFree(Picoc *pc, struct Value *Val)
|
|||
/* deallocate the global table and the string literal table */
|
||||
void VariableTableCleanup(Picoc *pc, struct Table *HashTable)
|
||||
{
|
||||
int Count;
|
||||
struct TableEntry *Entry;
|
||||
struct TableEntry *NextEntry;
|
||||
int Count;
|
||||
|
||||
for (Count = 0; Count < HashTable->Size; Count++) {
|
||||
for (Entry = HashTable->HashTable[Count]; Entry != NULL; Entry = NextEntry) {
|
||||
|
@ -114,10 +114,10 @@ struct Value *VariableAllocValueFromType(Picoc *pc, struct ParseState *Parser, s
|
|||
/* allocate a value either on the heap or the stack and copy its value. handles overlapping data */
|
||||
struct Value *VariableAllocValueAndCopy(Picoc *pc, struct ParseState *Parser, struct Value *FromValue, int OnHeap)
|
||||
{
|
||||
int CopySize = TypeSizeValue(FromValue, TRUE);
|
||||
char TmpBuf[MAX_TMP_COPY_BUF];
|
||||
struct ValueType *DType = FromValue->Typ;
|
||||
struct Value *NewValue;
|
||||
char TmpBuf[MAX_TMP_COPY_BUF];
|
||||
int CopySize = TypeSizeValue(FromValue, TRUE);
|
||||
|
||||
assert(CopySize <= MAX_TMP_COPY_BUF);
|
||||
memcpy((void*)&TmpBuf[0], (void*)FromValue->Val, CopySize);
|
||||
|
@ -202,7 +202,6 @@ void VariableScopeEnd(struct ParseState *Parser, int ScopeID, int PrevScopeID)
|
|||
int Count;
|
||||
struct TableEntry *Entry;
|
||||
struct TableEntry *NextEntry = NULL;
|
||||
|
||||
#ifdef VAR_SCOPE_DEBUG
|
||||
int FirstPrint = 0;
|
||||
#endif
|
||||
|
@ -232,8 +231,8 @@ void VariableScopeEnd(struct ParseState *Parser, int ScopeID, int PrevScopeID)
|
|||
|
||||
int VariableDefinedAndOutOfScope(Picoc * pc, const char* Ident)
|
||||
{
|
||||
struct TableEntry *Entry;
|
||||
int Count;
|
||||
struct TableEntry *Entry;
|
||||
|
||||
struct Table * HashTable = (pc->TopStackFrame == NULL) ? &(pc->GlobalTable) : &(pc->TopStackFrame)->LocalTable;
|
||||
for (Count = 0; Count < HashTable->Size; Count++) {
|
||||
|
@ -248,10 +247,10 @@ int VariableDefinedAndOutOfScope(Picoc * pc, const char* Ident)
|
|||
/* define a variable. Ident must be registered */
|
||||
struct Value *VariableDefine(Picoc *pc, struct ParseState *Parser, char *Ident, struct Value *InitValue, struct ValueType *Typ, int MakeWritable)
|
||||
{
|
||||
int ScopeID = Parser ? Parser->ScopeID : -1;
|
||||
struct Value * AssignValue;
|
||||
struct Table * currentTable = (pc->TopStackFrame == NULL) ? &(pc->GlobalTable) : &(pc->TopStackFrame)->LocalTable;
|
||||
|
||||
int ScopeID = Parser ? Parser->ScopeID : -1;
|
||||
#ifdef VAR_SCOPE_DEBUG
|
||||
if (Parser) fprintf(stderr, "def %s %x (%s:%d:%d)\n", Ident, ScopeID, Parser->FileName, Parser->Line, Parser->CharacterPos);
|
||||
#endif
|
||||
|
@ -274,11 +273,11 @@ struct Value *VariableDefine(Picoc *pc, struct ParseState *Parser, char *Ident,
|
|||
/* define a variable. Ident must be registered. If it's a redefinition from the same declaration don't throw an error */
|
||||
struct Value *VariableDefineButIgnoreIdentical(struct ParseState *Parser, char *Ident, struct ValueType *Typ, int IsStatic, int *FirstVisit)
|
||||
{
|
||||
Picoc *pc = Parser->pc;
|
||||
struct Value *ExistingValue;
|
||||
const char *DeclFileName;
|
||||
int DeclLine;
|
||||
int DeclColumn;
|
||||
const char *DeclFileName;
|
||||
Picoc *pc = Parser->pc;
|
||||
struct Value *ExistingValue;
|
||||
|
||||
/* is the type a forward declaration? */
|
||||
if (TypeIsForwardDeclared(Parser, Typ))
|
||||
|
|
Loading…
Reference in a new issue