Change format of error messages

This commit is contained in:
drmortalwombat 2021-09-21 14:55:11 +02:00
parent d9c565d898
commit 1d64404b24
10 changed files with 238 additions and 190 deletions

View File

@ -55,7 +55,7 @@ bool CompilationUnits::AddUnit(Location& location, const char* name, const char*
if (_access(filename, 0) != 0) 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; return false;
} }

View File

@ -57,7 +57,7 @@ bool Compiler::ParseSource(void)
parser->Parse(); parser->Parse();
} }
else 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; return mErrors->mErrorCount == 0;
@ -97,7 +97,7 @@ void Compiler::RegisterRuntime(const Location & loc, const Ident* ident)
} }
else 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; Declaration* dcrtstart = mCompilationUnits->mStartup;
if (!dcrtstart) if (!dcrtstart)
{ {
mErrors->Error(loc, "Runtime startup not found"); mErrors->Error(loc, EERR_RUNTIME_CODE, "Runtime startup not found");
return false; return false;
} }
@ -132,7 +132,7 @@ bool Compiler::GenerateCode(void)
Declaration* dmain = mCompilationUnits->mScope->Lookup(imain); Declaration* dmain = mCompilationUnits->mScope->Lookup(imain);
if (!dmain) if (!dmain)
{ {
mErrors->Error(loc, "main function not found"); mErrors->Error(loc, EERR_OBJECT_NOT_FOUND, "main function not found");
return false; return false;
} }
@ -231,7 +231,7 @@ bool Compiler::GenerateCode(void)
{ {
char n[10]; char n[10];
sprintf_s(n, "%d", i); 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]; char sd[20];
sprintf_s(sd, "%d", ecode); sprintf_s(sd, "%d", ecode);
mErrors->Error(loc, "Execution failed", sd); mErrors->Error(loc, EERR_EXECUTION_FAILED, "Execution failed", sd);
} }
return ecode; return ecode;

View File

@ -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)
{
void Errors::Error(const Location& loc, const char* error) level = "error";
{
printf("Error %s in %s: %d, %d\n", error, loc.mFileName, loc.mLine, loc.mColumn);
mErrorCount++; mErrorCount++;
if (mErrorCount > 10) }
exit(10); else if (eid >= EWARN_GENERIC)
} {
level = "warning";
}
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) if (mErrorCount > 10)
exit(10); exit(10);
} }

View File

@ -9,6 +9,48 @@ public:
Location() : mFileName(nullptr), mLine(0), mColumn(0) {} 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 class Errors
{ {
@ -17,7 +59,5 @@ public:
int mErrorCount; int mErrorCount;
void Error(const Location& loc, const char* msg); void Error(const Location& loc, ErrorID eid, const char* msg, const char* info = nullptr);
void Error(const Location& loc, const char* msg, const char * info);
void Warning(const Location& loc, const char* msg);
}; };

View File

