Changeset 984dce6 for src/Parser/DeclarationNode.cc
- Timestamp:
- Mar 22, 2016, 9:57:47 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, string, with_gc
- Children:
- 94980502
- Parents:
- a752883
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
ra752883 r984dce6 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 17:26:24201613 // Update Count : 1 3412 // Last Modified On : Mon Mar 21 21:04:23 2016 13 // Update Count : 142 14 14 // 15 15 … … 42 42 UniqueName DeclarationNode::anonymous( "__anonymous" ); 43 43 44 extern LinkageSpec::Type linkage; /* defined in cfa.y */44 extern LinkageSpec::Type linkage; // defined in parser.yy 45 45 46 46 DeclarationNode *DeclarationNode::clone() const { … … 55 55 newnode->linkage = linkage; 56 56 return newnode; 57 } 57 } // DeclarationNode::clone 58 58 59 59 DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) { … … 117 117 newnode->type->function->newStyle = newStyle; 118 118 newnode->type->function->body = body; 119 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 119 120 120 121 if ( body ) { … … 129 130 130 131 return newnode; 131 } 132 } // DeclarationNode::newFunction 132 133 133 134 DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) { … … 136 137 newnode->type->qualifiers.push_back( q ); 137 138 return newnode; 138 } 139 } // DeclarationNode::newQualifier 139 140 140 141 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { … … 142 143 newnode->storageClasses.push_back( sc ); 143 144 return newnode; 144 } 145 } // DeclarationNode::newStorageClass 145 146 146 147 DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) { … … 149 150 newnode->type->basic->typeSpec.push_back( bt ); 150 151 return newnode; 151 } 152 } // DeclarationNode::newBasicType 152 153 153 154 DeclarationNode *DeclarationNode::newBuiltinType( BuiltinType bt ) { … … 156 157 newnode->type->builtin->type = bt; 157 158 return newnode; 158 } 159 } // DeclarationNode::newBuiltinType 159 160 160 161 DeclarationNode *DeclarationNode::newModifier( Modifier mod ) { … … 163 164 newnode->type->basic->modifiers.push_back( mod ); 164 165 return newnode; 165 } 166 } // DeclarationNode::newModifier 166 167 167 168 DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) { … … 170 171 newnode->type->forall = forall; 171 172 return newnode; 172 } 173 } // DeclarationNode::newForall 173 174 174 175 DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) { … … 179 180 newnode->type->symbolic->params = 0; 180 181 return newnode; 181 } 182 } // DeclarationNode::newFromTypedef 182 183 183 184 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ) { … … 188 189 if ( newnode->type->aggregate->name == "" ) { // anonymous aggregate ? 189 190 newnode->type->aggregate->name = DeclarationNode::anonymous.newName(); 190 } else { 191 // SKULLDUGGERY: generate a typedef for the aggregate name so that the aggregate does not have to be qualified 192 // by "struct" 191 } else if ( ! typedefTable.exists( newnode->type->aggregate->name ) ) { 192 // SKULLDUGGERY: Generate a typedef for the aggregate name so the aggregate does not have to be qualified by 193 // "struct". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed 194 // if the name is explicitly used. 193 195 typedefTable.addToEnclosingScope( newnode->type->aggregate->name, TypedefTable::TD ); 194 196 DeclarationNode *typedf = new DeclarationNode; … … 199 201 newnode->type->aggregate->fields = fields; 200 202 return newnode; 201 } 203 } // DeclarationNode::newAggregate 202 204 203 205 DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) { … … 208 210 if ( newnode->type->enumeration->name == "" ) { // anonymous enumeration ? 209 211 newnode->type->enumeration->name = DeclarationNode::anonymous.newName(); 210 } else { 211 // SKULLDUGGERY: generate a typedef for the enumeration name so that the enumeration does not have to be 212 // qualified by "enum" 212 } else if ( ! typedefTable.exists( newnode->type->enumeration->name ) ) { 213 // SKULLDUGGERY: Generate a typedef for the enumeration name so the enumeration does not have to be qualified by 214 // "enum". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed if 215 // the name is explicitly used. 213 216 typedefTable.addToEnclosingScope( newnode->type->enumeration->name, TypedefTable::TD ); 214 217 DeclarationNode *typedf = new DeclarationNode; … … 218 221 newnode->type->enumeration->constants = constants; 219 222 return newnode; 220 } 223 } // DeclarationNode::newEnum 221 224 222 225 DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) { … … 224 227 newnode->name = assign_strptr( name ); 225 228 newnode->enumeratorValue = constant; 226 return newnode; 227 } 229 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 230 return newnode; 231 } // DeclarationNode::newEnumConstant 228 232 229 233 DeclarationNode *DeclarationNode::newName( std::string *name ) { … … 231 235 newnode->name = assign_strptr( name ); 232 236 return newnode; 233 } 237 } // DeclarationNode::newName 234 238 235 239 DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) { … … 240 244 newnode->type->symbolic->actuals = params; 241 245 return newnode; 242 } 246 } // DeclarationNode::newFromTypeGen 243 247 244 248 DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) { … … 249 253 newnode->type->variable->name = newnode->name; 250 254 return newnode; 251 } 255 } // DeclarationNode::newTypeParam 252 256 253 257 DeclarationNode *DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) { … … 259 263 newnode->type->aggregate->name = assign_strptr( name ); 260 264 return newnode; 261 } 265 } // DeclarationNode::newTrait 262 266 263 267 DeclarationNode *DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) { … … 269 273 newnode->type->aggInst->params = params; 270 274 return newnode; 271 } 275 } // DeclarationNode::newTraitUse 272 276 273 277 DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) { … … 279 283 newnode->type->symbolic->name = newnode->name; 280 284 return newnode; 281 } 285 } // DeclarationNode::newTypeDecl 282 286 283 287 DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) { … … 285 289 newnode->type = new TypeData( TypeData::Pointer ); 286 290 return newnode->addQualifiers( qualifiers ); 287 } 291 } // DeclarationNode::newPointer 288 292 289 293 DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) { … … 298 302 } // if 299 303 return newnode->addQualifiers( qualifiers ); 300 } 304 } // DeclarationNode::newArray 301 305 302 306 DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) {
Note: See TracChangeset
for help on using the changeset viewer.