Changeset a5a71d0 for src/Parser/DeclarationNode.cc
- Timestamp:
- Apr 6, 2016, 5:11:32 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- eab39cd
- Parents:
- 39786813 (diff), 3aba311 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r39786813 ra5a71d0 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 13:18:02201613 // Update Count : 1 3012 // Last Modified On : Mon Apr 04 17:09:46 2016 13 // Update Count : 142 14 14 // 15 15 … … 34 34 const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "" }; 35 35 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" }; 36 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary" };36 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary", }; 37 37 const char *DeclarationNode::modifierName[] = { "signed", "unsigned", "short", "long" }; 38 38 const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" }; 39 39 const char *DeclarationNode::typeClassName[] = { "type", "dtype", "ftype" }; 40 const char *DeclarationNode::builtinTypeName[] = { "__builtin_va_list" }; 40 41 41 42 UniqueName DeclarationNode::anonymous( "__anonymous" ); 42 43 43 extern LinkageSpec::Type linkage; /* defined in cfa.y */44 extern LinkageSpec::Type linkage; // defined in parser.yy 44 45 45 46 DeclarationNode *DeclarationNode::clone() const { … … 54 55 newnode->linkage = linkage; 55 56 return newnode; 56 } 57 } // DeclarationNode::clone 57 58 58 59 DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) { … … 118 119 newnode->type->function->newStyle = newStyle; 119 120 newnode->type->function->body = body; 121 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 120 122 121 123 if ( body ) { … … 130 132 131 133 return newnode; 132 } 134 } // DeclarationNode::newFunction 133 135 134 136 DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) { … … 137 139 newnode->type->qualifiers.push_back( q ); 138 140 return newnode; 139 } 141 } // DeclarationNode::newQualifier 140 142 141 143 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { … … 143 145 newnode->storageClasses.push_back( sc ); 144 146 return newnode; 145 } 147 } // DeclarationNode::newStorageClass 146 148 147 149 DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) { … … 150 152 newnode->type->basic->typeSpec.push_back( bt ); 151 153 return newnode; 152 } 154 } // DeclarationNode::newBasicType 155 156 DeclarationNode *DeclarationNode::newBuiltinType( BuiltinType bt ) { 157 DeclarationNode *newnode = new DeclarationNode; 158 newnode->type = new TypeData( TypeData::Builtin ); 159 newnode->type->builtin->type = bt; 160 return newnode; 161 } // DeclarationNode::newBuiltinType 153 162 154 163 DeclarationNode *DeclarationNode::newModifier( Modifier mod ) { … … 157 166 newnode->type->basic->modifiers.push_back( mod ); 158 167 return newnode; 159 } 168 } // DeclarationNode::newModifier 160 169 161 170 DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) { … … 164 173 newnode->type->forall = forall; 165 174 return newnode; 166 } 175 } // DeclarationNode::newForall 167 176 168 177 DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) { … … 173 182 newnode->type->symbolic->params = 0; 174 183 return newnode; 175 } 184 } // DeclarationNode::newFromTypedef 176 185 177 186 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ) { … … 182 191 if ( newnode->type->aggregate->name == "" ) { // anonymous aggregate ? 183 192 newnode->type->aggregate->name = DeclarationNode::anonymous.newName(); 184 } else { 185 // SKULLDUGGERY: generate a typedef for the aggregate name so that the aggregate does not have to be qualified 186 // by "struct" 193 } else if ( ! typedefTable.exists( newnode->type->aggregate->name ) ) { 194 // SKULLDUGGERY: Generate a typedef for the aggregate name so the aggregate does not have to be qualified by 195 // "struct". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed 196 // if the name is explicitly used. 187 197 typedefTable.addToEnclosingScope( newnode->type->aggregate->name, TypedefTable::TD ); 188 198 DeclarationNode *typedf = new DeclarationNode; … … 193 203 newnode->type->aggregate->fields = fields; 194 204 return newnode; 195 } 205 } // DeclarationNode::newAggregate 196 206 197 207 DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) { … … 202 212 if ( newnode->type->enumeration->name == "" ) { // anonymous enumeration ? 203 213 newnode->type->enumeration->name = DeclarationNode::anonymous.newName(); 204 } else { 205 // SKULLDUGGERY: generate a typedef for the enumeration name so that the enumeration does not have to be 206 // qualified by "enum" 214 } else if ( ! typedefTable.exists( newnode->type->enumeration->name ) ) { 215 // SKULLDUGGERY: Generate a typedef for the enumeration name so the enumeration does not have to be qualified by 216 // "enum". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed if 217 // the name is explicitly used. 207 218 typedefTable.addToEnclosingScope( newnode->type->enumeration->name, TypedefTable::TD ); 208 219 DeclarationNode *typedf = new DeclarationNode; … … 212 223 newnode->type->enumeration->constants = constants; 213 224 return newnode; 214 } 225 } // DeclarationNode::newEnum 215 226 216 227 DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) { 217 228 DeclarationNode *newnode = new DeclarationNode; 218 229 newnode->name = assign_strptr( name ); 219 // do something with the constant 220 return newnode; 221 } 230 newnode->enumeratorValue = constant; 231 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 232 return newnode; 233 } // DeclarationNode::newEnumConstant 222 234 223 235 DeclarationNode *DeclarationNode::newName( std::string *name ) { … … 225 237 newnode->name = assign_strptr( name ); 226 238 return newnode; 227 } 239 } // DeclarationNode::newName 228 240 229 241 DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) { … … 234 246 newnode->type->symbolic->actuals = params; 235 247 return newnode; 236 } 248 } // DeclarationNode::newFromTypeGen 237 249 238 250 DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) { … … 243 255 newnode->type->variable->name = newnode->name; 244 256 return newnode; 245 } 246 247 DeclarationNode *DeclarationNode::new Context( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {257 } // DeclarationNode::newTypeParam 258 259 DeclarationNode *DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) { 248 260 DeclarationNode *newnode = new DeclarationNode; 249 261 newnode->type = new TypeData( TypeData::Aggregate ); 250 newnode->type->aggregate->kind = Context;262 newnode->type->aggregate->kind = Trait; 251 263 newnode->type->aggregate->params = params; 252 264 newnode->type->aggregate->fields = asserts; 253 265 newnode->type->aggregate->name = assign_strptr( name ); 254 266 return newnode; 255 } 256 257 DeclarationNode *DeclarationNode::new ContextUse( std::string *name, ExpressionNode *params ) {267 } // DeclarationNode::newTrait 268 269 DeclarationNode *DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) { 258 270 DeclarationNode *newnode = new DeclarationNode; 259 271 newnode->type = new TypeData( TypeData::AggregateInst ); 260 272 newnode->type->aggInst->aggregate = new TypeData( TypeData::Aggregate ); 261 newnode->type->aggInst->aggregate->aggregate->kind = Context;273 newnode->type->aggInst->aggregate->aggregate->kind = Trait; 262 274 newnode->type->aggInst->aggregate->aggregate->name = assign_strptr( name ); 263 275 newnode->type->aggInst->params = params; 264 276 return newnode; 265 } 277 } // DeclarationNode::newTraitUse 266 278 267 279 DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) { … … 273 285 newnode->type->symbolic->name = newnode->name; 274 286 return newnode; 275 } 287 } // DeclarationNode::newTypeDecl 276 288 277 289 DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) { … … 279 291 newnode->type = new TypeData( TypeData::Pointer ); 280 292 return newnode->addQualifiers( qualifiers ); 281 } 293 } // DeclarationNode::newPointer 282 294 283 295 DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) { … … 292 304 } // if 293 305 return newnode->addQualifiers( qualifiers ); 294 } 306 } // DeclarationNode::newArray 295 307 296 308 DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) { … … 796 808 errors.append( e ); 797 809 } // try 798 cur = dynamic_cast< 810 cur = dynamic_cast<DeclarationNode *>( cur->get_link() ); 799 811 } // while 800 812 if ( ! errors.isEmpty() ) { … … 883 895 ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name ); 884 896 break; 885 case DeclarationNode:: Context:886 ret = new ContextInstType( type->buildQualifiers(), type->aggregate->name );897 case DeclarationNode::Trait: 898 ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name ); 887 899 break; 888 900 default:
Note: See TracChangeset
for help on using the changeset viewer.