- Timestamp:
- Feb 24, 2023, 3:31:50 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 2e77837
- Parents:
- f883ef1 (diff), f2a1cd2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 9 edited
-
AST/Fwd.hpp (modified) (2 diffs)
-
AST/Print.cpp (modified) (9 diffs)
-
AST/Print.hpp (modified) (2 diffs)
-
Parser/DeclarationNode.cc (modified) (8 diffs)
-
Parser/ParseNode.h (modified) (3 diffs)
-
Parser/TypeData.cc (modified) (2 diffs)
-
Parser/TypeData.h (modified) (2 diffs)
-
Parser/parser.yy (modified) (10 diffs)
-
SynTree/Type.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Fwd.hpp
rf883ef1 rae267366 15 15 16 16 #pragma once 17 18 template<typename> struct bitfield; 17 19 18 20 #include "AST/Node.hpp" … … 147 149 class TranslationGlobal; 148 150 151 // For the following types, only use the using type. 152 namespace CV { 153 struct qualifier_flags; 154 using Qualifiers = bitfield<qualifier_flags>; 149 155 } 156 namespace Function { 157 struct spec_flags; 158 using Specs = bitfield<spec_flags>; 159 } 160 namespace Storage { 161 struct class_flags; 162 using Classes = bitfield<class_flags>; 163 } 164 namespace Linkage { 165 struct spec_flags; 166 using Spec = bitfield<spec_flags>; 167 } 168 169 } -
src/AST/Print.cpp
rf883ef1 rae267366 29 29 namespace ast { 30 30 31 template <typename C, typename... T> 32 constexpr array<C,sizeof...(T)> make_array(T&&... values) 33 { 34 return array<C,sizeof...(T)>{ 35 std::forward<T>(values)... 36 }; 31 namespace { 32 33 template<typename C, typename... T> 34 constexpr array<C, sizeof...(T)> make_array( T&&... values ) { 35 return array<C, sizeof...(T)>{ std::forward<T>( values )... }; 36 } 37 38 namespace Names { 39 static constexpr auto FuncSpecifiers = make_array<const char*>( 40 "inline", "_Noreturn", "fortran" 41 ); 42 43 static constexpr auto StorageClasses = make_array<const char*>( 44 "extern", "static", "auto", "register", "__thread", "_Thread_local" 45 ); 46 47 static constexpr auto Qualifiers = make_array<const char*>( 48 "const", "restrict", "volatile", "mutex", "_Atomic" 49 ); 50 } 51 52 template<typename bits_t, size_t N> 53 void print( ostream & os, const bits_t & bits, 54 const array<const char *, N> & names ) { 55 if ( !bits.any() ) return; 56 for ( size_t i = 0 ; i < N ; i += 1 ) { 57 if ( bits[i] ) { 58 os << names[i] << ' '; 59 } 60 } 37 61 } 38 62 … … 80 104 static const char* Names[]; 81 105 82 struct Names {83 static constexpr auto FuncSpecifiers = make_array<const char*>(84 "inline", "_Noreturn", "fortran"85 );86 87 static constexpr auto StorageClasses = make_array<const char*>(88 "extern", "static", "auto", "register", "__thread", "_Thread_local"89 );90 91 static constexpr auto Qualifiers = make_array<const char*>(92 "const", "restrict", "volatile", "mutex", "_Atomic"93 );94 };95 96 template<typename storage_t, size_t N>97 void print(const storage_t & storage, const array<const char *, N> & Names ) {98 if ( storage.any() ) {99 for ( size_t i = 0; i < Names.size(); i += 1 ) {100 if ( storage[i] ) {101 os << Names[i] << ' ';102 }103 }104 }105 }106 107 void print( const ast::Function::Specs & specs ) {108 print(specs, Names::FuncSpecifiers);109 }110 111 void print( const ast::Storage::Classes & storage ) {112 print(storage, Names::StorageClasses);113 }114 115 void print( const ast::CV::Qualifiers & qualifiers ) {116 print(qualifiers, Names::Qualifiers);117 }118 119 106 void print( const std::vector<ast::Label> & labels ) { 120 107 if ( labels.empty() ) return; … … 230 217 } 231 218 232 print(node->storage );219 ast::print( os, node->storage ); 233 220 os << node->typeString(); 234 221 … … 272 259 273 260 void preprint( const ast::Type * node ) { 274 print(node->qualifiers );261 ast::print( os, node->qualifiers ); 275 262 } 276 263 … … 278 265 print( node->forall ); 279 266 print( node->assertions ); 280 print(node->qualifiers );267 ast::print( os, node->qualifiers ); 281 268 } 282 269 283 270 void preprint( const ast::BaseInstType * node ) { 284 271 print( node->attributes ); 285 print(node->qualifiers );272 ast::print( os, node->qualifiers ); 286 273 } 287 274 … … 294 281 } 295 282 296 print(node->storage );283 ast::print( os, node->storage ); 297 284 298 285 if ( node->type ) { … … 338 325 if ( ! short_mode ) printAll( node->attributes ); 339 326 340 print( node->storage ); 341 print( node->funcSpec ); 342 343 327 ast::print( os, node->storage ); 328 ast::print( os, node->funcSpec ); 344 329 345 330 if ( node->type && node->isTypeFixed ) { … … 1627 1612 }; 1628 1613 1614 } // namespace 1615 1629 1616 void print( ostream & os, const ast::Node * node, Indenter indent ) { 1630 1617 Printer printer { os, indent, false }; … … 1637 1624 } 1638 1625 1639 // Annoyingly these needed to be defined out of line to avoid undefined references. 1640 // The size here needs to be explicit but at least the compiler will produce an error 1641 // if the wrong size is specified 1642 constexpr array<const char*, 3> Printer::Names::FuncSpecifiers; 1643 constexpr array<const char*, 6> Printer::Names::StorageClasses; 1644 constexpr array<const char*, 5> Printer::Names::Qualifiers; 1626 void print( ostream & os, Function::Specs specs ) { 1627 print( os, specs, Names::FuncSpecifiers ); 1645 1628 } 1629 1630 void print( ostream & os, Storage::Classes storage ) { 1631 print( os, storage, Names::StorageClasses ); 1632 } 1633 1634 void print( ostream & os, CV::Qualifiers qualifiers ) { 1635 print( os, qualifiers, Names::Qualifiers ); 1636 } 1637 1638 } // namespace ast -
src/AST/Print.hpp
rf883ef1 rae267366 16 16 #pragma once 17 17 18 #include <iostream> 19 #include <utility> // for forward 18 #include <iosfwd> 20 19 21 #include "AST/ Node.hpp"20 #include "AST/Fwd.hpp" 22 21 #include "Common/Indenter.h" 23 22 24 23 namespace ast { 25 26 class Decl;27 24 28 25 /// Print a node with the given indenter … … 44 41 } 45 42 43 /// Print each cv-qualifier used in the set, followed by a space. 44 void print( std::ostream & os, CV::Qualifiers ); 45 /// Print each function specifier used in the set, followed by a space. 46 void print( std::ostream & os, Function::Specs ); 47 /// Print each storage class used in the set, followed by a space. 48 void print( std::ostream & os, Storage::Classes ); 49 46 50 } -
src/Parser/DeclarationNode.cc
rf883ef1 rae267366 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 16 14:12:03 202313 // Update Count : 1 38812 // Last Modified On : Fri Feb 24 11:10:03 2023 13 // Update Count : 1400 14 14 // 15 15 … … 61 61 variable.initializer = nullptr; 62 62 63 // attr.name = nullptr;64 attr.expr = nullptr;65 attr.type = nullptr;66 67 63 assert.condition = nullptr; 68 64 assert.message = nullptr; … … 70 66 71 67 DeclarationNode::~DeclarationNode() { 72 // delete attr.name;73 delete attr.expr;74 delete attr.type;75 76 68 // delete variable.name; 77 69 delete variable.assertions; … … 115 107 newnode->variable.initializer = maybeClone( variable.initializer ); 116 108 117 // newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr;118 newnode->attr.expr = maybeClone( attr.expr );119 newnode->attr.type = maybeClone( attr.type );120 121 109 newnode->assert.condition = maybeClone( assert.condition ); 122 110 newnode->assert.message = maybeClone( assert.message ); … … 266 254 newnode->type->enumeration.typed = typed; 267 255 newnode->type->enumeration.hiding = hiding; 268 if ( base && base->type ) {256 if ( base && base->type ) { 269 257 newnode->type->base = base->type; 270 258 } // if … … 579 567 580 568 checkQualifiers( type, q->type ); 581 if ( (builtin == Zero || builtin == One) && q->type->qualifiers. val != 0&& error.length() == 0 ) {569 if ( (builtin == Zero || builtin == One) && q->type->qualifiers.any() && error.length() == 0 ) { 582 570 SemanticWarning( yylloc, Warning::BadQualifiersZeroOne, Type::QualifiersNames[ilog2( q->type->qualifiers.val )], builtinTypeNames[builtin] ); 583 571 } // if … … 996 984 997 985 if ( DeclarationNode * extr = cur->extractAggregate() ) { 998 // handle the case where a structure declaration is contained within an object or type declaration 986 // Handle the case where a SUE declaration is contained within an object or type declaration. 987 988 assert( cur->type ); 989 // Replace anonymous SUE name with typedef name to prevent anonymous naming problems across translation units. 990 if ( cur->type->kind == TypeData::Symbolic && cur->type->symbolic.isTypedef ) { 991 assert( extr->type ); 992 // Handle anonymous aggregates: typedef struct { int i; } foo 993 extr->type->qualifiers.reset(); // clear any CVs associated with the aggregate 994 if ( extr->type->kind == TypeData::Aggregate && extr->type->aggregate.anon ) { 995 delete extr->type->aggregate.name; 996 extr->type->aggregate.name = new string( "__anonymous_" + *cur->name ); 997 extr->type->aggregate.anon = false; 998 assert( cur->type->base ); 999 if ( cur->type->base ) { 1000 delete cur->type->base->aggInst.aggregate->aggregate.name; 1001 cur->type->base->aggInst.aggregate->aggregate.name = new string( "__anonymous_" + *cur->name ); 1002 cur->type->base->aggInst.aggregate->aggregate.anon = false; 1003 cur->type->base->aggInst.aggregate->qualifiers.reset(); 1004 } // if 1005 } // if 1006 // Handle anonymous enumeration: typedef enum { A, B, C } foo 1007 if ( extr->type->kind == TypeData::Enum && extr->type->enumeration.anon ) { 1008 delete extr->type->enumeration.name; 1009 extr->type->enumeration.name = new string( "__anonymous_" + *cur->name ); 1010 extr->type->enumeration.anon = false; 1011 assert( cur->type->base ); 1012 if ( cur->type->base ) { 1013 delete cur->type->base->aggInst.aggregate->enumeration.name; 1014 cur->type->base->aggInst.aggregate->enumeration.name = new string( "__anonymous_" + *cur->name ); 1015 cur->type->base->aggInst.aggregate->enumeration.anon = false; 1016 } // if 1017 } // if 1018 } // if 999 1019 1000 1020 Declaration * decl = extr->build(); … … 1213 1233 assert( type ); 1214 1234 1215 if ( attr.expr ) {1216 return new AttrType( buildQualifiers( type ), *name, attr.expr->build(), attributes );1217 } else if ( attr.type ) {1218 return new AttrType( buildQualifiers( type ), *name, attr.type->buildType(), attributes );1219 } // if1220 1221 1235 switch ( type->kind ) { 1222 1236 case TypeData::Enum: -
src/Parser/ParseNode.h
rf883ef1 rae267366 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Nov 2 21:27:07 202213 // Update Count : 9 3912 // Last Modified On : Sun Feb 19 09:02:37 2023 13 // Update Count : 940 14 14 // 15 15 … … 325 325 Variable_t variable; 326 326 327 struct Attr_t {328 // const std::string * name;329 ExpressionNode * expr;330 DeclarationNode * type;331 };332 Attr_t attr;333 334 327 struct StaticAssert_t { 335 328 ExpressionNode * condition; … … 343 336 344 337 bool inLine = false; 345 bool enumInLine = false; 338 bool enumInLine = false; 346 339 Type::FuncSpecifiers funcSpecs; 347 340 Type::StorageClasses storageClasses; -
src/Parser/TypeData.cc
rf883ef1 rae267366 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 10 22:36:52 202213 // Update Count : 67 712 // Last Modified On : Sun Feb 19 11:00:46 2023 13 // Update Count : 679 14 14 // 15 15 … … 375 375 break; 376 376 case Enum: 377 os << "enumeration " ;377 os << "enumeration " << *enumeration.name << endl;; 378 378 if ( enumeration.constants ) { 379 379 os << "with constants" << endl; -
src/Parser/TypeData.h
rf883ef1 rae267366 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 10 22:18:49 202213 // Update Count : 20 312 // Last Modified On : Fri Feb 24 14:25:02 2023 13 // Update Count : 205 14 14 // 15 15 … … 37 37 bool body; 38 38 bool anon; 39 40 39 bool tagged; 41 40 const std::string * parent = nullptr; 42 41 }; 43 42 44 struct AggInst_t { 43 struct AggInst_t { // handles SUE 45 44 TypeData * aggregate = nullptr; 46 45 ExpressionNode * params = nullptr; -
src/Parser/parser.yy
rf883ef1 rae267366 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 14 21:11:39202313 // Update Count : 5 89312 // Last Modified On : Fri Feb 24 14:46:55 2023 13 // Update Count : 5983 14 14 // 15 15 … … 1941 1941 // if type_specifier is an anon aggregate => name 1942 1942 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" ); 1943 $$ = $3->addType( $2 )->addTypedef(); 1943 $$ = $3->addType( $2 )->addTypedef(); // watchout frees $2 and $3 1944 1944 } 1945 1945 | typedef_declaration pop ',' push declarator … … 1983 1983 | typedef_expression // deprecated GCC, naming expression type 1984 1984 | sue_declaration_specifier 1985 { 1986 assert( $1->type ); 1987 if ( $1->type->qualifiers.any() ) { // CV qualifiers ? 1988 SemanticError( yylloc, "Useless type qualifier(s) in empty declaration." ); $$ = nullptr; 1989 } 1990 // enums are never empty declarations because there must have at least one enumeration. 1991 if ( $1->type->kind == TypeData::AggregateInst && $1->storageClasses.any() ) { // storage class ? 1992 SemanticError( yylloc, "Useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr; 1993 } 1994 } 1985 1995 ; 1986 1996 … … 2000 2010 | sue_declaration_specifier invalid_types 2001 2011 { 2002 SemanticError( yylloc, 2003 ::toString( "Missing ';' after end of ", 2004 $1->type->enumeration.name ? "enum" : AggregateDecl::aggrString( $1->type->aggregate.kind ), 2005 " declaration" ) ); 2012 SemanticError( yylloc, ::toString( "Missing ';' after end of ", 2013 $1->type->enumeration.name ? "enum" : AggregateDecl::aggrString( $1->type->aggregate.kind ), 2014 " declaration" ) ); 2006 2015 $$ = nullptr; 2007 2016 } … … 2582 2591 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2583 2592 { 2584 if ( $3->storageClasses.val != 0 || $3->type->qualifiers. val != 0)2593 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() ) 2585 2594 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2586 2595 … … 2593 2602 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt 2594 2603 { 2595 if ( $3->storageClasses. val != 0|| $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }2604 if ( $3->storageClasses.any() || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2596 2605 typedefTable.makeTypedef( *$6 ); 2597 2606 } … … 3052 3061 { $$ = DeclarationNode::newDirectiveStmt( new StatementNode( build_directive( $1 ) ) ); } 3053 3062 | declaration 3063 { 3064 // Variable declarations of anonymous types requires creating a unique type-name across multiple translation 3065 // unit, which is a dubious task, especially because C uses name rather than structural typing; hence it is 3066 // disallowed at the moment. 3067 if ( $1->linkage == LinkageSpec::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) { 3068 if ( $1->type->aggInst.aggregate->kind == TypeData::Enum && $1->type->aggInst.aggregate->enumeration.anon ) { 3069 SemanticError( yylloc, "extern anonymous enumeration is currently unimplemented." ); $$ = nullptr; 3070 } else if ( $1->type->aggInst.aggregate->aggregate.anon ) { // handles struct or union 3071 SemanticError( yylloc, "extern anonymous struct/union is currently unimplemented." ); $$ = nullptr; 3072 } 3073 } 3074 } 3054 3075 | IDENTIFIER IDENTIFIER 3055 3076 { IdentifierBeforeIdentifier( *$1.str, *$2.str, " declaration" ); $$ = nullptr; } … … 3097 3118 | type_qualifier_list 3098 3119 { 3099 if ( $1->type->qualifiers. val) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }3120 if ( $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 3100 3121 if ( $1->type->forall ) forall = true; // remember generic type 3101 3122 } … … 3108 3129 | declaration_qualifier_list 3109 3130 { 3110 if ( $1->type && $1->type->qualifiers. val) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }3131 if ( $1->type && $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 3111 3132 if ( $1->type && $1->type->forall ) forall = true; // remember generic type 3112 3133 } … … 3119 3140 | declaration_qualifier_list type_qualifier_list 3120 3141 { 3121 if ( ($1->type && $1->type->qualifiers. val) || ($2->type && $2->type->qualifiers.val) ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }3142 if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 3122 3143 if ( ($1->type && $1->type->forall) || ($2->type && $2->type->forall) ) forall = true; // remember generic type 3123 3144 } -
src/SynTree/Type.h
rf883ef1 rae267366 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Feb 13 17:13:52202313 // Update Count : 17 312 // Last Modified On : Sun Feb 19 22:37:10 2023 13 // Update Count : 176 14 14 // 15 15 … … 125 125 bool operator!=( Qualifiers other ) const { return (val & Mask) != (other.val & Mask); } 126 126 bool operator<=( Qualifiers other ) const { 127 return is_const <= other.is_const // Any non-const converts to const without cost128 && is_volatile <= other.is_volatile //Any non-volatile converts to volatile without cost129 && is_mutex >= other.is_mutex //Any mutex converts to non-mutex without cost130 && is_atomic == other.is_atomic; //No conversion from atomic to non atomic is free127 return is_const <= other.is_const // Any non-const converts to const without cost 128 && is_volatile <= other.is_volatile // Any non-volatile converts to volatile without cost 129 && is_mutex >= other.is_mutex // Any mutex converts to non-mutex without cost 130 && is_atomic == other.is_atomic; // No conversion from atomic to non atomic is free 131 131 } 132 132 bool operator<( Qualifiers other ) const { return *this != other && *this <= other; } … … 632 632 class TypeofType : public Type { 633 633 public: 634 Expression * expr; ///< expression to take the type of635 bool is_basetypeof; ///< true iff is basetypeof type634 Expression * expr; ///< expression to take the type of 635 bool is_basetypeof; ///< true iff is basetypeof type 636 636 637 637 TypeofType( const Type::Qualifiers & tq, Expression * expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
Note:
See TracChangeset
for help on using the changeset viewer.