Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "errors_code.h"
00022 #include "compiler.h"
00023 #include <sstream>
00024 #include <string>
00025
00026 namespace Aseba
00027 {
00030
00031 static const wchar_t* error_map[ERROR_END];
00032
00033 ErrorMessages::ErrorMessages()
00034 {
00035
00036 error_map[ERROR_BROKEN_TARGET] = L"Broken target description: not enough room for internal variables";
00037 error_map[ERROR_STACK_OVERFLOW] = L"Execution stack will overflow, check for any recursive subroutine call and cut long mathematical expressions";
00038 error_map[ERROR_SCRIPT_TOO_BIG] = L"Script too big for target bytecode size";
00039
00040 error_map[ERROR_VARIABLE_NOT_DEFINED] = L"%0 is not a defined variable";
00041 error_map[ERROR_VARIABLE_NOT_DEFINED_GUESS] = L"%0 is not a defined variable, do you mean %1?";
00042 error_map[ERROR_FUNCTION_NOT_DEFINED] = L"Target does not provide function %0";
00043 error_map[ERROR_FUNCTION_NOT_DEFINED_GUESS] = L"Target does not provide function %0, do you mean %1?";
00044 error_map[ERROR_CONSTANT_NOT_DEFINED] = L"Constant %0 not defined";
00045 error_map[ERROR_CONSTANT_NOT_DEFINED_GUESS] = L"Constant %0 not defined, do you mean %1?";
00046 error_map[ERROR_EVENT_NOT_DEFINED] = L"%0 is not a known event";
00047 error_map[ERROR_EVENT_NOT_DEFINED_GUESS] = L"%0 is not a known event, do you mean %1?";
00048 error_map[ERROR_EMIT_LOCAL_EVENT] = L"%0 is a local event that you cannot emit";
00049 error_map[ERROR_SUBROUTINE_NOT_DEFINED] = L"Subroutine %0 does not exists";
00050 error_map[ERROR_SUBROUTINE_NOT_DEFINED_GUESS] = L"Subroutine %0 does not exists, do you mean %1?";
00051
00052 error_map[ERROR_LINE] = L"Line: ";
00053 error_map[ERROR_COL] = L" Col: ";
00054 error_map[ERROR_UNBALANCED_COMMENT_BLOCK] = L"Unbalanced comment block";
00055 error_map[ERROR_SYNTAX] = L"Syntax error";
00056 error_map[ERROR_INVALID_IDENTIFIER] = L"Identifiers must begin with _ or an alphanumeric character, found unicode character 0x%0 instead";
00057 error_map[ERROR_INVALID_HEXA_NUMBER] = L"Error in hexadecimal number";
00058 error_map[ERROR_INVALID_BINARY_NUMBER] = L"Error in binary number";
00059 error_map[ERROR_NUMBER_INVALID_BASE] = L"Error in number, invalid base";
00060 error_map[ERROR_IN_NUMBER] = L"Error in number";
00061
00062 error_map[ERROR_INTERNAL] = L"Internal compiler error, please report a bug containing the source which triggered this error";
00063 error_map[ERROR_EXPECTING] = L"Expecting %0, found %1 instead";
00064 error_map[ERROR_UINT12_OUT_OF_RANGE] = L"Integer value %0 out of [0;4095] range";
00065 error_map[ERROR_UINT16_OUT_OF_RANGE] = L"Integer value %0 out of [0;65535] range";
00066 error_map[ERROR_PINT16_OUT_OF_RANGE] = L"Integer value %0 out of [0;32767] range";
00067 error_map[ERROR_INT16_OUT_OF_RANGE] = L"Integer value %0 out of [-32768;32767] range";
00068 error_map[ERROR_PCONSTANT_OUT_OF_RANGE] = L"Constant %0 has value %1, which is out of [0;32767] range";
00069 error_map[ERROR_CONSTANT_OUT_OF_RANGE] = L"Constant %0 has value %1, which is out of [-32768;32767] range";
00070 error_map[ERROR_EXPECTING_ONE_OF] = L"Expecting one of %0; but found %1 instead";
00071 error_map[ERROR_NOT_ENOUGH_TEMP_SPACE] = L"Not enough free space to allocate this tempory variable";
00072 error_map[ERROR_MISPLACED_VARDEF] = L"Variable definition is allowed only at the beginning of the program before any statement";
00073 error_map[ERROR_EXPECTING_IDENTIFIER] = L"Expecting identifier, found %0";
00074 error_map[ERROR_VAR_ALREADY_DEFINED] = L"Variable %0 is already defined";
00075 error_map[ERROR_VAR_CONST_COLLISION] = L"Variable %0 has the same name as a constant";
00076 error_map[ERROR_UNDEFINED_SIZE] = L"Array %0 has undefined size";
00077 error_map[ERROR_NOT_ENOUGH_SPACE] = L"No more free variable space";
00078 error_map[ERROR_EXPECTING_ASSIGNMENT] = L"Expecting assignment, found %0 instead";
00079 error_map[ERROR_FOR_NULL_STEPS] = L"Null steps are not allowed in for loops";
00080 error_map[ERROR_FOR_START_HIGHER_THAN_END] = L"Start index must be lower than end index in increasing loops";
00081 error_map[ERROR_FOR_START_LOWER_THAN_END] = L"Start index must be higher than end index in decreasing loops";
00082 error_map[ERROR_EVENT_ALREADY_IMPL] = L"Event %0 is already implemented";
00083 error_map[ERROR_EVENT_WRONG_ARG_SIZE] = L"Event %0 needs an array of size %1, but one of size %2 is passed";
00084 error_map[ERROR_SUBROUTINE_ALREADY_DEF] = L"Subroutine %0 is already defined";
00085 error_map[ERROR_INDEX_EXPECTING_CONSTANT] = L"Expecting a constant expression as a second index";
00086 error_map[ERROR_INDEX_WRONG_END] = L"End of range index must be lower or equal to start of range index";
00087 error_map[ERROR_SIZE_IS_NEGATIVE] = L"Array size: result is negative (%0)";
00088 error_map[ERROR_SIZE_IS_NULL] = L"Array size: result is null";
00089 error_map[ERROR_NOT_CONST_EXPR] = L"Not a valid constant expression";
00090 error_map[ERROR_FUNCTION_HAS_NO_ARG] = L"Function %0 requires no argument, some are used";
00091 error_map[ERROR_FUNCTION_NO_ENOUGH_ARG] = L"Function %0 requires %1 arguments, only %2 are provided";
00092 error_map[ERROR_FUNCTION_WRONG_ARG_SIZE] = L"Argument %0 (%1) of function %2 is of size %3, function definition demands size %4";
00093 error_map[ERROR_FUNCTION_WRONG_ARG_SIZE_TEMPLATE] = L"Argument %0 (%1) of function %2 is of size %3, while a previous instance of the template parameter was of size %4";
00094 error_map[ERROR_FUNCTION_TOO_MANY_ARG] = L"Function %0 requires %1 arguments, more are used";
00095
00096 error_map[ERROR_UNARY_ARITH_BUILD_UNEXPECTED] = L"Unexpected token when building UnaryArithmeticAssignmentNode";
00097
00098 error_map[ERROR_INCORRECT_LEFT_VALUE] = L"Expecting an assignment to a variable, found %0 instead";
00099 error_map[ERROR_ARRAY_OUT_OF_BOUND] = L"Access of array %0 out of bounds: accessing index %1 while array is of size %2";
00100 error_map[ERROR_ARRAY_SIZE_MISMATCH] = L"Size error! Size of array1 = %0 ; size of array2 = %1";
00101 error_map[ERROR_IF_VECTOR_CONDITION] = L"Condition of the if cannot be a vector";
00102 error_map[ERROR_WHILE_VECTOR_CONDITION] = L"Condition of the while cannot be a vector";
00103 error_map[ERROR_ARRAY_ILLEGAL_ACCESS] = L"MemoryVectorNode::getVectorSize: illegal operation";
00104
00105 error_map[ERROR_INFINITE_LOOP] = L"Infinite loops not allowed";
00106 error_map[ERROR_DIVISION_BY_ZERO] = L"Division by zero";
00107 error_map[ERROR_ABS_NOT_POSSIBLE] = L"-32768 has no positive correspondance in 16 bits integers";
00108 error_map[ERROR_ARRAY_OUT_OF_BOUND_READ] = L"Out of bound static array access. Trying to read index %0 of array %1 of size %2";
00109 error_map[ERROR_ARRAY_OUT_OF_BOUND_WRITE] = L"Out of bound static array access. Trying to write index %0 of array %1 of size %2";
00110
00111 error_map[ERROR_EXPECTING_TYPE] = L"Expecting %0 type, found %1 type instead";
00112 error_map[ERROR_EXPECTING_CONDITION] = L"Expecting a condition, found a %0 instead";
00113
00114
00115 error_map[ERROR_TOKEN_END_OF_STREAM] = L"end of stream";
00116 error_map[ERROR_TOKEN_STR_when] = L"when keyword";
00117 error_map[ERROR_TOKEN_STR_emit] = L"emit keyword";
00118 error_map[ERROR_TOKEN_STR_for] = L"for keyword";
00119 error_map[ERROR_TOKEN_STR_in] = L"in keyword";
00120 error_map[ERROR_TOKEN_STR_step] = L"step keyword";
00121 error_map[ERROR_TOKEN_STR_while] = L"while keyword";
00122 error_map[ERROR_TOKEN_STR_do] = L"do keyword";
00123 error_map[ERROR_TOKEN_STR_if] = L"if keyword";
00124 error_map[ERROR_TOKEN_STR_then] = L"then keyword";
00125 error_map[ERROR_TOKEN_STR_else] = L"else keyword";
00126 error_map[ERROR_TOKEN_STR_elseif] = L"elseif keyword";
00127 error_map[ERROR_TOKEN_STR_end] = L"end keyword";
00128 error_map[ERROR_TOKEN_STR_var] = L"var keyword";
00129 error_map[ERROR_TOKEN_STR_call] = L"call keyword";
00130 error_map[ERROR_TOKEN_STR_sub] = L"sub keyword";
00131 error_map[ERROR_TOKEN_STR_callsub] = L"callsub keyword";
00132 error_map[ERROR_TOKEN_STR_onevent] = L"onevent keyword";
00133 error_map[ERROR_TOKEN_STR_abs] = L"abs keyword";
00134 error_map[ERROR_TOKEN_STR_return] = L"return keyword";
00135 error_map[ERROR_TOKEN_STRING_LITERAL] = L"string";
00136 error_map[ERROR_TOKEN_INT_LITERAL] = L"integer";
00137 error_map[ERROR_TOKEN_PAR_OPEN] = L"( (open parenthesis)";
00138 error_map[ERROR_TOKEN_PAR_CLOSE] = L") (close parenthesis)";
00139 error_map[ERROR_TOKEN_BRACKET_OPEN] = L"[ (open bracket)";
00140 error_map[ERROR_TOKEN_BRACKET_CLOSE] = L"] (close bracket)";
00141 error_map[ERROR_TOKEN_COLON] = L": (colon)";
00142 error_map[ERROR_TOKEN_COMMA] = L", (comma)";
00143 error_map[ERROR_TOKEN_ASSIGN] = L"= (assignation)";
00144 error_map[ERROR_TOKEN_OP_OR] = L"or";
00145 error_map[ERROR_TOKEN_OP_AND] = L"and";
00146 error_map[ERROR_TOKEN_OP_NOT] = L"not";
00147 error_map[ERROR_TOKEN_OP_BIT_OR] = L"binary or";
00148 error_map[ERROR_TOKEN_OP_BIT_XOR] = L"binary xor";
00149 error_map[ERROR_TOKEN_OP_BIT_AND] = L"binary and";
00150 error_map[ERROR_TOKEN_OP_BIT_NOT] = L"binary not";
00151 error_map[ERROR_TOKEN_OP_BIT_OR_EQUAL] = L"binary or equal";
00152 error_map[ERROR_TOKEN_OP_BIT_XOR_EQUAL] = L"binary xor equal";
00153 error_map[ERROR_TOKEN_OP_BIT_AND_EQUAL] = L"binary and equal";
00154 error_map[ERROR_TOKEN_OP_EQUAL] = L"== (equal to)";
00155 error_map[ERROR_TOKEN_OP_NOT_EQUAL] = L"!= (not equal to)";
00156 error_map[ERROR_TOKEN_OP_BIGGER] = L"> (bigger than)";
00157 error_map[ERROR_TOKEN_OP_BIGGER_EQUAL] = L">= (bigger or equal than)";
00158 error_map[ERROR_TOKEN_OP_SMALLER] = L"< (smaller than)";
00159 error_map[ERROR_TOKEN_OP_SMALLER_EQUAL] = L"<= (smaller or equal than)";
00160 error_map[ERROR_TOKEN_OP_SHIFT_LEFT] = L"<< (shift left)";
00161 error_map[ERROR_TOKEN_OP_SHIFT_RIGHT] = L">> (shift right)";
00162 error_map[ERROR_TOKEN_OP_SHIFT_LEFT_EQUAL] = L"<<= (shift left equal)";
00163 error_map[ERROR_TOKEN_OP_SHIFT_RIGHT_EQUAL] = L">>= (shift right equal)";
00164 error_map[ERROR_TOKEN_OP_ADD] = L"+ (plus)";
00165 error_map[ERROR_TOKEN_OP_NEG] = L"- (minus)";
00166 error_map[ERROR_TOKEN_OP_ADD_EQUAL] = L"+= (plus equal)";
00167 error_map[ERROR_TOKEN_OP_NEG_EQUAL] = L"-= (minus equal)";
00168 error_map[ERROR_TOKEN_OP_PLUS_PLUS] = L"++ (plus plus)";
00169 error_map[ERROR_TOKEN_OP_MINUS_MINUS] = L"-- (minus minus)";
00170 error_map[ERROR_TOKEN_OP_MULT] = L"* (time)";
00171 error_map[ERROR_TOKEN_OP_DIV] = L"/ (divide)";
00172 error_map[ERROR_TOKEN_OP_MOD] = L"modulo";
00173 error_map[ERROR_TOKEN_OP_MULT_EQUAL] = L"*= (time equal)";
00174 error_map[ERROR_TOKEN_OP_DIV_EQUAL] = L"/= (divide equal)";
00175 error_map[ERROR_TOKEN_OP_MOD_EQUAL] = L"modulo equal";
00176 error_map[ERROR_TOKEN_UNKNOWN] = L"unknown";
00177
00178 error_map[ERROR_UNKNOWN_ERROR] = L"Unknown error";
00179 }
00180
00181 const std::wstring ErrorMessages::defaultCallback(ErrorCode error)
00182 {
00183 if (error >= ERROR_END)
00184 return std::wstring(error_map[ERROR_UNKNOWN_ERROR]);
00185 else
00186 return std::wstring(error_map[error]);
00187 }
00188
00190 std::wstring Error::toWString() const
00191 {
00192 std::wostringstream oss;
00193 if (pos.valid)
00194 oss << "Error at Line: " << pos.row + 1 << " Col: " << pos.column + 1 << " : " << message;
00195 else
00196 oss << "Error : " << message;
00197 return oss.str();
00198 }
00199
00200 ErrorMessages::ErrorCallback TranslatableError::translateCB = NULL;
00201
00202 TranslatableError::TranslatableError(const SourcePos& pos, ErrorCode error)
00203 {
00204 this->pos = pos;
00205 message = translateCB(error);
00206 }
00207
00208 Error TranslatableError::toError(void)
00209 {
00210 return Error(pos, message);
00211 }
00212
00213 void TranslatableError::setTranslateCB(ErrorMessages::ErrorCallback newCB)
00214 {
00215 translateCB = newCB;
00216 }
00217
00218 TranslatableError &TranslatableError::arg(int value, int fieldWidth, int base, wchar_t fillChar)
00219 {
00220 message.arg(value, fieldWidth, base, fillChar);
00221 return *this;
00222 }
00223
00224 TranslatableError &TranslatableError::arg(unsigned value, int fieldWidth, int base, wchar_t fillChar)
00225 {
00226 message.arg(value, fieldWidth, base, fillChar);
00227 return *this;
00228 }
00229
00230 TranslatableError &TranslatableError::arg(float value, int fieldWidth, int precision, wchar_t fillChar )
00231 {
00232 message.arg(value, fieldWidth, precision, fillChar);
00233 return *this;
00234 }
00235
00236 TranslatableError &TranslatableError::arg(const std::wstring& value)
00237 {
00238 message.arg(value);
00239 return *this;
00240 }
00241
00244 };