Changes in / [7ae930a:9c23f31]
- Location:
- src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
r7ae930a r9c23f31 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 8 17:33:59201613 // Update Count : 2 212 // Last Modified On : Fri Sep 23 11:46:47 2016 13 // Update Count : 28 14 14 // 15 15 … … 25 25 #include <sstream> 26 26 #include <string> 27 #include <cassert> 27 28 28 29 template< typename T > … … 101 102 } // if 102 103 } // for 103 }104 105 static inline std::string assign_strptr( const std::string *str ) {106 if ( str == 0 ) {107 return "";108 } else {109 std::string tmp;110 tmp = *str;111 delete str;112 return tmp;113 } // if114 104 } 115 105 … … 141 131 142 132 template < typename T > 143 void toString_single 133 void toString_single( std::ostream & os, const T & value ) { 144 134 os << value; 145 135 } 146 136 147 137 template < typename T, typename... Params > 148 void toString_single 138 void toString_single( std::ostream & os, const T & value, const Params & ... params ) { 149 139 os << value; 150 140 toString_single( os, params ... ); … … 152 142 153 143 template < typename ... Params > 154 std::string toString 144 std::string toString( const Params & ... params ) { 155 145 std::ostringstream os; 156 146 toString_single( os, params... ); -
src/Parser/DeclarationNode.cc
r7ae930a r9c23f31 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Sep 14 23:13:28201613 // Update Count : 50212 // Last Modified On : Sat Sep 24 11:12:52 2016 13 // Update Count : 627 14 14 // 15 15 … … 31 31 32 32 // These must remain in the same order as the corresponding DeclarationNode enumerations. 33 const char * DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "NoStorageClass" };34 const char * DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic", "NoQualifier" };35 const char * DeclarationNode::basicTypeName[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicType" };36 const char * DeclarationNode::complexTypeName[] = { "_Complex", "_Imaginary", "NoComplexType" };37 const char * DeclarationNode::signednessName[] = { "signed", "unsigned", "NoSignedness" };38 const char * DeclarationNode::lengthName[] = { "short", "long", "long long", "NoLength" };39 const char * DeclarationNode::aggregateName[] = { "struct", "union", "context" };40 const char * DeclarationNode::typeClassName[] = { "otype", "dtype", "ftype" };41 const char * DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };33 const char * DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "NoStorageClass" }; 34 const char * DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic", "NoQualifier" }; 35 const char * DeclarationNode::basicTypeName[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicType" }; 36 const char * DeclarationNode::complexTypeName[] = { "_Complex", "_Imaginary", "NoComplexType" }; 37 const char * DeclarationNode::signednessName[] = { "signed", "unsigned", "NoSignedness" }; 38 const char * DeclarationNode::lengthName[] = { "short", "long", "long long", "NoLength" }; 39 const char * DeclarationNode::aggregateName[] = { "struct", "union", "context" }; 40 const char * DeclarationNode::typeClassName[] = { "otype", "dtype", "ftype" }; 41 const char * DeclarationNode::builtinTypeName[] = { "__builtin_va_list" }; 42 42 43 43 UniqueName DeclarationNode::anonymous( "__anonymous" ); … … 46 46 47 47 DeclarationNode::DeclarationNode() : 48 type( 0),48 type( nullptr ), 49 49 storageClass( NoStorageClass ), 50 50 isInline( false ), 51 51 isNoreturn( false ), 52 bitfieldWidth( 0),53 initializer( 0),52 bitfieldWidth( nullptr ), 53 initializer( nullptr ), 54 54 hasEllipsis( false ), 55 55 linkage( ::linkage ), 56 56 extension( false ) { 57 58 variable.name = nullptr; 57 59 variable.tyClass = DeclarationNode::Otype; 58 60 variable.assertions = nullptr; 59 61 62 attr.name = nullptr; 60 63 attr.expr = nullptr; 61 64 attr.type = nullptr; … … 63 66 64 67 DeclarationNode::~DeclarationNode() { 68 delete attr.name; 65 69 delete attr.expr; 66 70 delete attr.type; 71 72 delete variable.name; 73 delete variable.assertions; 74 67 75 delete type; 68 76 delete bitfieldWidth; … … 70 78 } 71 79 72 DeclarationNode * DeclarationNode::clone() const {73 DeclarationNode * newnode = new DeclarationNode;80 DeclarationNode * DeclarationNode::clone() const { 81 DeclarationNode * newnode = new DeclarationNode; 74 82 newnode->type = maybeClone( type ); 75 newnode->name = name ;83 newnode->name = name ? new string( *name ) : nullptr; 76 84 newnode->storageClass = storageClass; 77 85 newnode->isInline = isInline; … … 83 91 newnode->linkage = linkage; 84 92 93 newnode->variable.name = variable.name ? new string( *variable.name ) : nullptr; 85 94 newnode->variable.assertions = maybeClone( variable.assertions ); 86 newnode->variable.name = variable.name;87 95 newnode->variable.tyClass = variable.tyClass; 88 96 97 newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr; 89 98 newnode->attr.expr = maybeClone( attr.expr ); 90 99 newnode->attr.type = maybeClone( attr.type ); … … 98 107 void DeclarationNode::print( std::ostream &os, int indent ) const { 99 108 os << string( indent, ' ' ); 100 if ( name == "" ) { 109 if ( name ) { 110 os << *name << ": "; 111 } else { 101 112 os << "unnamed: "; 102 } else {103 os << name << ": ";104 113 } // if 105 114 … … 122 131 } // if 123 132 124 if ( initializer != 0) {133 if ( initializer ) { 125 134 os << endl << string( indent + 2, ' ' ) << "with initializer "; 126 135 initializer->printOneLine( os ); … … 139 148 } 140 149 141 DeclarationNode * DeclarationNode::newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle ) {142 DeclarationNode * newnode = new DeclarationNode;143 newnode->name = assign_strptr( name );150 DeclarationNode * DeclarationNode::newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle ) { 151 DeclarationNode * newnode = new DeclarationNode; 152 newnode->name = name; 144 153 145 154 newnode->type = new TypeData( TypeData::Function ); … … 147 156 newnode->type->function.newStyle = newStyle; 148 157 newnode->type->function.body = body; 149 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 158 // ignore unnamed routine declarations: void p( int (*)(int) ); 159 if ( newnode->name ) { 160 typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID ); 161 } // if 150 162 151 163 if ( body ) { … … 155 167 if ( ret ) { 156 168 newnode->type->base = ret->type; 157 ret->type = 0;169 ret->type = nullptr; 158 170 delete ret; 159 171 } // if … … 163 175 164 176 DeclarationNode * DeclarationNode::newQualifier( Qualifier q ) { 165 DeclarationNode * newnode = new DeclarationNode;177 DeclarationNode * newnode = new DeclarationNode; 166 178 newnode->type = new TypeData(); 167 179 newnode->type->qualifiers[ q ] = 1; … … 169 181 } // DeclarationNode::newQualifier 170 182 171 DeclarationNode * DeclarationNode::newForall( DeclarationNode * forall ) {172 DeclarationNode * newnode = new DeclarationNode;183 DeclarationNode * DeclarationNode::newForall( DeclarationNode * forall ) { 184 DeclarationNode * newnode = new DeclarationNode; 173 185 newnode->type = new TypeData( TypeData::Unknown ); 174 186 newnode->type->forall = forall; … … 177 189 178 190 DeclarationNode * DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { 179 DeclarationNode *newnode = new DeclarationNode; 180 //switch (sc) { 181 // case Inline: newnode->isInline = true; break; 182 // case Noreturn: newnode->isNoreturn = true; break; 183 // default: newnode->storageClass = sc; break; 184 //} 191 DeclarationNode * newnode = new DeclarationNode; 185 192 newnode->storageClass = sc; 186 193 return newnode; … … 188 195 189 196 DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) { 190 DeclarationNode * newnode = new DeclarationNode;197 DeclarationNode * newnode = new DeclarationNode; 191 198 newnode->type = new TypeData( TypeData::Basic ); 192 199 newnode->type->basictype = bt; … … 195 202 196 203 DeclarationNode * DeclarationNode::newComplexType( ComplexType ct ) { 197 DeclarationNode * newnode = new DeclarationNode;204 DeclarationNode * newnode = new DeclarationNode; 198 205 newnode->type = new TypeData( TypeData::Basic ); 199 206 newnode->type->complextype = ct; … … 202 209 203 210 DeclarationNode * DeclarationNode::newSignedNess( Signedness sn ) { 204 DeclarationNode * newnode = new DeclarationNode;211 DeclarationNode * newnode = new DeclarationNode; 205 212 newnode->type = new TypeData( TypeData::Basic ); 206 213 newnode->type->signedness = sn; … … 209 216 210 217 DeclarationNode * DeclarationNode::newLength( Length lnth ) { 211 DeclarationNode * newnode = new DeclarationNode;218 DeclarationNode * newnode = new DeclarationNode; 212 219 newnode->type = new TypeData( TypeData::Basic ); 213 220 newnode->type->length = lnth; … … 215 222 } // DeclarationNode::newLength 216 223 217 DeclarationNode * DeclarationNode::newFromTypedef( std::string * name ) {218 DeclarationNode * newnode = new DeclarationNode;224 DeclarationNode * DeclarationNode::newFromTypedef( std::string * name ) { 225 DeclarationNode * newnode = new DeclarationNode; 219 226 newnode->type = new TypeData( TypeData::SymbolicInst ); 220 newnode->type->symbolic.name = assign_strptr( name );227 newnode->type->symbolic.name = name ? new string( *name ) : nullptr; 221 228 newnode->type->symbolic.isTypedef = true; 222 newnode->type->symbolic.params = 0;229 newnode->type->symbolic.params = nullptr; 223 230 return newnode; 224 231 } // DeclarationNode::newFromTypedef 225 232 226 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string * name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {227 DeclarationNode * newnode = new DeclarationNode;233 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) { 234 DeclarationNode * newnode = new DeclarationNode; 228 235 newnode->type = new TypeData( TypeData::Aggregate ); 229 236 newnode->type->aggregate.kind = kind; 230 newnode->type->aggregate.name = assign_strptr( name ); 231 if ( newnode->type->aggregate.name == "" ) { // anonymous aggregate ? 232 newnode->type->aggregate.name = anonymous.newName(); 237 if ( name ) { 238 newnode->type->aggregate.name = new string( *name ); 239 } else { // anonymous aggregate ? 240 newnode->type->aggregate.name = new string( anonymous.newName() ); 233 241 } // if 234 242 newnode->type->aggregate.actuals = actuals; … … 238 246 } // DeclarationNode::newAggregate 239 247 240 DeclarationNode * DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) {241 DeclarationNode * newnode = new DeclarationNode;242 newnode->name = assign_strptr( name );248 DeclarationNode * DeclarationNode::newEnum( std::string * name, DeclarationNode * constants ) { 249 DeclarationNode * newnode = new DeclarationNode; 250 newnode->name = name; 243 251 newnode->type = new TypeData( TypeData::Enum ); 244 newnode->type->enumeration.name = newnode->name; 245 if ( newnode->type->enumeration.name == "" ) { // anonymous enumeration ? 246 newnode->type->enumeration.name = DeclarationNode::anonymous.newName(); 252 if ( name ) { 253 newnode->type->enumeration.name = new string( *name ); 254 } else { // anonymous aggregate ? 255 newnode->type->enumeration.name = new string( anonymous.newName() ); 247 256 } // if 248 257 newnode->type->enumeration.constants = constants; … … 250 259 } // DeclarationNode::newEnum 251 260 252 DeclarationNode * DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) {253 DeclarationNode * newnode = new DeclarationNode;254 newnode->name = assign_strptr( name );261 DeclarationNode * DeclarationNode::newEnumConstant( std::string * name, ExpressionNode * constant ) { 262 DeclarationNode * newnode = new DeclarationNode; 263 newnode->name = name; 255 264 newnode->enumeratorValue.reset( constant ); 256 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );265 typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID ); 257 266 return newnode; 258 267 } // DeclarationNode::newEnumConstant 259 268 260 DeclarationNode * DeclarationNode::newName( std::string *name ) {261 DeclarationNode * newnode = new DeclarationNode;262 newnode->name = assign_strptr( name );269 DeclarationNode * DeclarationNode::newName( std::string * name ) { 270 DeclarationNode * newnode = new DeclarationNode; 271 newnode->name = name; 263 272 return newnode; 264 273 } // DeclarationNode::newName 265 274 266 DeclarationNode * DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) {267 DeclarationNode * newnode = new DeclarationNode;275 DeclarationNode * DeclarationNode::newFromTypeGen( std::string * name, ExpressionNode * params ) { 276 DeclarationNode * newnode = new DeclarationNode; 268 277 newnode->type = new TypeData( TypeData::SymbolicInst ); 269 newnode->type->symbolic.name = assign_strptr( name );278 newnode->type->symbolic.name = name ? new string( *name ) : nullptr; 270 279 newnode->type->symbolic.isTypedef = false; 271 280 newnode->type->symbolic.actuals = params; … … 273 282 } // DeclarationNode::newFromTypeGen 274 283 275 DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) { 276 DeclarationNode *newnode = new DeclarationNode; 277 newnode->name = assign_strptr( name ); 278 newnode->type = new TypeData( TypeData::Variable ); 284 DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, std::string * name ) { 285 DeclarationNode * newnode = new DeclarationNode; 286 newnode->name = name; 287 // newnode->type = new TypeData( TypeData::Variable ); 288 newnode->type = nullptr; 279 289 newnode->variable.tyClass = tc; 280 newnode->variable.name = newnode->name ;290 newnode->variable.name = newnode->name ? new string( *newnode->name ) : nullptr; 281 291 return newnode; 282 292 } // DeclarationNode::newTypeParam 283 293 284 DeclarationNode * DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {285 DeclarationNode * newnode = new DeclarationNode;294 DeclarationNode * DeclarationNode::newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts ) { 295 DeclarationNode * newnode = new DeclarationNode; 286 296 newnode->type = new TypeData( TypeData::Aggregate ); 297 newnode->type->aggregate.name = name; 287 298 newnode->type->aggregate.kind = Trait; 288 299 newnode->type->aggregate.params = params; 289 300 newnode->type->aggregate.fields = asserts; 290 newnode->type->aggregate.name = assign_strptr( name );291 301 return newnode; 292 302 } // DeclarationNode::newTrait 293 303 294 DeclarationNode * DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) {295 DeclarationNode * newnode = new DeclarationNode;304 DeclarationNode * DeclarationNode::newTraitUse( const std::string * name, ExpressionNode * params ) { 305 DeclarationNode * newnode = new DeclarationNode; 296 306 newnode->type = new TypeData( TypeData::AggregateInst ); 297 307 newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate ); 298 308 newnode->type->aggInst.aggregate->aggregate.kind = Trait; 299 newnode->type->aggInst.aggregate->aggregate.name = assign_strptr( name );309 newnode->type->aggInst.aggregate->aggregate.name = name; 300 310 newnode->type->aggInst.params = params; 301 311 return newnode; 302 312 } // DeclarationNode::newTraitUse 303 313 304 DeclarationNode * DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) {305 DeclarationNode * newnode = new DeclarationNode;306 newnode->name = assign_strptr( name );314 DeclarationNode * DeclarationNode::newTypeDecl( std::string * name, DeclarationNode * typeParams ) { 315 DeclarationNode * newnode = new DeclarationNode; 316 newnode->name = name; 307 317 newnode->type = new TypeData( TypeData::Symbolic ); 308 318 newnode->type->symbolic.isTypedef = false; … … 312 322 } // DeclarationNode::newTypeDecl 313 323 314 DeclarationNode * DeclarationNode::newPointer( DeclarationNode *qualifiers ) {315 DeclarationNode * newnode = new DeclarationNode;324 DeclarationNode * DeclarationNode::newPointer( DeclarationNode * qualifiers ) { 325 DeclarationNode * newnode = new DeclarationNode; 316 326 newnode->type = new TypeData( TypeData::Pointer ); 317 327 return newnode->addQualifiers( qualifiers ); 318 328 } // DeclarationNode::newPointer 319 329 320 DeclarationNode * DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) {321 DeclarationNode * newnode = new DeclarationNode;330 DeclarationNode * DeclarationNode::newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic ) { 331 DeclarationNode * newnode = new DeclarationNode; 322 332 newnode->type = new TypeData( TypeData::Array ); 323 333 newnode->type->array.dimension = size; 324 334 newnode->type->array.isStatic = isStatic; 325 if ( newnode->type->array.dimension == 0 || newnode->type->array.dimension->isExpressionType<ConstantExpr *>() ) {335 if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ConstantExpr * >() ) { 326 336 newnode->type->array.isVarLen = false; 327 337 } else { … … 331 341 } // DeclarationNode::newArray 332 342 333 DeclarationNode * DeclarationNode::newVarArray( DeclarationNode *qualifiers ) {334 DeclarationNode * newnode = new DeclarationNode;343 DeclarationNode * DeclarationNode::newVarArray( DeclarationNode * qualifiers ) { 344 DeclarationNode * newnode = new DeclarationNode; 335 345 newnode->type = new TypeData( TypeData::Array ); 336 newnode->type->array.dimension = 0;346 newnode->type->array.dimension = nullptr; 337 347 newnode->type->array.isStatic = false; 338 348 newnode->type->array.isVarLen = true; … … 340 350 } 341 351 342 DeclarationNode * DeclarationNode::newBitfield( ExpressionNode *size ) {343 DeclarationNode * newnode = new DeclarationNode;352 DeclarationNode * DeclarationNode::newBitfield( ExpressionNode * size ) { 353 DeclarationNode * newnode = new DeclarationNode; 344 354 newnode->bitfieldWidth = size; 345 355 return newnode; 346 356 } 347 357 348 DeclarationNode * DeclarationNode::newTuple( DeclarationNode *members ) {349 DeclarationNode * newnode = new DeclarationNode;358 DeclarationNode * DeclarationNode::newTuple( DeclarationNode * members ) { 359 DeclarationNode * newnode = new DeclarationNode; 350 360 newnode->type = new TypeData( TypeData::Tuple ); 351 361 newnode->type->tuple = members; … … 353 363 } 354 364 355 DeclarationNode * DeclarationNode::newTypeof( ExpressionNode *expr ) {356 DeclarationNode * newnode = new DeclarationNode;365 DeclarationNode * DeclarationNode::newTypeof( ExpressionNode * expr ) { 366 DeclarationNode * newnode = new DeclarationNode; 357 367 newnode->type = new TypeData( TypeData::Typeof ); 358 368 newnode->type->typeexpr = expr; … … 361 371 362 372 DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) { 363 DeclarationNode * newnode = new DeclarationNode;373 DeclarationNode * newnode = new DeclarationNode; 364 374 newnode->type = new TypeData( TypeData::Builtin ); 365 375 newnode->builtin = bt; … … 367 377 } // DeclarationNode::newBuiltinType 368 378 369 DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) { 370 DeclarationNode *newnode = new DeclarationNode; 371 newnode->type = new TypeData( TypeData::Attr ); 372 newnode->attr.name = assign_strptr( name ); 379 DeclarationNode * DeclarationNode::newAttr( std::string * name, ExpressionNode * expr ) { 380 DeclarationNode * newnode = new DeclarationNode; 381 // newnode->type = new TypeData( TypeData::Attr ); 382 newnode->type = nullptr; 383 newnode->attr.name = name; 373 384 newnode->attr.expr = expr; 374 385 return newnode; 375 386 } 376 387 377 DeclarationNode *DeclarationNode::newAttr( std::string *name, DeclarationNode *type ) { 378 DeclarationNode *newnode = new DeclarationNode; 379 newnode->type = new TypeData( TypeData::Attr ); 380 newnode->attr.name = assign_strptr( name ); 388 DeclarationNode * DeclarationNode::newAttr( std::string * name, DeclarationNode * type ) { 389 DeclarationNode * newnode = new DeclarationNode; 390 // newnode->type = new TypeData( TypeData::Attr ); 391 newnode->type = nullptr; 392 newnode->attr.name = name; 381 393 newnode->attr.type = type; 382 394 return newnode; … … 389 401 } // appendError 390 402 391 void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData *dst ) {403 void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) { 392 404 TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization 393 405 … … 401 413 } // DeclarationNode::checkQualifiers 402 414 403 void DeclarationNode::checkStorageClasses( DeclarationNode * q ) {415 void DeclarationNode::checkStorageClasses( DeclarationNode * q ) { 404 416 if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) { 405 417 if ( storageClass == q->storageClass ) { // duplicate qualifier … … 413 425 } // DeclarationNode::copyStorageClasses 414 426 415 DeclarationNode * DeclarationNode::copyStorageClasses( DeclarationNode *q ) {427 DeclarationNode * DeclarationNode::copyStorageClasses( DeclarationNode * q ) { 416 428 isInline = isInline || q->isInline; 417 429 isNoreturn = isNoreturn || q->isNoreturn; … … 424 436 } // DeclarationNode::copyStorageClasses 425 437 426 static void addQualifiersToType( TypeData *&src, TypeData * dst ) {438 static void addQualifiersToType( TypeData *&src, TypeData * dst ) { 427 439 if ( src->forall && dst->kind == TypeData::Function ) { 428 440 if ( dst->forall ) { … … 431 443 dst->forall = src->forall; 432 444 } // if 433 src->forall = 0;445 src->forall = nullptr; 434 446 } // if 435 447 if ( dst->base ) { … … 437 449 } else if ( dst->kind == TypeData::Function ) { 438 450 dst->base = src; 439 src = 0;451 src = nullptr; 440 452 } else { 441 453 dst->qualifiers |= src->qualifiers; … … 443 455 } // addQualifiersToType 444 456 445 DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode *q ) {446 if ( ! q ) return this;457 DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) { 458 if ( ! q ) { delete q; return this; } 447 459 448 460 checkStorageClasses( q ); 449 461 copyStorageClasses( q ); 450 462 451 if ( ! q->type ) { delete q; return this; } 463 if ( ! q->type ) { 464 delete q; 465 return this; 466 } // if 452 467 453 468 if ( ! type ) { 454 // type = new TypeData; 455 type = q->type; 469 type = q->type; // reuse this structure 470 q->type = nullptr; 471 delete q; 456 472 return this; 457 473 } // if … … 467 483 type->aggregate.params = q->type->forall; 468 484 // change implicit typedef from TYPEDEFname to TYPEGENname 469 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );485 typedefTable.changeKind( *type->aggregate.name, TypedefTable::TG ); 470 486 } else { 471 487 type->forall = q->type->forall; 472 488 } // if 473 489 } // if 474 q->type->forall = 0;490 q->type->forall = nullptr; 475 491 } // if 476 492 delete q; … … 485 501 dst->forall = src->forall; 486 502 } // if 487 src->forall = 0;503 src->forall = nullptr; 488 504 } // if 489 505 if ( dst->base ) { … … 494 510 src->qualifiers |= dst->qualifiers; 495 511 dst = src; 496 src = 0;512 src = nullptr; 497 513 break; 498 514 case TypeData::Basic: … … 534 550 } // if 535 551 dst->base->qualifiers |= src->qualifiers; 536 src = 0;552 src = nullptr; 537 553 break; 538 554 default: … … 542 558 dst->forall = src->forall; 543 559 } // if 544 src->forall = 0;560 src->forall = nullptr; 545 561 dst->base = src; 546 src = 0;562 src = nullptr; 547 563 } // switch 548 564 } // switch … … 550 566 } 551 567 552 DeclarationNode * DeclarationNode::addType( DeclarationNode *o ) {568 DeclarationNode * DeclarationNode::addType( DeclarationNode * o ) { 553 569 if ( o ) { 554 570 checkStorageClasses( o ); … … 566 582 type = o->type; 567 583 } // if 568 o->type = 0;584 o->type = nullptr; 569 585 } else { 570 586 addTypeToType( o->type, type ); … … 584 600 } 585 601 586 DeclarationNode * DeclarationNode::addTypedef() {587 TypeData * newtype = new TypeData( TypeData::Symbolic );588 newtype->symbolic.params = 0;602 DeclarationNode * DeclarationNode::addTypedef() { 603 TypeData * newtype = new TypeData( TypeData::Symbolic ); 604 newtype->symbolic.params = nullptr; 589 605 newtype->symbolic.isTypedef = true; 590 newtype->symbolic.name = name ;606 newtype->symbolic.name = name ? new string( *name ) : nullptr; 591 607 newtype->base = type; 592 608 type = newtype; … … 594 610 } 595 611 596 DeclarationNode *DeclarationNode::addAssertions( DeclarationNode *assertions ) { 612 DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) { 613 if ( variable.name ) { 614 if ( variable.assertions ) { 615 variable.assertions->appendList( assertions ); 616 } else { 617 variable.assertions = assertions; 618 } // if 619 return this; 620 } // if 621 597 622 assert( type ); 598 623 switch ( type->kind ) { … … 604 629 } // if 605 630 break; 606 case TypeData::Variable:607 if ( variable.assertions ) {608 variable.assertions->appendList( assertions );609 } else {610 variable.assertions = assertions;611 } // if612 break;631 // case TypeData::Variable: 632 // if ( variable.assertions ) { 633 // variable.assertions->appendList( assertions ); 634 // } else { 635 // variable.assertions = assertions; 636 // } // if 637 // break; 613 638 default: 614 639 assert( false ); … … 618 643 } 619 644 620 DeclarationNode *DeclarationNode::addName( std::string *newname ) { 621 name = assign_strptr( newname ); 622 return this; 623 } 624 625 DeclarationNode *DeclarationNode::addBitfield( ExpressionNode *size ) { 645 DeclarationNode * DeclarationNode::addName( std::string * newname ) { 646 assert( ! name ); 647 name = newname; 648 return this; 649 } 650 651 DeclarationNode * DeclarationNode::addBitfield( ExpressionNode * size ) { 626 652 bitfieldWidth = size; 627 653 return this; 628 654 } 629 655 630 DeclarationNode * DeclarationNode::addVarArgs() {656 DeclarationNode * DeclarationNode::addVarArgs() { 631 657 assert( type ); 632 658 hasEllipsis = true; … … 634 660 } 635 661 636 DeclarationNode * DeclarationNode::addFunctionBody( StatementNode *body ) {662 DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body ) { 637 663 assert( type ); 638 664 assert( type->kind == TypeData::Function ); 639 assert( type->function.body == 0);665 assert( ! type->function.body ); 640 666 type->function.body = body; 641 667 type->function.hasBody = true; … … 643 669 } 644 670 645 DeclarationNode * DeclarationNode::addOldDeclList( DeclarationNode *list ) {671 DeclarationNode * DeclarationNode::addOldDeclList( DeclarationNode * list ) { 646 672 assert( type ); 647 673 assert( type->kind == TypeData::Function ); 648 assert( type->function.oldDeclList == 0);674 assert( ! type->function.oldDeclList ); 649 675 type->function.oldDeclList = list; 650 676 return this; 651 677 } 652 678 653 static void setBase( TypeData *&type, TypeData * newType ) {679 static void setBase( TypeData *&type, TypeData * newType ) { 654 680 if ( type ) { 655 TypeData * prevBase = type;656 TypeData * curBase = type->base;657 while ( curBase != 0) {681 TypeData * prevBase = type; 682 TypeData * curBase = type->base; 683 while ( curBase != nullptr ) { 658 684 prevBase = curBase; 659 685 curBase = curBase->base; … … 665 691 } 666 692 667 DeclarationNode * DeclarationNode::addPointer( DeclarationNode *p ) {693 DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) { 668 694 if ( p ) { 669 695 assert( p->type->kind == TypeData::Pointer ); 670 696 setBase( type, p->type ); 671 p->type = 0;697 p->type = nullptr; 672 698 delete p; 673 699 } // if … … 675 701 } 676 702 677 DeclarationNode * DeclarationNode::addArray( DeclarationNode *a ) {703 DeclarationNode * DeclarationNode::addArray( DeclarationNode * a ) { 678 704 if ( a ) { 679 705 assert( a->type->kind == TypeData::Array ); 680 706 setBase( type, a->type ); 681 a->type = 0;707 a->type = nullptr; 682 708 delete a; 683 709 } // if … … 685 711 } 686 712 687 DeclarationNode * DeclarationNode::addNewPointer( DeclarationNode *p ) {713 DeclarationNode * DeclarationNode::addNewPointer( DeclarationNode * p ) { 688 714 if ( p ) { 689 715 assert( p->type->kind == TypeData::Pointer ); … … 703 729 p->type->base = type; 704 730 } // switch 705 type = 0;731 type = nullptr; 706 732 } // if 707 733 delete this; … … 712 738 } 713 739 714 static TypeData * findLast( TypeData *a ) {740 static TypeData * findLast( TypeData * a ) { 715 741 assert( a ); 716 TypeData * cur = a;742 TypeData * cur = a; 717 743 while ( cur->base ) { 718 744 cur = cur->base; … … 721 747 } 722 748 723 DeclarationNode * DeclarationNode::addNewArray( DeclarationNode *a ) {749 DeclarationNode * DeclarationNode::addNewArray( DeclarationNode * a ) { 724 750 if ( a ) { 725 751 assert( a->type->kind == TypeData::Array ); 726 TypeData * lastArray = findLast( a->type );752 TypeData * lastArray = findLast( a->type ); 727 753 if ( type ) { 728 754 switch ( type->kind ) { … … 739 765 lastArray->base = type; 740 766 } // switch 741 type = 0;767 type = nullptr; 742 768 } // if 743 769 delete this; … … 748 774 } 749 775 750 DeclarationNode * DeclarationNode::addParamList( DeclarationNode *params ) {751 TypeData * ftype = new TypeData( TypeData::Function );776 DeclarationNode * DeclarationNode::addParamList( DeclarationNode * params ) { 777 TypeData * ftype = new TypeData( TypeData::Function ); 752 778 ftype->function.params = params; 753 779 setBase( type, ftype ); … … 755 781 } 756 782 757 static TypeData * addIdListToType( TypeData *type, DeclarationNode *ids ) {783 static TypeData * addIdListToType( TypeData * type, DeclarationNode * ids ) { 758 784 if ( type ) { 759 785 if ( type->kind != TypeData::Function ) { … … 764 790 return type; 765 791 } else { 766 TypeData * newtype = new TypeData( TypeData::Function );792 TypeData * newtype = new TypeData( TypeData::Function ); 767 793 newtype->function.idList = ids; 768 794 return newtype; 769 795 } // if 770 } 771 772 DeclarationNode * DeclarationNode::addIdList( DeclarationNode *ids ) {796 } // addIdListToType 797 798 DeclarationNode * DeclarationNode::addIdList( DeclarationNode * ids ) { 773 799 type = addIdListToType( type, ids ); 774 800 return this; 775 801 } 776 802 777 DeclarationNode *DeclarationNode::addInitializer( InitializerNode *init ) { 778 //assert 803 DeclarationNode * DeclarationNode::addInitializer( InitializerNode * init ) { 779 804 initializer = init; 780 805 return this; 781 806 } 782 807 783 DeclarationNode *DeclarationNode::cloneBaseType( string *newName ) { 784 DeclarationNode *newnode = new DeclarationNode; 785 TypeData *srcType = type; 786 while ( srcType->base ) { 787 srcType = srcType->base; 788 } // while 789 newnode->type = maybeClone( srcType ); 790 if ( newnode->type->kind == TypeData::AggregateInst ) { 791 // don't duplicate members 792 if ( newnode->type->aggInst.aggregate->kind == TypeData::Enum ) { 793 delete newnode->type->aggInst.aggregate->enumeration.constants; 794 newnode->type->aggInst.aggregate->enumeration.constants = 0; 795 } else { 796 assert( newnode->type->aggInst.aggregate->kind == TypeData::Aggregate ); 797 delete newnode->type->aggInst.aggregate->aggregate.fields; 798 newnode->type->aggInst.aggregate->aggregate.fields = 0; 799 } // if 800 } // if 801 newnode->type->forall = maybeClone( type->forall ); 802 assert( storageClass == NoStorageClass ); 803 newnode->copyStorageClasses( this ); 804 newnode->name = assign_strptr( newName ); 805 return newnode; 806 } 807 808 DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) { 809 if ( o ) { 810 o->copyStorageClasses( this ); 811 if ( type ) { 812 TypeData *srcType = type; 813 while ( srcType->base ) { 814 srcType = srcType->base; 815 } // while 816 TypeData *newType = srcType->clone(); 817 if ( newType->kind == TypeData::AggregateInst ) { 818 // don't duplicate members 819 if ( newType->aggInst.aggregate->kind == TypeData::Enum ) { 820 delete newType->aggInst.aggregate->enumeration.constants; 821 newType->aggInst.aggregate->enumeration.constants = 0; 822 } else { 823 assert( newType->aggInst.aggregate->kind == TypeData::Aggregate ); 824 delete newType->aggInst.aggregate->aggregate.fields; 825 newType->aggInst.aggregate->aggregate.fields = 0; 826 } // if 827 } // if 828 newType->forall = maybeClone( type->forall ); 829 if ( ! o->type ) { 830 o->type = newType; 831 } else { 832 addTypeToType( newType, o->type ); 833 delete newType; 834 } // if 835 } // if 836 } // if 837 return o; 838 } 839 840 DeclarationNode *DeclarationNode::cloneType( string *newName ) { 841 DeclarationNode *newnode = new DeclarationNode; 808 DeclarationNode * DeclarationNode::cloneType( string * newName ) { 809 DeclarationNode * newnode = new DeclarationNode; 842 810 newnode->type = maybeClone( type ); 843 811 assert( storageClass == NoStorageClass ); 844 812 newnode->copyStorageClasses( this ); 845 newnode->name = assign_strptr( newName ); 846 return newnode; 847 } 848 849 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) { 850 if ( o ) { 851 assert( storageClass == NoStorageClass ); 852 o->copyStorageClasses( this ); 853 if ( type ) { 854 TypeData *newType = type->clone(); 855 if ( ! o->type ) { 856 o->type = newType; 813 assert( newName ); 814 newnode->name = newName; 815 return newnode; 816 } 817 818 DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) { 819 if ( ! o ) return nullptr; 820 821 o->copyStorageClasses( this ); 822 if ( type ) { 823 TypeData * srcType = type; 824 825 while ( srcType->base ) { 826 srcType = srcType->base; 827 } // while 828 829 TypeData * newType = srcType->clone(); 830 if ( newType->kind == TypeData::AggregateInst ) { 831 // don't duplicate members 832 if ( newType->aggInst.aggregate->kind == TypeData::Enum ) { 833 delete newType->aggInst.aggregate->enumeration.constants; 834 newType->aggInst.aggregate->enumeration.constants = nullptr; 857 835 } else { 858 addTypeToType( newType, o->type ); 859 delete newType; 836 assert( newType->aggInst.aggregate->kind == TypeData::Aggregate ); 837 delete newType->aggInst.aggregate->aggregate.fields; 838 newType->aggInst.aggregate->aggregate.fields = nullptr; 860 839 } // if 861 840 } // if 862 } // if 863 delete o; 841 842 newType->forall = maybeClone( type->forall ); 843 if ( ! o->type ) { 844 o->type = newType; 845 } else { 846 addTypeToType( newType, o->type ); 847 delete newType; 848 } // if 849 } // if 864 850 return o; 865 851 } 866 852 867 DeclarationNode * DeclarationNode::extractAggregate() const {853 DeclarationNode * DeclarationNode::extractAggregate() const { 868 854 if ( type ) { 869 TypeData * ret = typeextractAggregate( type );855 TypeData * ret = typeextractAggregate( type ); 870 856 if ( ret ) { 871 DeclarationNode * newnode = new DeclarationNode;857 DeclarationNode * newnode = new DeclarationNode; 872 858 newnode->type = ret; 873 859 return newnode; 874 860 } // if 875 861 } // if 876 return 0;877 } 878 879 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ) {862 return nullptr; 863 } 864 865 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ) { 880 866 SemanticError errors; 881 867 std::back_insert_iterator< std::list< Declaration * > > out( outputList ); 882 const DeclarationNode *cur = firstNode; 868 const DeclarationNode * cur = firstNode; 869 883 870 while ( cur ) { 884 871 try { 885 if ( DeclarationNode * extr = cur->extractAggregate() ) {872 if ( DeclarationNode * extr = cur->extractAggregate() ) { 886 873 // handle the case where a structure declaration is contained within an object or type declaration 887 Declaration * decl = extr->build();874 Declaration * decl = extr->build(); 888 875 if ( decl ) { 889 * out++ = decl;876 * out++ = decl; 890 877 } // if 891 878 delete extr; 892 879 } // if 893 Declaration *decl = cur->build(); 880 881 Declaration * decl = cur->build(); 894 882 if ( decl ) { 895 * out++ = decl;883 * out++ = decl; 896 884 } // if 897 885 } catch( SemanticError &e ) { … … 900 888 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 901 889 } // while 890 902 891 if ( ! errors.isEmpty() ) { 903 892 throw errors; 904 893 } // if 905 } 906 907 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) {894 } // buildList 895 896 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) { 908 897 SemanticError errors; 909 898 std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList ); 910 const DeclarationNode * cur = firstNode;899 const DeclarationNode * cur = firstNode; 911 900 while ( cur ) { 912 901 try { 913 Declaration * decl = cur->build();902 Declaration * decl = cur->build(); 914 903 if ( decl ) { 915 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {916 * out++ = dwt;917 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {918 StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() );919 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0);904 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) { 905 * out++ = dwt; 906 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) { 907 StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() ); 908 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr ); 920 909 delete agg; 921 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {922 UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );923 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0);910 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) { 911 UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); 912 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr ); 924 913 } // if 925 914 } // if … … 932 921 throw errors; 933 922 } // if 934 } 935 936 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) {923 } // buildList 924 925 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) { 937 926 SemanticError errors; 938 927 std::back_insert_iterator< std::list< Type * > > out( outputList ); 939 const DeclarationNode *cur = firstNode; 928 const DeclarationNode * cur = firstNode; 929 940 930 while ( cur ) { 941 931 try { 942 * out++ = cur->buildType();932 * out++ = cur->buildType(); 943 933 } catch( SemanticError &e ) { 944 934 errors.append( e ); … … 946 936 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 947 937 } // while 938 948 939 if ( ! errors.isEmpty() ) { 949 940 throw errors; 950 941 } // if 951 } 952 953 Declaration * DeclarationNode::build() const {942 } // buildTypeList 943 944 Declaration * DeclarationNode::build() const { 954 945 if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this ); 946 947 if ( variable.name ) { 948 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 949 TypeDecl * ret = new TypeDecl( *variable.name, DeclarationNode::NoStorageClass, nullptr, kindMap[ variable.tyClass ] ); 950 buildList( variable.assertions, ret->get_assertions() ); 951 return ret; 952 } // if 953 955 954 if ( type ) { 956 if ( type->kind == TypeData::Variable ) { 957 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 958 TypeDecl * ret = new TypeDecl( variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ variable.tyClass ] ); 959 buildList( variable.assertions, ret->get_assertions() ); 960 return ret; 955 return buildDecl( type, name ? *name : string( "" ), storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 956 } // if 957 958 if ( ! isInline && ! isNoreturn ) { 959 assertf( name, "ObjectDecl are assumed to have names\n" ); 960 return (new ObjectDecl( *name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), nullptr, maybeBuild< Initializer >( initializer ) ))->set_extension( extension ); 961 } // if 962 963 throw SemanticError( "invalid function specifier ", this ); 964 } 965 966 Type * DeclarationNode::buildType() const { 967 assert( type ); 968 969 if ( attr.name ) { 970 AttrType * ret; 971 if ( attr.expr ) { 972 ret = new AttrType( buildQualifiers( type ), *attr.name, attr.expr->build() ); 961 973 } else { 962 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 963 } // if 964 } // if 965 if ( ! isInline && ! isNoreturn ) { 966 return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension ); 967 } // if 968 throw SemanticError( "invalid function specifier ", this ); 969 } 970 971 Type *DeclarationNode::buildType() const { 972 assert( type ); 974 assert( attr.type ); 975 ret = new AttrType( buildQualifiers( type ), *attr.name, attr.type->buildType() ); 976 } // if 977 return ret; 978 } // if 973 979 974 980 switch ( type->kind ) { 975 981 case TypeData::Enum: 976 return new EnumInstType( buildQualifiers( type ), type->enumeration.name );982 return new EnumInstType( buildQualifiers( type ), *type->enumeration.name ); 977 983 case TypeData::Aggregate: { 978 ReferenceToType * ret;984 ReferenceToType * ret; 979 985 switch ( type->aggregate.kind ) { 980 986 case DeclarationNode::Struct: 981 ret = new StructInstType( buildQualifiers( type ), type->aggregate.name );987 ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name ); 982 988 break; 983 989 case DeclarationNode::Union: 984 ret = new UnionInstType( buildQualifiers( type ), type->aggregate.name );990 ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name ); 985 991 break; 986 992 case DeclarationNode::Trait: 987 ret = new TraitInstType( buildQualifiers( type ), type->aggregate.name );993 ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name ); 988 994 break; 989 995 default: … … 994 1000 } 995 1001 case TypeData::Symbolic: { 996 TypeInstType * ret = new TypeInstType( buildQualifiers( type ),type->symbolic.name, false );1002 TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false ); 997 1003 buildList( type->symbolic.actuals, ret->get_parameters() ); 998 return ret;999 }1000 case TypeData::Attr: {1001 assert( type->kind == TypeData::Attr );1002 // assert( type->attr );1003 AttrType * ret;1004 if ( attr.expr ) {1005 ret = new AttrType( buildQualifiers( type ), attr.name, attr.expr->build() );1006 } else {1007 assert( attr.type );1008 ret = new AttrType( buildQualifiers( type ), attr.name, attr.type->buildType() );1009 } // if1010 1004 return ret; 1011 1005 } -
src/Parser/ExpressionNode.cc
r7ae930a r9c23f31 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 25 21:39:40201613 // Update Count : 50 312 // Last Modified On : Fri Sep 16 16:27:44 2016 13 // Update Count : 508 14 14 // 15 15 … … 31 31 32 32 using namespace std; 33 34 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.get_name() ), extension( other.extension ) {}35 33 36 34 //############################################################################## -
src/Parser/ParseNode.h
r7ae930a r9c23f31 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 12 08:00:05201613 // Update Count : 6 0312 // Last Modified On : Sat Sep 24 11:12:04 2016 13 // Update Count : 633 14 14 // 15 15 … … 41 41 public: 42 42 ParseNode() {}; 43 ParseNode( const std::string * name ) : name( * name ) { assert( false ); delete name; } 44 ParseNode( const std::string &name ) : name( name ) { assert( false ); } 45 virtual ~ParseNode() { delete next; }; 43 virtual ~ParseNode() { delete next; delete name; }; 46 44 virtual ParseNode * clone() const = 0; 47 45 48 46 ParseNode * get_next() const { return next; } 49 47 ParseNode * set_next( ParseNode * newlink ) { next = newlink; return this; } 48 50 49 ParseNode * get_last() { 51 50 ParseNode * current; 52 for ( current = this; current->get_next() != 0; current = current->get_next() );51 for ( current = this; current->get_next() != nullptr; current = current->get_next() ); 53 52 return current; 54 53 } 55 54 ParseNode * set_last( ParseNode * newlast ) { 56 if ( newlast != 0) get_last()->set_next( newlast );55 if ( newlast != nullptr ) get_last()->set_next( newlast ); 57 56 return this; 58 57 } 59 60 const std::string &get_name() const { return name; }61 void set_name( const std::string &newValue ) { name = newValue; }62 58 63 59 virtual void print( std::ostream &os, int indent = 0 ) const {} 64 60 virtual void printList( std::ostream &os, int indent = 0 ) const {} 65 private: 61 66 62 static int indent_by; 67 63 68 64 ParseNode * next = nullptr; 69 std::string name;65 std::string * name = nullptr; 70 66 }; // ParseNode 71 67 … … 74 70 class InitializerNode : public ParseNode { 75 71 public: 76 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = 0);77 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = 0);72 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = nullptr ); 73 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = nullptr ); 78 74 ~InitializerNode(); 79 75 virtual InitializerNode * clone() const { assert( false ); return nullptr; } … … 106 102 public: 107 103 ExpressionNode( Expression * expr = nullptr ) : expr( expr ) {} 108 ExpressionNode( Expression * expr, const std::string * name ) : ParseNode( name ), expr( expr ) {}109 104 ExpressionNode( const ExpressionNode &other ); 110 105 virtual ~ExpressionNode() {} … … 183 178 Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node ); 184 179 Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node ); 185 Expression * build_tuple( ExpressionNode * expr_node = 0);180 Expression * build_tuple( ExpressionNode * expr_node = nullptr ); 186 181 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ); 187 182 Expression * build_range( ExpressionNode * low, ExpressionNode * high ); … … 219 214 static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle = false ); 220 215 static DeclarationNode * newQualifier( Qualifier ); 221 static DeclarationNode * newForall( DeclarationNode * );216 static DeclarationNode * newForall( DeclarationNode * ); 222 217 static DeclarationNode * newStorageClass( StorageClass ); 223 218 static DeclarationNode * newBasicType( BasicType ); … … 226 221 static DeclarationNode * newLength( Length lnth ); 227 222 static DeclarationNode * newBuiltinType( BuiltinType ); 228 static DeclarationNode * newFromTypedef( std::string * );223 static DeclarationNode * newFromTypedef( std::string * ); 229 224 static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ); 230 225 static DeclarationNode * newEnum( std::string * name, DeclarationNode * constants ); 231 226 static DeclarationNode * newEnumConstant( std::string * name, ExpressionNode * constant ); 232 static DeclarationNode * newName( std::string * );227 static DeclarationNode * newName( std::string * ); 233 228 static DeclarationNode * newFromTypeGen( std::string *, ExpressionNode * params ); 234 static DeclarationNode * newTypeParam( TypeClass, std::string * );235 static DeclarationNode * newTrait( std::string * name, DeclarationNode * params, DeclarationNode * asserts );236 static DeclarationNode * newTraitUse( std::string * name, ExpressionNode * params );229 static DeclarationNode * newTypeParam( TypeClass, std::string * ); 230 static DeclarationNode * newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts ); 231 static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params ); 237 232 static DeclarationNode * newTypeDecl( std::string * name, DeclarationNode * typeParams ); 238 233 static DeclarationNode * newPointer( DeclarationNode * qualifiers ); … … 249 244 DeclarationNode * clone() const; 250 245 251 DeclarationNode * addQualifiers( DeclarationNode * );246 DeclarationNode * addQualifiers( DeclarationNode * ); 252 247 void checkQualifiers( const TypeData *, const TypeData * ); 253 void checkStorageClasses( DeclarationNode * q);254 DeclarationNode * copyStorageClasses( DeclarationNode * );255 DeclarationNode * addType( DeclarationNode * );248 void checkStorageClasses( DeclarationNode * ); 249 DeclarationNode * copyStorageClasses( DeclarationNode * ); 250 DeclarationNode * addType( DeclarationNode * ); 256 251 DeclarationNode * addTypedef(); 257 DeclarationNode * addAssertions( DeclarationNode * );258 DeclarationNode * addName( std::string * );252 DeclarationNode * addAssertions( DeclarationNode * ); 253 DeclarationNode * addName( std::string * ); 259 254 DeclarationNode * addBitfield( ExpressionNode * size ); 260 255 DeclarationNode * addVarArgs(); … … 270 265 271 266 DeclarationNode * cloneType( std::string * newName ); 272 DeclarationNode * cloneType( DeclarationNode * existing );273 DeclarationNode * cloneType( int ) { return cloneType( ( std::string *)0 ); }274 DeclarationNode * cloneBaseType( std::string * newName );275 267 DeclarationNode * cloneBaseType( DeclarationNode * newdecl ); 276 268 … … 286 278 287 279 bool get_hasEllipsis() const; 288 const std::string &get_name() const { return name; }289 280 LinkageSpec::Spec get_linkage() const { return linkage; } 290 281 DeclarationNode * extractAggregate() const; … … 295 286 DeclarationNode * set_extension( bool exten ) { extension = exten; return this; } 296 287 public: 297 // StorageClass buildStorageClass() const;298 // bool buildFuncSpecifier( StorageClass key ) const;299 300 288 struct Variable_t { 289 const std::string * name; 301 290 DeclarationNode::TypeClass tyClass; 302 std::string name;303 291 DeclarationNode * assertions; 304 292 }; … … 306 294 307 295 struct Attr_t { 308 std::stringname;296 const std::string * name; 309 297 ExpressionNode * expr; 310 298 DeclarationNode * type; … … 315 303 316 304 TypeData * type; 317 std::string name;318 305 StorageClass storageClass; 319 306 bool isInline, isNoreturn; … … 331 318 332 319 Type * buildType( TypeData * type ); 333 //Type::Qualifiers buildQualifiers( const TypeData::Qualifiers & qualifiers );334 320 335 321 static inline Type * maybeMoveBuildType( const DeclarationNode * orig ) { … … 393 379 Statement * build_finally( StatementNode * stmt ); 394 380 Statement * build_compound( StatementNode * first ); 395 Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = 0, ExpressionNode * input = 0, ExpressionNode * clobber = 0, LabelNode * gotolabels = 0);381 Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr ); 396 382 397 383 //############################################################################## -
src/Parser/TypeData.cc
r7ae930a r9c23f31 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 12 21:11:22201613 // Update Count : 37712 // Last Modified On : Sat Sep 24 11:14:26 2016 13 // Update Count : 415 14 14 // 15 15 … … 24 24 #include "SynTree/Statement.h" 25 25 #include "SynTree/Initializer.h" 26 27 TypeData::TypeData( Kind k ) : kind( k ), base( 0 ), forall( 0 ) { 26 using namespace std; 27 28 TypeData::TypeData( Kind k ) : kind( k ), base( nullptr ), forall( nullptr ) { 28 29 switch ( kind ) { 29 30 case Unknown: … … 37 38 case Array: 38 39 // array = new Array_t; 39 array.dimension = 0;40 array.dimension = nullptr; 40 41 array.isVarLen = false; 41 42 array.isStatic = false; … … 43 44 case Function: 44 45 // function = new Function_t; 45 function.params = 0;46 function.idList = 0;47 function.oldDeclList = 0;48 function.body = 0;46 function.params = nullptr; 47 function.idList = nullptr; 48 function.oldDeclList = nullptr; 49 function.body = nullptr; 49 50 function.hasBody = false; 50 51 function.newStyle = false; … … 52 53 case Aggregate: 53 54 // aggregate = new Aggregate_t; 54 aggregate.params = 0; 55 aggregate.actuals = 0; 56 aggregate.fields = 0; 55 aggregate.name = nullptr; 56 aggregate.params = nullptr; 57 aggregate.actuals = nullptr; 58 aggregate.fields = nullptr; 57 59 break; 58 60 case AggregateInst: 59 61 // aggInst = new AggInst_t; 60 aggInst.aggregate = 0;61 aggInst.params = 0;62 aggInst.aggregate = nullptr; 63 aggInst.params = nullptr; 62 64 break; 63 65 case Enum: 64 66 // enumeration = new Enumeration_t; 65 enumeration.constants = 0; 67 enumeration.name = nullptr; 68 enumeration.constants = nullptr; 66 69 break; 67 70 case Symbolic: 68 71 case SymbolicInst: 69 72 // symbolic = new Symbolic_t; 70 symbolic.params = 0; 71 symbolic.actuals = 0; 72 symbolic.assertions = 0; 73 break; 74 case Variable: 75 // variable = new Variable_t; 76 // variable.tyClass = DeclarationNode::Type; 77 // variable.assertions = 0; 73 symbolic.name = nullptr; 74 symbolic.params = nullptr; 75 symbolic.actuals = nullptr; 76 symbolic.assertions = nullptr; 78 77 break; 79 78 case Tuple: … … 84 83 // typeexpr = new Typeof_t; 85 84 typeexpr = nullptr; 86 break;87 case Attr:88 // attr = new Attr_t;89 // attr.expr = nullptr;90 // attr.type = nullptr;91 85 break; 92 86 case Builtin: … … 121 115 break; 122 116 case Aggregate: 117 delete aggregate.name; 123 118 delete aggregate.params; 124 119 delete aggregate.actuals; … … 132 127 break; 133 128 case Enum: 129 delete enumeration.name; 134 130 delete enumeration.constants; 135 131 // delete enumeration; … … 137 133 case Symbolic: 138 134 case SymbolicInst: 135 delete symbolic.name; 139 136 delete symbolic.params; 140 137 delete symbolic.actuals; … … 142 139 // delete symbolic; 143 140 break; 144 case Variable:145 // delete variable.assertions;146 // delete variable;147 break;148 141 case Tuple: 149 142 // delete tuple->members; … … 153 146 // delete typeexpr->expr; 154 147 delete typeexpr; 155 break;156 case Attr:157 // delete attr.expr;158 // delete attr.type;159 // delete attr;160 148 break; 161 149 case Builtin: … … 197 185 break; 198 186 case Aggregate: 187 newtype->aggregate.name = aggregate.name ? new string( *aggregate.name ) : nullptr; 199 188 newtype->aggregate.params = maybeClone( aggregate.params ); 200 189 newtype->aggregate.actuals = maybeClone( aggregate.actuals ); 201 190 newtype->aggregate.fields = maybeClone( aggregate.fields ); 202 newtype->aggregate.name = aggregate.name;203 191 newtype->aggregate.kind = aggregate.kind; 204 192 newtype->aggregate.body = aggregate.body; … … 209 197 break; 210 198 case Enum: 211 newtype->enumeration.name = enumeration.name ;199 newtype->enumeration.name = enumeration.name ? new string( *enumeration.name ) : nullptr; 212 200 newtype->enumeration.constants = maybeClone( enumeration.constants ); 213 201 break; 214 202 case Symbolic: 215 203 case SymbolicInst: 204 newtype->symbolic.name = symbolic.name ? new string( *symbolic.name ) : nullptr; 216 205 newtype->symbolic.params = maybeClone( symbolic.params ); 217 206 newtype->symbolic.actuals = maybeClone( symbolic.actuals ); 218 207 newtype->symbolic.assertions = maybeClone( symbolic.assertions ); 219 208 newtype->symbolic.isTypedef = symbolic.isTypedef; 220 newtype->symbolic.name = symbolic.name;221 break;222 case Variable:223 assert( false );224 // newtype->variable.assertions = maybeClone( variable.assertions );225 // newtype->variable.name = variable.name;226 // newtype->variable.tyClass = variable.tyClass;227 209 break; 228 210 case Tuple: … … 231 213 case Typeof: 232 214 newtype->typeexpr = maybeClone( typeexpr ); 233 break;234 case Attr:235 assert( false );236 // newtype->attr.expr = maybeClone( attr.expr );237 // newtype->attr.type = maybeClone( attr.type );238 215 break; 239 216 case Builtin: … … 245 222 } // TypeData::clone 246 223 247 void TypeData::print( std::ostream &os, int indent ) const { 248 using std::endl; 249 using std::string; 250 224 void TypeData::print( ostream &os, int indent ) const { 251 225 for ( int i = 0; i < DeclarationNode::NoQualifier; i += 1 ) { 252 226 if ( qualifiers[i] ) os << DeclarationNode::qualifierName[ i ] << ' '; … … 326 300 break; 327 301 case Aggregate: 328 os << DeclarationNode::aggregateName[ aggregate.kind ] << ' ' << aggregate.name << endl;302 os << DeclarationNode::aggregateName[ aggregate.kind ] << ' ' << *aggregate.name << endl; 329 303 if ( aggregate.params ) { 330 304 os << string( indent + 2, ' ' ) << "with type parameters " << endl; … … 363 337 break; 364 338 case SymbolicInst: 365 os << "instance of type " << symbolic.name;339 os << "instance of type " << *symbolic.name; 366 340 if ( symbolic.actuals ) { 367 341 os << " with parameters" << endl; … … 389 363 } // if 390 364 break; 391 case Variable:392 // os << DeclarationNode::typeClassName[ variable.tyClass ] << " variable ";393 // if ( variable.assertions ) {394 // os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;395 // variable.assertions->printList( os, indent + 4 );396 // os << string( indent + 2, ' ' );397 // } // if398 break;399 365 case Tuple: 400 366 os << "tuple "; … … 410 376 } // if 411 377 break; 412 case Attr:413 // os << "attribute type decl " << attr.name << " applied to ";414 // if ( attr.expr ) {415 // attr.expr->print( os, indent + 2 );416 // } // if417 // if ( attr.type ) {418 // attr.type->print( os, indent + 2 );419 // } // if420 break;421 378 case Builtin: 422 379 os << "gcc builtin type"; … … 428 385 } // TypeData::print 429 386 430 void buildForall( const DeclarationNode * firstNode, std::list< TypeDecl* > &outputList ) {387 void buildForall( const DeclarationNode * firstNode, list< TypeDecl* > &outputList ) { 431 388 buildList( firstNode, outputList ); 432 for ( std::list< TypeDecl* >::iterator i = outputList.begin(); i != outputList.end(); ++i ) {389 for ( list< TypeDecl* >::iterator i = outputList.begin(); i != outputList.end(); ++i ) { 433 390 if ( (*i)->get_kind() == TypeDecl::Any ) { 434 391 // add assertion parameters to `type' tyvars in reverse order 435 392 // add dtor: void ^?{}(T *) 436 393 FunctionType * dtorType = new FunctionType( Type::Qualifiers(), false ); 437 dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0) );438 (*i)->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, dtorType, 0, false, false ) );394 dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), nullptr ) ); 395 (*i)->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, dtorType, nullptr, false, false ) ); 439 396 440 397 // add copy ctor: void ?{}(T *, T) 441 398 FunctionType * copyCtorType = new FunctionType( Type::Qualifiers(), false ); 442 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0) );443 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0) );444 (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, copyCtorType, 0, false, false ) );399 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), nullptr ) ); 400 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), nullptr ) ); 401 (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, copyCtorType, nullptr, false, false ) ); 445 402 446 403 // add default ctor: void ?{}(T *) 447 404 FunctionType * ctorType = new FunctionType( Type::Qualifiers(), false ); 448 ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0) );449 (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, ctorType, 0, false, false ) );405 ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), nullptr ) ); 406 (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, ctorType, nullptr, false, false ) ); 450 407 451 408 // add assignment operator: T * ?=?(T *, T) 452 409 FunctionType * assignType = new FunctionType( Type::Qualifiers(), false ); 453 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0) );454 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0) );455 assignType->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0) );456 (*i)->get_assertions().push_front( new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignType, 0, false, false ) );410 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), nullptr ) ); 411 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), nullptr ) ); 412 assignType->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), nullptr ) ); 413 (*i)->get_assertions().push_front( new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignType, nullptr, false, false ) ); 457 414 } // if 458 415 } // for … … 486 443 case TypeData::Builtin: 487 444 return new VarArgsType( buildQualifiers( td ) ); 488 case TypeData::Attr:489 assert( false );490 return buildAttr( td );491 445 case TypeData::Symbolic: 492 446 case TypeData::Enum: 493 447 case TypeData::Aggregate: 494 case TypeData::Variable:495 448 assert( false ); 496 449 } // switch 497 return 0;450 return nullptr; 498 451 } // typebuild 499 452 500 453 TypeData * typeextractAggregate( const TypeData * td, bool toplevel ) { 501 TypeData * ret = 0;454 TypeData * ret = nullptr; 502 455 503 456 switch ( td->kind ) { … … 549 502 case DeclarationNode::Bool: 550 503 if ( td->signedness != DeclarationNode::NoSignedness ) { 551 throw SemanticError( st d::string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td );504 throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td ); 552 505 } // if 553 506 if ( td->length != DeclarationNode::NoLength ) { 554 throw SemanticError( st d::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );507 throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td ); 555 508 } // if 556 509 … … 565 518 566 519 if ( td->length != DeclarationNode::NoLength ) { 567 throw SemanticError( st d::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );520 throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td ); 568 521 } // if 569 522 … … 595 548 FloatingPoint: ; 596 549 if ( td->signedness != DeclarationNode::NoSignedness ) { 597 throw SemanticError( st d::string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td );550 throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td ); 598 551 } // if 599 552 if ( td->length == DeclarationNode::Short || td->length == DeclarationNode::LongLong ) { 600 throw SemanticError( st d::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );553 throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td ); 601 554 } // if 602 555 if ( td->basictype == DeclarationNode::Float && td->length == DeclarationNode::Long ) { … … 655 608 switch ( td->aggregate.kind ) { 656 609 case DeclarationNode::Struct: 657 at = new StructDecl( td->aggregate.name );610 at = new StructDecl( *td->aggregate.name ); 658 611 buildForall( td->aggregate.params, at->get_parameters() ); 659 612 break; 660 613 case DeclarationNode::Union: 661 at = new UnionDecl( td->aggregate.name );614 at = new UnionDecl( *td->aggregate.name ); 662 615 buildForall( td->aggregate.params, at->get_parameters() ); 663 616 break; 664 617 case DeclarationNode::Trait: 665 at = new TraitDecl( td->aggregate.name );618 at = new TraitDecl( *td->aggregate.name ); 666 619 buildList( td->aggregate.params, at->get_parameters() ); 667 620 break; … … 681 634 ReferenceToType * ret; 682 635 if ( td->aggInst.aggregate->kind == TypeData::Enum ) { 683 ret = new EnumInstType( buildQualifiers( td ), td->aggInst.aggregate->enumeration.name );636 ret = new EnumInstType( buildQualifiers( td ), *td->aggInst.aggregate->enumeration.name ); 684 637 } else { 685 638 assert( td->aggInst.aggregate->kind == TypeData::Aggregate ); 686 639 switch ( td->aggInst.aggregate->aggregate.kind ) { 687 640 case DeclarationNode::Struct: 688 ret = new StructInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name ); 641 assert( td->aggInst.aggregate->aggregate.name ); 642 ret = new StructInstType( buildQualifiers( td ), *td->aggInst.aggregate->aggregate.name ); 689 643 break; 690 644 case DeclarationNode::Union: 691 ret = new UnionInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );645 ret = new UnionInstType( buildQualifiers( td ), *td->aggInst.aggregate->aggregate.name ); 692 646 break; 693 647 case DeclarationNode::Trait: 694 ret = new TraitInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );648 ret = new TraitInstType( buildQualifiers( td ), *td->aggInst.aggregate->aggregate.name ); 695 649 break; 696 650 default: … … 703 657 } // buildAggInst 704 658 705 NamedTypeDecl * buildSymbolic( const TypeData * td, const st d::string & name, DeclarationNode::StorageClass sc ) {659 NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, DeclarationNode::StorageClass sc ) { 706 660 assert( td->kind == TypeData::Symbolic ); 707 661 NamedTypeDecl * ret; … … 717 671 } // buildSymbolic 718 672 719 TypeDecl * buildVariable( const TypeData * td ) {720 assert( false );721 return nullptr;722 // assert( td->kind == TypeData::Variable );723 // static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };724 725 // TypeDecl * ret = new TypeDecl( td->variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable.tyClass ] );726 // buildList( td->variable.assertions, ret->get_assertions() );727 // return ret;728 } // buildSymbolic729 730 673 EnumDecl * buildEnum( const TypeData * td ) { 731 674 assert( td->kind == TypeData::Enum ); 732 EnumDecl * ret = new EnumDecl( td->enumeration.name );675 EnumDecl * ret = new EnumDecl( *td->enumeration.name ); 733 676 buildList( td->enumeration.constants, ret->get_members() ); 734 std::list< Declaration * >::iterator members = ret->get_members().begin();677 list< Declaration * >::iterator members = ret->get_members().begin(); 735 678 for ( const DeclarationNode * cur = td->enumeration. constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 736 679 if ( cur->has_enumeratorValue() ) { 737 680 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 738 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), std::list< Expression * >() ) );681 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), list< Expression * >() ) ); 739 682 } // if 740 683 } // for … … 744 687 TypeInstType * buildSymbolicInst( const TypeData * td ) { 745 688 assert( td->kind == TypeData::SymbolicInst ); 746 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic.name, false );689 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), *td->symbolic.name, false ); 747 690 buildList( td->symbolic.actuals, ret->get_parameters() ); 748 691 buildForall( td->forall, ret->get_forall() ); … … 765 708 } // buildTypeof 766 709 767 AttrType * buildAttr( const TypeData * td ) { 768 assert( false ); 769 return nullptr; 770 // assert( td->kind == TypeData::Attr ); 771 // // assert( td->attr ); 772 // AttrType * ret; 773 // if ( td->attr.expr ) { 774 // ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.expr->build() ); 775 // } else { 776 // assert( td->attr.type ); 777 // ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.type->buildType() ); 778 // } // if 779 // return ret; 780 } // buildAttr 781 782 Declaration * buildDecl( const TypeData * td, std::string name, DeclarationNode::StorageClass sc, Expression * bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, Initializer * init ) { 710 Declaration * buildDecl( const TypeData * td, const string &name, DeclarationNode::StorageClass sc, Expression * bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, Initializer * init ) { 783 711 if ( td->kind == TypeData::Function ) { 784 712 FunctionDecl * decl; … … 790 718 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), body, isInline, isNoreturn ); 791 719 } else { 792 // std::list< Label > ls;793 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), new CompoundStmt( std::list< Label >() ), isInline, isNoreturn );720 // list< Label > ls; 721 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), new CompoundStmt( list< Label >() ), isInline, isNoreturn ); 794 722 } // if 795 723 } else { 796 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), 0, isInline, isNoreturn );797 } // if 798 for ( DeclarationNode * cur = td->function.idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {799 if ( cur-> get_name() != "") {800 decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name());724 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), nullptr, isInline, isNoreturn ); 725 } // if 726 for ( DeclarationNode * cur = td->function.idList; cur != nullptr; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) { 727 if ( cur->name ) { 728 decl->get_oldIdents().insert( decl->get_oldIdents().end(), *cur->name ); 801 729 } // if 802 730 } // for … … 809 737 } else if ( td->kind == TypeData::Symbolic ) { 810 738 return buildSymbolic( td, name, sc ); 811 } else if ( td->kind == TypeData::Variable ) {812 assert( false );813 return buildVariable( td );814 739 } else { 815 return new ObjectDecl( name, sc, linkage, bitfieldWidth, typebuild( td ), init, std::list< Attribute * >(), isInline, isNoreturn );740 return new ObjectDecl( name, sc, linkage, bitfieldWidth, typebuild( td ), init, list< Attribute * >(), isInline, isNoreturn ); 816 741 } // if 817 return 0;742 return nullptr; 818 743 } // buildDecl 819 744 … … 831 756 break; 832 757 default: 833 ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( buildDecl( td->base, "", DeclarationNode::NoStorageClass, 0, false, false, LinkageSpec::Cforall ) ) );758 ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( buildDecl( td->base, "", DeclarationNode::NoStorageClass, nullptr, false, false, LinkageSpec::Cforall ) ) ); 834 759 } // switch 835 760 } else { 836 ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0) );761 ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) ); 837 762 } // if 838 763 return ft; -
src/Parser/TypeData.h
r7ae930a r9c23f31 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 12 17:15:49201613 // Update Count : 1 2912 // Last Modified On : Sat Sep 24 11:10:38 2016 13 // Update Count : 141 14 14 // 15 15 … … 24 24 struct TypeData { 25 25 enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst, 26 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr};26 Enum, EnumConstant, Symbolic, SymbolicInst, Tuple, Typeof, Builtin }; 27 27 28 28 struct Aggregate_t { 29 29 DeclarationNode::Aggregate kind; 30 std::stringname;30 const std::string * name; 31 31 DeclarationNode * params; 32 ExpressionNode 32 ExpressionNode * actuals; // holds actual parameters later applied to AggInst 33 33 DeclarationNode * fields; 34 34 bool body; … … 47 47 48 48 struct Enumeration_t { 49 std::stringname;49 const std::string * name; 50 50 DeclarationNode * constants; 51 51 }; … … 61 61 62 62 struct Symbolic_t { 63 std::stringname;63 const std::string * name; 64 64 bool isTypedef; // false => TYPEGENname, true => TYPEDEFname 65 65 DeclarationNode * params; … … 88 88 DeclarationNode * tuple; 89 89 ExpressionNode * typeexpr; 90 // Attr_t attr;91 90 // DeclarationNode::BuiltinType builtin; 92 91 … … 111 110 TupleType * buildTuple( const TypeData * ); 112 111 TypeofType * buildTypeof( const TypeData * ); 113 AttrType * buildAttr( const TypeData * ); 114 Declaration * buildDecl( const TypeData *, std::string, DeclarationNode::StorageClass, Expression *, bool isInline, bool isNoreturn, LinkageSpec::Spec, Initializer * init = 0 ); 112 Declaration * buildDecl( const TypeData *, const std::string &, DeclarationNode::StorageClass, Expression *, bool isInline, bool isNoreturn, LinkageSpec::Spec, Initializer * init = nullptr ); 115 113 FunctionType * buildFunction( const TypeData * ); 116 114 -
src/Parser/parser.h
r7ae930a r9c23f31 262 262 263 263 /* Line 2068 of yacc.c */ 264 #line 11 5"parser.yy"264 #line 116 "parser.yy" 265 265 266 266 Token tok; -
src/Parser/parser.yy
r7ae930a r9c23f31 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 12 17:29:45201613 // Update Count : 19 6912 // Last Modified On : Sat Sep 24 12:16:53 2016 13 // Update Count : 1992 14 14 // 15 15 … … 54 54 #include "TypeData.h" 55 55 #include "LinkageSpec.h" 56 using namespace std; 56 57 57 58 extern DeclarationNode * parseTree; … … 59 60 extern TypedefTable typedefTable; 60 61 61 st d::stack< LinkageSpec::Spec > linkageStack;62 63 void appendStr( st d::string *to, std::string *from ) {62 stack< LinkageSpec::Spec > linkageStack; 63 64 void appendStr( string *to, string *from ) { 64 65 // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string. 65 66 to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) ); … … 359 360 { $$ = $2; } 360 361 | '(' compound_statement ')' // GCC, lambda expression 361 { $$ = new ExpressionNode( build_valexpr( $2 ) ); }362 { $$ = new ExpressionNode( build_valexpr( $2 ) ); } 362 363 ; 363 364 … … 389 390 { 390 391 Token fn; 391 fn.str = new std::string( "?{}" ); 392 fn.str = new std::string( "?{}" ); // location undefined - use location of '{'? 392 393 $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) ); 393 394 } … … 666 667 { 667 668 Token fn; 668 fn.str = new st d::string( "^?{}" );// location undefined669 fn.str = new string( "^?{}" ); // location undefined 669 670 $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) ); 670 671 } … … 896 897 { $$ = new StatementNode( build_catch( $5, $8 ) ); } 897 898 | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop 898 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }899 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); } 899 900 | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 900 901 { $$ = new StatementNode( build_catch( $5, $8 ) ); } … … 968 969 { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); } 969 970 | '[' constant_expression ']' string_literal '(' constant_expression ')' 970 { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }971 { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); } 971 972 ; 972 973 … … 1467 1468 aggregate_name: 1468 1469 aggregate_key '{' field_declaration_list '}' 1469 { $$ = DeclarationNode::newAggregate( $1, 0, 0, $3, true ); }1470 { $$ = DeclarationNode::newAggregate( $1, nullptr, nullptr, $3, true ); } 1470 1471 | aggregate_key no_attr_identifier_or_type_name 1471 1472 { 1472 1473 typedefTable.makeTypedef( *$2 ); 1473 $$ = DeclarationNode::newAggregate( $1, $2, 0, 0, false );1474 $$ = DeclarationNode::newAggregate( $1, $2, nullptr, nullptr, false ); 1474 1475 } 1475 1476 | aggregate_key no_attr_identifier_or_type_name 1476 1477 { typedefTable.makeTypedef( *$2 ); } 1477 1478 '{' field_declaration_list '}' 1478 { $$ = DeclarationNode::newAggregate( $1, $2, 0, $5, true ); }1479 { $$ = DeclarationNode::newAggregate( $1, $2, nullptr, $5, true ); } 1479 1480 | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA 1480 { $$ = DeclarationNode::newAggregate( $1, 0, $3, $6, false ); }1481 { $$ = DeclarationNode::newAggregate( $1, nullptr, $3, $6, false ); } 1481 1482 | aggregate_key typegen_name // CFA, S/R conflict 1482 1483 { $$ = $2; } … … 1559 1560 enum_name: 1560 1561 enum_key '{' enumerator_list comma_opt '}' 1561 { $$ = DeclarationNode::newEnum( 0, $3 ); }1562 { $$ = DeclarationNode::newEnum( nullptr, $3 ); } 1562 1563 | enum_key no_attr_identifier_or_type_name 1563 1564 { … … 2520 2521 abstract_function: 2521 2522 '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2522 { $$ = DeclarationNode::newFunction( 0, 0, $3, 0); }2523 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); } 2523 2524 | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2524 2525 { $$ = $2->addParamList( $6 ); } … … 2589 2590 abstract_parameter_function: 2590 2591 '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2591 { $$ = DeclarationNode::newFunction( 0, 0, $3, 0); }2592 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); } 2592 2593 | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2593 2594 { $$ = $2->addParamList( $6 ); } … … 2793 2794 // empty (void) function return type. 2794 2795 '[' ']' type_specifier 2795 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2796 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2796 2797 | '[' ']' multi_array_dimension type_specifier 2797 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2798 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2798 2799 | multi_array_dimension type_specifier 2799 2800 { $$ = $2->addNewArray( $1 ); } 2800 2801 | '[' ']' new_abstract_ptr 2801 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2802 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2802 2803 | '[' ']' multi_array_dimension new_abstract_ptr 2803 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2804 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2804 2805 | multi_array_dimension new_abstract_ptr 2805 2806 { $$ = $2->addNewArray( $1 ); } … … 2813 2814 new_abstract_function: // CFA 2814 2815 '[' ']' '(' new_parameter_type_list_opt ')' 2815 { $$ = DeclarationNode::newFunction( 0, DeclarationNode::newTuple( 0 ), $4, 0); }2816 { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); } 2816 2817 | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')' 2817 { $$ = DeclarationNode::newFunction( 0, $1, $4, 0); }2818 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 2818 2819 | new_function_return '(' push new_parameter_type_list_opt pop ')' 2819 { $$ = DeclarationNode::newFunction( 0, $1, $4, 0); }2820 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 2820 2821 ; 2821 2822 … … 2852 2853 2853 2854 void yyerror( const char * ) { 2854 std::cout << "Error ";2855 cout << "Error "; 2855 2856 if ( yyfilename ) { 2856 std::cout << "in file " << yyfilename << " ";2857 cout << "in file " << yyfilename << " "; 2857 2858 } // if 2858 std::cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << std::endl;2859 cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << endl; 2859 2860 } 2860 2861
Note: See TracChangeset
for help on using the changeset viewer.