@ -204,7 +204,7 @@ void InterCodeGenerator::InitGlobalVariable(InterCodeModule * mod, Declaration*
BuildInitializer(mod, d, 0, dec->mValue->mDecValue, var); BuildInitializer(mod, d, 0, dec->mValue->mDecValue, var);
} }
else 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->mFlags & DTF_SIGNED)
{ {
if (dec->mInteger < -128 || dec->mInteger > 127) 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 else
{ {
if (dec->mInteger < 0 || dec->mInteger > 255) 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); ins->mIntValue = char(dec->mInteger);
} }
@ -478,12 +478,12 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
if (dec->mFlags & DTF_SIGNED) if (dec->mFlags & DTF_SIGNED)
{ {
if (dec->mInteger < -32768 || dec->mInteger > 32767) 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 else
{ {
if (dec->mInteger < 0 || dec->mInteger > 65535) 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); ins->mIntValue = short(dec->mInteger);
} }
@ -607,7 +607,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
default: default:
mErrors->Error(dec->mLocation, "Unimplemented constant type"); mErrors->Error(dec->mLocation, EERR_CONSTANT_TYPE, "Unimplemented constant type");
} }
return ExValue(TheVoidTypeDeclaration); return ExValue(TheVoidTypeDeclaration);
@ -637,7 +637,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
block->Append(ins); block->Append(ins);
if (!(dec->mBase->mFlags & DTF_DEFINED)) 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); 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 (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)) 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) 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) 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); vl = Dereference(proc, block, vl, 1);
if (vl.mReference != 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) 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(); InterInstruction * ins = new InterInstruction();
@ -688,7 +688,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vl = Dereference(proc, block, vl, 1); vl = Dereference(proc, block, vl, 1);
if (vl.mReference != 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(); InterInstruction * ins = new InterInstruction();
@ -710,10 +710,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
cins->mIntValue = -vl.mType->mBase->mSize; cins->mIntValue = -vl.mType->mBase->mSize;
} }
else else
mErrors->Error(exp->mLocation, "Invalid pointer assignment"); mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Invalid pointer assignment");
if (!vr.mType->IsIntegerType()) 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->mTType = IT_INT16;
cins->mTTemp = proc->AddTemporary(cins->mTType); cins->mTTemp = proc->AddTemporary(cins->mTType);
@ -758,9 +758,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
oins->mTTemp = proc->AddTemporary(oins->mTType); oins->mTTemp = proc->AddTemporary(oins->mTType);
if (!vll.mType->IsNumericType()) 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()) 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) switch (exp->mToken)
{ {
@ -838,10 +838,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vr = Dereference(proc, block, vr); vr = Dereference(proc, block, vr);
if (vl.mType->mType != DT_TYPE_ARRAY && vl.mType->mType != DT_TYPE_POINTER) 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()) 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); vr = CoerceType(proc, block, vr, TheSignedIntTypeDeclaration);
@ -883,7 +883,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vl = Dereference(proc, block, vl, 1); vl = Dereference(proc, block, vl, 1);
if (vl.mReference != 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(); InterInstruction * cins = new InterInstruction();
cins->mCode = IC_CONSTANT; cins->mCode = IC_CONSTANT;
@ -942,7 +942,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
cins->mIntValue = -vl.mType->mBase->mSize; cins->mIntValue = -vl.mType->mBase->mSize;
} }
else else
mErrors->Error(exp->mLocation, "Invalid pointer operation"); mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Invalid pointer operation");
cins->mTType = IT_INT16; cins->mTType = IT_INT16;
cins->mTTemp = proc->AddTemporary(cins->mTType); cins->mTTemp = proc->AddTemporary(cins->mTType);
@ -1019,7 +1019,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
return ExValue(TheSignedIntTypeDeclaration, dins->mTTemp); return ExValue(TheSignedIntTypeDeclaration, dins->mTTemp);
} }
else else
mErrors->Error(exp->mLocation, "Invalid pointer operation"); mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Invalid pointer operation");
} }
} }
else else
@ -1027,9 +1027,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vl = Dereference(proc, block, vl); vl = Dereference(proc, block, vl);
if (!vl.mType->IsNumericType()) 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()) 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; Declaration* dtype;
if (vr.mType->mType == DT_TYPE_FLOAT || vl.mType->mType == DT_TYPE_FLOAT) 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); vl = Dereference(proc, block, vl, 1);
if (vl.mReference != 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) 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(); 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()) else if (vdl.mType->IsNumericType())
cins->mIntValue = exp->mToken == TK_INC ? 1 : -1; cins->mIntValue = exp->mToken == TK_INC ? 1 : -1;
else 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); block->Append(cins);
@ -1154,10 +1154,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vl = Dereference(proc, block, vl, 1); vl = Dereference(proc, block, vl, 1);
if (vl.mReference != 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) 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(); 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()) else if (vdl.mType->IsNumericType())
cins->mIntValue = exp->mToken == TK_INC ? 1 : -1; cins->mIntValue = exp->mToken == TK_INC ? 1 : -1;
else 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); block->Append(cins);
ains->mCode = IC_BINARY_OPERATOR; ains->mCode = IC_BINARY_OPERATOR;
@ -1216,23 +1216,23 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case TK_SUB: case TK_SUB:
vl = Dereference(proc, block, vl); vl = Dereference(proc, block, vl);
if (!vl.mType->IsNumericType()) 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; ins->mOperator = IA_NEG;
break; break;
case TK_BINARY_NOT: case TK_BINARY_NOT:
vl = Dereference(proc, block, vl); vl = Dereference(proc, block, vl);
if (!(vl.mType->mType == DT_TYPE_POINTER || vl.mType->IsNumericType())) 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; ins->mOperator = IA_NOT;
break; break;
case TK_MUL: case TK_MUL:
if (vl.mType->mType != DT_TYPE_POINTER) 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); return ExValue(vl.mType->mBase, vl.mTemp, vl.mReference + 1);
case TK_BINARY_AND: case TK_BINARY_AND:
{ {
if (vl.mReference < 1) 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); Declaration* dec = new Declaration(exp->mLocation, DT_TYPE_POINTER);
dec->mBase = vl.mType; dec->mBase = vl.mType;
@ -1267,10 +1267,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
{ {
dtype = vl.mType; dtype = vl.mType;
if (!vl.mType->IsSame(vr.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()) 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) else if (vr.mType->mType == DT_TYPE_FLOAT || vl.mType->mType == DT_TYPE_FLOAT)
dtype = TheFloatTypeDeclaration; dtype = TheFloatTypeDeclaration;
else if (vr.mType->mSize < vl.mType->mSize && (vl.mType->mFlags & DTF_SIGNED)) 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); vr = Dereference(proc, block, vr);
if (decf->mBase->mParams->CanAssign(vr.mType)) 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); vr = CoerceType(proc, block, vr, decf->mBase->mParams);
InterInstruction * ins = new InterInstruction(); InterInstruction * ins = new InterInstruction();
@ -1354,7 +1354,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vr = Dereference(proc, block, vr); vr = Dereference(proc, block, vr);
if (decf->mBase->mParams->CanAssign(vr.mType)) 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); vr = CoerceType(proc, block, vr, decf->mBase->mParams);
InterInstruction * ins = new InterInstruction(); InterInstruction * ins = new InterInstruction();
@ -1374,7 +1374,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vr = Dereference(proc, block, vr); vr = Dereference(proc, block, vr);
if (decf->mBase->mParams->CanAssign(vr.mType)) 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); vr = CoerceType(proc, block, vr, decf->mBase->mParams);
InterInstruction * ins = new InterInstruction(); InterInstruction * ins = new InterInstruction();
@ -1389,7 +1389,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
return ExValue(TheFloatTypeDeclaration, ins->mTTemp); return ExValue(TheFloatTypeDeclaration, ins->mTTemp);
} }
else 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); return ExValue(TheVoidTypeDeclaration);
} }
@ -1435,7 +1435,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
else 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); 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 (vr.mType->mType == DT_TYPE_STRUCT || vr.mType->mType == DT_TYPE_UNION)
{ {
if (pdec && !pdec->mBase->CanAssign(vr.mType)) 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); vr = Dereference(proc, block, vr, 1);
if (vr.mReference != 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(); InterInstruction* cins = new InterInstruction();
cins->mCode = IC_COPY; cins->mCode = IC_COPY;
@ -1486,7 +1486,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
if (pdec) if (pdec)
{ {
if (!pdec->mBase->CanAssign(vr.mType)) 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); vr = CoerceType(proc, block, vr, pdec->mBase);
} }
else if (vr.mType->IsIntegerType() && vr.mType->mSize < 2) else if (vr.mType->IsIntegerType() && vr.mType->mSize < 2)
@ -1519,7 +1519,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
if (pdec) 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(); InterInstruction * cins = new InterInstruction();
if (exp->mLeft->mDecValue && exp->mLeft->mDecValue->mFlags & DTF_NATIVE) if (exp->mLeft->mDecValue && exp->mLeft->mDecValue->mFlags & DTF_NATIVE)
@ -1587,9 +1587,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vr = Dereference(proc, block, vr); vr = Dereference(proc, block, vr);
if (!procType->mBase || procType->mBase->mType == DT_TYPE_VOID) 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)) 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->mSType[0] = InterTypeOf(vr.mType);
ins->mSTemp[0] = vr.mTemp; ins->mSTemp[0] = vr.mTemp;
@ -1598,7 +1598,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
else else
{ {
if (procType->mBase && procType->mBase->mType != DT_TYPE_VOID) 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; ins->mCode = IC_RETURN;
} }
@ -1624,7 +1624,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
proc->Append(block); proc->Append(block);
} }
else else
mErrors->Error(exp->mLocation, "No break target"); mErrors->Error(exp->mLocation, EERR_INVALID_BREAK, "No break target");
return ExValue(TheVoidTypeDeclaration); return ExValue(TheVoidTypeDeclaration);
} }
@ -1642,7 +1642,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
proc->Append(block); proc->Append(block);
} }
else else
mErrors->Error(exp->mLocation, "No continue target"); mErrors->Error(exp->mLocation, EERR_INVALID_CONTINUE, "No continue target");
return ExValue(TheVoidTypeDeclaration); return ExValue(TheVoidTypeDeclaration);
} }
@ -1705,7 +1705,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
if (stypel == IT_POINTER || styper == IT_POINTER) if (stypel == IT_POINTER || styper == IT_POINTER)
{ {
if (!vl.mType->IsSame(vr.mType)) 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; ttype = IT_POINTER;
dtype = vl.mType; 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) 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); return ExValue(exp->mLeft->mDecType, vr.mTemp, vr.mReference);
} }
else else
@ -2033,7 +2033,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
block = dblock; block = dblock;
} }
else else
mErrors->Error(cexp->mLocation, "Duplicate default"); mErrors->Error(cexp->mLocation, EERR_DUPLICATE_DEFAULT, "Duplicate default");
} }
if (cexp->mRight) if (cexp->mRight)
@ -2065,7 +2065,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
return ExValue(TheVoidTypeDeclaration); return ExValue(TheVoidTypeDeclaration);
} }
default: default:
mErrors->Error(exp->mLocation, "Unimplemented expression"); mErrors->Error(exp->mLocation, EERR_UNIMPLEMENTED, "Unimplemented expression");
return ExValue(TheVoidTypeDeclaration); return ExValue(TheVoidTypeDeclaration);
} }
} }
@ -2242,7 +2242,7 @@ InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod
if (dec->mFlags & DTF_DEFINED) if (dec->mFlags & DTF_DEFINED)
TranslateExpression(dec->mBase, proc, exitBlock, exp, nullptr, nullptr); TranslateExpression(dec->mBase, proc, exitBlock, exp, nullptr, nullptr);
else 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(); InterInstruction * ins = new InterInstruction();
ins->mCode = IC_RETURN; ins->mCode = IC_RETURN;

