Changes in src/Parser/DeclarationNode.cc [45161b4d:1db21619]
- File:
-
- 1 edited
-
src/Parser/DeclarationNode.cc (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r45161b4d r1db21619 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 13 16:53:17 201613 // Update Count : 1 6112 // Last Modified On : Tue Jul 14 14:46:32 2015 13 // Update Count : 126 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" };41 40 42 41 UniqueName DeclarationNode::anonymous( "__anonymous" ); 43 42 44 extern LinkageSpec::Type linkage; // defined in parser.yy43 extern LinkageSpec::Type linkage; /* defined in cfa.y */ 45 44 46 45 DeclarationNode *DeclarationNode::clone() const { … … 55 54 newnode->linkage = linkage; 56 55 return newnode; 57 } // DeclarationNode::clone56 } 58 57 59 58 DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) { … … 117 116 newnode->type->function->newStyle = newStyle; 118 117 newnode->type->function->body = body; 119 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );120 118 121 119 if ( body ) { … … 130 128 131 129 return newnode; 132 } // DeclarationNode::newFunction130 } 133 131 134 132 DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) { … … 137 135 newnode->type->qualifiers.push_back( q ); 138 136 return newnode; 139 } // DeclarationNode::newQualifier137 } 140 138 141 139 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { … … 143 141 newnode->storageClasses.push_back( sc ); 144 142 return newnode; 145 } // DeclarationNode::newStorageClass143 } 146 144 147 145 DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) { … … 150 148 newnode->type->basic->typeSpec.push_back( bt ); 151 149 return newnode; 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 150 } 160 151 161 152 DeclarationNode *DeclarationNode::newModifier( Modifier mod ) { … … 164 155 newnode->type->basic->modifiers.push_back( mod ); 165 156 return newnode; 166 } // DeclarationNode::newModifier157 } 167 158 168 159 DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) { … … 171 162 newnode->type->forall = forall; 172 163 return newnode; 173 } // DeclarationNode::newForall164 } 174 165 175 166 DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) { … … 180 171 newnode->type->symbolic->params = 0; 181 172 return newnode; 182 } // DeclarationNode::newFromTypedef173 } 183 174 184 175 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ) { … … 188 179 newnode->type->aggregate->name = assign_strptr( name ); 189 180 if ( newnode->type->aggregate->name == "" ) { // anonymous aggregate ? 190 newnode->type->aggregate->name = anonymous.newName(); 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() ); 191 189 } // if 192 190 newnode->type->aggregate->actuals = actuals; 193 191 newnode->type->aggregate->fields = fields; 194 192 return newnode; 195 } // DeclarationNode::newAggregate193 } 196 194 197 195 DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) { … … 202 200 if ( newnode->type->enumeration->name == "" ) { // anonymous enumeration ? 203 201 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 be 204 // 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() ); 204 209 } // if 205 210 newnode->type->enumeration->constants = constants; 206 211 return newnode; 207 } // DeclarationNode::newEnum212 } 208 213 209 214 DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) { 210 215 DeclarationNode *newnode = new DeclarationNode; 211 216 newnode->name = assign_strptr( name ); 212 newnode->enumeratorValue = constant; 213 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 214 return newnode; 215 } // DeclarationNode::newEnumConstant 217 // do something with the constant 218 return newnode; 219 } 216 220 217 221 DeclarationNode *DeclarationNode::newName( std::string *name ) { … … 219 223 newnode->name = assign_strptr( name ); 220 224 return newnode; 221 } // DeclarationNode::newName225 } 222 226 223 227 DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) { … … 228 232 newnode->type->symbolic->actuals = params; 229 233 return newnode; 230 } // DeclarationNode::newFromTypeGen234 } 231 235 232 236 DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) { … … 237 241 newnode->type->variable->name = newnode->name; 238 242 return newnode; 239 } // DeclarationNode::newTypeParam240 241 DeclarationNode *DeclarationNode::new Trait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {243 } 244 245 DeclarationNode *DeclarationNode::newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) { 242 246 DeclarationNode *newnode = new DeclarationNode; 243 247 newnode->type = new TypeData( TypeData::Aggregate ); 244 newnode->type->aggregate->kind = Trait;248 newnode->type->aggregate->kind = Context; 245 249 newnode->type->aggregate->params = params; 246 250 newnode->type->aggregate->fields = asserts; 247 251 newnode->type->aggregate->name = assign_strptr( name ); 248 252 return newnode; 249 } // DeclarationNode::newTrait250 251 DeclarationNode *DeclarationNode::new TraitUse( std::string *name, ExpressionNode *params ) {253 } 254 255 DeclarationNode *DeclarationNode::newContextUse( std::string *name, ExpressionNode *params ) { 252 256 DeclarationNode *newnode = new DeclarationNode; 253 257 newnode->type = new TypeData( TypeData::AggregateInst ); 254 258 newnode->type->aggInst->aggregate = new TypeData( TypeData::Aggregate ); 255 newnode->type->aggInst->aggregate->aggregate->kind = Trait;259 newnode->type->aggInst->aggregate->aggregate->kind = Context; 256 260 newnode->type->aggInst->aggregate->aggregate->name = assign_strptr( name ); 257 261 newnode->type->aggInst->params = params; 258 262 return newnode; 259 } // DeclarationNode::newTraitUse263 } 260 264 261 265 DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) { … … 267 271 newnode->type->symbolic->name = newnode->name; 268 272 return newnode; 269 } // DeclarationNode::newTypeDecl273 } 270 274 271 275 DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) { … … 273 277 newnode->type = new TypeData( TypeData::Pointer ); 274 278 return newnode->addQualifiers( qualifiers ); 275 } // DeclarationNode::newPointer279 } 276 280 277 281 DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) { … … 286 290 } // if 287 291 return newnode->addQualifiers( qualifiers ); 288 } // DeclarationNode::newArray292 } 289 293 290 294 DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) { … … 790 794 errors.append( e ); 791 795 } // try 792 cur = dynamic_cast< DeclarationNode *>( cur->get_link() );796 cur = dynamic_cast< DeclarationNode *>( cur->get_link() ); 793 797 } // while 794 798 if ( ! errors.isEmpty() ) { … … 877 881 ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name ); 878 882 break; 879 case DeclarationNode:: Trait:880 ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name );883 case DeclarationNode::Context: 884 ret = new ContextInstType( type->buildQualifiers(), type->aggregate->name ); 881 885 break; 882 886 default:
Note:
See TracChangeset
for help on using the changeset viewer.