Changeset 640b3df for src/Parser
- Timestamp:
- Feb 21, 2023, 4:24:34 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 257a8f5, ce44c5f
- Parents:
- 1180175 (diff), 9a533ba (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/Parser
- Files:
-
- 9 edited
-
DeclarationNode.cc (modified) (12 diffs)
-
ExpressionNode.cc (modified) (3 diffs)
-
ParseNode.h (modified) (4 diffs)
-
RunParser.cpp (modified) (2 diffs)
-
RunParser.hpp (modified) (3 diffs)
-
TypeData.cc (modified) (2 diffs)
-
TypeData.h (modified) (2 diffs)
-
parser.yy (modified) (5 diffs)
-
parserutility.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r1180175 r640b3df 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 8 17:07:00 202213 // Update Count : 1 18512 // Last Modified On : Thu Feb 16 14:12:03 2023 13 // Update Count : 1388 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 ); … … 154 142 } // if 155 143 156 for ( Attribute * attr: reverseIterate( attributes ) ) { 157 os << string( indent + 2, ' ' ) << "attr " << attr->name.c_str(); 158 } // for 144 if ( ! attributes.empty() ) { 145 os << string( indent + 2, ' ' ) << "with attributes " << endl; 146 for ( Attribute * attr: reverseIterate( attributes ) ) { 147 os << string( indent + 4, ' ' ) << attr->name.c_str() << endl; 148 } // for 149 } // if 159 150 160 151 os << endl; … … 244 235 newnode->type = new TypeData( TypeData::Aggregate ); 245 236 newnode->type->aggregate.kind = kind; 246 newnode->type->aggregate.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name; 237 newnode->type->aggregate.anon = name == nullptr; 238 newnode->type->aggregate.name = newnode->type->aggregate.anon ? new string( DeclarationNode::anonymous.newName() ) : name; 247 239 newnode->type->aggregate.actuals = actuals; 248 240 newnode->type->aggregate.fields = fields; … … 250 242 newnode->type->aggregate.tagged = false; 251 243 newnode->type->aggregate.parent = nullptr; 252 newnode->type->aggregate.anon = name == nullptr;253 244 return newnode; 254 245 } // DeclarationNode::newAggregate … … 257 248 DeclarationNode * newnode = new DeclarationNode; 258 249 newnode->type = new TypeData( TypeData::Enum ); 259 newnode->type->enumeration.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name; 250 newnode->type->enumeration.anon = name == nullptr; 251 newnode->type->enumeration.name = newnode->type->enumeration.anon ? new string( DeclarationNode::anonymous.newName() ) : name; 260 252 newnode->type->enumeration.constants = constants; 261 253 newnode->type->enumeration.body = body; 262 newnode->type->enumeration.anon = name == nullptr;263 254 newnode->type->enumeration.typed = typed; 264 255 newnode->type->enumeration.hiding = hiding; … … 989 980 for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) { 990 981 try { 991 bool extracted = false; 992 bool anon = false; 982 bool extracted = false, anon = false; 983 AggregateDecl * unionDecl = nullptr; 984 993 985 if ( DeclarationNode * extr = cur->extractAggregate() ) { 994 986 // handle the case where a structure declaration is contained within an object or type declaration 987 995 988 Declaration * decl = extr->build(); 996 989 if ( decl ) { 997 // hoist the structure declaration 990 // Remember the declaration if it is a union aggregate ? 991 unionDecl = dynamic_cast<UnionDecl *>( decl ); 992 998 993 decl->location = cur->location; 999 * out++ = decl;994 *out++ = decl; 1000 995 1001 996 // need to remember the cases where a declaration contains an anonymous aggregate definition … … 1003 998 assert( extr->type ); 1004 999 if ( extr->type->kind == TypeData::Aggregate ) { 1000 // typedef struct { int A } B is the only case? 1005 1001 anon = extr->type->aggregate.anon; 1006 1002 } else if ( extr->type->kind == TypeData::Enum ) { 1007 // xxx - is it useful to have an implicit anonymous enum member?1003 // typedef enum { A } B is the only case? 1008 1004 anon = extr->type->enumeration.anon; 1009 1005 } … … 1014 1010 Declaration * decl = cur->build(); 1015 1011 if ( decl ) { 1012 if ( TypedefDecl * typedefDecl = dynamic_cast<TypedefDecl *>( decl ) ) { 1013 if ( unionDecl ) { // is the typedef alias a union aggregate ? 1014 // This code handles a special issue with the attribute transparent_union. 1015 // 1016 // typedef union U { int i; } typedef_name __attribute__(( aligned(16) )) __attribute__(( transparent_union )) 1017 // 1018 // Here the attribute aligned goes with the typedef_name, so variables declared of this type are 1019 // aligned. However, the attribute transparent_union must be moved from the typedef_name to 1020 // alias union U. Currently, this is the only know attribute that must be moved from typedef to 1021 // alias. 1022 1023 // If typedef is an alias for a union, then its alias type was hoisted above and remembered. 1024 if ( UnionInstType * unionInstType = dynamic_cast<UnionInstType *>( typedefDecl->base ) ) { 1025 // Remove all transparent_union attributes from typedef and move to alias union. 1026 list<Attribute *>::iterator attr; 1027 for ( attr = unionInstType->attributes.begin(); attr != unionInstType->attributes.end(); ) { // forward order 1028 if ( (*attr)->name == "transparent_union" || (*attr)->name == "__transparent_union__" ) { 1029 list<Attribute *>::iterator cur = attr; // remember current node 1030 attr++; // advance iterator 1031 unionDecl->attributes.emplace_back( *cur ); // move current 1032 unionInstType->attributes.erase( cur ); // remove current 1033 } else { 1034 attr++; // advance iterator 1035 } // if 1036 } // for 1037 } // if 1038 } // if 1039 } // if 1040 1016 1041 // don't include anonymous declaration for named aggregates, but do include them for anonymous aggregates, e.g.: 1017 1042 // struct S { … … 1176 1201 assert( type ); 1177 1202 1178 if ( attr.expr ) {1179 return new AttrType( buildQualifiers( type ), *name, attr.expr->build(), attributes );1180 } else if ( attr.type ) {1181 return new AttrType( buildQualifiers( type ), *name, attr.type->buildType(), attributes );1182 } // if1183 1184 1203 switch ( type->kind ) { 1185 1204 case TypeData::Enum: -
src/Parser/ExpressionNode.cc
r1180175 r640b3df 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Aug 7 09:18:56 202113 // Update Count : 107 712 // Last Modified On : Sat Feb 11 14:49:00 2023 13 // Update Count : 1079 14 14 // 15 15 … … 173 173 if ( posn != string::npos ) { Unsigned = true; type = 2; ltype = 4; str.erase( posn, 1 ); goto FINI; } 174 174 175 posn = str.rfind( "hh" ); // char175 posn = str.rfind( "hh" ); // signed char 176 176 if ( posn != string::npos ) { type = 1; str.erase( posn, 2 ); goto FINI; } 177 177 178 posn = str.rfind( "HH" ); // char178 posn = str.rfind( "HH" ); // signed char 179 179 if ( posn != string::npos ) { type = 1; str.erase( posn, 2 ); goto FINI; } 180 180 … … 592 592 Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) { 593 593 list< Expression * > args; 594 args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code.594 args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code. 595 595 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 596 596 } // build_unary_ptr -
src/Parser/ParseNode.h
r1180175 r640b3df 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 … … 27 27 #include "Common/SemanticError.h" // for SemanticError 28 28 #include "Common/UniqueName.h" // for UniqueName 29 #include "Common/utility.h" // for maybeClone, maybeBuild 29 #include "Common/utility.h" // for maybeClone 30 #include "Parser/parserutility.h" // for maybeBuild 30 31 #include "SynTree/LinkageSpec.h" // for Spec 31 32 #include "SynTree/Declaration.h" // for Aggregate … … 324 325 Variable_t variable; 325 326 326 struct Attr_t {327 // const std::string * name;328 ExpressionNode * expr;329 DeclarationNode * type;330 };331 Attr_t attr;332 333 327 struct StaticAssert_t { 334 328 ExpressionNode * condition; … … 342 336 343 337 bool inLine = false; 344 bool enumInLine = false; 338 bool enumInLine = false; 345 339 Type::FuncSpecifiers funcSpecs; 346 340 Type::StorageClasses storageClasses; -
src/Parser/RunParser.cpp
r1180175 r640b3df 10 10 // Created On : Mon Dec 19 11:00:00 2022 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Dec 22 10:18:00 202213 // Update Count : 112 // Last Modified On : Thr Feb 16 10:08:00 2023 13 // Update Count : 2 14 14 // 15 15 … … 24 24 25 25 // Variables global to the parsing code. 26 LinkageSpec::Spec linkage = LinkageSpec::Cforall;26 ast::Linkage::Spec linkage = ast::Linkage::Cforall; 27 27 TypedefTable typedefTable; 28 28 DeclarationNode * parseTree = nullptr; 29 29 30 void parse( FILE * input, LinkageSpec::Spec linkage, bool alwaysExit ) {30 void parse( FILE * input, ast::Linkage::Spec linkage, bool alwaysExit ) { 31 31 extern int yyparse( void ); 32 32 extern FILE * yyin; -
src/Parser/RunParser.hpp
r1180175 r640b3df 10 10 // Created On : Mon Dec 19 10:42:00 2022 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Dec 22 10:23:00 202213 // Update Count : 112 // Last Modified On : Thr Feb 16 10:08:00 2023 13 // Update Count : 2 14 14 // 15 15 … … 18 18 #include <iosfwd> // for ostream 19 19 20 #include " SynTree/LinkageSpec.h"// for Spec20 #include "AST/LinkageSpec.hpp" // for Spec 21 21 namespace ast { 22 22 class TranslationUnit; … … 29 29 /// The input file is closed when complete. Exits instead of returning on 30 30 /// error or if alwaysExit is true. 31 void parse( FILE * input, LinkageSpec::Spec linkage, bool alwaysExit = false );31 void parse( FILE * input, ast::Linkage::Spec linkage, bool alwaysExit = false ); 32 32 33 33 /// Drain the internal accumulator of parsed code and build a translation -
src/Parser/TypeData.cc
r1180175 r640b3df 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
r1180175 r640b3df 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 : Sun Feb 19 09:09:39 2023 13 // Update Count : 204 14 14 // 15 15 … … 37 37 bool body; 38 38 bool anon; 39 40 39 bool tagged; 41 40 const std::string * parent = nullptr; -
src/Parser/parser.yy
r1180175 r640b3df 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 2 21:36:16 202313 // Update Count : 58 6512 // Last Modified On : Mon Feb 20 11:31:26 2023 13 // Update Count : 5896 14 14 // 15 15 … … 55 55 #include "Common/utility.h" // for maybeMoveBuild, maybeBuild, CodeLo... 56 56 57 #include "SynTree/Attribute.h" // for Attribute57 #include "SynTree/Attribute.h" // for Attribute 58 58 59 59 // lex uses __null in a boolean context, it's fine. … … 1951 1951 { 1952 1952 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6" ); 1953 $$ = $4->add Type( $3 )->addQualifiers( $1)->addTypedef();1953 $$ = $4->addQualifiers( $1 )->addType( $3 )->addTypedef(); 1954 1954 } 1955 1955 | type_specifier TYPEDEF declarator … … 1961 1961 { 1962 1962 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8" ); 1963 $$ = $4->addQualifiers( $1 )->addType def()->addType( $1);1963 $$ = $4->addQualifiers( $1 )->addType( $1 )->addTypedef(); 1964 1964 } 1965 1965 ; … … 1983 1983 | typedef_expression // deprecated GCC, naming expression type 1984 1984 | sue_declaration_specifier 1985 { 1986 assert( $1->type ); 1987 if ( $1->type->qualifiers.val != 0 ) { 1988 SemanticError( yylloc, "Useless type qualifier in empty declaration." ); $$ = nullptr; 1989 } 1990 } 1985 1991 ; 1986 1992 -
src/Parser/parserutility.h
r1180175 r640b3df 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // parserutility.h -- 7 // parserutility.h -- Collected utilities for the parser. 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:31:46 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:32:58 201713 // Update Count : 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Feb 16 12:34:00 2023 13 // Update Count : 5 14 14 // 15 15 … … 20 20 Expression *notZeroExpr( Expression *orig ); 21 21 22 template< typename T, typename U > 23 struct maybeBuild_t { 24 static T * doit( const U *orig ) { 25 if ( orig ) { 26 return orig->build(); 27 } else { 28 return 0; 29 } 30 } 31 }; 32 33 template< typename T, typename U > 34 static inline T * maybeBuild( const U *orig ) { 35 return maybeBuild_t<T,U>::doit(orig); 36 } 37 38 template< typename T, typename U > 39 static inline T * maybeMoveBuild( const U *orig ) { 40 T* ret = maybeBuild<T>(orig); 41 delete orig; 42 return ret; 43 } 44 22 45 // Local Variables: // 23 46 // tab-width: 4 //
Note:
See TracChangeset
for help on using the changeset viewer.