View File

@ -96,7 +96,7 @@ void Linker::Link(void)
lsec->mUsed += obj->mSize; lsec->mUsed += obj->mSize;
} }
else 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);
} }
} }

View File

@ -38,7 +38,7 @@ Declaration* Parser::ParseStructDeclaration(uint32 flags, DecType dt)
} }
else 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) while (mdec)
{ {
if (!(mdec->mBase->mFlags & DTF_DEFINED)) 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; mdec->mType = DT_ELEMENT;
if (dt == DT_TYPE_UNION) if (dt == DT_TYPE_UNION)
{ {
@ -85,7 +85,7 @@ Declaration* Parser::ParseStructDeclaration(uint32 flags, DecType dt)
mScanner->NextToken(); mScanner->NextToken();
else else
{ {
mErrors->Error(mScanner->mLocation, "';' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "';' expected");
break; break;
} }
@ -217,12 +217,12 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags)
mScanner->NextToken(); mScanner->NextToken();
else if (!dec) 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(); mScanner->NextToken();
} }
else 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(); mScanner->NextToken();
} }
break; break;
@ -239,7 +239,7 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags)
dec->mIdent = mScanner->mTokenIdent; dec->mIdent = mScanner->mTokenIdent;
if (mScope->Insert(dec->mIdent, dec)) if (mScope->Insert(dec->mIdent, dec))
mErrors->Error(dec->mLocation, "Duplicate name"); mErrors->Error(dec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate name");
mScanner->NextToken(); mScanner->NextToken();
} }
@ -258,7 +258,7 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags)
{ {
cdec->mIdent = mScanner->mTokenIdent; cdec->mIdent = mScanner->mTokenIdent;
if (mScope->Insert(cdec->mIdent, cdec) != nullptr) 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(); mScanner->NextToken();
} }
if (mScanner->mToken == TK_ASSIGN) 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) if (exp->mType == EX_CONSTANT && exp->mDecValue->mType == DT_CONST_INTEGER)
nitem = int(exp->mDecValue->mInteger); nitem = int(exp->mDecValue->mInteger);
else else
mErrors->Error(mScanner->mLocation, "Integer constant expected"); mErrors->Error(mScanner->mLocation, EERR_CONSTANT_TYPE, "Integer constant expected");
} }
cdec->mInteger = nitem++; cdec->mInteger = nitem++;
@ -282,10 +282,10 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags)
if (mScanner->mToken == TK_CLOSE_BRACE) if (mScanner->mToken == TK_CLOSE_BRACE)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "'}' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'}' expected");
} }
else else
mErrors->Error(mScanner->mLocation, "'{' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'{' expected");
dec->mFlags |= DTF_DEFINED; dec->mFlags |= DTF_DEFINED;
break; break;
@ -297,7 +297,7 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags)
dec = ParseStructDeclaration(flags, DT_TYPE_UNION); dec = ParseStructDeclaration(flags, DT_TYPE_UNION);
break; break;
default: 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(); mScanner->NextToken();
} }
@ -333,7 +333,7 @@ Declaration* Parser::ParsePostfixDeclaration(void)
if (mScanner->mToken == TK_CLOSE_PARENTHESIS) if (mScanner->mToken == TK_CLOSE_PARENTHESIS)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "')' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected");
dec = vdec; dec = vdec;
} }
else if (mScanner->mToken == TK_IDENT) 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) if (exp->mType == EX_CONSTANT && exp->mDecType->IsIntegerType() && exp->mDecValue->mType == DT_CONST_INTEGER)
ndec->mSize = int(exp->mDecValue->mInteger); ndec->mSize = int(exp->mDecValue->mInteger);
else else
mErrors->Error(exp->mLocation, "Constant integer expression expected"); mErrors->Error(exp->mLocation, EERR_CONSTANT_TYPE, "Constant integer expression expected");
ndec->mFlags |= DTF_DEFINED; ndec->mFlags |= DTF_DEFINED;
} }
if (mScanner->mToken == TK_CLOSE_BRACKET) if (mScanner->mToken == TK_CLOSE_BRACKET)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "']' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "']' expected");
ndec->mBase = dec; ndec->mBase = dec;
dec = ndec; dec = ndec;
} }
@ -400,13 +400,13 @@ Declaration* Parser::ParsePostfixDeclaration(void)
if (adec->mBase->mType == DT_TYPE_VOID) if (adec->mBase->mType == DT_TYPE_VOID)
{ {
if (pdec) if (pdec)
mErrors->Error(pdec->mLocation, "Invalid void argument"); mErrors->Error(pdec->mLocation, EERR_WRONG_PARAMETER, "Invalid void argument");
break; break;
} }
else else
{ {
if (!(adec->mBase->mFlags & DTF_DEFINED)) 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->mType = DT_ARGUMENT;
adec->mVarIndex = vi; adec->mVarIndex = vi;
@ -429,7 +429,7 @@ Declaration* Parser::ParsePostfixDeclaration(void)
if (mScanner->mToken == TK_CLOSE_PARENTHESIS) if (mScanner->mToken == TK_CLOSE_PARENTHESIS)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "')' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected");
} }
else else
mScanner->NextToken(); mScanner->NextToken();
@ -467,7 +467,7 @@ Declaration * Parser::CopyConstantInitializer(int offset, Declaration* dtype, Ex
if (exp->mType == EX_CONSTANT) if (exp->mType == EX_CONSTANT)
{ {
if (!dtype->CanAssign(exp->mDecType)) if (!dtype->CanAssign(exp->mDecType))
mErrors->Error(exp->mLocation, "Incompatible constant initializer"); mErrors->Error(exp->mLocation, EERR_CONSTANT_INITIALIZER, "Incompatible constant initializer");
else else
{ {
if (dec->mType == DT_CONST_FLOAT) if (dec->mType == DT_CONST_FLOAT)
@ -528,7 +528,7 @@ Declaration * Parser::CopyConstantInitializer(int offset, Declaration* dtype, Ex
} }
} }
else else
mErrors->Error(exp->mLocation, "Constant initializer expected"); mErrors->Error(exp->mLocation, EERR_CONSTANT_INITIALIZER, "Constant initializer expected");
return dec; return dec;
} }
@ -543,9 +543,9 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
if (dtype->mType != DT_TYPE_ARRAY && !(dtype->mFlags & DTF_DEFINED)) if (dtype->mType != DT_TYPE_ARRAY && !(dtype->mFlags & DTF_DEFINED))
{ {
if (dtype->mIdent) 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 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)) if (ConsumeTokenIf(TK_OPEN_BRACE))
{ {
@ -633,7 +633,7 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
strcpy_s((char *)d, dec->mSize, mScanner->mTokenString); strcpy_s((char *)d, dec->mSize, mScanner->mTokenString);
} }
else 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(); mScanner->NextToken();
} }
@ -707,7 +707,7 @@ Declaration* Parser::ParseDeclaration(bool variable)
{ {
Declaration* pdec = mScope->Insert(ndec->mIdent, ndec->mBase); Declaration* pdec = mScope->Insert(ndec->mIdent, ndec->mBase);
if (pdec) 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 else
@ -732,7 +732,7 @@ Declaration* Parser::ParseDeclaration(bool variable)
pdec = mCompilationUnits->mScope->Insert(ndec->mIdent, ndec); pdec = mCompilationUnits->mScope->Insert(ndec->mIdent, ndec);
Declaration * ldec = mScope->Insert(ndec->mIdent, pdec ? pdec : ndec); Declaration * ldec = mScope->Insert(ndec->mIdent, pdec ? pdec : ndec);
if (ldec && ldec != pdec) if (ldec && ldec != pdec)
mErrors->Error(ndec->mLocation, "Duplicate definition"); mErrors->Error(ndec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate definition");
} }
else else
pdec = mScope->Insert(ndec->mIdent, ndec); 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 (pdec->mType == DT_CONST_FUNCTION && ndec->mBase->mType == DT_TYPE_FUNCTION)
{ {
if (!ndec->mBase->IsSame(pdec->mBase)) if (!ndec->mBase->IsSame(pdec->mBase))
mErrors->Error(ndec->mLocation, "Function declaration differs"); mErrors->Error(ndec->mLocation, EERR_DECLARATION_DIFFERS, "Function declaration differs");
else else
{ {
// //
@ -761,7 +761,7 @@ Declaration* Parser::ParseDeclaration(bool variable)
ndec = pdec; ndec = pdec;
} }
else 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->mBase->mType == DT_TYPE_FUNCTION)
{ {
if (ndec->mFlags & DTF_DEFINED) 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->mVarIndex = -1;
ndec->mValue = ParseFunction(ndec->mBase); ndec->mValue = ParseFunction(ndec->mBase);
@ -1005,13 +1005,13 @@ Expression* Parser::ParseSimpleExpression(void)
} }
else else
{ {
mErrors->Error(mScanner->mLocation, "Invalid identifier", mScanner->mTokenIdent->mString); mErrors->Error(mScanner->mLocation, EERR_INVALID_IDENTIFIER, "Invalid identifier", mScanner->mTokenIdent->mString);
mScanner->NextToken(); mScanner->NextToken();
} }
} }
else 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(); mScanner->NextToken();
} }
@ -1033,7 +1033,7 @@ Expression* Parser::ParseSimpleExpression(void)
if (mScanner->mToken == TK_CLOSE_PARENTHESIS) if (mScanner->mToken == TK_CLOSE_PARENTHESIS)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "')' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected");
if (exp->mType == EX_TYPE) if (exp->mType == EX_TYPE)
{ {
@ -1045,7 +1045,7 @@ Expression* Parser::ParseSimpleExpression(void)
} }
break; break;
default: 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(); mScanner->NextToken();
} }
@ -1068,7 +1068,7 @@ Expression* Parser::ParsePostfixExpression(void)
if (mScanner->mToken == TK_OPEN_BRACKET) if (mScanner->mToken == TK_OPEN_BRACKET)
{ {
if (exp->mDecType->mType != DT_TYPE_ARRAY && exp->mDecType->mType != DT_TYPE_POINTER) 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(); mScanner->NextToken();
Expression* nexp = new Expression(mScanner->mLocation, EX_INDEX); Expression* nexp = new Expression(mScanner->mLocation, EX_INDEX);
nexp->mLeft = exp; nexp->mLeft = exp;
@ -1076,7 +1076,7 @@ Expression* Parser::ParsePostfixExpression(void)
if (mScanner->mToken == TK_CLOSE_BRACKET) if (mScanner->mToken == TK_CLOSE_BRACKET)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "']' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "']' expected");
nexp->mDecType = exp->mDecType->mBase; nexp->mDecType = exp->mDecType->mBase;
if (!nexp->mDecType) if (!nexp->mDecType)
nexp->mDecType = TheVoidTypeDeclaration; nexp->mDecType = TheVoidTypeDeclaration;
@ -1091,7 +1091,7 @@ Expression* Parser::ParsePostfixExpression(void)
{ {
} }
else else
mErrors->Error(mScanner->mLocation, "Function expected for call"); mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Function expected for call");
mScanner->NextToken(); mScanner->NextToken();
Expression* nexp = new Expression(mScanner->mLocation, EX_CALL); Expression* nexp = new Expression(mScanner->mLocation, EX_CALL);
@ -1142,17 +1142,17 @@ Expression* Parser::ParsePostfixExpression(void)
exp = nexp; exp = nexp;
} }
else 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(); mScanner->NextToken();
} }
else else
mErrors->Error(mScanner->mLocation, "Struct member identifier expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Struct member identifier expected");
} }
else else
mErrors->Error(mScanner->mLocation, "Struct expected"); mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Struct expected");
} }
else else
mErrors->Error(mScanner->mLocation, "Pointer expected"); mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Pointer expected");
} }
else if (mScanner->mToken == TK_DOT) else if (mScanner->mToken == TK_DOT)
{ {
@ -1171,14 +1171,14 @@ Expression* Parser::ParsePostfixExpression(void)
exp = nexp; exp = nexp;
} }
else 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(); mScanner->NextToken();
} }
else else
mErrors->Error(mScanner->mLocation, "Struct member identifier expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Struct member identifier expected");
} }
else else
mErrors->Error(mScanner->mLocation, "Struct expected"); mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Struct expected");
} }
else else
return exp; return exp;
@ -1221,7 +1221,7 @@ Expression* Parser::ParsePrefixExpression(void)
nexp->mDecType = nexp->mLeft->mDecType; nexp->mDecType = nexp->mLeft->mDecType;
} }
else 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) else if (nexp->mToken == TK_BINARY_AND)
{ {
@ -1449,14 +1449,14 @@ Expression* Parser::ParseParenthesisExpression(void)
if (mScanner->mToken == TK_OPEN_PARENTHESIS) if (mScanner->mToken == TK_OPEN_PARENTHESIS)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "'(' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'(' expected");
Expression* exp = ParseExpression(); Expression* exp = ParseExpression();
if (mScanner->mToken == TK_CLOSE_PARENTHESIS) if (mScanner->mToken == TK_CLOSE_PARENTHESIS)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "')' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected");
return exp; return exp;
} }
@ -1554,7 +1554,7 @@ Expression* Parser::ParseStatement(void)
} while (mScanner->mToken != TK_CLOSE_BRACE && mScanner->mToken != TK_EOF); } while (mScanner->mToken != TK_CLOSE_BRACE && mScanner->mToken != TK_EOF);
if (mScanner->mToken != TK_CLOSE_BRACE) if (mScanner->mToken != TK_CLOSE_BRACE)
mErrors->Error(mScanner->mLocation, "'}' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'}' expected");
mScanner->NextToken(); mScanner->NextToken();
} }
else else
@ -1607,7 +1607,7 @@ Expression* Parser::ParseStatement(void)
exp->mLeft = ParseParenthesisExpression(); exp->mLeft = ParseParenthesisExpression();
} }
else else
mErrors->Error(mScanner->mLocation, "'while' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'while' expected");
break; break;
case TK_FOR: case TK_FOR:
mScanner->NextToken(); mScanner->NextToken();
@ -1624,24 +1624,24 @@ Expression* Parser::ParseStatement(void)
if (mScanner->mToken == TK_SEMICOLON) if (mScanner->mToken == TK_SEMICOLON)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "';' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "';' expected");
exp->mLeft->mLeft->mLeft = ParseExpression(); exp->mLeft->mLeft->mLeft = ParseExpression();
if (mScanner->mToken == TK_SEMICOLON) if (mScanner->mToken == TK_SEMICOLON)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "';' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "';' expected");
if (mScanner->mToken != TK_CLOSE_PARENTHESIS) if (mScanner->mToken != TK_CLOSE_PARENTHESIS)
exp->mLeft->mLeft->mRight = ParseExpression(); exp->mLeft->mLeft->mRight = ParseExpression();
if (mScanner->mToken == TK_CLOSE_PARENTHESIS) if (mScanner->mToken == TK_CLOSE_PARENTHESIS)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "')' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected");
exp->mRight = ParseStatement(); exp->mRight = ParseStatement();
mScope = mScope->mParent; mScope = mScope->mParent;
} }
else else
mErrors->Error(mScanner->mLocation, "'(' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'(' expected");
break; break;
case TK_SWITCH: case TK_SWITCH:
mScanner->NextToken(); mScanner->NextToken();
@ -1672,7 +1672,7 @@ Expression* Parser::ParseStatement(void)
if (mScanner->mToken == TK_CLOSE_BRACE) if (mScanner->mToken == TK_CLOSE_BRACE)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "'}' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'}' expected");
} }
break; break;
default: default:
@ -1696,10 +1696,10 @@ Expression* Parser::ParseSwitchStatement(void)
if (mScanner->mToken == TK_CLOSE_PARENTHESIS) if (mScanner->mToken == TK_CLOSE_PARENTHESIS)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "')' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected");
} }
else else
mErrors->Error(mScanner->mLocation, "'(' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'(' expected");
if (mScanner->mToken == TK_OPEN_BRACE) if (mScanner->mToken == TK_OPEN_BRACE)
{ {
@ -1724,7 +1724,7 @@ Expression* Parser::ParseSwitchStatement(void)
if (mScanner->mToken == TK_COLON) if (mScanner->mToken == TK_COLON)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "':' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "':' expected");
Expression* csexp = new Expression(mScanner->mLocation, EX_SEQUENCE); Expression* csexp = new Expression(mScanner->mLocation, EX_SEQUENCE);
csexp->mLeft = cexp; csexp->mLeft = cexp;
@ -1744,7 +1744,7 @@ Expression* Parser::ParseSwitchStatement(void)
if (mScanner->mToken == TK_COLON) if (mScanner->mToken == TK_COLON)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "':' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "':' expected");
Expression * csexp = new Expression(mScanner->mLocation, EX_SEQUENCE); Expression * csexp = new Expression(mScanner->mLocation, EX_SEQUENCE);
csexp->mLeft = cexp; csexp->mLeft = cexp;
@ -1772,10 +1772,10 @@ Expression* Parser::ParseSwitchStatement(void)
if (mScanner->mToken == TK_CLOSE_BRACE) if (mScanner->mToken == TK_CLOSE_BRACE)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "'}' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'}' expected");
} }
else else
mErrors->Error(mScanner->mLocation, "'{' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'{' expected");
return sexp; return sexp;
} }
@ -1805,7 +1805,7 @@ Expression* Parser::ParseAssemblerBaseOperand(void)
exp->mDecType = dec->mBase; exp->mDecType = dec->mBase;
} }
else else
mErrors->Error(exp->mLocation, "Cannot negate expression"); mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Cannot negate expression");
break; break;
case TK_INTEGER: case TK_INTEGER:
@ -1868,16 +1868,16 @@ Expression* Parser::ParseAssemblerBaseOperand(void)
exp->mDecType = TheUnsignedIntTypeDeclaration; exp->mDecType = TheUnsignedIntTypeDeclaration;
} }
else 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(); mScanner->NextToken();
} }
else else
mErrors->Error(mScanner->mLocation, "Identifier for qualification expected"); mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Identifier for qualification expected");
} }
break; break;
default: default:
mErrors->Error(mScanner->mLocation, "Invalid assembler operand"); mErrors->Error(mScanner->mLocation, EERR_ASM_INVALD_OPERAND, "Invalid assembler operand");
} }
if (!exp) if (!exp)
@ -1925,7 +1925,7 @@ Expression* Parser::ParseAssemblerAddOperand(void)
exp->mDecValue = ndec; exp->mDecValue = ndec;
} }
else 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) else if (nexp->mLeft->mDecValue->mType == DT_CONST_FUNCTION)
{ {
@ -1938,7 +1938,7 @@ Expression* Parser::ParseAssemblerAddOperand(void)
exp->mDecValue = ndec; exp->mDecValue = ndec;
} }
else 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) else if (nexp->mLeft->mDecValue->mType == DT_LABEL)
{ {
@ -1951,7 +1951,7 @@ Expression* Parser::ParseAssemblerAddOperand(void)
exp->mDecValue = ndec; exp->mDecValue = ndec;
} }
else else
mErrors->Error(mScanner->mLocation, "Integer offset expected"); mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Integer offset expected");
} }
else else
exp = nexp->ConstantFold(); exp = nexp->ConstantFold();
@ -2024,10 +2024,10 @@ Expression* Parser::ParseAssemblerOperand(void)
exp->mDecValue = ndec; exp->mDecValue = ndec;
} }
else 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 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; return exp;
} }
@ -2094,10 +2094,10 @@ Expression* Parser::ParseAssemblerOperand(void)
exp->mDecValue = ndec; exp->mDecValue = ndec;
} }
else 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 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; return exp;
} }
@ -2154,7 +2154,7 @@ Expression* Parser::ParseAssembler(void)
const Ident* label = mScanner->mTokenIdent; const Ident* label = mScanner->mTokenIdent;
mScanner->NextToken(); mScanner->NextToken();
if (mScanner->mToken != TK_COLON) if (mScanner->mToken != TK_COLON)
mErrors->Error(mScanner->mLocation, "':' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "':' expected");
else else
mScanner->NextToken(); mScanner->NextToken();
@ -2162,7 +2162,7 @@ Expression* Parser::ParseAssembler(void)
if (dec) if (dec)
{ {
if (dec->mType != DT_LABEL || dec->mBase) 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 else
dec = new Declaration(mScanner->mLocation, DT_LABEL); dec = new Declaration(mScanner->mLocation, DT_LABEL);
@ -2199,10 +2199,10 @@ Expression* Parser::ParseAssembler(void)
if (mScanner->mToken == TK_CLOSE_PARENTHESIS) if (mScanner->mToken == TK_CLOSE_PARENTHESIS)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "')' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected");
} }
else else
mErrors->Error(mScanner->mLocation, "',x' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "',x' expected");
} }
else if (mScanner->mToken == TK_CLOSE_PARENTHESIS) else if (mScanner->mToken == TK_CLOSE_PARENTHESIS)
{ {
@ -2216,7 +2216,7 @@ Expression* Parser::ParseAssembler(void)
mScanner->NextToken(); mScanner->NextToken();
} }
else else
mErrors->Error(mScanner->mLocation, "',y' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "',y' expected");
} }
else else
{ {
@ -2224,7 +2224,7 @@ Expression* Parser::ParseAssembler(void)
} }
} }
else else
mErrors->Error(mScanner->mLocation, "',' or ')' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "',' or ')' expected");
} }
else else
{ {
@ -2243,7 +2243,7 @@ Expression* Parser::ParseAssembler(void)
mScanner->NextToken(); mScanner->NextToken();
} }
else else
mErrors->Error(mScanner->mLocation, "',x' or ',y' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "',x' or ',y' expected");
} }
else else
{ {
@ -2269,7 +2269,7 @@ Expression* Parser::ParseAssembler(void)
if (mScanner->mToken != TK_EOL) 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) while (mScanner->mToken != TK_EOL && mScanner->mToken != TK_EOF)
@ -2287,7 +2287,7 @@ Expression* Parser::ParseAssembler(void)
} }
else 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) while (mScanner->mToken != TK_EOL && mScanner->mToken != TK_EOF)
mScanner->NextToken(); mScanner->NextToken();
@ -2339,7 +2339,7 @@ bool Parser::ConsumeToken(Token token)
{ {
char buffer[100]; char buffer[100];
sprintf_s(buffer, "%s expected", TokenNames[token]); sprintf_s(buffer, "%s expected", TokenNames[token]);
mErrors->Error(mScanner->mLocation, buffer); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, buffer);
return false; return false;
} }
} }
@ -2392,7 +2392,7 @@ void Parser::ParsePragma(void)
if (dec && dec->mType == DT_CONST_FUNCTION) if (dec && dec->mType == DT_CONST_FUNCTION)
dec->mFlags |= DTF_INTRINSIC; dec->mFlags |= DTF_INTRINSIC;
else else
mErrors->Error(mScanner->mLocation, "Intrinsic function not found"); mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Intrinsic function not found");
mScanner->NextToken(); mScanner->NextToken();
} }
ConsumeToken(TK_CLOSE_PARENTHESIS); ConsumeToken(TK_CLOSE_PARENTHESIS);
@ -2407,7 +2407,7 @@ void Parser::ParsePragma(void)
if (dec && dec->mType == DT_CONST_FUNCTION) if (dec && dec->mType == DT_CONST_FUNCTION)
dec->mFlags |= DTF_NATIVE; dec->mFlags |= DTF_NATIVE;
else else
mErrors->Error(mScanner->mLocation, "Native function not found"); mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Native function not found");
mScanner->NextToken(); mScanner->NextToken();
} }
ConsumeToken(TK_CLOSE_PARENTHESIS); ConsumeToken(TK_CLOSE_PARENTHESIS);
@ -2415,7 +2415,7 @@ void Parser::ParsePragma(void)
else if (!strcmp(mScanner->mTokenIdent->mString, "startup")) else if (!strcmp(mScanner->mTokenIdent->mString, "startup"))
{ {
if (mCompilationUnits->mStartup) if (mCompilationUnits->mStartup)
mErrors->Error(mScanner->mLocation, "Duplicate startup pragma"); mErrors->Error(mScanner->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate startup pragma");
mScanner->NextToken(); mScanner->NextToken();
ConsumeToken(TK_OPEN_PARENTHESIS); ConsumeToken(TK_OPEN_PARENTHESIS);
@ -2425,7 +2425,7 @@ void Parser::ParsePragma(void)
if (dec && dec->mType == DT_CONST_ASSEMBLER) if (dec && dec->mType == DT_CONST_ASSEMBLER)
mCompilationUnits->mStartup = dec; mCompilationUnits->mStartup = dec;
else else
mErrors->Error(mScanner->mLocation, "Startup function not found"); mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Startup function not found");
mScanner->NextToken(); mScanner->NextToken();
} }
ConsumeToken(TK_CLOSE_PARENTHESIS); ConsumeToken(TK_CLOSE_PARENTHESIS);
@ -2451,26 +2451,26 @@ void Parser::ParsePragma(void)
if (ndec) if (ndec)
dec = ndec; dec = ndec;
else 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(); mScanner->NextToken();
} }
else 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 (exp->mType == EX_CONSTANT && exp->mDecValue->mType == DT_CONST_INTEGER && exp->mDecValue->mInteger >= 0 && exp->mDecValue->mInteger < 128)
{ {
if (mCompilationUnits->mByteCodes[exp->mDecValue->mInteger]) 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; mCompilationUnits->mByteCodes[exp->mDecValue->mInteger] = dec;
} }
else 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 else
{ {
mErrors->Error(mScanner->mLocation, "Bytecode function not found"); mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Bytecode function not found");
mScanner->NextToken(); mScanner->NextToken();
} }
@ -2489,7 +2489,7 @@ void Parser::ParsePragma(void)
mScanner->NextToken(); mScanner->NextToken();
} }
else else
mErrors->Error(mScanner->mLocation, "Identifier expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Identifier expected");
ConsumeToken(TK_COMMA); ConsumeToken(TK_COMMA);
if (mScanner->mToken == TK_IDENT) if (mScanner->mToken == TK_IDENT)
@ -2506,11 +2506,11 @@ void Parser::ParsePragma(void)
if (ndec) if (ndec)
dec = ndec; dec = ndec;
else 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(); mScanner->NextToken();
} }
else else
mErrors->Error(mScanner->mLocation, "Identifier expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Identifier expected");
} }
if (rtident) if (rtident)
@ -2524,7 +2524,7 @@ void Parser::ParsePragma(void)
} }
else else
{ {
mErrors->Error(mScanner->mLocation, "Runtime function not found"); mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Runtime function not found");
mScanner->NextToken(); mScanner->NextToken();
} }
@ -2540,11 +2540,11 @@ void Parser::ParsePragma(void)
mScanner->NextToken(); mScanner->NextToken();
ConsumeToken(TK_CLOSE_PARENTHESIS); 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 else
mErrors->Error(mScanner->mLocation, "Invalid pragma directive"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Invalid pragma directive");
} }
void Parser::Parse(void) void Parser::Parse(void)
@ -2578,11 +2578,11 @@ void Parser::Parse(void)
if (mScanner->mToken == TK_CLOSE_BRACE) if (mScanner->mToken == TK_CLOSE_BRACE)
mScanner->NextToken(); mScanner->NextToken();
else else
mErrors->Error(mScanner->mLocation, "'}' expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'}' expected");
} }
} }
else else
mErrors->Error(mScanner->mLocation, "Identifier expected"); mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Identifier expected");
} }
else if (mScanner->mToken == TK_SEMICOLON) else if (mScanner->mToken == TK_SEMICOLON)
mScanner->NextToken(); mScanner->NextToken();

