PRINT_SOURCE_POS macro refactors

This commit is contained in:
Joseph Poirier 2015-06-10 12:33:16 -05:00
parent c504c52cd1
commit f26b78f29f
6 changed files with 19 additions and 19 deletions

View file

@ -2,7 +2,7 @@ CC=gcc
# -O3
# -std=gnu11
CFLAGS=-Wall -g -std=gnu11 -pedantic -DUNIX_HOST -DVER=\"`git show-ref --abbrev=8 --head --hash head`\" -DTAG=\"`git describe --abbrev=0 --tags`\"
CFLAGS=-Wall -O3 -g -std=gnu11 -pedantic -DUNIX_HOST -DVER=\"`git show-ref --abbrev=8 --head --hash head`\" -DTAG=\"`git describe --abbrev=0 --tags`\"
LIBS=-lm -lreadline
TARGET = picoc

View file

@ -429,7 +429,7 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct
if (DestValue->Typ->ArraySize == 0) { /* char x[] = "abcd", x is unsized */
int Size = strlen(SourceValue->Val->Pointer) + 1;
#ifdef DEBUG_ARRAY_INITIALIZER
PRINT_SOURCE_POS;
PRINT_SOURCE_POS();
fprintf(stderr, "str size: %d\n", Size);
#endif
DestValue->Typ = TypeGetMatching(Parser->pc, Parser, DestValue->Typ->FromType, DestValue->Typ->Base, Size, DestValue->Typ->Identifier, TRUE);
@ -438,7 +438,7 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct
/* else, it's char x[10] = "abcd" */
#ifdef DEBUG_ARRAY_INITIALIZER
PRINT_SOURCE_POS;
PRINT_SOURCE_POS();
fprintf(stderr, "char[%d] from char* (len=%d)\n", DestValue->Typ->ArraySize, strlen(SourceValue->Val->Pointer));
#endif
memcpy((void *)DestValue->Val, SourceValue->Val->Pointer, TypeSizeValue(DestValue, FALSE));

View file

@ -27,7 +27,12 @@
#define GETS_BUF_MAX (256)
/* for debugging */
#define PRINT_SOURCE_POS ({ PrintSourceTextErrorLine(Parser->pc->CStdOut, Parser->FileName, Parser->SourceText, Parser->Line, Parser->CharacterPos); PlatformPrintf(Parser->pc->CStdOut, "\n"); })
#define PRINT_SOURCE_POS() { \
PrintSourceTextErrorLine(Parser->pc->CStdOut, \
Parser->FileName, Parser->SourceText, Parser->Line, Parser->CharacterPos); \
PlatformPrintf(Parser->pc->CStdOut, "\n"); \
}
#define PRINT_TYPE(typ) PlatformPrintf(Parser->pc->CStdOut, "%t\n", typ);
typedef FILE IOFILE;

View file

@ -181,7 +181,7 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
VariableRealloc(Parser, NewVariable, TypeSizeValue(NewVariable, FALSE));
}
#ifdef DEBUG_ARRAY_INITIALIZER
PRINT_SOURCE_POS;
PRINT_SOURCE_POS();
printf("array size: %d \n", NewVariable->Typ->ArraySize);
#endif
}
@ -198,7 +198,7 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
SubArray = VariableAllocValueFromExistingData(Parser, NewVariable->Typ->FromType, (union AnyValue *)(&NewVariable->Val->ArrayMem[0] + SubArraySize * ArrayIndex), TRUE, NewVariable);
#ifdef DEBUG_ARRAY_INITIALIZER
int FullArraySize = TypeSize(NewVariable->Typ, NewVariable->Typ->ArraySize, TRUE);
PRINT_SOURCE_POS;
PRINT_SOURCE_POS();
PRINT_TYPE(NewVariable->Typ)
printf("[%d] subarray size: %d (full: %d,%d) \n", ArrayIndex, SubArraySize, FullArraySize, NewVariable->Typ->ArraySize);
#endif
@ -226,7 +226,7 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
}
ElementSize = TypeSize(ElementType, ElementType->ArraySize, TRUE);
#ifdef DEBUG_ARRAY_INITIALIZER
PRINT_SOURCE_POS;
PRINT_SOURCE_POS();
printf("[%d/%d] element size: %d (x%d) \n", ArrayIndex, TotalSize, ElementSize, ElementType->ArraySize);
#endif
if (ArrayIndex >= TotalSize)
@ -582,7 +582,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
ProgramFail(Parser, "expected: expression");
}
#if 0
PRINT_SOURCE_POS;
PRINT_SOURCE_POS();
PlatformPrintf(Parser->pc->CStdOut, "%t %s = %d;\n", CValue->Typ, Identifier, CValue->Val->Integer);
printf("%d\n", VariableDefined(Parser->pc, Identifier));
#endif

