1 /// Copyright: Copyright (c) 2017-2019 Andrey Penechko. 2 /// License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 3 /// Authors: Andrey Penechko. 4 module vox.fe.ast.decl.static_if; 5 6 import vox.all; 7 8 9 mixin template ConditionalDeclNodeData(AstType _astType, int default_flags = 0, AstNodeState _init_state = AstNodeState.parse_done) { 10 mixin AstNodeData!(_astType, default_flags, _init_state); 11 AstIndex next; // Next conditional declaration. Used during expansion 12 AstIndex prev; // Prev conditional declaration. Used during expansion 13 uint arrayIndex; // Index into AstNodes of the parent node, where items are to be inserted 14 } 15 16 // Abstract node, must not be instantiated 17 struct ConditionalDeclNode 18 { 19 mixin ConditionalDeclNodeData!(AstType.abstract_node); 20 } 21 22 23 @(AstType.decl_static_if) 24 struct StaticIfDeclNode 25 { 26 mixin ConditionalDeclNodeData!(AstType.decl_static_if); 27 AstIndex condition; 28 AstNodes thenItems; // can be empty 29 AstNodes elseItems; // can be empty 30 } 31 32 void print_static_if(StaticIfDeclNode* node, ref AstPrintState state) 33 { 34 state.print("#IF"); 35 print_ast(node.condition, state); 36 state.print("#THEN"); 37 print_ast(node.thenItems, state); 38 state.print("#ELSE"); 39 print_ast(node.elseItems, state); 40 } 41 42 void post_clone_static_if(StaticIfDeclNode* node, ref CloneState state) 43 { 44 state.fixAstIndex(node.condition); 45 state.fixAstNodes(node.thenItems); 46 state.fixAstNodes(node.elseItems); 47 } 48 49 50 @(AstType.decl_static_version) 51 struct StaticVersionDeclNode 52 { 53 mixin ConditionalDeclNodeData!(AstType.decl_static_version); 54 Identifier versionId; 55 AstNodes thenItems; // can be empty 56 AstNodes elseItems; // can be empty 57 } 58 59 void print_static_version(StaticVersionDeclNode* node, ref AstPrintState state) 60 { 61 state.print("#VERSION", state.context.idString(node.versionId)); 62 state.print("#THEN"); 63 print_ast(node.thenItems, state); 64 state.print("#ELSE"); 65 print_ast(node.elseItems, state); 66 } 67 68 void post_clone_static_version(StaticVersionDeclNode* node, ref CloneState state) 69 { 70 state.fixAstNodes(node.thenItems); 71 state.fixAstNodes(node.elseItems); 72 }