1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2020, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 #pragma once
21 
22 /**
23  * \file CBotEnums.h
24  * \brief Some enum values used across the CBot engine
25  */
26 
27 namespace CBot
28 {
29 
30 /**
31  * \brief Defines known types. This types are modeled on Java types.
32  *
33  * Do not change the order of elements.
34  */
35 enum CBotType
36 {
37     CBotTypVoid         = 0,  //!< void
38     CBotTypByte         = 1,  //!< byte
39     CBotTypShort        = 2,  //!< short
40     CBotTypChar         = 3,  //!< char
41     CBotTypInt          = 4,  //!< int
42     CBotTypLong         = 5,  //!< long
43     CBotTypFloat        = 6,  //!< float
44     CBotTypDouble       = 7,  //!< double
45     CBotTypBoolean      = 8,  //!< bool
46     CBotTypString       = 9,  //!< string
47 
48     CBotTypArrayPointer = 10, //!< Pointer to an array (::CBotTypArrayBody)
49     CBotTypArrayBody    = 11, //!< Array
50 
51     CBotTypPointer      = 12, //!< Pointer to a class (::CBotTypClass or ::CBotTypIntrinsic)
52     CBotTypNullPointer  = 13, //!< Null pointer
53     CBotTypClass        = 15, //!< Class instance
54     CBotTypIntrinsic    = 16, //!< Intrinsic class instance
55 
56     CBotTypMAX = 20
57 };
58 
59 /**
60  * \brief Different modes for CBotProgram::GetPosition
61  */
62 enum CBotGet
63 {
64     GetPosExtern = 1,
65     GetPosNom    = 2,
66     GetPosParam  = 3,
67     GetPosBloc   = 4
68 };
69 
70 /**
71  * \brief This enum contains possible token types
72  */
73 enum TokenId
74 {
75     TokenKeyWord = 2000, //!< keywords
76     ID_IF = 2000,
77     ID_ELSE,
78     ID_WHILE,
79     ID_DO,
80     ID_FOR,
81     ID_BREAK,
82     ID_CONTINUE,
83     ID_SWITCH,
84     ID_CASE,
85     ID_DEFAULT,
86     ID_TRY,
87     ID_THROW,
88     ID_CATCH,
89     ID_FINALLY,
90     ID_TXT_AND,
91     ID_TXT_OR,
92     ID_TXT_NOT,
93     ID_RETURN,
94     ID_CLASS,
95     ID_EXTENDS,
96     ID_SYNCHO,
97     ID_NEW,
98     ID_PUBLIC,
99     ID_EXTERN,
100     ID_STATIC,
101     ID_PROTECTED,
102     ID_PRIVATE,
103     ID_REPEAT,
104     ID_INT,
105     ID_FLOAT,
106     ID_BOOLEAN,
107     ID_STRING,
108     ID_VOID,
109     ID_BOOL,
110     ID_BYTE,
111     ID_SHORT,
112     ID_CHAR,
113     ID_LONG,
114     ID_DOUBLE,
115 
116     TokenKeyVal = 2200, //!< keywords that represent values (true, false, null, nan)
117     ID_TRUE = 2200,
118     ID_FALSE,
119     ID_NULL,
120     ID_NAN,
121 
122     TokenKeyOp = 2300, //!< operators
123     ID_OPENPAR = 2300,
124     ID_CLOSEPAR,
125     ID_OPBLK,
126     ID_CLBLK,
127     ID_SEP,
128     ID_COMMA,
129     ID_DOTS,
130     ID_DOT,
131     ID_OPBRK,
132     ID_CLBRK,
133     ID_DBLDOTS,
134     ID_LOGIC,
135     ID_ADD,
136     ID_SUB,
137     ID_MUL,
138     ID_DIV,
139     ID_ASS,
140     ID_ASSADD,
141     ID_ASSSUB,
142     ID_ASSMUL,
143     ID_ASSDIV,
144     ID_ASSOR,
145     ID_ASSAND,
146     ID_ASSXOR,
147     ID_ASSSL,
148     ID_ASSSR,
149     ID_ASSASR,
150     ID_SL,
151     ID_SR,
152     ID_ASR,
153     ID_INC,
154     ID_DEC,
155     ID_LO,
156     ID_HI,
157     ID_LS,
158     ID_HS,
159     ID_EQ,
160     ID_NE,
161     ID_AND,
162     ID_XOR,
163     ID_OR,
164     ID_LOG_AND,
165     ID_LOG_OR,
166     ID_LOG_NOT,
167     ID_NOT,
168     ID_MODULO,
169     ID_POWER,
170     ID_ASSMODULO,
171 
172     TX_UNDEF = 4000,
173     TX_NAN
174 };
175 
176 /**
177  * \brief Types of tokens
178  */
179 enum TokenType
180 {
181     TokenTypNone = 0,
182     TokenTypKeyWord = 1, //!< keyword of the language (see TokenKeyWord)
183     TokenTypNum = 2,     //!< number
184     TokenTypString = 3,  //!< string
185     TokenTypVar = 4,     //!< a variable name
186     TokenTypDef = 5,     //!< value according DefineNum
187     TokenTypChar = 6,    //!< character literal
188 };
189 
190 /**
191  * \brief This enum contains possible CBot error values. Values in range 5000-5999 are compile errors, 6000-6999 are runtime errors
192  *
193  * Note that other values ​​may be returned, for example exceptions for user-defined builtin functions, or "throw" instruction
194  *
195  * Also note that these can't overlap with CBotType, see CBotTypResult for explanation
196  */
197 enum CBotError : int
198 {
199     CBotNoErr = 0,
200 
201     // Compile errors
202     CBotErrOpenPar       = 5000, //!< missing the opening parenthesis
203     CBotErrClosePar      = 5001, //!< missing the closing parenthesis
204     CBotErrNotBoolean    = 5002, //!< expression must be a boolean
205     CBotErrUndefVar      = 5003, //!< undeclared variable
206     CBotErrBadLeft       = 5004, //!< assignment impossible ( 5 = ... )
207     CBotErrNoTerminator  = 5005, //!< semicolon expected
208     CBotErrCaseOut       = 5006, //!< case outside a switch
209     CBotErrNoEnd         = 5007, //!< instructions after final closing brace
210     CBotErrCloseBlock    = 5008, //!< missing " } "
211     CBotErrElseWhitoutIf = 5009, //!< else without matching if
212     CBotErrOpenBlock     = 5010, //!< missing " { "
213     CBotErrBadType1      = 5011, //!< wrong type for the assignment
214     CBotErrRedefVar      = 5012, //!< redefinition of the variable
215     CBotErrBadType2      = 5013, //!< Two operands are incompatible
216     CBotErrUndefCall     = 5014, //!< routine undefined
217     CBotErrNoDoubleDots  = 5015, //!< " : " expected
218     CBotErrNoWhile       = 5016, //!< "while" expected (in do..while)
219     CBotErrBreakOutside  = 5017, //!< break outside of a loop
220     CBotErrUndefLabel    = 5019, //!< label udnefined
221     CBotErrLabel         = 5018, //!< label ne peut se mettre ici (label can not get here)
222     CBotErrNoCase        = 5020, //!< missing " case "
223     CBotErrBadNum        = 5021, //!< expected number
224     CBotErrVoid          = 5022, //!< " void " not possible here
225     CBotErrNoType        = 5023, //!< type declaration expected
226     CBotErrNoVar         = 5024, //!< variable name expected
227     CBotErrNoFunc        = 5025, //!< expected function name
228     CBotErrOverParam     = 5026, //!< too many parameters
229     CBotErrRedefFunc     = 5027, //!< this function already exists
230     CBotErrLowParam      = 5028, //!< not enough parameters
231     CBotErrBadParam      = 5029, //!< wrong types of parameters
232     CBotErrNbParam       = 5030, //!< wrong number of parameters
233     CBotErrUndefItem     = 5031, //!< element does not exist in the class
234     CBotErrUndefClass    = 5032, //!< variable is not a class
235     CBotErrNoConstruct   = 5033, //!< no appropriate constructor
236     CBotErrRedefClass    = 5034, //!< class already exists
237     CBotErrCloseIndex    = 5035, //!< " ] " expected
238     CBotErrReserved      = 5036, //!< reserved word (for a DefineNum)
239     CBotErrBadNew        = 5037, //!< wrong setting for new
240     CBotErrOpenIndex     = 5038, //!< " [ " expected
241     CBotErrBadString     = 5039, //!< expected string
242     CBotErrBadIndex      = 5040, //!< wrong index type "[ false ]"
243     CBotErrPrivate       = 5041, //!< protected item
244     CBotErrNoPublic      = 5042, //!< missing word "public"
245     CBotErrNoExpression  = 5043, //!< expression expected after =
246     CBotErrAmbiguousCall = 5044, //!< ambiguous call to overloaded function
247     CBotErrFuncNotVoid   = 5045, //!< function needs return type "void"
248     CBotErrNoClassName   = 5046, //!< class name expected
249     CBotErrNoReturn      = 5047, //!< non-void function needs "return;"
250     CBotErrDefaultValue  = 5048, //!< this parameter needs a default value
251     CBotErrEndQuote      = 5049, //!< missing end quote
252     CBotErrBadEscape     = 5050, //!< unknown escape sequence
253     CBotErrOctalRange    = 5051, //!< octal value out of range
254     CBotErrHexDigits     = 5052, //!< missing hex digits after escape sequence
255     CBotErrHexRange      = 5053, //!< hex value out of range
256     CBotErrUnicodeName   = 5054, //!< invalid universal character name
257     CBotErrCharEmpty     = 5055, //!< empty character constant
258     CBotErrRedefCase     = 5056, //!< duplicate label in switch
259 
260     // Runtime errors
261     CBotErrZeroDiv       = 6000, //!< division by zero
262     CBotErrNotInit       = 6001, //!< uninitialized variable
263     CBotErrBadThrow      = 6002, //!< throw a negative value
264     CBotErrNoRetVal      = 6003, //!< function did not return results
265     CBotErrNoRun         = 6004, //!< Run() without active function
266     CBotErrUndefFunc     = 6005, //!< calling a function that no longer exists
267     CBotErrNotClass      = 6006, //!< this class does not exist
268     CBotErrNull          = 6007, //!< null pointer
269     CBotErrNan           = 6008, //!< calculation with a NAN
270     CBotErrOutArray      = 6009, //!< index out of array
271     CBotErrStackOver     = 6010, //!< stack overflow
272     CBotErrDeletedPtr    = 6011, //!< pointer to an object destroyed
273     CBotErrFileOpen      = 6012, //!< cannot open the file
274     CBotErrNotOpen       = 6013, //!< channel not open
275     CBotErrRead          = 6014, //!< error while reading
276     CBotErrWrite         = 6015, //!< writing error
277 
278     CBotErrMAX, //!< Max errors
279 };
280 
281 } // namespace CBot
282