Changeset 0f9e4403 for src/Parser/DeclarationNode.cc
- Timestamp:
- Apr 15, 2016, 12:03:11 PM (9 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:
- 29ad0ac
- Parents:
- c5833e8 (diff), 37f0da8 (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
rc5833e8 r0f9e4403 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 14 14:46:32 201513 // Update Count : 1 2612 // Last Modified On : Wed Apr 13 16:53:17 2016 13 // Update Count : 161 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 ) { … … 116 117 newnode->type->function->newStyle = newStyle; 117 118 newnode->type->function->body = body; 119 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 118 120 119 121 if ( body ) { … … 128 130 129 131 return newnode; 130 } 132 } // DeclarationNode::newFunction 131 133 132 134 DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) { … … 135 137 newnode->type->qualifiers.push_back( q ); 136 138 return newnode; 137 } 139 } // DeclarationNode::newQualifier 138 140 139 141 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { … … 141 143 newnode->storageClasses.push_back( sc ); 142 144 return newnode; 143 } 145 } // DeclarationNode::newStorageClass 144 146 145 147 DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) { … … 148 150 newnode->type->basic->typeSpec.push_back( bt ); 149 151 return newnode; 150 } 152 } // DeclarationNode::newBasicType 153 154 DeclarationNode *DeclarationNode::newBuiltinType( BuiltinType bt ) { 155 DeclarationNode *newnode = new DeclarationNode; 156 newnode->type = new TypeData( TypeData::Builtin ); 157 newnode->type->builtin->type = bt; 158 return newnode; 159 } // DeclarationNode::newBuiltinType 151 160 152 161 DeclarationNode *DeclarationNode::newModifier( Modifier mod ) { … … 155 164 newnode->type->basic->modifiers.push_back( mod ); 156 165 return newnode; 157 } 166 } // DeclarationNode::newModifier 158 167 159 168 DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) { … … 162 171 newnode->type->forall = forall; 163 172 return newnode; 164 } 173 } // DeclarationNode::newForall 165 174 166 175 DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) { … … 171 180 newnode->type->symbolic->params = 0; 172 181 return newnode; 173 } 182 } // DeclarationNode::newFromTypedef 174 183 175 184 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ) { … … 179 188 newnode->type->aggregate->name = assign_strptr( name ); 180 189 if ( newnode->type->aggregate->name == "" ) { // anonymous aggregate ? 181 newnode->type->aggregate->name = DeclarationNode::anonymous.newName(); 182 } else { 183 // SKULLDUGGERY: generate a typedef for the aggregate name so that the aggregate does not have to be qualified 184 // by "struct" 185 typedefTable.addToEnclosingScope( newnode->type->aggregate->name, TypedefTable::TD ); 186 DeclarationNode *typedf = new DeclarationNode; 187 typedf->name = newnode->type->aggregate->name; 188 newnode->appendList( typedf->addType( newnode->clone() )->addTypedef() ); 190 newnode->type->aggregate->name = anonymous.newName(); 189 191 } // if 190 192 newnode->type->aggregate->actuals = actuals; 191 193 newnode->type->aggregate->fields = fields; 192 194 return newnode; 193 } 195 } // DeclarationNode::newAggregate 194 196 195 197 DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) { … … 200 202 if ( newnode->type->enumeration->name == "" ) { // anonymous enumeration ? 201 203 newnode->type->enumeration->name = DeclarationNode::anonymous.newName(); 202 } else {203 // SKULLDUGGERY: generate a typedef for the enumeration name so that the enumeration does not have to be204 // qualified by "enum"205 typedefTable.addToEnclosingScope( newnode->type->enumeration->name, TypedefTable::TD );206 DeclarationNode *typedf = new DeclarationNode;207 typedf->name = newnode->type->enumeration->name;208 newnode->appendList( typedf->addType( newnode->clone() )->addTypedef() );209 204 } // if 210 205 newnode->type->enumeration->constants = constants; 211 206 return newnode; 212 } 207 } // DeclarationNode::newEnum 213 208 214 209 DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) { 215 210 DeclarationNode *newnode = new DeclarationNode; 216 211 newnode->name = assign_strptr( name ); 217 // do something with the constant 218 return newnode; 219 } 212 newnode->enumeratorValue = constant; 213 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 214 return newnode; 215 } // DeclarationNode::newEnumConstant 220 216 221 217 DeclarationNode *DeclarationNode::newName( std::string *name ) { … … 223 219 newnode->name = assign_strptr( name ); 224 220 return newnode; 225 } 221 } // DeclarationNode::newName 226 222 227 223 DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) { … … 232 228 newnode->type->symbolic->actuals = params; 233 229 return newnode; 234 } 230 } // DeclarationNode::newFromTypeGen 235 231 236 232 DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) { … … 241 237 newnode->type->variable->name = newnode->name; 242 238 return newnode; 243 } 244 245 DeclarationNode *DeclarationNode::new Context( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {239 } // DeclarationNode::newTypeParam 240 241 DeclarationNode *DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) { 246 242 DeclarationNode *newnode = new DeclarationNode; 247 243 newnode->type = new TypeData( TypeData::Aggregate ); 248 newnode->type->aggregate->kind = Context;244 newnode->type->aggregate->kind = Trait; 249 245 newnode->type->aggregate->params = params; 250 246 newnode->type->aggregate->fields = asserts; 251 247 newnode->type->aggregate->name = assign_strptr( name ); 252 248 return newnode; 253 } 254 255 DeclarationNode *DeclarationNode::new ContextUse( std::string *name, ExpressionNode *params ) {249 } // DeclarationNode::newTrait 250 251 DeclarationNode *DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) { 256 252 DeclarationNode *newnode = new DeclarationNode; 257 253 newnode->type = new TypeData( TypeData::AggregateInst ); 258 254 newnode->type->aggInst->aggregate = new TypeData( TypeData::Aggregate ); 259 newnode->type->aggInst->aggregate->aggregate->kind = Context;255 newnode->type->aggInst->aggregate->aggregate->kind = Trait; 260 256 newnode->type->aggInst->aggregate->aggregate->name = assign_strptr( name ); 261 257 newnode->type->aggInst->params = params; 262 258 return newnode; 263 } 259 } // DeclarationNode::newTraitUse 264 260 265 261 DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) { … … 271 267 newnode->type->symbolic->name = newnode->name; 272 268 return newnode; 273 } 269 } // DeclarationNode::newTypeDecl 274 270 275 271 DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) { … … 277 273 newnode->type = new TypeData( TypeData::Pointer ); 278 274 return newnode->addQualifiers( qualifiers ); 279 } 275 } // DeclarationNode::newPointer 280 276 281 277 DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) { … … 290 286 } // if 291 287 return newnode->addQualifiers( qualifiers ); 292 } 288 } // DeclarationNode::newArray 293 289 294 290 DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) { … … 794 790 errors.append( e ); 795 791 } // try 796 cur = dynamic_cast< 792 cur = dynamic_cast<DeclarationNode *>( cur->get_link() ); 797 793 } // while 798 794 if ( ! errors.isEmpty() ) { … … 881 877 ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name ); 882 878 break; 883 case DeclarationNode:: Context:884 ret = new ContextInstType( type->buildQualifiers(), type->aggregate->name );879 case DeclarationNode::Trait: 880 ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name ); 885 881 break; 886 882 default:
Note:
See TracChangeset
for help on using the changeset viewer.