View file

@ -120,7 +120,6 @@ void PrintSourceTextErrorLine(IOFILE *Stream, const char *FileName, const char *
PrintCh(' ', Stream);
}
PlatformPrintf(Stream, "^\n%s:%d:%d ", FileName, Line, CharacterPos);
}
/* exit with a message */

View file

@ -162,18 +162,17 @@ void VariableRealloc(struct ParseState *Parser, struct Value *FromValue, int New
int VariableScopeBegin(struct ParseState *Parser, int* OldScopeID)
{
int Count;
Picoc *pc = Parser->pc;
struct TableEntry *Entry;
struct TableEntry *NextEntry;
#ifdef VAR_SCOPE_DEBUG
int FirstPrint = 0;
#endif
struct Table *HashTable = (pc->TopStackFrame == NULL) ? &(pc->GlobalTable) : &(pc->TopStackFrame)->LocalTable;
if (Parser->ScopeID == -1)
return -1;
struct Table *HashTable = (Parser->pc->TopStackFrame == NULL) ? &(Parser->pc->GlobalTable) : &(Parser->pc->TopStackFrame)->LocalTable;
/* XXX dumb hash, let's hope for no collisions... */
*OldScopeID = Parser->ScopeID;
Parser->ScopeID = (int)(intptr_t)(Parser->SourceText) * ((int)(intptr_t)(Parser->Pos) / sizeof(char*));
@ -187,7 +186,7 @@ int VariableScopeBegin(struct ParseState *Parser, int* OldScopeID)
Entry->p.v.Val->OutOfScope = FALSE;
Entry->p.v.Key = (char*)((intptr_t)Entry->p.v.Key & ~1);
#ifdef VAR_SCOPE_DEBUG
if (!FirstPrint) { PRINT_SOURCE_POS; }
if (!FirstPrint) PRINT_SOURCE_POS();
FirstPrint = 1;
printf(">>> back into scope: %s %x %d\n", Entry->p.v.Key, Entry->p.v.Val->ScopeID, Entry->p.v.Val->Val->Integer);
#endif
@ -201,7 +200,6 @@ int VariableScopeBegin(struct ParseState *Parser, int* OldScopeID)
void VariableScopeEnd(struct ParseState *Parser, int ScopeID, int PrevScopeID)
{
int Count;
Picoc *pc = Parser->pc;
struct TableEntry *Entry;
struct TableEntry *NextEntry = NULL;
@ -209,19 +207,17 @@ void VariableScopeEnd(struct ParseState *Parser, int ScopeID, int PrevScopeID)
int FirstPrint = 0;
#endif
struct Table *HashTable = (pc->TopStackFrame == NULL) ? &(pc->GlobalTable) : &(pc->TopStackFrame)->LocalTable;
if (ScopeID == -1)
return;
struct Table *HashTable = (Parser->pc->TopStackFrame == NULL) ? &(Parser->pc->GlobalTable) : &(Parser->pc->TopStackFrame)->LocalTable;
for (Count = 0; Count < HashTable->Size; Count++) {
for (Entry = HashTable->HashTable[Count]; Entry != NULL; Entry = NextEntry) {
NextEntry = Entry->Next;
if ((Entry->p.v.Val->ScopeID == ScopeID) && (Entry->p.v.Val->OutOfScope == FALSE)) {
#ifdef VAR_SCOPE_DEBUG
if (!FirstPrint) {
PRINT_SOURCE_POS;
}
if (!FirstPrint) PRINT_SOURCE_POS();
FirstPrint = 1;
printf(">>> out of scope: %s %x %d\n", Entry->p.v.Key, Entry->p.v.Val->ScopeID, Entry->p.v.Val->Val->Integer);
#endif