View File

@ -4,6 +4,13 @@
SourcePath::SourcePath(const char* path) SourcePath::SourcePath(const char* path)
{ {
strcpy_s(mPathName, path); strcpy_s(mPathName, path);
char* p = mPathName;
while (*p)
{
if (*p == '\\')
*p = '/';
p++;
}
} }
SourcePath::~SourcePath(void) SourcePath::~SourcePath(void)

View File

@ -359,7 +359,7 @@ void Scanner::NextToken(void)
else if (mPrepPending > 0) else if (mPrepPending > 0)
mPrepPending--; mPrepPending--;
else else
mErrors->Error(mLocation, "Unexpected #endif"); mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Unexpected #endif");
} }
else if (mToken == TK_EOF) else if (mToken == TK_EOF)
{ {
@ -379,14 +379,14 @@ void Scanner::NextToken(void)
if (mToken == TK_STRING) if (mToken == TK_STRING)
{ {
if (!mPreprocessor->OpenSource(mTokenString, true)) 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) else if (mToken == TK_LESS_THAN)
{ {
mOffset--; mOffset--;
StringToken('>'); StringToken('>');
if (!mPreprocessor->OpenSource(mTokenString, false)) 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) else if (mToken == TK_PREP_DEFINE)
@ -410,7 +410,7 @@ void Scanner::NextToken(void)
NextRawToken(); NextRawToken();
} }
else else
mErrors->Error(mLocation, "Invalid define argument"); mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Invalid define argument");
} while (mToken == TK_COMMA); } while (mToken == TK_COMMA);
@ -419,7 +419,7 @@ void Scanner::NextToken(void)
// No need to goto next token, mOffset is already behind it // No need to goto next token, mOffset is already behind it
} }
else else
mErrors->Error(mLocation, "')' expected in defined parameter list"); mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "')' expected in defined parameter list");
} }
macro->SetString(mLine + mOffset); macro->SetString(mLine + mOffset);
@ -501,19 +501,19 @@ void Scanner::NextToken(void)
if (mLine[mOffset] == ',') if (mLine[mOffset] == ',')
mOffset++; mOffset++;
else else
mErrors->Error(mLocation, "Invalid define expansion argument"); mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Invalid define expansion argument");
} }
else else
{ {
if (mLine[mOffset] == ')') if (mLine[mOffset] == ')')
mOffset++; mOffset++;
else else
mErrors->Error(mLocation, "Invalid define expansion closing argument"); mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Invalid define expansion closing argument");
} }
} }
} }
else else
mErrors->Error(mLocation, "Missing arguments for macro expansion"); mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Missing arguments for macro expansion");
NextChar(); NextChar();
} }
else else
@ -661,7 +661,7 @@ void Scanner::NextRawToken(void)
} }
if (n == 0) if (n == 0)
mErrors->Error(mLocation, "Missing digits in hex constant"); mErrors->Error(mLocation, EERR_SYNTAX, "Missing digits in hex constant");
mToken = TK_INTEGER; mToken = TK_INTEGER;
mTokenInteger = mant; mTokenInteger = mant;
@ -870,7 +870,7 @@ void Scanner::NextRawToken(void)
else if (!strcmp(tkprep, "pragma")) else if (!strcmp(tkprep, "pragma"))
mToken = TK_PREP_PRAGMA; mToken = TK_PREP_PRAGMA;
else else
mErrors->Error(mLocation, "Invalid preprocessor command", tkprep); mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Invalid preprocessor command", tkprep);
} }
else else
{ {
@ -900,7 +900,7 @@ void Scanner::NextRawToken(void)
} }
if (n == 0) if (n == 0)
mErrors->Error(mLocation, "Missing digits in hex constant"); mErrors->Error(mLocation, EERR_SYNTAX, "Missing digits in hex constant");
mToken = TK_INTEGER; mToken = TK_INTEGER;
mTokenInteger = mant; mTokenInteger = mant;
@ -1021,12 +1021,12 @@ void Scanner::NextRawToken(void)
void Scanner::Warning(const char* error) void Scanner::Warning(const char* error)
{ {
mErrors->Warning(mLocation, error); mErrors->Error(mLocation, EWARN_SYNTAX, error);
} }
void Scanner::Error(const char* error) void Scanner::Error(const char* error)
{ {
mErrors->Error(mLocation, error); mErrors->Error(mLocation, EERR_SYNTAX, error);
} }
void Scanner::StringToken(char terminator) void Scanner::StringToken(char terminator)
@ -1071,7 +1071,7 @@ void Scanner::StringToken(char terminator)
if (IsHex(c0) && IsHex(c1)) if (IsHex(c0) && IsHex(c1))
mTokenChar = 16 * HexValue(c0) + HexValue(c1); mTokenChar = 16 * HexValue(c0) + HexValue(c1);
else else
mErrors->Error(mLocation, "Invalid hex escape code"); mErrors->Error(mLocation, EERR_SYNTAX, "Invalid hex escape code");
} }
break; break;
default: default:
@ -1139,7 +1139,7 @@ void Scanner::CharToken(void)
if (IsHex(c0) && IsHex(c1)) if (IsHex(c0) && IsHex(c1))
mTokenChar = 16 * HexValue(c0) + HexValue(c1); mTokenChar = 16 * HexValue(c0) + HexValue(c1);
else else
mErrors->Error(mLocation, "Invalid hex escape code"); mErrors->Error(mLocation, EERR_SYNTAX, "Invalid hex escape code");
} }
break; break;
default: default:

View File

@ -135,7 +135,7 @@ int main(int argc, const char** argv)
compiler->AddDefine(Ident::Unique(def), ""); compiler->AddDefine(Ident::Unique(def), "");
} }
else else
compiler->mErrors->Error(loc, "Invalid command line argument", arg); compiler->mErrors->Error(loc, EERR_COMMAND_LINE, "Invalid command line argument", arg);
} }
else else
{ {