(494 lines)
1 // Logic defining ASTs (abstract syntax trees) to represent code15 (new (ast_t, .file = _file, .start = _start, .end = _end, .tag = ast_tag, .__data.ast_tag = {__VA_ARGS__}))17 (new (type_ast_t, .file = _file, .start = _start, .end = _end, .tag = ast_tag, .__data.ast_tag = {__VA_ARGS__}))25 .__data.InlineCCode = {.chunks = new (ast_list_t, .ast = FakeAST(TextLiteral, code)), __VA_ARGS__})27 new (ast_t, .tag = InlineCCode, .file = (_ast)->file, .start = (_ast)->start, .end = (_ast)->end, \28 .__data.InlineCCode = {.chunks = new (ast_list_t, .ast = WrapAST(_ast, TextLiteral, code)), __VA_ARGS__})34 ({ \35 if (!is_binary_operation(ast)) errx(1, __FILE__ ":%d This is not a binary operation!", __LINE__); \37 })39 ({ \40 if (!is_update_assignment(ast)) errx(1, __FILE__ ":%d This is not an update assignment!", __LINE__); \42 })50 _next = _current->next; \51 _current->next = _prev; \52 _prev = _current; \53 _current = _next; \54 } \55 list = _prev; \62 ast_t *lhs, *rhs;63 } binary_operands_t;66 ast_t *ast;68 } ast_list_t;71 file_t *file;74 Text_t comment;75 type_ast_t *type;76 ast_t *value;78 } arg_ast_t;81 ast_t *pattern, *body;83 } when_clause_t;86 UnknownTypeAST,87 VarTypeAST,88 PointerTypeAST,89 ListTypeAST,90 TableTypeAST,91 FunctionTypeAST,92 OptionalTypeAST,93 EnumTypeAST,94 } type_ast_e;97 file_t *file;100 arg_ast_t *fields;103 } tag_ast_t;106 type_ast_e tag;107 file_t *file;111 } UnknownTypeAST;114 } VarTypeAST;116 type_ast_t *pointed;118 } PointerTypeAST;120 type_ast_t *item;121 } ListTypeAST;124 ast_t *default_value;125 } TableTypeAST;127 arg_ast_t *args;128 type_ast_t *ret;129 } FunctionTypeAST;131 type_ast_t *type;132 } OptionalTypeAST;134 Text_t name;135 tag_ast_t *tags;136 } EnumTypeAST;137 } __data;138 };141 Power: \179 PowerUpdate: \197 None,198 Bool,199 Var,200 Int,201 Num,202 TextLiteral,203 TextJoin,204 Path,205 Declare,206 Assign,207 Power,208 Multiply,209 Divide,210 Mod,211 Mod1,212 Plus,213 Minus,214 Concat,215 LeftShift,216 UnsignedLeftShift,217 RightShift,218 UnsignedRightShift,219 Equals,220 NotEquals,221 LessThan,222 LessThanOrEquals,223 GreaterThan,224 GreaterThanOrEquals,225 Compare,226 And,227 Or,228 Xor,229 PowerUpdate,230 MultiplyUpdate,231 DivideUpdate,232 ModUpdate,233 Mod1Update,234 PlusUpdate,235 MinusUpdate,236 ConcatUpdate,237 LeftShiftUpdate,238 UnsignedLeftShiftUpdate,239 RightShiftUpdate,240 UnsignedRightShiftUpdate,241 AndUpdate,242 OrUpdate,243 XorUpdate,244 Not,245 Negative,246 HeapAllocate,247 StackReference,248 Min,249 Max,250 List,251 Table,252 TableEntry,253 Comprehension,254 FunctionDef,255 Lambda,256 ConvertDef,257 FunctionCall,258 MethodCall,259 Block,260 For,261 While,262 If,263 When,264 Repeat,265 Reduction,266 Skip,267 Stop,268 Pass,269 Defer,270 Return,271 StructDef,272 EnumDef,273 LangDef,274 Index,275 FieldAccess,276 NonOptional,277 DebugLog,278 Assert,279 Use,280 InlineCCode,281 ExplicitlyTyped,282 Metadata,283 } ast_e;287 ast_e tag;288 file_t *file;292 } Unknown;295 } None;298 } Bool;301 } Var;304 } Int;307 } Num;309 Text_t text;310 } TextLiteral;313 ast_list_t *children;315 } TextJoin;318 } Path;320 ast_t *var;321 type_ast_t *type;322 ast_t *value;324 } Declare;326 ast_list_t *targets, *values;327 } Assign;328 binary_operands_t Power, Multiply, Divide, Mod, Mod1, Plus, Minus, Concat, LeftShift, UnsignedLeftShift,329 RightShift, UnsignedRightShift, Equals, NotEquals, LessThan, LessThanOrEquals, GreaterThan,330 GreaterThanOrEquals, Compare, And, Or, Xor, PowerUpdate, MultiplyUpdate, DivideUpdate, ModUpdate,331 Mod1Update, PlusUpdate, MinusUpdate, ConcatUpdate, LeftShiftUpdate, UnsignedLeftShiftUpdate,332 RightShiftUpdate, UnsignedRightShiftUpdate, AndUpdate, OrUpdate, XorUpdate;334 ast_t *value;335 } Not, Negative, HeapAllocate, StackReference;337 ast_t *lhs, *rhs, *key;338 } Min, Max;340 ast_list_t *items;341 } List;343 ast_t *default_value;344 ast_t *fallback;345 ast_list_t *entries;346 } Table;349 } TableEntry;351 ast_list_t *vars;352 ast_t *expr, *iter, *filter;353 } Comprehension;355 ast_t *name;356 arg_ast_t *args;357 type_ast_t *ret_type;358 ast_t *body;359 ast_t *cache;361 } FunctionDef;363 arg_ast_t *args;364 type_ast_t *ret_type;365 ast_t *body;366 ast_t *cache;368 } ConvertDef;370 arg_ast_t *args;371 type_ast_t *ret_type;372 ast_t *body;374 } Lambda;376 ast_t *fn;377 arg_ast_t *args;378 } FunctionCall;382 arg_ast_t *args;383 } MethodCall;385 ast_list_t *statements;386 } Block;388 ast_list_t *vars;389 ast_t *iter, *body, *empty;390 } For;392 ast_t *condition, *body;393 } While;395 ast_t *body;396 } Repeat;398 ast_t *condition, *body, *else_body;399 } If;401 ast_t *subject;402 when_clause_t *clauses;403 ast_t *else_body;404 } When;406 ast_t *iter, *key;407 ast_e op;408 } Reduction;411 } Skip, Stop;413 } Pass;415 ast_t *body;416 } Defer;418 ast_t *value;419 } Return;422 arg_ast_t *fields;423 ast_t *namespace;425 } StructDef;428 tag_ast_t *tags;429 ast_t *namespace;430 } EnumDef;433 ast_t *namespace;434 } LangDef;436 ast_t *indexed, *index;437 } Index;439 ast_t *fielded;441 } FieldAccess;443 ast_t *value;444 } NonOptional;446 ast_list_t *values;447 } DebugLog;449 ast_t *expr, *message;450 } Assert;452 ast_t *var;455 } Use;457 ast_list_t *chunks;459 type_ast_t *type_ast;460 } InlineCCode;462 ast_t *ast;464 } ExplicitlyTyped;466 Text_t key, value;467 } Metadata;468 } __data;469 };476 } binop_info_t;493 void type_ast_visit(ast_t *ast, visit_behavior_t (*visitor)(type_ast_t *, void *), void *userdata);