Rune - Change regsave burden for syscalls
[rune.git] / librune / lex.h
1 /*
2  * LEX.H
3  *
4  * (c)Copyright 1993-2014, Matthew Dillon, All Rights Reserved.  See the  
5  *    COPYRIGHT file at the base of the distribution.
6  */
7
8 struct Lex;
9
10 typedef RUNE_HEAD(lexlist, Lex) lexlist_t;
11
12 typedef struct Lex {
13         RUNE_ENTRY(Lex) l_Node; /* saved Lex structures for error reporting */
14         char    *l_Path;
15         char    *l_Base;
16         int     l_Fd;
17         int     l_Bytes;
18         int     l_CacheLine;    /* cached line number */
19         int     l_CacheOff;     /* start of cache line */
20         int     l_RefCount;     /* LexRef count */
21         int     l_OpenCount;    /* open/close count */
22         int     l_DebugFileNo;  /* assigned during emit phase if debugging */
23 } Lex;
24
25 typedef struct {
26         const char *t_Ptr;
27         const char *t_End;
28         int     t_Len;
29         int     t_Type;
30         int     t_Line;
31         int     t_LinesInToken;
32         Lex     *t_Lex;
33 } token_t;
34
35 /*
36  * LexRef - save lexical position for error generation after lexical
37  *          processing has completed.
38  *
39  * WARNING! Embedded in Declaration, fields must match classes/sys/runtime.d
40  */
41 typedef struct {
42         Lex     *lr_Lex;        /* pointer to (closed) Lex structure */
43         int     lr_Offset;      /* offset in file */
44         int     lr_Len;         /* length of token in file */
45         int     lr_Line;        /* line number */
46         int     lr_Reserved03;
47 } LexRef;
48
49 #define T_WS    0x01    /* white space CR LF FF SP TAB */
50 #define T_AL    0x02    /* alpha */
51 #define T_NU    0x04    /* numeric */
52 #define T_QU    0x08    /* single/backtick/double quote */
53 #define T_SP    0x10    /* single-character special */
54 #define T_CM    0x20    /* comment '#' */
55 #define T_MP    0x40    /* multi-character special or operator */
56 #define T_XP    0x80    /* possible comment (/) */
57
58 #define T_ALNU  (T_AL | T_NU)
59
60 #define TOK_DOLLAR      '$'
61 #define TOK_OPAREN      '('
62 #define TOK_CPAREN      ')'
63 #define TOK_COMMA       ','
64 #define TOK_DOT         '.'
65 #define TOK_COLON       ':'
66 #define TOK_SEMI        ';'
67 #define TOK_AT          '@'
68 #define TOK_OBRACKET    '['
69 #define TOK_CBRACKET    ']'
70 #define TOK_OBRACE      '{'
71 #define TOK_CBRACE      '}'
72 #define TOK_NOT         '!'     /* synthesized for exp, not actual lex token */
73
74 #define TOK_DSTRING     '"'
75 #define TOK_SSTRING     '\''
76 #define TOK_BSTRING     '`'
77 #define TOK_ANGLESTR    '<'     /* (specially flagged, nominally TOK_OPER) */
78
79 #define TOK_ASS         0x0100
80 #define TOK_ANDAND      0x0101
81 #define TOK_OROR        0x0102
82 #define TOK_OPER        0x0103
83 #define TOK_INTEGER     0x0104
84 #define TOK_FLOAT       0x0105
85 #define TOK_ID          (0x0106 | TOKF_ID)
86 #define TOK_EOF         (0x0107 | TOKF_EOF)
87 #define TOK_COMPOUND    0x0108  /* synthesized for exp (exp, exp, ...) */
88 #define TOK_UNUSED0109  0x0109
89 #define TOK_CALL        0x010A  /* synthesized for exp (exp, exp, ...) */
90 #define TOK_STRIND      0x010B  /* -> */
91 #define TOK_UNUSED010C  0x010C
92 #define TOK_PTRIND      0x010D  /* (synthesized) pointer indirect */
93 #define TOK_STRUCT_ID   0x010E  /* rhs side of '.' or '->' expression */
94 #define TOK_SEMGRP_ID   0x010F
95 #define TOK_UNUSED110   0x0110
96 #define TOK_DECL        0x0111  /* collapsed into declaration */
97 #define TOK_VOIDEXP     0x0112  /* like an integer, but represents void */
98 #define TOK_ADDR        0x0113  /* (synthesized) address of */
99 #define TOK_TYPE        0x0114  /* a type (in ex_Type) */
100 #define TOK_THREAD_SCHEDULE     0x0115  /* thread schedule */
101 #define TOK_CLASSID     (0x0116 | TOKF_ID)
102 #define TOK_UNUSED117   0x0117
103 #define TOK_UNUSED118   0x0118
104 #define TOK_SIZEOF      0x0119
105 #define TOK_ARYSIZE     0x011A
106 #define TOK_TYPEOF      0x011B
107 #define TOK_CONSTEXP    0x011C  /* resolved to cacheable constant */
108 #define TOK_INLINE_CALL 0x011D  /* call -> inlined call */
109 #define TOK_BRACKETED   0x011E  /* synthesized [ exp, exp, exp, ... ] */
110
111 #define TOKF_ID         0x01000000
112 #define TOKF_ERROR      0x02000000
113 #define TOKF_EOF        0x04000000
114 #define TOKF_SCOPE_QUAL 0x08000000
115 #define TOKF_STOR_QUAL  0x10000000
116 #define TOKF_KEYWORD    0x20000000
117 #define TOKF_ERREOF     (TOKF_ERROR|TOKF_EOF)
118
119 #define TOKF_ERR_MASK   0x0000FFFF
120 #define TOKF_SCOPE_MASK 0x00000FFF
121 #define TOKF_STOR_MASK  0x00000FFF
122
123 #define TOK_ERR_NOERROR                 (TOKF_ERROR|0x00)       /* special */
124 #define TOK_ERR_UNKNOWN                 (TOKF_ERROR|0x01)       /* special */
125 #define TOK_ERR_UNTERMINATED_COMMENT    (TOKF_ERROR|0x02)
126 #define TOK_ERR_UNEXPECTED_CHAR         (TOKF_ERROR|0x03)
127 #define TOK_ERR_UNEXPECTED_TOKEN        (TOKF_ERROR|0x04)
128 #define TOK_ERR_BAD_NUMERIC_CONST       (TOKF_ERROR|0x05)
129 #define TOK_ERR_EMBEDDED_CRLF           (TOKF_ERROR|0x06)
130 #define TOK_ERR_ILLEGAL_ESCAPE          (TOKF_ERROR|0x07)
131 #define TOK_ERR_UNTERMINATED_STR        (TOKF_ERROR|0x08)
132 #define TOK_ERR_MULTIPLE_SCOPES         (TOKF_ERROR|0x09)
133 #define TOK_ERR_MISSING_OBRACE          (TOKF_ERROR|0x0A)
134 #define TOK_ERR_MISSING_CBRACE          (TOKF_ERROR|0x0B)
135 #define TOK_ERR_CASE_WITHOUT_SWITCH     (TOKF_ERROR|0x0C)
136 #define TOK_ERR_DEFAULT_WITHOUT_SWITCH  (TOKF_ERROR|0x0D)
137 #define TOK_ERR_ELSE_WITHOUT_IF         (TOKF_ERROR|0x0E)
138 #define TOK_ERR_DO_WITHOUT_WHILE        (TOKF_ERROR|0x0F)
139 #define TOK_ERR_BAD_BREAK_KEYWORD       (TOKF_ERROR|0x10)
140 #define TOK_ERR_MULTIPLE_DEFAULTS       (TOKF_ERROR|0x11)
141 #define TOK_ERR_SYNTAX                  (TOKF_ERROR|0x12)
142 #define TOK_ERR_EXPECTED_STRING         (TOKF_ERROR|0x13)
143 #define TOK_ERR_EXPECTED_ID             (TOKF_ERROR|0x14)
144 #define TOK_ERR_IMPORT_NOT_FOUND        (TOKF_ERROR|0x15)
145 #define TOK_ERR_DECL_NOT_PROCEDURE      (TOKF_ERROR|0x16)
146 #define TOK_ERR_EXPECTED_COMMA          (TOKF_ERROR|0x17)
147
148 #define TOK_ERR_EXP_SYNTAX              (TOKF_ERROR|0x18)
149 #define TOK_ERR_CLASS_ILLEGAL_TYPE      (TOKF_ERROR|0x19)
150 #define TOK_ERR_EXPECTED_CPAREN         (TOKF_ERROR|0x1A)
151 #define TOK_ERR_EXPECTED_TYPE           (TOKF_ERROR|0x1B)
152 #define TOK_ERR_MUTILPLE_IDS            (TOKF_ERROR|0x1C)
153 #define TOK_ERR_EXPECTED_DECLARATOR     (TOKF_ERROR|0x1D)
154 #define TOK_ERR_ILLEGAL_ID_CONTEXT      (TOKF_ERROR|0x1E)
155 #define TOK_ERR_IMPORT_FAILED           (TOKF_ERROR|0x1F)
156 #define TOK_ERR_EXPECTED_QUOTED_OPERATOR (TOKF_ERROR|0x20)
157 #define TOK_ERR_EXPECTED_SIMPLE_INTEGER (TOKF_ERROR|0x21)
158 #define TOK_ERR_BREAK_CONT_NOT_FOUND    (TOKF_ERROR|0x22)
159 #define TOK_ERR_DUPLICATE_ATTACH        (TOKF_ERROR|0x23)
160 #define TOK_ERR_UNRECOGNIZED_ATTACH     (TOKF_ERROR|0x24)
161 #define TOK_ERR_ILLEGAL_TYPEDEF         (TOKF_ERROR|0x25)
162 #define TOK_ERR_OPERATOR_NOT_PROCEDURE  (TOKF_ERROR|0x26)
163 #define TOK_ERR_EMPTY_PATH              (TOKF_ERROR|0x27)
164 #define TOK_ERR_NOT_SUPPORTED           (TOKF_ERROR|0x28)
165 #define TOK_ERR_BADLY_FORMED_SIZEOF     (TOKF_ERROR|0x29)
166 #define TOK_ERR_EXP_REMOVED             (TOKF_ERROR|0x2A)
167 #define TOK_ERR_EXP_SYNTAX_MAYTYPE      (TOKF_ERROR|0x2B)
168 #define TOK_ERR_PARSE_ID_NOT_CLASS      (TOKF_ERROR|0x2C)
169 #define TOK_ERR_PARSE_CLASS_NOT_FOUND   (TOKF_ERROR|0x2D)
170 #define TOK_ERR_NO_DOTTED_ID_HERE       (TOKF_ERROR|0x2E)
171 #define TOK_ERR_NESTED_CLASS            (TOKF_ERROR|0x2F)
172 #define TOK_ERR_DUPLICATE_ID            (TOKF_ERROR|0x30)
173 #define TOK_ERR_METHOD_REQUIRES_OBJ     (TOKF_ERROR|0x31)
174 #define TOK_ERR_SCOPE_NOT_VISIBLE       (TOKF_ERROR|0x32)
175 #define TOK_ERR_ID_NOT_FOUND            (TOKF_ERROR|0x33)
176 #define TOK_ERR_EXPECTED_CLASSID        (TOKF_ERROR|0x34)
177
178 #define TOK_ERR_INCOMPATIBLE_SUBCLASS   (TOKF_ERROR|0x35)
179 #define TOK_ERR_INCOMPATIBLE_BINDING    (TOKF_ERROR|0x36)
180 #define TOK_ERR_EXPECTED_INTEGRAL_TYPE  (TOKF_ERROR|0x37)
181 #define TOK_ERR_EXPECTED_INTEGRER_CONST (TOKF_ERROR|0x38)
182 #define TOK_ERR_ILLEGAL_UNLOCKED        (TOKF_ERROR|0x39)
183 #define TOK_ERR_ILLEGAL_ADDRLOCKED      (TOKF_ERROR|0x3A)
184 #define TOK_ERR_ILLEGAL_SUFFIX          (TOKF_ERROR|0x3B)
185 #define TOK_ERR_AUTOCAST_VALUE          (TOKF_ERROR|0x3C)
186 #define TOK_ERR_RESULT_SEQUENCING       (TOKF_ERROR|0x3D)
187 #define TOK_ERR_READONLY                (TOKF_ERROR|0x3E)
188 #define TOK_ERR_LIMITED_VOIDP_CAST      (TOKF_ERROR|0x3F)
189 #define TOK_ERR_SCOPE_MISMATCH          (TOKF_ERROR|0x40)
190 #define TOK_ERR_SCOPE_MISMATCH_THIS     (TOKF_ERROR|0x41)
191 #define TOK_ERR_ILLEGAL_LOCKING_REFINEMENT (TOKF_ERROR|0x42)
192 #define TOK_ERR_ILLEGAL_LOCKED          (TOKF_ERROR|0x43)
193
194 #define LEX_ERR_STRINGS         \
195                 "",                                                     \
196                 "Unknown Error",                                        \
197                 "Unterminated Comment",                                 \
198                 "Unexpected Lexical Character",                         \
199                 "Unexpected Token",                                     \
200                 "Badly formed numerical constant",                      \
201                 "Embedded CR or LFs in strings are illegal",            \
202                 "Illegal escape in string",                             \
203 /* 0x08 */      "Unterminated string",                                  \
204                 "Multiple scopes specified",                            \
205                 "Expected open-brace",                                  \
206                 "Expected close-brace",                                 \
207                 "Case outside of switch",                               \
208                 "Default outside of switch",                            \
209                 "Else without if",                                      \
210                 "Do without while/until",                               \
211 /* 0x10 */      "Bad break/continue keyword",                           \
212                 "Multiple default: clauses were specified",             \
213                 "Syntax error",                                         \
214                 "Expected string constant",                             \
215                 "Expected identifier",                                  \
216                 "Import not found",                                     \
217                 "Illegal statement block, declaration is not a procedure",\
218                 "Expected comma",                                       \
219 /* 0x18 */      "Syntax error in expression",                           \
220                 "Illegal type for class declaration",                   \
221                 "Expected close parenthesis",                           \
222                 "Expected type",                                        \
223                 "Multiple identifiers were specified",                  \
224                 "Expected declarator",                                  \
225                 "Wrong kind of identifier was found for this context",  \
226                 "Error parsing imported file",                          \
227 /* 0x20 */      "Expected quoted operator",                             \
228                 "Expected simple integer",                              \
229                 "Break/continue point not found",                       \
230                 "Duplicate internal attach",                            \
231                 "Unrecognize internal attach id",                       \
232                 "Illegal typedef",                                      \
233                 "Operator/cast/method declaration is not a procedure!", \
234                 "Empty string not allowed",                             \
235 /* 0x28 */      "Not yet supported",                                    \
236                 "Badly formed sizeof(), typeof(), or arysize() operator",\
237                 "Expression removed from tree",                         \
238                 "Syntax error in expression.  If trying to make a "     \
239                  "declaration, do not forget the required scope or "    \
240                  "storage qualifier",                                   \
241                 "Can only enter declaration into a class",              \
242                 "Unable to find class to enter declaration into",       \
243                 "Dotted ids are not allowed here",                      \
244                 "You cannot nest classes or subclasses.  Perhaps "      \
245                  "you meant to use an interface here?",                 \
246 /* 0x30 */      "Duplicate identifier during parsing",                  \
247                 "A non-global method call must be called through an "   \
248                  "object context",                                      \
249                 "The id was found but is outside its visibility scope", \
250                 "Identifier could not be located",                      \
251                 "Expected type/class identifier",                       \
252                 "Subclass is not compatible with its superclass",       \
253                 "Subclass is incompatible for binding purposes",        \
254                 "Expected integral type",                               \
255                 "Expected resolvable integer constant",                 \
256                 "Rune only allows 'unlocked' or 'locked' scope if "     \
257                  "storage defaults to soft-locked",                     \
258                 "Cannot take the address of content-locked storage, "   \
259                  "you must make it 'unlocked'",                         \
260                 "Unrecognize suffix for constant",                      \
261                 "Autocast of constant would change its value",          \
262                 "Illegal placement of result; or use of argument "      \
263                  "or return value after result;",                       \
264                 "Storage is read-only and may not be modified",         \
265                 "Objects cast to void* may not contain lvalues, "       \
266                  "pointers, or references",                             \
267                 "Locking scope mismatch",                               \
268                 "Locking scope mismatch on method object ('this')",     \
269                 "Procedure refinement cannot change locking mode",      \
270                 "Locking scope illegal here",                           \
271                 NULL    /* terminate the macro, the NULL is not really used */
272