diff --git a/oscar64/CompilationUnits.cpp b/oscar64/CompilationUnits.cpp index 983bb69..8bb22f3 100644 --- a/oscar64/CompilationUnits.cpp +++ b/oscar64/CompilationUnits.cpp @@ -55,7 +55,7 @@ bool CompilationUnits::AddUnit(Location& location, const char* name, const char* if (_access(filename, 0) != 0) { - mErrors->Error(location, "Could not open source file.", filename); + mErrors->Error(location, EERR_FILE_NOT_FOUND, "Could not open source file.", filename); return false; } diff --git a/oscar64/Compiler.cpp b/oscar64/Compiler.cpp index 8754b15..159e964 100644 --- a/oscar64/Compiler.cpp +++ b/oscar64/Compiler.cpp @@ -57,7 +57,7 @@ bool Compiler::ParseSource(void) parser->Parse(); } else - mErrors->Error(cunit->mLocation, "Could not open source file", cunit->mFileName); + mErrors->Error(cunit->mLocation, EERR_FILE_NOT_FOUND, "Could not open source file", cunit->mFileName); } return mErrors->mErrorCount == 0; @@ -97,7 +97,7 @@ void Compiler::RegisterRuntime(const Location & loc, const Ident* ident) } else { - mErrors->Error(loc, "Missing runtime code implementation", ident->mString); + mErrors->Error(loc, EERR_RUNTIME_CODE, "Missing runtime code implementation", ident->mString); } } @@ -108,7 +108,7 @@ bool Compiler::GenerateCode(void) Declaration* dcrtstart = mCompilationUnits->mStartup; if (!dcrtstart) { - mErrors->Error(loc, "Runtime startup not found"); + mErrors->Error(loc, EERR_RUNTIME_CODE, "Runtime startup not found"); return false; } @@ -132,7 +132,7 @@ bool Compiler::GenerateCode(void) Declaration* dmain = mCompilationUnits->mScope->Lookup(imain); if (!dmain) { - mErrors->Error(loc, "main function not found"); + mErrors->Error(loc, EERR_OBJECT_NOT_FOUND, "main function not found"); return false; } @@ -231,7 +231,7 @@ bool Compiler::GenerateCode(void) { char n[10]; sprintf_s(n, "%d", i); - mErrors->Error(loc, "Missing byte code implementation", n); + mErrors->Error(loc, EERR_RUNTIME_CODE, "Missing byte code implementation", n); } } } @@ -289,7 +289,7 @@ int Compiler::ExecuteCode(void) { char sd[20]; sprintf_s(sd, "%d", ecode); - mErrors->Error(loc, "Execution failed", sd); + mErrors->Error(loc, EERR_EXECUTION_FAILED, "Execution failed", sd); } return ecode; diff --git a/oscar64/Errors.cpp b/oscar64/Errors.cpp index 8ee2e63..f8394e6 100644 --- a/oscar64/Errors.cpp +++ b/oscar64/Errors.cpp @@ -8,23 +8,24 @@ Errors::Errors(void) } -void Errors::Warning(const Location& loc, const char* error) +void Errors::Error(const Location& loc, ErrorID eid, const char* msg, const char* info) { - printf("Warning %s in %s: %d, %d\n", error, loc.mFileName, loc.mLine, loc.mColumn); -} + const char* level = "info"; + if (eid >= EERR_GENERIC) + { + level = "error"; + mErrorCount++; + } + else if (eid >= EWARN_GENERIC) + { + level = "warning"; + } -void Errors::Error(const Location& loc, const char* error) -{ - printf("Error %s in %s: %d, %d\n", error, loc.mFileName, loc.mLine, loc.mColumn); - mErrorCount++; - if (mErrorCount > 10) - exit(10); -} + if (info) + printf("%s(%d, %d) : error %d: %s '%s'\n", loc.mFileName, loc.mLine, loc.mColumn, eid, msg, info); + else + printf("%s(%d, %d) : error %d: %s\n", loc.mFileName, loc.mLine, loc.mColumn, eid, msg); -void Errors::Error(const Location& loc, const char* error, const char* info) -{ - printf("Error %s '%s' in %s: %d, %d\n", error, info, loc.mFileName, loc.mLine, loc.mColumn); - mErrorCount++; if (mErrorCount > 10) exit(10); } diff --git a/oscar64/Errors.h b/oscar64/Errors.h index 4a63985..bc63c8f 100644 --- a/oscar64/Errors.h +++ b/oscar64/Errors.h @@ -9,6 +9,48 @@ public: Location() : mFileName(nullptr), mLine(0), mColumn(0) {} }; +enum ErrorID +{ + EINFO_GENERIC = 1000, + + EWARN_GENERIC = 2000, + EWARN_CONSTANT_TRUNCATED, + EWARN_UNKNOWN_PRAGMA, + EWARN_SYNTAX, + + EERR_GENERIC = 3000, + EERR_FILE_NOT_FOUND, + EERR_RUNTIME_CODE, + EERR_UNIMPLEMENTED, + EERR_COMMAND_LINE, + EERR_OUT_OF_MEMORY, + EERR_OBJECT_NOT_FOUND, + EERR_SYNTAX, + EERR_EXECUTION_FAILED, + EERR_CONSTANT_INITIALIZER, + EERR_CONSTANT_TYPE, + EERR_VARIABLE_TYPE, + EERR_INCOMPATIBLE_TYPES, + EERR_INCOMPATIBLE_OPERATOR, + EERR_CONST_ASSIGN, + EERR_NOT_AN_LVALUE, + EERR_INVALID_INDEX, + EERR_WRONG_PARAMETER, + EERR_INVALID_RETURN, + EERR_INVALID_BREAK, + EERR_INVALID_CONTINUE, + EERR_DUPLICATE_DEFAULT, + EERR_UNDEFINED_OBJECT, + EERR_DUPLICATE_DEFINITION, + EERR_NOT_A_TYPE, + EERR_DECLARATION_DIFFERS, + EERR_INVALID_IDENTIFIER, + EERR_ASM_INVALD_OPERAND, + EERR_ASM_INVALID_INSTRUCTION, + EERR_ASM_INVALID_MODE, + + EERR_INVALID_PREPROCESSOR, +}; class Errors { @@ -17,7 +59,5 @@ public: int mErrorCount; - void Error(const Location& loc, const char* msg); - void Error(const Location& loc, const char* msg, const char * info); - void Warning(const Location& loc, const char* msg); + void Error(const Location& loc, ErrorID eid, const char* msg, const char* info = nullptr); }; diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index d937bf1..2fd1612 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -204,7 +204,7 @@ void InterCodeGenerator::InitGlobalVariable(InterCodeModule * mod, Declaration* BuildInitializer(mod, d, 0, dec->mValue->mDecValue, var); } else - mErrors->Error(dec->mLocation, "Non constant initializer"); + mErrors->Error(dec->mLocation, EERR_CONSTANT_INITIALIZER, "Non constant initializer"); } } } @@ -464,12 +464,12 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (dec->mFlags & DTF_SIGNED) { if (dec->mInteger < -128 || dec->mInteger > 127) - mErrors->Warning(dec->mLocation, "Integer constant truncated"); + mErrors->Error(dec->mLocation, EWARN_CONSTANT_TRUNCATED, "Integer constant truncated"); } else { if (dec->mInteger < 0 || dec->mInteger > 255) - mErrors->Warning(dec->mLocation, "Unsigned integer constant truncated"); + mErrors->Error(dec->mLocation, EWARN_CONSTANT_TRUNCATED, "Unsigned integer constant truncated"); } ins->mIntValue = char(dec->mInteger); } @@ -478,12 +478,12 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (dec->mFlags & DTF_SIGNED) { if (dec->mInteger < -32768 || dec->mInteger > 32767) - mErrors->Warning(dec->mLocation, "Integer constant truncated"); + mErrors->Error(dec->mLocation, EWARN_CONSTANT_TRUNCATED, "Integer constant truncated"); } else { if (dec->mInteger < 0 || dec->mInteger > 65535) - mErrors->Warning(dec->mLocation, "Unsigned integer constant truncated"); + mErrors->Error(dec->mLocation, EWARN_CONSTANT_TRUNCATED, "Unsigned integer constant truncated"); } ins->mIntValue = short(dec->mInteger); } @@ -607,7 +607,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* } default: - mErrors->Error(dec->mLocation, "Unimplemented constant type"); + mErrors->Error(dec->mLocation, EERR_CONSTANT_TYPE, "Unimplemented constant type"); } return ExValue(TheVoidTypeDeclaration); @@ -637,7 +637,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* block->Append(ins); if (!(dec->mBase->mFlags & DTF_DEFINED)) - mErrors->Error(dec->mLocation, "Undefined variable type"); + mErrors->Error(dec->mLocation, EERR_VARIABLE_TYPE, "Undefined variable type"); return ExValue(dec->mBase, ins->mTTemp, 1); } @@ -651,11 +651,11 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (exp->mToken == TK_ASSIGN || !(vl.mType->mType == IT_POINTER && vr.mType->IsIntegerType() && (exp->mToken == TK_ASSIGN_ADD || exp->mToken == TK_ASSIGN_SUB))) { if (!vl.mType->CanAssign(vr.mType)) - mErrors->Error(exp->mLocation, "Cannot assign incompatible types"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types"); } if (vl.mType->mFlags & DTF_CONST) - mErrors->Error(exp->mLocation, "Cannot assign to const type"); + mErrors->Error(exp->mLocation, EERR_CONST_ASSIGN, "Cannot assign to const type"); if (vl.mType->mType == DT_TYPE_STRUCT || vl.mType->mType == DT_TYPE_ARRAY || vl.mType->mType == DT_TYPE_UNION) { @@ -663,9 +663,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vl = Dereference(proc, block, vl, 1); if (vl.mReference != 1) - mErrors->Error(exp->mLeft->mLocation, "Not a left hand expression"); + mErrors->Error(exp->mLeft->mLocation, EERR_NOT_AN_LVALUE, "Not a left hand expression"); if (vr.mReference != 1) - mErrors->Error(exp->mLeft->mLocation, "Not an adressable expression"); + mErrors->Error(exp->mLeft->mLocation, EERR_NOT_AN_LVALUE, "Not an adressable expression"); InterInstruction * ins = new InterInstruction(); @@ -688,7 +688,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vl = Dereference(proc, block, vl, 1); if (vl.mReference != 1) - mErrors->Error(exp->mLeft->mLocation, "Not a left hand expression"); + mErrors->Error(exp->mLeft->mLocation, EERR_NOT_AN_LVALUE, "Not a left hand expression"); InterInstruction * ins = new InterInstruction(); @@ -710,10 +710,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* cins->mIntValue = -vl.mType->mBase->mSize; } else - mErrors->Error(exp->mLocation, "Invalid pointer assignment"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Invalid pointer assignment"); if (!vr.mType->IsIntegerType()) - mErrors->Error(exp->mLocation, "Invalid argument for pointer inc/dec"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_TYPES, "Invalid argument for pointer inc/dec"); cins->mTType = IT_INT16; cins->mTTemp = proc->AddTemporary(cins->mTType); @@ -758,9 +758,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* oins->mTTemp = proc->AddTemporary(oins->mTType); if (!vll.mType->IsNumericType()) - mErrors->Error(exp->mLocation, "Left hand element type is not numeric"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Left hand element type is not numeric"); if (!vr.mType->IsNumericType()) - mErrors->Error(exp->mLocation, "Right hand element type is not numeric"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Right hand element type is not numeric"); switch (exp->mToken) { @@ -838,10 +838,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vr = Dereference(proc, block, vr); if (vl.mType->mType != DT_TYPE_ARRAY && vl.mType->mType != DT_TYPE_POINTER) - mErrors->Error(exp->mLocation, "Invalid type for indexing"); + mErrors->Error(exp->mLocation, EERR_INVALID_INDEX, "Invalid type for indexing"); if (!vr.mType->IsIntegerType()) - mErrors->Error(exp->mLocation, "Index operand is not integral number"); + mErrors->Error(exp->mLocation, EERR_INVALID_INDEX, "Index operand is not integral number"); vr = CoerceType(proc, block, vr, TheSignedIntTypeDeclaration); @@ -883,7 +883,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vl = Dereference(proc, block, vl, 1); if (vl.mReference != 1) - mErrors->Error(exp->mLocation, "Not an addressable expression"); + mErrors->Error(exp->mLocation, EERR_NOT_AN_LVALUE, "Not an addressable expression"); InterInstruction * cins = new InterInstruction(); cins->mCode = IC_CONSTANT; @@ -942,7 +942,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* cins->mIntValue = -vl.mType->mBase->mSize; } else - mErrors->Error(exp->mLocation, "Invalid pointer operation"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Invalid pointer operation"); cins->mTType = IT_INT16; cins->mTTemp = proc->AddTemporary(cins->mTType); @@ -1019,7 +1019,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* return ExValue(TheSignedIntTypeDeclaration, dins->mTTemp); } else - mErrors->Error(exp->mLocation, "Invalid pointer operation"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Invalid pointer operation"); } } else @@ -1027,9 +1027,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vl = Dereference(proc, block, vl); if (!vl.mType->IsNumericType()) - mErrors->Error(exp->mLocation, "Left hand operand type is not numeric"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Left hand operand type is not numeric"); if (!vr.mType->IsNumericType()) - mErrors->Error(exp->mLocation, "Right hand operand type is not numeric"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Right hand operand type is not numeric"); Declaration* dtype; if (vr.mType->mType == DT_TYPE_FLOAT || vl.mType->mType == DT_TYPE_FLOAT) @@ -1102,10 +1102,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vl = Dereference(proc, block, vl, 1); if (vl.mReference != 1) - mErrors->Error(exp->mLeft->mLocation, "Not a left hand expression"); + mErrors->Error(exp->mLeft->mLocation, EERR_NOT_AN_LVALUE, "Not a left hand expression"); if (vl.mType->mFlags & DTF_CONST) - mErrors->Error(exp->mLocation, "Cannot change const value"); + mErrors->Error(exp->mLocation, EERR_CONST_ASSIGN, "Cannot change const value"); InterInstruction * cins = new InterInstruction(), * ains = new InterInstruction(), * rins = new InterInstruction(), * sins = new InterInstruction(); @@ -1121,7 +1121,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* else if (vdl.mType->IsNumericType()) cins->mIntValue = exp->mToken == TK_INC ? 1 : -1; else - mErrors->Error(exp->mLocation, "Not a numeric value or pointer"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a numeric value or pointer"); block->Append(cins); @@ -1154,10 +1154,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vl = Dereference(proc, block, vl, 1); if (vl.mReference != 1) - mErrors->Error(exp->mLeft->mLocation, "Not a left hand expression"); + mErrors->Error(exp->mLeft->mLocation, EERR_NOT_AN_LVALUE, "Not a left hand expression"); if (vl.mType->mFlags & DTF_CONST) - mErrors->Error(exp->mLocation, "Cannot change const value"); + mErrors->Error(exp->mLocation, EERR_CONST_ASSIGN, "Cannot change const value"); InterInstruction * cins = new InterInstruction(), * ains = new InterInstruction(), * rins = new InterInstruction(), * sins = new InterInstruction(); @@ -1173,7 +1173,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* else if (vdl.mType->IsNumericType()) cins->mIntValue = exp->mToken == TK_INC ? 1 : -1; else - mErrors->Error(exp->mLocation, "Not a numeric value or pointer"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a numeric value or pointer"); block->Append(cins); ains->mCode = IC_BINARY_OPERATOR; @@ -1216,23 +1216,23 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* case TK_SUB: vl = Dereference(proc, block, vl); if (!vl.mType->IsNumericType()) - mErrors->Error(exp->mLocation, "Not a numeric type"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a numeric type"); ins->mOperator = IA_NEG; break; case TK_BINARY_NOT: vl = Dereference(proc, block, vl); if (!(vl.mType->mType == DT_TYPE_POINTER || vl.mType->IsNumericType())) - mErrors->Error(exp->mLocation, "Not a numeric or pointer type"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a numeric or pointer type"); ins->mOperator = IA_NOT; break; case TK_MUL: if (vl.mType->mType != DT_TYPE_POINTER) - mErrors->Error(exp->mLocation, "Not a pointer type"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a pointer type"); return ExValue(vl.mType->mBase, vl.mTemp, vl.mReference + 1); case TK_BINARY_AND: { if (vl.mReference < 1) - mErrors->Error(exp->mLocation, "Not an addressable value"); + mErrors->Error(exp->mLocation, EERR_NOT_AN_LVALUE, "Not an addressable value"); Declaration* dec = new Declaration(exp->mLocation, DT_TYPE_POINTER); dec->mBase = vl.mType; @@ -1267,10 +1267,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* { dtype = vl.mType; if (!vl.mType->IsSame(vr.mType)) - mErrors->Error(exp->mLocation, "Incompatible pointer types"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible pointer types"); } else if (!vl.mType->IsNumericType() || !vr.mType->IsNumericType()) - mErrors->Error(exp->mLocation, "Not a numeric or pointer type"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a numeric or pointer type"); else if (vr.mType->mType == DT_TYPE_FLOAT || vl.mType->mType == DT_TYPE_FLOAT) dtype = TheFloatTypeDeclaration; else if (vr.mType->mSize < vl.mType->mSize && (vl.mType->mFlags & DTF_SIGNED)) @@ -1334,7 +1334,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vr = Dereference(proc, block, vr); if (decf->mBase->mParams->CanAssign(vr.mType)) - mErrors->Error(exp->mLocation, "Cannot assign incompatible types"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types"); vr = CoerceType(proc, block, vr, decf->mBase->mParams); InterInstruction * ins = new InterInstruction(); @@ -1354,7 +1354,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vr = Dereference(proc, block, vr); if (decf->mBase->mParams->CanAssign(vr.mType)) - mErrors->Error(exp->mLocation, "Cannot assign incompatible types"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types"); vr = CoerceType(proc, block, vr, decf->mBase->mParams); InterInstruction * ins = new InterInstruction(); @@ -1374,7 +1374,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vr = Dereference(proc, block, vr); if (decf->mBase->mParams->CanAssign(vr.mType)) - mErrors->Error(exp->mLocation, "Cannot assign incompatible types"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types"); vr = CoerceType(proc, block, vr, decf->mBase->mParams); InterInstruction * ins = new InterInstruction(); @@ -1389,7 +1389,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* return ExValue(TheFloatTypeDeclaration, ins->mTTemp); } else - mErrors->Error(exp->mLeft->mDecValue->mLocation, "Unknown intrinsic function", iname->mString); + mErrors->Error(exp->mLeft->mDecValue->mLocation, EERR_OBJECT_NOT_FOUND, "Unknown intrinsic function", iname->mString); return ExValue(TheVoidTypeDeclaration); } @@ -1435,7 +1435,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* } else { - mErrors->Error(pex->mLocation, "Too many arguments for function call"); + mErrors->Error(pex->mLocation, EERR_WRONG_PARAMETER, "Too many arguments for function call"); } block->Append(ains); @@ -1457,12 +1457,12 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (vr.mType->mType == DT_TYPE_STRUCT || vr.mType->mType == DT_TYPE_UNION) { if (pdec && !pdec->mBase->CanAssign(vr.mType)) - mErrors->Error(texp->mLocation, "Cannot assign incompatible types"); + mErrors->Error(texp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types"); vr = Dereference(proc, block, vr, 1); if (vr.mReference != 1) - mErrors->Error(exp->mLeft->mLocation, "Not an adressable expression"); + mErrors->Error(exp->mLeft->mLocation, EERR_NOT_AN_LVALUE, "Not an adressable expression"); InterInstruction* cins = new InterInstruction(); cins->mCode = IC_COPY; @@ -1486,7 +1486,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (pdec) { if (!pdec->mBase->CanAssign(vr.mType)) - mErrors->Error(texp->mLocation, "Cannot assign incompatible types"); + mErrors->Error(texp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types"); vr = CoerceType(proc, block, vr, pdec->mBase); } else if (vr.mType->IsIntegerType() && vr.mType->mSize < 2) @@ -1519,7 +1519,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* } if (pdec) - mErrors->Error(exp->mLocation, "Not enough arguments for function call"); + mErrors->Error(exp->mLocation, EERR_WRONG_PARAMETER, "Not enough arguments for function call"); InterInstruction * cins = new InterInstruction(); if (exp->mLeft->mDecValue && exp->mLeft->mDecValue->mFlags & DTF_NATIVE) @@ -1587,9 +1587,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vr = Dereference(proc, block, vr); if (!procType->mBase || procType->mBase->mType == DT_TYPE_VOID) - mErrors->Error(exp->mLocation, "Function has void return type"); + mErrors->Error(exp->mLocation, EERR_INVALID_RETURN, "Function has void return type"); else if (!procType->mBase->CanAssign(vr.mType)) - mErrors->Error(exp->mLocation, "Cannot return incompatible type"); + mErrors->Error(exp->mLocation, EERR_INVALID_RETURN, "Cannot return incompatible type"); ins->mSType[0] = InterTypeOf(vr.mType); ins->mSTemp[0] = vr.mTemp; @@ -1598,7 +1598,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* else { if (procType->mBase && procType->mBase->mType != DT_TYPE_VOID) - mErrors->Error(exp->mLocation, "Function has non void return type"); + mErrors->Error(exp->mLocation, EERR_INVALID_RETURN, "Function has non void return type"); ins->mCode = IC_RETURN; } @@ -1624,7 +1624,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* proc->Append(block); } else - mErrors->Error(exp->mLocation, "No break target"); + mErrors->Error(exp->mLocation, EERR_INVALID_BREAK, "No break target"); return ExValue(TheVoidTypeDeclaration); } @@ -1642,7 +1642,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* proc->Append(block); } else - mErrors->Error(exp->mLocation, "No continue target"); + mErrors->Error(exp->mLocation, EERR_INVALID_CONTINUE, "No continue target"); return ExValue(TheVoidTypeDeclaration); } @@ -1705,7 +1705,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (stypel == IT_POINTER || styper == IT_POINTER) { if (!vl.mType->IsSame(vr.mType)) - mErrors->Error(exp->mLocation, "Incompatible conditional types"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible conditional types"); ttype = IT_POINTER; dtype = vl.mType; @@ -1796,7 +1796,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* } else if (exp->mLeft->mDecType->mType != DT_TYPE_VOID && vr.mType->mType == DT_TYPE_VOID) { - mErrors->Error(exp->mLocation, "Cannot cast void object to non void object"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Cannot cast void object to non void object"); return ExValue(exp->mLeft->mDecType, vr.mTemp, vr.mReference); } else @@ -2033,7 +2033,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* block = dblock; } else - mErrors->Error(cexp->mLocation, "Duplicate default"); + mErrors->Error(cexp->mLocation, EERR_DUPLICATE_DEFAULT, "Duplicate default"); } if (cexp->mRight) @@ -2065,7 +2065,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* return ExValue(TheVoidTypeDeclaration); } default: - mErrors->Error(exp->mLocation, "Unimplemented expression"); + mErrors->Error(exp->mLocation, EERR_UNIMPLEMENTED, "Unimplemented expression"); return ExValue(TheVoidTypeDeclaration); } } @@ -2242,7 +2242,7 @@ InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod if (dec->mFlags & DTF_DEFINED) TranslateExpression(dec->mBase, proc, exitBlock, exp, nullptr, nullptr); else - mErrors->Error(dec->mLocation, "Calling undefined function", dec->mIdent->mString); + mErrors->Error(dec->mLocation, EERR_UNDEFINED_OBJECT, "Calling undefined function", dec->mIdent->mString); InterInstruction * ins = new InterInstruction(); ins->mCode = IC_RETURN; diff --git a/oscar64/Linker.cpp b/oscar64/Linker.cpp index b84e639..7d73dcd 100644 --- a/oscar64/Linker.cpp +++ b/oscar64/Linker.cpp @@ -96,7 +96,7 @@ void Linker::Link(void) lsec->mUsed += obj->mSize; } else - mErrors->Error(obj->mLocation, "Out of space in section", obj->mSection->mString); + mErrors->Error(obj->mLocation, EERR_OUT_OF_MEMORY, "Out of space in section", obj->mSection->mString); } } diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index a966a11..c28d19a 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -38,7 +38,7 @@ Declaration* Parser::ParseStructDeclaration(uint32 flags, DecType dt) } else { - mErrors->Error(mScanner->mLocation, "Error duplicate struct declaration", structName->mString); + mErrors->Error(mScanner->mLocation, EERR_DUPLICATE_DEFINITION, "Error duplicate struct declaration", structName->mString); } } } @@ -59,7 +59,7 @@ Declaration* Parser::ParseStructDeclaration(uint32 flags, DecType dt) while (mdec) { if (!(mdec->mBase->mFlags & DTF_DEFINED)) - mErrors->Error(mdec->mLocation, "Undefined type used in struct member declaration"); + mErrors->Error(mdec->mLocation, EERR_UNDEFINED_OBJECT, "Undefined type used in struct member declaration"); mdec->mType = DT_ELEMENT; if (dt == DT_TYPE_UNION) { @@ -85,7 +85,7 @@ Declaration* Parser::ParseStructDeclaration(uint32 flags, DecType dt) mScanner->NextToken(); else { - mErrors->Error(mScanner->mLocation, "';' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "';' expected"); break; } @@ -217,12 +217,12 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags) mScanner->NextToken(); else if (!dec) { - mErrors->Error(mScanner->mLocation, "Identifier not defined", mScanner->mTokenIdent->mString); + mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Identifier not defined", mScanner->mTokenIdent->mString); mScanner->NextToken(); } else { - mErrors->Error(mScanner->mLocation, "Identifier is no type", mScanner->mTokenIdent->mString); + mErrors->Error(mScanner->mLocation, EERR_NOT_A_TYPE, "Identifier is no type", mScanner->mTokenIdent->mString); mScanner->NextToken(); } break; @@ -239,7 +239,7 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags) dec->mIdent = mScanner->mTokenIdent; if (mScope->Insert(dec->mIdent, dec)) - mErrors->Error(dec->mLocation, "Duplicate name"); + mErrors->Error(dec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate name"); mScanner->NextToken(); } @@ -258,7 +258,7 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags) { cdec->mIdent = mScanner->mTokenIdent; if (mScope->Insert(cdec->mIdent, cdec) != nullptr) - mErrors->Error(mScanner->mLocation, "Duplicate declaration", mScanner->mTokenIdent->mString); + mErrors->Error(mScanner->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate declaration", mScanner->mTokenIdent->mString); mScanner->NextToken(); } if (mScanner->mToken == TK_ASSIGN) @@ -268,7 +268,7 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags) if (exp->mType == EX_CONSTANT && exp->mDecValue->mType == DT_CONST_INTEGER) nitem = int(exp->mDecValue->mInteger); else - mErrors->Error(mScanner->mLocation, "Integer constant expected"); + mErrors->Error(mScanner->mLocation, EERR_CONSTANT_TYPE, "Integer constant expected"); } cdec->mInteger = nitem++; @@ -282,10 +282,10 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags) if (mScanner->mToken == TK_CLOSE_BRACE) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "'}' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'}' expected"); } else - mErrors->Error(mScanner->mLocation, "'{' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'{' expected"); dec->mFlags |= DTF_DEFINED; break; @@ -297,7 +297,7 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags) dec = ParseStructDeclaration(flags, DT_TYPE_UNION); break; default: - mErrors->Error(mScanner->mLocation, "Declaration starts with invalid token", TokenNames[mScanner->mToken]); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Declaration starts with invalid token", TokenNames[mScanner->mToken]); mScanner->NextToken(); } @@ -333,7 +333,7 @@ Declaration* Parser::ParsePostfixDeclaration(void) if (mScanner->mToken == TK_CLOSE_PARENTHESIS) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "')' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected"); dec = vdec; } else if (mScanner->mToken == TK_IDENT) @@ -364,13 +364,13 @@ Declaration* Parser::ParsePostfixDeclaration(void) if (exp->mType == EX_CONSTANT && exp->mDecType->IsIntegerType() && exp->mDecValue->mType == DT_CONST_INTEGER) ndec->mSize = int(exp->mDecValue->mInteger); else - mErrors->Error(exp->mLocation, "Constant integer expression expected"); + mErrors->Error(exp->mLocation, EERR_CONSTANT_TYPE, "Constant integer expression expected"); ndec->mFlags |= DTF_DEFINED; } if (mScanner->mToken == TK_CLOSE_BRACKET) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "']' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "']' expected"); ndec->mBase = dec; dec = ndec; } @@ -400,13 +400,13 @@ Declaration* Parser::ParsePostfixDeclaration(void) if (adec->mBase->mType == DT_TYPE_VOID) { if (pdec) - mErrors->Error(pdec->mLocation, "Invalid void argument"); + mErrors->Error(pdec->mLocation, EERR_WRONG_PARAMETER, "Invalid void argument"); break; } else { if (!(adec->mBase->mFlags & DTF_DEFINED)) - mErrors->Error(adec->mLocation, "Type of argument not defined"); + mErrors->Error(adec->mLocation, EERR_UNDEFINED_OBJECT, "Type of argument not defined"); adec->mType = DT_ARGUMENT; adec->mVarIndex = vi; @@ -429,7 +429,7 @@ Declaration* Parser::ParsePostfixDeclaration(void) if (mScanner->mToken == TK_CLOSE_PARENTHESIS) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "')' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected"); } else mScanner->NextToken(); @@ -467,7 +467,7 @@ Declaration * Parser::CopyConstantInitializer(int offset, Declaration* dtype, Ex if (exp->mType == EX_CONSTANT) { if (!dtype->CanAssign(exp->mDecType)) - mErrors->Error(exp->mLocation, "Incompatible constant initializer"); + mErrors->Error(exp->mLocation, EERR_CONSTANT_INITIALIZER, "Incompatible constant initializer"); else { if (dec->mType == DT_CONST_FLOAT) @@ -528,7 +528,7 @@ Declaration * Parser::CopyConstantInitializer(int offset, Declaration* dtype, Ex } } else - mErrors->Error(exp->mLocation, "Constant initializer expected"); + mErrors->Error(exp->mLocation, EERR_CONSTANT_INITIALIZER, "Constant initializer expected"); return dec; } @@ -543,9 +543,9 @@ Expression* Parser::ParseInitExpression(Declaration* dtype) if (dtype->mType != DT_TYPE_ARRAY && !(dtype->mFlags & DTF_DEFINED)) { if (dtype->mIdent) - mErrors->Error(mScanner->mLocation, "Constant for undefined type", dtype->mIdent->mString); + mErrors->Error(mScanner->mLocation, EERR_UNDEFINED_OBJECT, "Constant for undefined type", dtype->mIdent->mString); else - mErrors->Error(mScanner->mLocation, "Constant for undefined annonymous type"); + mErrors->Error(mScanner->mLocation, EERR_UNDEFINED_OBJECT, "Constant for undefined annonymous type"); } if (ConsumeTokenIf(TK_OPEN_BRACE)) { @@ -633,7 +633,7 @@ Expression* Parser::ParseInitExpression(Declaration* dtype) strcpy_s((char *)d, dec->mSize, mScanner->mTokenString); } else - mErrors->Error(mScanner->mLocation, "String constant is too large for char array"); + mErrors->Error(mScanner->mLocation, EERR_CONSTANT_INITIALIZER, "String constant is too large for char array"); mScanner->NextToken(); } @@ -707,7 +707,7 @@ Declaration* Parser::ParseDeclaration(bool variable) { Declaration* pdec = mScope->Insert(ndec->mIdent, ndec->mBase); if (pdec) - mErrors->Error(ndec->mLocation, "Duplicate type declaration", ndec->mIdent->mString); + mErrors->Error(ndec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate type declaration", ndec->mIdent->mString); } } else @@ -732,7 +732,7 @@ Declaration* Parser::ParseDeclaration(bool variable) pdec = mCompilationUnits->mScope->Insert(ndec->mIdent, ndec); Declaration * ldec = mScope->Insert(ndec->mIdent, pdec ? pdec : ndec); if (ldec && ldec != pdec) - mErrors->Error(ndec->mLocation, "Duplicate definition"); + mErrors->Error(ndec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate definition"); } else pdec = mScope->Insert(ndec->mIdent, ndec); @@ -742,7 +742,7 @@ Declaration* Parser::ParseDeclaration(bool variable) if (pdec->mType == DT_CONST_FUNCTION && ndec->mBase->mType == DT_TYPE_FUNCTION) { if (!ndec->mBase->IsSame(pdec->mBase)) - mErrors->Error(ndec->mLocation, "Function declaration differs"); + mErrors->Error(ndec->mLocation, EERR_DECLARATION_DIFFERS, "Function declaration differs"); else { // @@ -761,7 +761,7 @@ Declaration* Parser::ParseDeclaration(bool variable) ndec = pdec; } else - mErrors->Error(ndec->mLocation, "Duplicate variable declaration", ndec->mIdent->mString); + mErrors->Error(ndec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate variable declaration", ndec->mIdent->mString); } } @@ -798,7 +798,7 @@ Declaration* Parser::ParseDeclaration(bool variable) if (ndec->mBase->mType == DT_TYPE_FUNCTION) { if (ndec->mFlags & DTF_DEFINED) - mErrors->Error(ndec->mLocation, "Duplicate function definition"); + mErrors->Error(ndec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate function definition"); ndec->mVarIndex = -1; ndec->mValue = ParseFunction(ndec->mBase); @@ -1005,13 +1005,13 @@ Expression* Parser::ParseSimpleExpression(void) } else { - mErrors->Error(mScanner->mLocation, "Invalid identifier", mScanner->mTokenIdent->mString); + mErrors->Error(mScanner->mLocation, EERR_INVALID_IDENTIFIER, "Invalid identifier", mScanner->mTokenIdent->mString); mScanner->NextToken(); } } else { - mErrors->Error(mScanner->mLocation, "Unknown identifier", mScanner->mTokenIdent->mString); + mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Unknown identifier", mScanner->mTokenIdent->mString); mScanner->NextToken(); } @@ -1033,7 +1033,7 @@ Expression* Parser::ParseSimpleExpression(void) if (mScanner->mToken == TK_CLOSE_PARENTHESIS) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "')' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected"); if (exp->mType == EX_TYPE) { @@ -1045,7 +1045,7 @@ Expression* Parser::ParseSimpleExpression(void) } break; default: - mErrors->Error(mScanner->mLocation, "Term starts with invalid token", TokenNames[mScanner->mToken]); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Term starts with invalid token", TokenNames[mScanner->mToken]); mScanner->NextToken(); } @@ -1068,7 +1068,7 @@ Expression* Parser::ParsePostfixExpression(void) if (mScanner->mToken == TK_OPEN_BRACKET) { if (exp->mDecType->mType != DT_TYPE_ARRAY && exp->mDecType->mType != DT_TYPE_POINTER) - mErrors->Error(mScanner->mLocation, "Array expected for indexing"); + mErrors->Error(mScanner->mLocation, EERR_INVALID_INDEX, "Array expected for indexing"); mScanner->NextToken(); Expression* nexp = new Expression(mScanner->mLocation, EX_INDEX); nexp->mLeft = exp; @@ -1076,7 +1076,7 @@ Expression* Parser::ParsePostfixExpression(void) if (mScanner->mToken == TK_CLOSE_BRACKET) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "']' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "']' expected"); nexp->mDecType = exp->mDecType->mBase; if (!nexp->mDecType) nexp->mDecType = TheVoidTypeDeclaration; @@ -1091,7 +1091,7 @@ Expression* Parser::ParsePostfixExpression(void) { } else - mErrors->Error(mScanner->mLocation, "Function expected for call"); + mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Function expected for call"); mScanner->NextToken(); Expression* nexp = new Expression(mScanner->mLocation, EX_CALL); @@ -1142,17 +1142,17 @@ Expression* Parser::ParsePostfixExpression(void) exp = nexp; } else - mErrors->Error(mScanner->mLocation, "Struct member identifier not found", mScanner->mTokenIdent->mString); + mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Struct member identifier not found", mScanner->mTokenIdent->mString); mScanner->NextToken(); } else - mErrors->Error(mScanner->mLocation, "Struct member identifier expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Struct member identifier expected"); } else - mErrors->Error(mScanner->mLocation, "Struct expected"); + mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Struct expected"); } else - mErrors->Error(mScanner->mLocation, "Pointer expected"); + mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Pointer expected"); } else if (mScanner->mToken == TK_DOT) { @@ -1171,14 +1171,14 @@ Expression* Parser::ParsePostfixExpression(void) exp = nexp; } else - mErrors->Error(mScanner->mLocation, "Struct member identifier not found", mScanner->mTokenIdent->mString); + mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Struct member identifier not found", mScanner->mTokenIdent->mString); mScanner->NextToken(); } else - mErrors->Error(mScanner->mLocation, "Struct member identifier expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Struct member identifier expected"); } else - mErrors->Error(mScanner->mLocation, "Struct expected"); + mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Struct expected"); } else return exp; @@ -1221,7 +1221,7 @@ Expression* Parser::ParsePrefixExpression(void) nexp->mDecType = nexp->mLeft->mDecType; } else - mErrors->Error(nexp->mLocation, "Pointer or array type expected"); + mErrors->Error(nexp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Pointer or array type expected"); } else if (nexp->mToken == TK_BINARY_AND) { @@ -1449,14 +1449,14 @@ Expression* Parser::ParseParenthesisExpression(void) if (mScanner->mToken == TK_OPEN_PARENTHESIS) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "'(' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'(' expected"); Expression* exp = ParseExpression(); if (mScanner->mToken == TK_CLOSE_PARENTHESIS) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "')' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected"); return exp; } @@ -1554,7 +1554,7 @@ Expression* Parser::ParseStatement(void) } while (mScanner->mToken != TK_CLOSE_BRACE && mScanner->mToken != TK_EOF); if (mScanner->mToken != TK_CLOSE_BRACE) - mErrors->Error(mScanner->mLocation, "'}' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'}' expected"); mScanner->NextToken(); } else @@ -1607,7 +1607,7 @@ Expression* Parser::ParseStatement(void) exp->mLeft = ParseParenthesisExpression(); } else - mErrors->Error(mScanner->mLocation, "'while' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'while' expected"); break; case TK_FOR: mScanner->NextToken(); @@ -1624,24 +1624,24 @@ Expression* Parser::ParseStatement(void) if (mScanner->mToken == TK_SEMICOLON) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "';' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "';' expected"); exp->mLeft->mLeft->mLeft = ParseExpression(); if (mScanner->mToken == TK_SEMICOLON) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "';' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "';' expected"); if (mScanner->mToken != TK_CLOSE_PARENTHESIS) exp->mLeft->mLeft->mRight = ParseExpression(); if (mScanner->mToken == TK_CLOSE_PARENTHESIS) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "')' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected"); exp->mRight = ParseStatement(); mScope = mScope->mParent; } else - mErrors->Error(mScanner->mLocation, "'(' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'(' expected"); break; case TK_SWITCH: mScanner->NextToken(); @@ -1672,7 +1672,7 @@ Expression* Parser::ParseStatement(void) if (mScanner->mToken == TK_CLOSE_BRACE) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "'}' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'}' expected"); } break; default: @@ -1696,10 +1696,10 @@ Expression* Parser::ParseSwitchStatement(void) if (mScanner->mToken == TK_CLOSE_PARENTHESIS) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "')' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected"); } else - mErrors->Error(mScanner->mLocation, "'(' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'(' expected"); if (mScanner->mToken == TK_OPEN_BRACE) { @@ -1724,7 +1724,7 @@ Expression* Parser::ParseSwitchStatement(void) if (mScanner->mToken == TK_COLON) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "':' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "':' expected"); Expression* csexp = new Expression(mScanner->mLocation, EX_SEQUENCE); csexp->mLeft = cexp; @@ -1744,7 +1744,7 @@ Expression* Parser::ParseSwitchStatement(void) if (mScanner->mToken == TK_COLON) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "':' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "':' expected"); Expression * csexp = new Expression(mScanner->mLocation, EX_SEQUENCE); csexp->mLeft = cexp; @@ -1772,10 +1772,10 @@ Expression* Parser::ParseSwitchStatement(void) if (mScanner->mToken == TK_CLOSE_BRACE) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "'}' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'}' expected"); } else - mErrors->Error(mScanner->mLocation, "'{' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'{' expected"); return sexp; } @@ -1805,7 +1805,7 @@ Expression* Parser::ParseAssemblerBaseOperand(void) exp->mDecType = dec->mBase; } else - mErrors->Error(exp->mLocation, "Cannot negate expression"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Cannot negate expression"); break; case TK_INTEGER: @@ -1868,16 +1868,16 @@ Expression* Parser::ParseAssemblerBaseOperand(void) exp->mDecType = TheUnsignedIntTypeDeclaration; } else - mErrors->Error(mScanner->mLocation, "Assembler label not found", mScanner->mTokenIdent->mString); + mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Assembler label not found", mScanner->mTokenIdent->mString); } mScanner->NextToken(); } else - mErrors->Error(mScanner->mLocation, "Identifier for qualification expected"); + mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Identifier for qualification expected"); } break; default: - mErrors->Error(mScanner->mLocation, "Invalid assembler operand"); + mErrors->Error(mScanner->mLocation, EERR_ASM_INVALD_OPERAND, "Invalid assembler operand"); } if (!exp) @@ -1925,7 +1925,7 @@ Expression* Parser::ParseAssemblerAddOperand(void) exp->mDecValue = ndec; } else - mErrors->Error(mScanner->mLocation, "Integer offset expected"); + mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Integer offset expected"); } else if (nexp->mLeft->mDecValue->mType == DT_CONST_FUNCTION) { @@ -1938,7 +1938,7 @@ Expression* Parser::ParseAssemblerAddOperand(void) exp->mDecValue = ndec; } else - mErrors->Error(mScanner->mLocation, "Integer offset expected"); + mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Integer offset expected"); } else if (nexp->mLeft->mDecValue->mType == DT_LABEL) { @@ -1951,7 +1951,7 @@ Expression* Parser::ParseAssemblerAddOperand(void) exp->mDecValue = ndec; } else - mErrors->Error(mScanner->mLocation, "Integer offset expected"); + mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Integer offset expected"); } else exp = nexp->ConstantFold(); @@ -2024,10 +2024,10 @@ Expression* Parser::ParseAssemblerOperand(void) exp->mDecValue = ndec; } else - mErrors->Error(mScanner->mLocation, "Label or integer value for lower byte operator expected"); + mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Label or integer value for lower byte operator expected"); } else - mErrors->Error(mScanner->mLocation, "Constant for lower byte operator expected"); + mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Constant for lower byte operator expected"); return exp; } @@ -2094,10 +2094,10 @@ Expression* Parser::ParseAssemblerOperand(void) exp->mDecValue = ndec; } else - mErrors->Error(mScanner->mLocation, "Label or integer value for lower byte operator expected"); + mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Label or integer value for lower byte operator expected"); } else - mErrors->Error(mScanner->mLocation, "Constant for upper byte operator expected"); + mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Constant for upper byte operator expected"); return exp; } @@ -2154,7 +2154,7 @@ Expression* Parser::ParseAssembler(void) const Ident* label = mScanner->mTokenIdent; mScanner->NextToken(); if (mScanner->mToken != TK_COLON) - mErrors->Error(mScanner->mLocation, "':' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "':' expected"); else mScanner->NextToken(); @@ -2162,7 +2162,7 @@ Expression* Parser::ParseAssembler(void) if (dec) { if (dec->mType != DT_LABEL || dec->mBase) - mErrors->Error(mScanner->mLocation, "Duplicate label definition"); + mErrors->Error(mScanner->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate label definition"); } else dec = new Declaration(mScanner->mLocation, DT_LABEL); @@ -2199,10 +2199,10 @@ Expression* Parser::ParseAssembler(void) if (mScanner->mToken == TK_CLOSE_PARENTHESIS) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "')' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected"); } else - mErrors->Error(mScanner->mLocation, "',x' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "',x' expected"); } else if (mScanner->mToken == TK_CLOSE_PARENTHESIS) { @@ -2216,7 +2216,7 @@ Expression* Parser::ParseAssembler(void) mScanner->NextToken(); } else - mErrors->Error(mScanner->mLocation, "',y' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "',y' expected"); } else { @@ -2224,7 +2224,7 @@ Expression* Parser::ParseAssembler(void) } } else - mErrors->Error(mScanner->mLocation, "',' or ')' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "',' or ')' expected"); } else { @@ -2243,7 +2243,7 @@ Expression* Parser::ParseAssembler(void) mScanner->NextToken(); } else - mErrors->Error(mScanner->mLocation, "',x' or ',y' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "',x' or ',y' expected"); } else { @@ -2269,7 +2269,7 @@ Expression* Parser::ParseAssembler(void) if (mScanner->mToken != TK_EOL) { - mErrors->Error(mScanner->mLocation, "End of line expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "End of line expected"); } while (mScanner->mToken != TK_EOL && mScanner->mToken != TK_EOF) @@ -2287,7 +2287,7 @@ Expression* Parser::ParseAssembler(void) } else { - mErrors->Error(mScanner->mLocation, "Invalid assembler token"); + mErrors->Error(mScanner->mLocation, EERR_ASM_INVALID_INSTRUCTION, "Invalid assembler token"); while (mScanner->mToken != TK_EOL && mScanner->mToken != TK_EOF) mScanner->NextToken(); @@ -2339,7 +2339,7 @@ bool Parser::ConsumeToken(Token token) { char buffer[100]; sprintf_s(buffer, "%s expected", TokenNames[token]); - mErrors->Error(mScanner->mLocation, buffer); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, buffer); return false; } } @@ -2392,7 +2392,7 @@ void Parser::ParsePragma(void) if (dec && dec->mType == DT_CONST_FUNCTION) dec->mFlags |= DTF_INTRINSIC; else - mErrors->Error(mScanner->mLocation, "Intrinsic function not found"); + mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Intrinsic function not found"); mScanner->NextToken(); } ConsumeToken(TK_CLOSE_PARENTHESIS); @@ -2407,7 +2407,7 @@ void Parser::ParsePragma(void) if (dec && dec->mType == DT_CONST_FUNCTION) dec->mFlags |= DTF_NATIVE; else - mErrors->Error(mScanner->mLocation, "Native function not found"); + mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Native function not found"); mScanner->NextToken(); } ConsumeToken(TK_CLOSE_PARENTHESIS); @@ -2415,7 +2415,7 @@ void Parser::ParsePragma(void) else if (!strcmp(mScanner->mTokenIdent->mString, "startup")) { if (mCompilationUnits->mStartup) - mErrors->Error(mScanner->mLocation, "Duplicate startup pragma"); + mErrors->Error(mScanner->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate startup pragma"); mScanner->NextToken(); ConsumeToken(TK_OPEN_PARENTHESIS); @@ -2425,7 +2425,7 @@ void Parser::ParsePragma(void) if (dec && dec->mType == DT_CONST_ASSEMBLER) mCompilationUnits->mStartup = dec; else - mErrors->Error(mScanner->mLocation, "Startup function not found"); + mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Startup function not found"); mScanner->NextToken(); } ConsumeToken(TK_CLOSE_PARENTHESIS); @@ -2451,26 +2451,26 @@ void Parser::ParsePragma(void) if (ndec) dec = ndec; else - mErrors->Error(mScanner->mLocation, "Label not found in assembler code"); + mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Label not found in assembler code"); mScanner->NextToken(); } else - mErrors->Error(mScanner->mLocation, "Identifier expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Identifier expected"); } if (exp->mType == EX_CONSTANT && exp->mDecValue->mType == DT_CONST_INTEGER && exp->mDecValue->mInteger >= 0 && exp->mDecValue->mInteger < 128) { if (mCompilationUnits->mByteCodes[exp->mDecValue->mInteger]) - mErrors->Error(mScanner->mLocation, "Duplicate bytecode function"); + mErrors->Error(mScanner->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate bytecode function"); mCompilationUnits->mByteCodes[exp->mDecValue->mInteger] = dec; } else - mErrors->Error(exp->mLocation, "Numeric value for byte code expected"); + mErrors->Error(exp->mLocation, EERR_CONSTANT_TYPE, "Numeric value for byte code expected"); } else { - mErrors->Error(mScanner->mLocation, "Bytecode function not found"); + mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Bytecode function not found"); mScanner->NextToken(); } @@ -2489,7 +2489,7 @@ void Parser::ParsePragma(void) mScanner->NextToken(); } else - mErrors->Error(mScanner->mLocation, "Identifier expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Identifier expected"); ConsumeToken(TK_COMMA); if (mScanner->mToken == TK_IDENT) @@ -2506,11 +2506,11 @@ void Parser::ParsePragma(void) if (ndec) dec = ndec; else - mErrors->Error(mScanner->mLocation, "Label not found in assembler code"); + mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Label not found in assembler code"); mScanner->NextToken(); } else - mErrors->Error(mScanner->mLocation, "Identifier expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Identifier expected"); } if (rtident) @@ -2524,7 +2524,7 @@ void Parser::ParsePragma(void) } else { - mErrors->Error(mScanner->mLocation, "Runtime function not found"); + mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Runtime function not found"); mScanner->NextToken(); } @@ -2540,11 +2540,11 @@ void Parser::ParsePragma(void) mScanner->NextToken(); ConsumeToken(TK_CLOSE_PARENTHESIS); } - mErrors->Error(mScanner->mLocation, "Unknown pragma, ignored", mScanner->mTokenIdent->mString); + mErrors->Error(mScanner->mLocation, EWARN_UNKNOWN_PRAGMA, "Unknown pragma, ignored", mScanner->mTokenIdent->mString); } } else - mErrors->Error(mScanner->mLocation, "Invalid pragma directive"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Invalid pragma directive"); } void Parser::Parse(void) @@ -2578,11 +2578,11 @@ void Parser::Parse(void) if (mScanner->mToken == TK_CLOSE_BRACE) mScanner->NextToken(); else - mErrors->Error(mScanner->mLocation, "'}' expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'}' expected"); } } else - mErrors->Error(mScanner->mLocation, "Identifier expected"); + mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Identifier expected"); } else if (mScanner->mToken == TK_SEMICOLON) mScanner->NextToken(); diff --git a/oscar64/Preprocessor.cpp b/oscar64/Preprocessor.cpp index 2e49773..31e2b00 100644 --- a/oscar64/Preprocessor.cpp +++ b/oscar64/Preprocessor.cpp @@ -4,6 +4,13 @@ SourcePath::SourcePath(const char* path) { strcpy_s(mPathName, path); + char* p = mPathName; + while (*p) + { + if (*p == '\\') + *p = '/'; + p++; + } } SourcePath::~SourcePath(void) diff --git a/oscar64/Scanner.cpp b/oscar64/Scanner.cpp index 901d671..5c053bf 100644 --- a/oscar64/Scanner.cpp +++ b/oscar64/Scanner.cpp @@ -359,7 +359,7 @@ void Scanner::NextToken(void) else if (mPrepPending > 0) mPrepPending--; else - mErrors->Error(mLocation, "Unexpected #endif"); + mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Unexpected #endif"); } else if (mToken == TK_EOF) { @@ -379,14 +379,14 @@ void Scanner::NextToken(void) if (mToken == TK_STRING) { if (!mPreprocessor->OpenSource(mTokenString, true)) - mErrors->Error(mLocation, "Could not open source file", mTokenString); + mErrors->Error(mLocation, EERR_FILE_NOT_FOUND, "Could not open source file", mTokenString); } else if (mToken == TK_LESS_THAN) { mOffset--; StringToken('>'); if (!mPreprocessor->OpenSource(mTokenString, false)) - mErrors->Error(mLocation, "Could not open source file", mTokenString); + mErrors->Error(mLocation, EERR_FILE_NOT_FOUND, "Could not open source file", mTokenString); } } else if (mToken == TK_PREP_DEFINE) @@ -410,7 +410,7 @@ void Scanner::NextToken(void) NextRawToken(); } else - mErrors->Error(mLocation, "Invalid define argument"); + mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Invalid define argument"); } while (mToken == TK_COMMA); @@ -419,7 +419,7 @@ void Scanner::NextToken(void) // No need to goto next token, mOffset is already behind it } else - mErrors->Error(mLocation, "')' expected in defined parameter list"); + mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "')' expected in defined parameter list"); } macro->SetString(mLine + mOffset); @@ -501,19 +501,19 @@ void Scanner::NextToken(void) if (mLine[mOffset] == ',') mOffset++; else - mErrors->Error(mLocation, "Invalid define expansion argument"); + mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Invalid define expansion argument"); } else { if (mLine[mOffset] == ')') mOffset++; else - mErrors->Error(mLocation, "Invalid define expansion closing argument"); + mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Invalid define expansion closing argument"); } } } else - mErrors->Error(mLocation, "Missing arguments for macro expansion"); + mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Missing arguments for macro expansion"); NextChar(); } else @@ -661,7 +661,7 @@ void Scanner::NextRawToken(void) } if (n == 0) - mErrors->Error(mLocation, "Missing digits in hex constant"); + mErrors->Error(mLocation, EERR_SYNTAX, "Missing digits in hex constant"); mToken = TK_INTEGER; mTokenInteger = mant; @@ -870,7 +870,7 @@ void Scanner::NextRawToken(void) else if (!strcmp(tkprep, "pragma")) mToken = TK_PREP_PRAGMA; else - mErrors->Error(mLocation, "Invalid preprocessor command", tkprep); + mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Invalid preprocessor command", tkprep); } else { @@ -900,7 +900,7 @@ void Scanner::NextRawToken(void) } if (n == 0) - mErrors->Error(mLocation, "Missing digits in hex constant"); + mErrors->Error(mLocation, EERR_SYNTAX, "Missing digits in hex constant"); mToken = TK_INTEGER; mTokenInteger = mant; @@ -1021,12 +1021,12 @@ void Scanner::NextRawToken(void) void Scanner::Warning(const char* error) { - mErrors->Warning(mLocation, error); + mErrors->Error(mLocation, EWARN_SYNTAX, error); } void Scanner::Error(const char* error) { - mErrors->Error(mLocation, error); + mErrors->Error(mLocation, EERR_SYNTAX, error); } void Scanner::StringToken(char terminator) @@ -1071,7 +1071,7 @@ void Scanner::StringToken(char terminator) if (IsHex(c0) && IsHex(c1)) mTokenChar = 16 * HexValue(c0) + HexValue(c1); else - mErrors->Error(mLocation, "Invalid hex escape code"); + mErrors->Error(mLocation, EERR_SYNTAX, "Invalid hex escape code"); } break; default: @@ -1139,7 +1139,7 @@ void Scanner::CharToken(void) if (IsHex(c0) && IsHex(c1)) mTokenChar = 16 * HexValue(c0) + HexValue(c1); else - mErrors->Error(mLocation, "Invalid hex escape code"); + mErrors->Error(mLocation, EERR_SYNTAX, "Invalid hex escape code"); } break; default: diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index baa554b..341f429 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -135,7 +135,7 @@ int main(int argc, const char** argv) compiler->AddDefine(Ident::Unique(def), ""); } else - compiler->mErrors->Error(loc, "Invalid command line argument", arg); + compiler->mErrors->Error(loc, EERR_COMMAND_LINE, "Invalid command line argument", arg); } else {