Changeset dc3fbe5
- Timestamp:
- Feb 27, 2024, 12:28:58 PM (19 months ago)
- Branches:
- master
- Children:
- 924534e
- Parents:
- 4c0b674
- Location:
- src/Parser
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r4c0b674 rdc3fbe5 172 172 173 173 void DeclarationNode::printList( std::ostream & os, int indent ) const { 174 Parse Node::printList( os, indent );174 ParseList::printList( os, indent ); 175 175 if ( hasEllipsis ) { 176 176 os << string( indent, ' ' ) << "and a variable number of other arguments" << endl; … … 584 584 if ( q->type->forall ) { // forall qualifier ? 585 585 if ( type->forall ) { // polymorphic routine ? 586 type->forall-> appendList( q->type->forall ); // augment forall qualifier586 type->forall->set_last( q->type->forall ); // augment forall qualifier 587 587 } else { 588 588 if ( type->kind == TypeData::Aggregate ) { // struct/union ? 589 589 if ( type->aggregate.params ) { // polymorphic ? 590 type->aggregate.params-> appendList( q->type->forall ); // augment forall qualifier590 type->aggregate.params->set_last( q->type->forall ); // augment forall qualifier 591 591 } else { // not polymorphic 592 592 type->aggregate.params = q->type->forall; // set forall qualifier … … 612 612 if ( src->forall && dst->kind == TypeData::Function ) { 613 613 if ( dst->forall ) { 614 dst->forall-> appendList( src->forall );614 dst->forall->set_last( src->forall ); 615 615 } else { 616 616 dst->forall = src->forall; … … 674 674 default: 675 675 if ( dst->forall ) { 676 dst->forall-> appendList( src->forall );676 dst->forall->set_last( src->forall ); 677 677 } else { 678 678 dst->forall = src->forall; … … 747 747 if ( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS ) { 748 748 if ( variable.assertions ) { 749 variable.assertions-> appendList( assertions );749 variable.assertions->set_last( assertions ); 750 750 } else { 751 751 variable.assertions = assertions; … … 758 758 case TypeData::Symbolic: 759 759 if ( type->symbolic.assertions ) { 760 type->symbolic.assertions-> appendList( assertions );760 type->symbolic.assertions->set_last( assertions ); 761 761 } else { 762 762 type->symbolic.assertions = assertions; … … 1101 1101 std::back_insert_iterator<std::vector<ast::ptr<ast::Decl>>> out( outputList ); 1102 1102 1103 for ( const DeclarationNode * cur = firstNode ; cur ; cur = strict_next( cur )) {1103 for ( const DeclarationNode * cur = firstNode ; cur ; cur = cur->next ) { 1104 1104 try { 1105 1105 bool extracted_named = false; … … 1169 1169 std::back_insert_iterator<std::vector<ast::ptr<ast::DeclWithType>>> out( outputList ); 1170 1170 1171 for ( const DeclarationNode * cur = firstNode; cur; cur = strict_next( cur )) {1171 for ( const DeclarationNode * cur = firstNode; cur; cur = cur->next ) { 1172 1172 try { 1173 1173 ast::Decl * decl = cur->build(); … … 1219 1219 std::back_insert_iterator<std::vector<ast::ptr<ast::Type>>> out( outputList ); 1220 1220 1221 for ( const DeclarationNode * cur = firstNode ; cur ; cur = strict_next( cur )) {1221 for ( const DeclarationNode * cur = firstNode ; cur ; cur = cur->next ) { 1222 1222 try { 1223 1223 * out++ = cur->buildType(); -
src/Parser/DeclarationNode.h
r4c0b674 rdc3fbe5 19 19 20 20 struct TypeData; 21 classInitializerNode;22 23 struct DeclarationNode : public ParseNode{21 struct InitializerNode; 22 23 struct DeclarationNode final : public ParseList<DeclarationNode> { 24 24 // These enumerations must harmonize with their names in DeclarationNode.cc. 25 25 enum BasicType { … … 108 108 DeclarationNode * cloneBaseType( DeclarationNode * newdecl, bool = true ); 109 109 110 DeclarationNode * appendList( DeclarationNode * node ) {111 return (DeclarationNode *)set_last( node );112 }113 114 110 virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const override; 115 111 virtual void printList( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const override; … … 128 124 bool get_inLine() const { return inLine; } 129 125 DeclarationNode * set_inLine( bool inL ) { inLine = inL; return this; } 130 131 DeclarationNode * get_last() { return (DeclarationNode *)ParseNode::get_last(); }132 126 133 127 const std::string * name = nullptr; … … 179 173 } 180 174 181 template<typename NodeType>182 NodeType * strict_next( NodeType * node ) {183 ParseNode * next = node->get_next();184 if ( nullptr == next ) return nullptr;185 if ( NodeType * ret = dynamic_cast<NodeType *>( next ) ) return ret;186 SemanticError( next->location, "internal error, non-homogeneous nodes founds in buildList processing." );187 }188 189 175 // This generic buildList is here along side its overloads. 190 176 template<typename AstType, typename NodeType, … … 195 181 std::back_insert_iterator<Container<ast::ptr<AstType>, Args...>> out( output ); 196 182 197 for ( NodeType * cur = firstNode ; cur ; cur = strict_next( cur )) {183 for ( NodeType * cur = firstNode ; cur ; cur = cur->next ) { 198 184 try { 199 185 AstType * node = dynamic_cast<AstType *>( maybeBuild( cur ) ); -
src/Parser/ExpressionNode.h
r4c0b674 rdc3fbe5 18 18 #include "ParseNode.h" 19 19 20 classInitializerNode;20 struct InitializerNode; 21 21 22 class ExpressionNode final : public ParseNode { 23 public: 22 struct ExpressionNode final : public ParseList<ExpressionNode> { 24 23 ExpressionNode( ast::Expr * expr = nullptr ) : expr( expr ) {} 25 24 virtual ~ExpressionNode() {} 26 25 virtual ExpressionNode * clone() const override { 27 26 if ( nullptr == expr ) return nullptr; 28 return static_cast<ExpressionNode*>( 29 (new ExpressionNode( ast::shallowCopy( expr.get() ) ))->set_next( maybeCopy( get_next() ) )); 27 ExpressionNode * node = new ExpressionNode( ast::shallowCopy( expr.get() ) ); 28 node->set_next( maybeCopy( get_next() ) ); 29 return node; 30 30 } 31 31 -
src/Parser/InitializerNode.h
r4c0b674 rdc3fbe5 18 18 #include "ParseNode.h" 19 19 20 class InitializerNode : public ParseNode { 21 public: 20 struct InitializerNode final : public ParseList<InitializerNode> { 22 21 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = nullptr ); 23 22 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = nullptr ); -
src/Parser/ParseNode.h
r4c0b674 rdc3fbe5 33 33 34 34 struct DeclarationNode; 35 classInitializerNode;36 classExpressionNode;35 struct InitializerNode; 36 struct ExpressionNode; 37 37 struct StatementNode; 38 38 … … 45 45 extern YYLTYPE yylloc; 46 46 47 class ParseNode { 48 public: 49 ParseNode() {}; 50 virtual ~ParseNode() { delete next; }; 47 struct ParseNode { 48 ParseNode() {} 49 virtual ~ParseNode() {} 51 50 virtual ParseNode * clone() const = 0; 52 51 53 ParseNode * get_next() const { return next; } 54 ParseNode * set_next( ParseNode * newlink ) { next = newlink; return this; } 52 virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {} 55 53 56 ParseNode * get_last() { 57 ParseNode * current; 58 for ( current = this; current->get_next() != nullptr; current = current->get_next() ); 54 static int indent_by; 55 56 CodeLocation location = yylloc; 57 }; // ParseNode 58 59 /// Only ever use in the form `struct NAME final : public ParseList<NAME>`! 60 template<typename Next> 61 struct ParseList : public ParseNode { 62 ParseList() {} 63 virtual ~ParseList() { delete next; }; 64 virtual ParseList<Next> * clone() const = 0; 65 66 Next * get_next() const { return next; } 67 void set_next( Next * newlink ) { next = newlink; } 68 69 Next * get_last() { 70 Next * current = static_cast<Next *>( this ); 71 while ( current->next != nullptr ) current = current->next; 59 72 return current; 60 73 } 61 ParseNode * set_last( ParseNode* newlast ) {62 if ( newlast != nullptr ) get_last()-> set_next( newlast );63 return this;74 Next * set_last( Next * newlast ) { 75 if ( newlast != nullptr ) get_last()->next = newlast; 76 return static_cast<Next *>( this ); 64 77 } 65 78 66 virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {}67 79 virtual void printList( std::ostream & os, int indent = 0 ) const { 68 80 print( os, indent ); … … 70 82 } 71 83 72 static int indent_by; 73 74 ParseNode * next = nullptr; 75 CodeLocation location = yylloc; 76 }; // ParseNode 84 Next * next = nullptr; 85 }; 77 86 78 87 // Must harmonize with OperName. -
src/Parser/StatementNode.h
r4c0b674 rdc3fbe5 18 18 #include "ParseNode.h" 19 19 20 struct StatementNode final : public Parse Node{20 struct StatementNode final : public ParseList<StatementNode> { 21 21 StatementNode() : stmt( nullptr ) {} 22 22 StatementNode( ast::Stmt * stmt ) : stmt( stmt ) {} … … 39 39 }; // StatementNode 40 40 41 struct ClauseNode final : public Parse Node{41 struct ClauseNode final : public ParseList<ClauseNode> { 42 42 ClauseNode( ast::StmtClause * clause ) : clause( clause ) {} 43 43 virtual ~ClauseNode() {} 44 45 ClauseNode * set_last( ParseNode * newlast ) {46 ParseNode::set_last( newlast );47 return this;48 }49 44 50 45 virtual ClauseNode * clone() const final { assert( false ); return nullptr; } -
src/Parser/parser.yy
r4c0b674 rdc3fbe5 1897 1897 declaration_list: 1898 1898 declaration 1899 | declaration_list declaration { $$ = $1-> appendList( $2 ); }1899 | declaration_list declaration { $$ = $1->set_last( $2 ); } 1900 1900 ; 1901 1901 … … 1910 1910 { $$ = $1; } 1911 1911 | KR_parameter_list c_declaration ';' 1912 { $$ = $1-> appendList( $2 ); }1912 { $$ = $1->set_last( $2 ); } 1913 1913 ; 1914 1914 … … 1968 1968 { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); } 1969 1969 | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt 1970 { $$ = $1-> appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); }1970 { $$ = $1->set_last( $1->cloneType( $5 )->addInitializer( $6 ) ); } 1971 1971 ; 1972 1972 … … 1995 1995 DeclarationNode * ret = new DeclarationNode; 1996 1996 ret->type = maybeCopy( $1->type->base ); 1997 $$ = $1-> appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );1997 $$ = $1->set_last( DeclarationNode::newFunction( $3, ret, $6, nullptr ) ); 1998 1998 } 1999 1999 ; … … 2034 2034 | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']' 2035 2035 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'. 2036 { $$ = DeclarationNode::newTuple( $3-> appendList( $7 ) ); }2036 { $$ = DeclarationNode::newTuple( $3->set_last( $7 ) ); } 2037 2037 ; 2038 2038 … … 2051 2051 { 2052 2052 typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "cfa_typedef_declaration 3" ); 2053 $$ = $1-> appendList( $1->cloneType( $5 ) );2053 $$ = $1->set_last( $1->cloneType( $5 ) ); 2054 2054 } 2055 2055 ; … … 2069 2069 { 2070 2070 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "typedef_declaration 2" ); 2071 $$ = $1-> appendList( $1->cloneBaseType( $3 )->addTypedef() );2071 $$ = $1->set_last( $1->cloneBaseType( $3 )->addTypedef() ); 2072 2072 } 2073 2073 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) … … 2123 2123 2124 2124 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 2125 { $$ = $1-> appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }2125 { $$ = $1->set_last( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); } 2126 2126 ; 2127 2127 … … 2587 2587 { $$ = nullptr; } 2588 2588 | field_declaration_list_opt field_declaration 2589 { $$ = $1 ? $1-> appendList( $2 ) : $2; }2589 { $$ = $1 ? $1->set_last( $2 ) : $2; } 2590 2590 ; 2591 2591 … … 2635 2635 | field_declarator 2636 2636 | field_declaring_list_opt ',' attribute_list_opt field_declarator 2637 { $$ = $1-> appendList( $4->addQualifiers( $3 ) ); }2637 { $$ = $1->set_last( $4->addQualifiers( $3 ) ); } 2638 2638 ; 2639 2639 … … 2657 2657 | field_abstract 2658 2658 | field_abstract_list_opt ',' attribute_list_opt field_abstract 2659 { $$ = $1-> appendList( $4->addQualifiers( $3 ) ); }2659 { $$ = $1->set_last( $4->addQualifiers( $3 ) ); } 2660 2660 ; 2661 2661 … … 2670 2670 { $$ = $1->addName( $2 ); } 2671 2671 | cfa_field_declaring_list ',' identifier_or_type_name 2672 { $$ = $1-> appendList( $1->cloneType( $3 ) ); }2672 { $$ = $1->set_last( $1->cloneType( $3 ) ); } 2673 2673 ; 2674 2674 … … 2677 2677 cfa_abstract_declarator_tuple 2678 2678 | cfa_field_abstract_list ',' 2679 { $$ = $1-> appendList( $1->cloneType( 0 ) ); }2679 { $$ = $1->set_last( $1->cloneType( 0 ) ); } 2680 2680 ; 2681 2681 … … 2769 2769 { $$ = DeclarationNode::newEnumInLine( *$2->type->symbolic.name ); } 2770 2770 | enumerator_list ',' visible_hide_opt identifier_or_type_name enumerator_value_opt 2771 { $$ = $1-> appendList( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); }2771 { $$ = $1->set_last( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); } 2772 2772 | enumerator_list ',' INLINE type_name enumerator_value_opt 2773 { $$ = $1-> appendList( DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ) ); }2773 { $$ = $1->set_last( DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ) ); } 2774 2774 ; 2775 2775 … … 2797 2797 | cfa_parameter_list 2798 2798 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list 2799 { $$ = $1-> appendList( $5 ); }2799 { $$ = $1->set_last( $5 ); } 2800 2800 | cfa_abstract_parameter_list pop ',' push ELLIPSIS 2801 2801 { $$ = $1->addVarArgs(); } … … 2809 2809 cfa_parameter_declaration 2810 2810 | cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration 2811 { $$ = $1-> appendList( $5 ); }2811 { $$ = $1->set_last( $5 ); } 2812 2812 | cfa_parameter_list pop ',' push cfa_parameter_declaration 2813 { $$ = $1-> appendList( $5 ); }2813 { $$ = $1->set_last( $5 ); } 2814 2814 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration 2815 { $$ = $1-> appendList( $5 )->appendList( $9 ); }2815 { $$ = $1->set_last( $5 )->set_last( $9 ); } 2816 2816 ; 2817 2817 … … 2819 2819 cfa_abstract_parameter_declaration 2820 2820 | cfa_abstract_parameter_list pop ',' push cfa_abstract_parameter_declaration 2821 { $$ = $1-> appendList( $5 ); }2821 { $$ = $1->set_last( $5 ); } 2822 2822 ; 2823 2823 … … 2836 2836 | parameter_declaration 2837 2837 | parameter_list ',' abstract_parameter_declaration 2838 { $$ = $1-> appendList( $3 ); }2838 { $$ = $1->set_last( $3 ); } 2839 2839 | parameter_list ',' parameter_declaration 2840 { $$ = $1-> appendList( $3 ); }2840 { $$ = $1->set_last( $3 ); } 2841 2841 ; 2842 2842 … … 2889 2889 { $$ = DeclarationNode::newName( $1 ); } 2890 2890 | identifier_list ',' identifier 2891 { $$ = $1-> appendList( DeclarationNode::newName( $3 ) ); }2891 { $$ = $1->set_last( DeclarationNode::newName( $3 ) ); } 2892 2892 ; 2893 2893 … … 2990 2990 type_parameter 2991 2991 | type_parameter_list ',' type_parameter 2992 { $$ = $1-> appendList( $3 ); }2992 { $$ = $1->set_last( $3 ); } 2993 2993 ; 2994 2994 … … 3063 3063 assertion 3064 3064 | assertion_list assertion 3065 { $$ = $1-> appendList( $2 ); }3065 { $$ = $1->set_last( $2 ); } 3066 3066 ; 3067 3067 … … 3091 3091 { $$ = $3->addQualifiers( $1 ); } 3092 3092 | type_declaring_list ',' type_declarator 3093 { $$ = $1-> appendList( $3->copySpecifiers( $1 ) ); }3093 { $$ = $1->set_last( $3->copySpecifiers( $1 ) ); } 3094 3094 ; 3095 3095 … … 3134 3134 trait_declaration 3135 3135 | trait_declaration_list pop push trait_declaration 3136 { $$ = $1-> appendList( $4 ); }3136 { $$ = $1->set_last( $4 ); } 3137 3137 ; 3138 3138 … … 3146 3146 | cfa_function_specifier 3147 3147 | cfa_trait_declaring_list pop ',' push identifier_or_type_name 3148 { $$ = $1-> appendList( $1->cloneType( $5 ) ); }3148 { $$ = $1->set_last( $1->cloneType( $5 ) ); } 3149 3149 ; 3150 3150 … … 3153 3153 { $$ = $2->addType( $1 ); } 3154 3154 | trait_declaring_list pop ',' push declarator 3155 { $$ = $1-> appendList( $1->cloneBaseType( $5 ) ); }3155 { $$ = $1->set_last( $1->cloneBaseType( $5 ) ); } 3156 3156 ; 3157 3157 … … 3161 3161 // empty, input file 3162 3162 | external_definition_list 3163 { parseTree = parseTree ? parseTree-> appendList( $1 ) : $1; }3163 { parseTree = parseTree ? parseTree->set_last( $1 ) : $1; } 3164 3164 ; 3165 3165 … … 3168 3168 { $$ = $2; } 3169 3169 | external_definition_list push external_definition pop 3170 { $$ = $1 ? $1-> appendList( $3 ) : $3; }3170 { $$ = $1 ? $1->set_last( $3 ) : $3; } 3171 3171 ; 3172 3172
Note:
See TracChangeset
for help on using the changeset viewer.