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