| [b87a5ed] | 1 | //
|
|---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
|
|---|
| 3 | //
|
|---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
|---|
| 5 | // file "LICENCE" distributed with Cforall.
|
|---|
| 6 | //
|
|---|
| [974906e2] | 7 | // DeclarationNode.cc --
|
|---|
| [b87a5ed] | 8 | //
|
|---|
| 9 | // Author : Rodolfo G. Esteves
|
|---|
| 10 | // Created On : Sat May 16 12:34:05 2015
|
|---|
| [b38f6da] | 11 | // Last Modified By : Peter A. Buhr
|
|---|
| [4eb3a7c5] | 12 | // Last Modified On : Fri Feb 23 18:25:57 2024
|
|---|
| 13 | // Update Count : 1533
|
|---|
| [b87a5ed] | 14 | //
|
|---|
| 15 |
|
|---|
| [c468150] | 16 | #include "DeclarationNode.h"
|
|---|
| 17 |
|
|---|
| [e3e16bc] | 18 | #include <cassert> // for assert, assertf, strict_dynamic_cast
|
|---|
| [d180746] | 19 | #include <iterator> // for back_insert_iterator
|
|---|
| 20 | #include <list> // for list
|
|---|
| 21 | #include <memory> // for unique_ptr
|
|---|
| 22 | #include <ostream> // for operator<<, ostream, basic_ostream
|
|---|
| 23 | #include <string> // for string, operator+, allocator, char...
|
|---|
| [51b73452] | 24 |
|
|---|
| [bb7422a] | 25 | #include "AST/Attribute.hpp" // for Attribute
|
|---|
| 26 | #include "AST/Copy.hpp" // for shallowCopy
|
|---|
| 27 | #include "AST/Decl.hpp" // for Decl
|
|---|
| 28 | #include "AST/Expr.hpp" // for Expr
|
|---|
| 29 | #include "AST/Print.hpp" // for print
|
|---|
| 30 | #include "AST/Stmt.hpp" // for AsmStmt, DirectiveStmt
|
|---|
| 31 | #include "AST/StorageClasses.hpp" // for Storage::Class
|
|---|
| 32 | #include "AST/Type.hpp" // for Type
|
|---|
| 33 | #include "Common/CodeLocation.h" // for CodeLocation
|
|---|
| 34 | #include "Common/Iterate.hpp" // for reverseIterate
|
|---|
| [d180746] | 35 | #include "Common/SemanticError.h" // for SemanticError
|
|---|
| 36 | #include "Common/UniqueName.h" // for UniqueName
|
|---|
| [5bf685f] | 37 | #include "Common/utility.h" // for copy, spliceBegin
|
|---|
| [c468150] | 38 | #include "Parser/ExpressionNode.h" // for ExpressionNode
|
|---|
| 39 | #include "Parser/InitializerNode.h"// for InitializerNode
|
|---|
| 40 | #include "Parser/StatementNode.h" // for StatementNode
|
|---|
| [d180746] | 41 | #include "TypeData.h" // for TypeData, TypeData::Aggregate_t
|
|---|
| [2f0a0678] | 42 | #include "TypedefTable.h" // for TypedefTable
|
|---|
| [bdd516a] | 43 |
|
|---|
| [de62360d] | 44 | extern TypedefTable typedefTable;
|
|---|
| 45 |
|
|---|
| [51b73452] | 46 | using namespace std;
|
|---|
| 47 |
|
|---|
| 48 | UniqueName DeclarationNode::anonymous( "__anonymous" );
|
|---|
| 49 |
|
|---|
| [bb7422a] | 50 | extern ast::Linkage::Spec linkage; // defined in parser.yy
|
|---|
| [51b73452] | 51 |
|
|---|
| [7d05e7e] | 52 | DeclarationNode::DeclarationNode() :
|
|---|
| [e07caa2] | 53 | linkage( ::linkage ) {
|
|---|
| [2298f728] | 54 |
|
|---|
| [faddbd8] | 55 | // variable.name = nullptr;
|
|---|
| [bb7422a] | 56 | variable.tyClass = ast::TypeDecl::NUMBER_OF_KINDS;
|
|---|
| [28307be] | 57 | variable.assertions = nullptr;
|
|---|
| [67cf18c] | 58 | variable.initializer = nullptr;
|
|---|
| [7d05e7e] | 59 |
|
|---|
| [f6e3e34] | 60 | assert.condition = nullptr;
|
|---|
| 61 | assert.message = nullptr;
|
|---|
| [28307be] | 62 | }
|
|---|
| 63 |
|
|---|
| 64 | DeclarationNode::~DeclarationNode() {
|
|---|
| [4c0b674] | 65 | delete name;
|
|---|
| 66 |
|
|---|
| [faddbd8] | 67 | // delete variable.name;
|
|---|
| [2298f728] | 68 | delete variable.assertions;
|
|---|
| [67cf18c] | 69 | delete variable.initializer;
|
|---|
| [2298f728] | 70 |
|
|---|
| [702e826] | 71 | // delete type;
|
|---|
| [28307be] | 72 | delete bitfieldWidth;
|
|---|
| [e994912] | 73 |
|
|---|
| 74 | delete asmStmt;
|
|---|
| [58dd019] | 75 | // asmName, no delete, passed to next stage
|
|---|
| [28307be] | 76 | delete initializer;
|
|---|
| [f6e3e34] | 77 |
|
|---|
| 78 | delete assert.condition;
|
|---|
| 79 | delete assert.message;
|
|---|
| [28307be] | 80 | }
|
|---|
| 81 |
|
|---|
| [ba7aa2d] | 82 | DeclarationNode * DeclarationNode::clone() const {
|
|---|
| 83 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [44adf1b] | 84 | newnode->next = maybeCopy( next );
|
|---|
| [2298f728] | 85 | newnode->name = name ? new string( *name ) : nullptr;
|
|---|
| [c0aa336] | 86 |
|
|---|
| [5bf685f] | 87 | newnode->type = maybeCopy( type );
|
|---|
| [679e644] | 88 | newnode->inLine = inLine;
|
|---|
| [a7c90d4] | 89 | newnode->storageClasses = storageClasses;
|
|---|
| 90 | newnode->funcSpecs = funcSpecs;
|
|---|
| [5bf685f] | 91 | newnode->bitfieldWidth = maybeCopy( bitfieldWidth );
|
|---|
| 92 | newnode->enumeratorValue.reset( maybeCopy( enumeratorValue.get() ) );
|
|---|
| [b87a5ed] | 93 | newnode->hasEllipsis = hasEllipsis;
|
|---|
| 94 | newnode->linkage = linkage;
|
|---|
| [bb7422a] | 95 | newnode->asmName = maybeCopy( asmName );
|
|---|
| 96 | newnode->attributes = attributes;
|
|---|
| [5bf685f] | 97 | newnode->initializer = maybeCopy( initializer );
|
|---|
| [c0aa336] | 98 | newnode->extension = extension;
|
|---|
| [5bf685f] | 99 | newnode->asmStmt = maybeCopy( asmStmt );
|
|---|
| [c0aa336] | 100 | newnode->error = error;
|
|---|
| [3848e0e] | 101 |
|
|---|
| [faddbd8] | 102 | // newnode->variable.name = variable.name ? new string( *variable.name ) : nullptr;
|
|---|
| [28307be] | 103 | newnode->variable.tyClass = variable.tyClass;
|
|---|
| [5bf685f] | 104 | newnode->variable.assertions = maybeCopy( variable.assertions );
|
|---|
| 105 | newnode->variable.initializer = maybeCopy( variable.initializer );
|
|---|
| [3848e0e] | 106 |
|
|---|
| [5bf685f] | 107 | newnode->assert.condition = maybeCopy( assert.condition );
|
|---|
| [bb7422a] | 108 | newnode->assert.message = maybeCopy( assert.message );
|
|---|
| [28307be] | 109 | return newnode;
|
|---|
| 110 | } // DeclarationNode::clone
|
|---|
| [3848e0e] | 111 |
|
|---|
| [f2f512ba] | 112 | void DeclarationNode::print( std::ostream & os, int indent ) const {
|
|---|
| [59db689] | 113 | os << string( indent, ' ' );
|
|---|
| [2298f728] | 114 | if ( name ) {
|
|---|
| 115 | os << *name << ": ";
|
|---|
| [68cd1ce] | 116 | } // if
|
|---|
| [51b73452] | 117 |
|
|---|
| [bb7422a] | 118 | if ( linkage != ast::Linkage::Cforall ) {
|
|---|
| 119 | os << ast::Linkage::name( linkage ) << " ";
|
|---|
| [68cd1ce] | 120 | } // if
|
|---|
| [3848e0e] | 121 |
|
|---|
| [bb7422a] | 122 | ast::print( os, storageClasses );
|
|---|
| 123 | ast::print( os, funcSpecs );
|
|---|
| [dd020c0] | 124 |
|
|---|
| [b87a5ed] | 125 | if ( type ) {
|
|---|
| 126 | type->print( os, indent );
|
|---|
| 127 | } else {
|
|---|
| 128 | os << "untyped entity ";
|
|---|
| [68cd1ce] | 129 | } // if
|
|---|
| [3848e0e] | 130 |
|
|---|
| [b87a5ed] | 131 | if ( bitfieldWidth ) {
|
|---|
| [59db689] | 132 | os << endl << string( indent + 2, ' ' ) << "with bitfield width ";
|
|---|
| [b87a5ed] | 133 | bitfieldWidth->printOneLine( os );
|
|---|
| [68cd1ce] | 134 | } // if
|
|---|
| [3848e0e] | 135 |
|
|---|
| [2298f728] | 136 | if ( initializer ) {
|
|---|
| [59db689] | 137 | os << endl << string( indent + 2, ' ' ) << "with initializer ";
|
|---|
| [b87a5ed] | 138 | initializer->printOneLine( os );
|
|---|
| [974906e2] | 139 | os << " maybe constructed? " << initializer->get_maybeConstructed();
|
|---|
| [68cd1ce] | 140 | } // if
|
|---|
| [3848e0e] | 141 |
|
|---|
| [692c1cc] | 142 | if ( ! attributes.empty() ) {
|
|---|
| [4eb3a7c5] | 143 | os << string( indent + 2, ' ' ) << "with attributes" << endl;
|
|---|
| [bb7422a] | 144 | for ( ast::ptr<ast::Attribute> const & attr : reverseIterate( attributes ) ) {
|
|---|
| [4eb3a7c5] | 145 | os << string( indent + 4, ' ' );
|
|---|
| 146 | ast::print( os, attr, indent + 2 );
|
|---|
| [692c1cc] | 147 | } // for
|
|---|
| 148 | } // if
|
|---|
| [66406f3] | 149 |
|
|---|
| [b87a5ed] | 150 | os << endl;
|
|---|
| [51b73452] | 151 | }
|
|---|
| 152 |
|
|---|
| [f2f512ba] | 153 | void DeclarationNode::printList( std::ostream & os, int indent ) const {
|
|---|
| [dc3fbe5] | 154 | ParseList::printList( os, indent );
|
|---|
| [b87a5ed] | 155 | if ( hasEllipsis ) {
|
|---|
| 156 | os << string( indent, ' ' ) << "and a variable number of other arguments" << endl;
|
|---|
| [68cd1ce] | 157 | } // if
|
|---|
| [51b73452] | 158 | }
|
|---|
| 159 |
|
|---|
| [6cef439] | 160 | DeclarationNode * DeclarationNode::newFromTypeData( TypeData * type ) {
|
|---|
| 161 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| 162 | newnode->type = type;
|
|---|
| 163 | return newnode;
|
|---|
| 164 | } // DeclarationNode::newFromTypeData
|
|---|
| 165 |
|
|---|
| [bb7422a] | 166 | DeclarationNode * DeclarationNode::newStorageClass( ast::Storage::Classes sc ) {
|
|---|
| [ba7aa2d] | 167 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [08d5507b] | 168 | newnode->storageClasses = sc;
|
|---|
| [b87a5ed] | 169 | return newnode;
|
|---|
| [dd020c0] | 170 | } // DeclarationNode::newStorageClass
|
|---|
| [3848e0e] | 171 |
|
|---|
| [bb7422a] | 172 | DeclarationNode * DeclarationNode::newFuncSpecifier( ast::Function::Specs fs ) {
|
|---|
| [ba7aa2d] | 173 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [08d5507b] | 174 | newnode->funcSpecs = fs;
|
|---|
| [c1c1112] | 175 | return newnode;
|
|---|
| [dd020c0] | 176 | } // DeclarationNode::newFuncSpecifier
|
|---|
| [c1c1112] | 177 |
|
|---|
| [bb7422a] | 178 | DeclarationNode * DeclarationNode::newAggregate( ast::AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
|
|---|
| [ba7aa2d] | 179 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [b87a5ed] | 180 | newnode->type = new TypeData( TypeData::Aggregate );
|
|---|
| [8f6f47d7] | 181 | newnode->type->aggregate.kind = kind;
|
|---|
| [692c1cc] | 182 | newnode->type->aggregate.anon = name == nullptr;
|
|---|
| 183 | newnode->type->aggregate.name = newnode->type->aggregate.anon ? new string( DeclarationNode::anonymous.newName() ) : name;
|
|---|
| [8f6f47d7] | 184 | newnode->type->aggregate.actuals = actuals;
|
|---|
| 185 | newnode->type->aggregate.fields = fields;
|
|---|
| 186 | newnode->type->aggregate.body = body;
|
|---|
| [6ea87486] | 187 | newnode->type->aggregate.tagged = false;
|
|---|
| 188 | newnode->type->aggregate.parent = nullptr;
|
|---|
| [b87a5ed] | 189 | return newnode;
|
|---|
| [984dce6] | 190 | } // DeclarationNode::newAggregate
|
|---|
| [3848e0e] | 191 |
|
|---|
| [e4d7c1c] | 192 | DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base, EnumHiding hiding ) {
|
|---|
| [ba7aa2d] | 193 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [b87a5ed] | 194 | newnode->type = new TypeData( TypeData::Enum );
|
|---|
| [692c1cc] | 195 | newnode->type->enumeration.anon = name == nullptr;
|
|---|
| 196 | newnode->type->enumeration.name = newnode->type->enumeration.anon ? new string( DeclarationNode::anonymous.newName() ) : name;
|
|---|
| [8f6f47d7] | 197 | newnode->type->enumeration.constants = constants;
|
|---|
| [ca1a547] | 198 | newnode->type->enumeration.body = body;
|
|---|
| [b0d9ff7] | 199 | newnode->type->enumeration.typed = typed;
|
|---|
| [e4d7c1c] | 200 | newnode->type->enumeration.hiding = hiding;
|
|---|
| [78e2fca] | 201 | if ( base && base->type ) {
|
|---|
| [ed9a1ae] | 202 | newnode->type->base = base->type;
|
|---|
| [9e7236f4] | 203 | } // if
|
|---|
| 204 |
|
|---|
| [b87a5ed] | 205 | return newnode;
|
|---|
| [984dce6] | 206 | } // DeclarationNode::newEnum
|
|---|
| [3848e0e] | 207 |
|
|---|
| [a46b69c] | 208 | DeclarationNode * DeclarationNode::newName( const string * name ) {
|
|---|
| [ba7aa2d] | 209 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [a46b69c] | 210 | assert( ! newnode->name );
|
|---|
| [2298f728] | 211 | newnode->name = name;
|
|---|
| [a46b69c] | 212 | return newnode;
|
|---|
| 213 | } // DeclarationNode::newName
|
|---|
| 214 |
|
|---|
| [374cb117] | 215 | DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) {
|
|---|
| [a46b69c] | 216 | DeclarationNode * newnode = newName( name );
|
|---|
| [4f147cc] | 217 | newnode->enumeratorValue.reset( constant );
|
|---|
| [b87a5ed] | 218 | return newnode;
|
|---|
| [984dce6] | 219 | } // DeclarationNode::newEnumConstant
|
|---|
| [3848e0e] | 220 |
|
|---|
| [374cb117] | 221 | DeclarationNode * DeclarationNode::newEnumValueGeneric( const string * name, InitializerNode * init ) {
|
|---|
| [b0d9ff7] | 222 | if ( init ) {
|
|---|
| 223 | if ( init->get_expression() ) {
|
|---|
| [374cb117] | 224 | return newEnumConstant( name, init->get_expression() );
|
|---|
| [b0d9ff7] | 225 | } else {
|
|---|
| [374cb117] | 226 | DeclarationNode * newnode = newName( name );
|
|---|
| 227 | newnode->initializer = init;
|
|---|
| 228 | return newnode;
|
|---|
| 229 | } // if
|
|---|
| 230 | } else {
|
|---|
| [b0d9ff7] | 231 | return newName( name );
|
|---|
| [374cb117] | 232 | } // if
|
|---|
| [9e7236f4] | 233 | } // DeclarationNode::newEnumValueGeneric
|
|---|
| [374cb117] | 234 |
|
|---|
| [1e30df7] | 235 | DeclarationNode * DeclarationNode::newEnumInLine( const string name ) {
|
|---|
| 236 | DeclarationNode * newnode = newName( new std::string(name) );
|
|---|
| 237 | newnode->enumInLine = true;
|
|---|
| 238 | return newnode;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| [bb7422a] | 241 | DeclarationNode * DeclarationNode::newTypeParam( ast::TypeDecl::Kind tc, const string * name ) {
|
|---|
| [a46b69c] | 242 | DeclarationNode * newnode = newName( name );
|
|---|
| [2298f728] | 243 | newnode->type = nullptr;
|
|---|
| [28307be] | 244 | newnode->variable.tyClass = tc;
|
|---|
| [faddbd8] | 245 | newnode->variable.assertions = nullptr;
|
|---|
| [b87a5ed] | 246 | return newnode;
|
|---|
| [984dce6] | 247 | } // DeclarationNode::newTypeParam
|
|---|
| [3848e0e] | 248 |
|
|---|
| [fb114fa1] | 249 | DeclarationNode * DeclarationNode::newTrait( const string * name, DeclarationNode * params, DeclarationNode * asserts ) {
|
|---|
| [ba7aa2d] | 250 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [b87a5ed] | 251 | newnode->type = new TypeData( TypeData::Aggregate );
|
|---|
| [2298f728] | 252 | newnode->type->aggregate.name = name;
|
|---|
| [bb7422a] | 253 | newnode->type->aggregate.kind = ast::AggregateDecl::Trait;
|
|---|
| [8f6f47d7] | 254 | newnode->type->aggregate.params = params;
|
|---|
| 255 | newnode->type->aggregate.fields = asserts;
|
|---|
| [b87a5ed] | 256 | return newnode;
|
|---|
| [984dce6] | 257 | } // DeclarationNode::newTrait
|
|---|
| [3848e0e] | 258 |
|
|---|
| [fb114fa1] | 259 | DeclarationNode * DeclarationNode::newTraitUse( const string * name, ExpressionNode * params ) {
|
|---|
| [ba7aa2d] | 260 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [b87a5ed] | 261 | newnode->type = new TypeData( TypeData::AggregateInst );
|
|---|
| [8f6f47d7] | 262 | newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
|
|---|
| [bb7422a] | 263 | newnode->type->aggInst.aggregate->aggregate.kind = ast::AggregateDecl::Trait;
|
|---|
| [2298f728] | 264 | newnode->type->aggInst.aggregate->aggregate.name = name;
|
|---|
| [8f6f47d7] | 265 | newnode->type->aggInst.params = params;
|
|---|
| [b87a5ed] | 266 | return newnode;
|
|---|
| [984dce6] | 267 | } // DeclarationNode::newTraitUse
|
|---|
| [3848e0e] | 268 |
|
|---|
| [25bca42] | 269 | DeclarationNode * DeclarationNode::newTypeDecl( const string * name, DeclarationNode * typeParams ) {
|
|---|
| [a46b69c] | 270 | DeclarationNode * newnode = newName( name );
|
|---|
| [b87a5ed] | 271 | newnode->type = new TypeData( TypeData::Symbolic );
|
|---|
| [8f6f47d7] | 272 | newnode->type->symbolic.isTypedef = false;
|
|---|
| 273 | newnode->type->symbolic.params = typeParams;
|
|---|
| [b87a5ed] | 274 | return newnode;
|
|---|
| [984dce6] | 275 | } // DeclarationNode::newTypeDecl
|
|---|
| [3848e0e] | 276 |
|
|---|
| [ce8c12f] | 277 | DeclarationNode * DeclarationNode::newPointer( DeclarationNode * qualifiers, OperKinds kind ) {
|
|---|
| [ba7aa2d] | 278 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [ce8c12f] | 279 | newnode->type = new TypeData( kind == OperKinds::PointTo ? TypeData::Pointer : TypeData::Reference );
|
|---|
| [71d0eab] | 280 | if ( kind == OperKinds::And ) {
|
|---|
| 281 | // T && is parsed as 'And' operator rather than two references => add a second reference type
|
|---|
| 282 | TypeData * td = new TypeData( TypeData::Reference );
|
|---|
| 283 | td->base = newnode->type;
|
|---|
| 284 | newnode->type = td;
|
|---|
| 285 | }
|
|---|
| [c3396e0] | 286 | if ( qualifiers ) {
|
|---|
| 287 | return newnode->addQualifiers( qualifiers );
|
|---|
| 288 | } else {
|
|---|
| 289 | return newnode;
|
|---|
| 290 | } // if
|
|---|
| [984dce6] | 291 | } // DeclarationNode::newPointer
|
|---|
| [3848e0e] | 292 |
|
|---|
| [ba7aa2d] | 293 | DeclarationNode * DeclarationNode::newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic ) {
|
|---|
| 294 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [b87a5ed] | 295 | newnode->type = new TypeData( TypeData::Array );
|
|---|
| [8f6f47d7] | 296 | newnode->type->array.dimension = size;
|
|---|
| 297 | newnode->type->array.isStatic = isStatic;
|
|---|
| [a3525c4] | 298 | newnode->type->array.isVarLen = size && !size->isExpressionType<ast::ConstantExpr *>();
|
|---|
| [b87a5ed] | 299 | return newnode->addQualifiers( qualifiers );
|
|---|
| [984dce6] | 300 | } // DeclarationNode::newArray
|
|---|
| [3848e0e] | 301 |
|
|---|
| [ba7aa2d] | 302 | DeclarationNode * DeclarationNode::newVarArray( DeclarationNode * qualifiers ) {
|
|---|
| 303 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [b87a5ed] | 304 | newnode->type = new TypeData( TypeData::Array );
|
|---|
| [2298f728] | 305 | newnode->type->array.dimension = nullptr;
|
|---|
| [8f6f47d7] | 306 | newnode->type->array.isStatic = false;
|
|---|
| 307 | newnode->type->array.isVarLen = true;
|
|---|
| [b87a5ed] | 308 | return newnode->addQualifiers( qualifiers );
|
|---|
| [3848e0e] | 309 | }
|
|---|
| 310 |
|
|---|
| [ba7aa2d] | 311 | DeclarationNode * DeclarationNode::newBitfield( ExpressionNode * size ) {
|
|---|
| 312 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [b87a5ed] | 313 | newnode->bitfieldWidth = size;
|
|---|
| 314 | return newnode;
|
|---|
| [3848e0e] | 315 | }
|
|---|
| 316 |
|
|---|
| [ba7aa2d] | 317 | DeclarationNode * DeclarationNode::newTuple( DeclarationNode * members ) {
|
|---|
| 318 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [b87a5ed] | 319 | newnode->type = new TypeData( TypeData::Tuple );
|
|---|
| [8f6f47d7] | 320 | newnode->type->tuple = members;
|
|---|
| [b87a5ed] | 321 | return newnode;
|
|---|
| [3848e0e] | 322 | }
|
|---|
| 323 |
|
|---|
| [f855545] | 324 | DeclarationNode * DeclarationNode::newTypeof( ExpressionNode * expr, bool basetypeof ) {
|
|---|
| [ba7aa2d] | 325 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [f855545] | 326 | newnode->type = new TypeData( basetypeof ? TypeData::Basetypeof : TypeData::Typeof );
|
|---|
| [8f6f47d7] | 327 | newnode->type->typeexpr = expr;
|
|---|
| [b87a5ed] | 328 | return newnode;
|
|---|
| [3848e0e] | 329 | }
|
|---|
| 330 |
|
|---|
| [a46b69c] | 331 | DeclarationNode * DeclarationNode::newFunction( const string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ) {
|
|---|
| 332 | DeclarationNode * newnode = newName( name );
|
|---|
| 333 | newnode->type = new TypeData( TypeData::Function );
|
|---|
| 334 | newnode->type->function.params = param;
|
|---|
| 335 | newnode->type->function.body = body;
|
|---|
| 336 |
|
|---|
| 337 | if ( ret ) {
|
|---|
| 338 | newnode->type->base = ret->type;
|
|---|
| 339 | ret->type = nullptr;
|
|---|
| 340 | delete ret;
|
|---|
| 341 | } // if
|
|---|
| 342 |
|
|---|
| 343 | return newnode;
|
|---|
| 344 | } // DeclarationNode::newFunction
|
|---|
| 345 |
|
|---|
| [25bca42] | 346 | DeclarationNode * DeclarationNode::newAttribute( const string * name, ExpressionNode * expr ) {
|
|---|
| [44a81853] | 347 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| 348 | newnode->type = nullptr;
|
|---|
| [bb7422a] | 349 | std::vector<ast::ptr<ast::Expr>> exprs;
|
|---|
| [44a81853] | 350 | buildList( expr, exprs );
|
|---|
| [b38f6da] | 351 | newnode->attributes.push_back( new ast::Attribute( *name, std::move( exprs ) ) );
|
|---|
| [44a81853] | 352 | delete name;
|
|---|
| 353 | return newnode;
|
|---|
| 354 | }
|
|---|
| 355 |
|
|---|
| [2d019af] | 356 | DeclarationNode * DeclarationNode::newDirectiveStmt( StatementNode * stmt ) {
|
|---|
| 357 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| 358 | newnode->directiveStmt = stmt;
|
|---|
| 359 | return newnode;
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| [e994912] | 362 | DeclarationNode * DeclarationNode::newAsmStmt( StatementNode * stmt ) {
|
|---|
| 363 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| 364 | newnode->asmStmt = stmt;
|
|---|
| 365 | return newnode;
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| [bb7422a] | 368 | DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, ast::Expr * message ) {
|
|---|
| [f6e3e34] | 369 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| 370 | newnode->assert.condition = condition;
|
|---|
| 371 | newnode->assert.message = message;
|
|---|
| 372 | return newnode;
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| [bb7422a] | 375 | static void appendError( string & dst, const string & src ) {
|
|---|
| [5b639ee] | 376 | if ( src.empty() ) return;
|
|---|
| 377 | if ( dst.empty() ) { dst = src; return; }
|
|---|
| 378 | dst += ", " + src;
|
|---|
| 379 | } // appendError
|
|---|
| 380 |
|
|---|
| [ba7aa2d] | 381 | void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) {
|
|---|
| [bb7422a] | 382 | const ast::CV::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
|
|---|
| 383 | const ast::CV::Qualifiers duplicates = qsrc & qdst;
|
|---|
| 384 |
|
|---|
| 385 | if ( duplicates.any() ) {
|
|---|
| 386 | std::stringstream str;
|
|---|
| 387 | str << "duplicate ";
|
|---|
| 388 | ast::print( str, duplicates );
|
|---|
| 389 | str << "qualifier(s)";
|
|---|
| 390 | appendError( error, str.str() );
|
|---|
| [a7c90d4] | 391 | } // for
|
|---|
| [c1c1112] | 392 | } // DeclarationNode::checkQualifiers
|
|---|
| 393 |
|
|---|
| [a7c90d4] | 394 | void DeclarationNode::checkSpecifiers( DeclarationNode * src ) {
|
|---|
| [bb7422a] | 395 | ast::Function::Specs fsDups = funcSpecs & src->funcSpecs;
|
|---|
| 396 | if ( fsDups.any() ) {
|
|---|
| 397 | std::stringstream str;
|
|---|
| 398 | str << "duplicate ";
|
|---|
| 399 | ast::print( str, fsDups );
|
|---|
| 400 | str << "function specifier(s)";
|
|---|
| 401 | appendError( error, str.str() );
|
|---|
| [dd020c0] | 402 | } // if
|
|---|
| 403 |
|
|---|
| [bb7422a] | 404 | // Skip if everything is unset.
|
|---|
| 405 | if ( storageClasses.any() && src->storageClasses.any() ) {
|
|---|
| 406 | ast::Storage::Classes dups = storageClasses & src->storageClasses;
|
|---|
| 407 | // Check for duplicates.
|
|---|
| 408 | if ( dups.any() ) {
|
|---|
| 409 | std::stringstream str;
|
|---|
| 410 | str << "duplicate ";
|
|---|
| 411 | ast::print( str, dups );
|
|---|
| 412 | str << "storage class(es)";
|
|---|
| 413 | appendError( error, str.str() );
|
|---|
| 414 | // Check for conflicts.
|
|---|
| 415 | } else if ( !src->storageClasses.is_threadlocal_any() ) {
|
|---|
| 416 | std::stringstream str;
|
|---|
| 417 | str << "conflicting ";
|
|---|
| 418 | ast::print( str, ast::Storage::Classes( 1 << storageClasses.ffs() ) );
|
|---|
| 419 | str << "& ";
|
|---|
| 420 | ast::print( str, ast::Storage::Classes( 1 << src->storageClasses.ffs() ) );
|
|---|
| 421 | str << "storage classes";
|
|---|
| 422 | appendError( error, str.str() );
|
|---|
| 423 | // FIX to preserve invariant of one basic storage specifier
|
|---|
| 424 | src->storageClasses.reset();
|
|---|
| 425 | }
|
|---|
| [b6424d9] | 426 | } // if
|
|---|
| [dd020c0] | 427 |
|
|---|
| [a7c90d4] | 428 | appendError( error, src->error );
|
|---|
| 429 | } // DeclarationNode::checkSpecifiers
|
|---|
| [b6424d9] | 430 |
|
|---|
| [4eb3a7c5] | 431 | DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q, bool copyattr ) {
|
|---|
| [6f95000] | 432 | funcSpecs |= q->funcSpecs;
|
|---|
| 433 | storageClasses |= q->storageClasses;
|
|---|
| [c0aa336] | 434 |
|
|---|
| [4eb3a7c5] | 435 | if ( copyattr ) {
|
|---|
| 436 | std::vector<ast::ptr<ast::Attribute>> tmp;
|
|---|
| 437 | tmp.reserve( q->attributes.size() );
|
|---|
| 438 | for ( auto const & attr : q->attributes ) {
|
|---|
| 439 | tmp.emplace_back( ast::shallowCopy( attr.get() ) );
|
|---|
| 440 | } // for
|
|---|
| 441 | spliceBegin( attributes, tmp );
|
|---|
| 442 | } // if
|
|---|
| [bb7422a] | 443 |
|
|---|
| [b6424d9] | 444 | return this;
|
|---|
| [a7c90d4] | 445 | } // DeclarationNode::copySpecifiers
|
|---|
| [b6424d9] | 446 |
|
|---|
| [ba7aa2d] | 447 | DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) {
|
|---|
| [af9da5f] | 448 | if ( ! q ) { return this; } // empty qualifier
|
|---|
| [101e0bd] | 449 |
|
|---|
| [a7c90d4] | 450 | checkSpecifiers( q );
|
|---|
| 451 | copySpecifiers( q );
|
|---|
| [101e0bd] | 452 |
|
|---|
| [c38ae92] | 453 | if ( ! q->type ) { delete q; return this; }
|
|---|
| [101e0bd] | 454 |
|
|---|
| 455 | if ( ! type ) {
|
|---|
| [c38ae92] | 456 | type = q->type; // reuse structure
|
|---|
| [1b772749] | 457 | q->type = nullptr;
|
|---|
| 458 | delete q;
|
|---|
| [101e0bd] | 459 | return this;
|
|---|
| 460 | } // if
|
|---|
| 461 |
|
|---|
| [a7c90d4] | 462 | checkQualifiers( type, q->type );
|
|---|
| [e048ece] | 463 | TypeData::BuiltinType const builtin = type->builtintype;
|
|---|
| 464 | if ( (builtin == TypeData::Zero || builtin == TypeData::One) && q->type->qualifiers.any() && error.length() == 0 ) {
|
|---|
| 465 | SemanticWarning( yylloc, Warning::BadQualifiersZeroOne, TypeData::builtinTypeNames[builtin] );
|
|---|
| [9dc31c10] | 466 | } // if
|
|---|
| [af60383] | 467 | type = ::addQualifiers( q->type, type );
|
|---|
| 468 | q->type = nullptr;
|
|---|
| [6ef2d81] | 469 |
|
|---|
| [b87a5ed] | 470 | delete q;
|
|---|
| 471 | return this;
|
|---|
| [101e0bd] | 472 | } // addQualifiers
|
|---|
| [3848e0e] | 473 |
|
|---|
| [af60383] | 474 | DeclarationNode * DeclarationNode::addType( DeclarationNode * o, bool copyattr ) {
|
|---|
| 475 | if ( !o ) return this;
|
|---|
| 476 |
|
|---|
| 477 | checkSpecifiers( o );
|
|---|
| 478 | copySpecifiers( o, copyattr );
|
|---|
| 479 | if ( o->type ) {
|
|---|
| 480 | type = ::addType( o->type, type, o->attributes );
|
|---|
| 481 | o->type = nullptr;
|
|---|
| [101e0bd] | 482 | } // if
|
|---|
| [af60383] | 483 | if ( o->bitfieldWidth ) {
|
|---|
| 484 | bitfieldWidth = o->bitfieldWidth;
|
|---|
| [68cd1ce] | 485 | } // if
|
|---|
| [3848e0e] | 486 |
|
|---|
| [af60383] | 487 | // there may be typedefs chained onto the type
|
|---|
| 488 | if ( o->next ) {
|
|---|
| 489 | set_last( o->next->clone() );
|
|---|
| [68cd1ce] | 490 | } // if
|
|---|
| [66406f3] | 491 |
|
|---|
| [af60383] | 492 | delete o;
|
|---|
| [b87a5ed] | 493 | return this;
|
|---|
| [3848e0e] | 494 | }
|
|---|
| 495 |
|
|---|
| [f135b50] | 496 | DeclarationNode * DeclarationNode::addEnumBase( DeclarationNode * o ) {
|
|---|
| [af60383] | 497 | if ( o && o->type ) {
|
|---|
| 498 | type->base = o->type;
|
|---|
| [b38f6da] | 499 | } // if
|
|---|
| [f135b50] | 500 | delete o;
|
|---|
| 501 | return this;
|
|---|
| 502 | }
|
|---|
| 503 |
|
|---|
| [2583407] | 504 | // This code handles a special issue with the attribute transparent_union.
|
|---|
| 505 | //
|
|---|
| 506 | // typedef union U { int i; } typedef_name __attribute__(( aligned(16) )) __attribute__(( transparent_union ))
|
|---|
| 507 | //
|
|---|
| 508 | // Here the attribute aligned goes with the typedef_name, so variables declared of this type are
|
|---|
| 509 | // aligned. However, the attribute transparent_union must be moved from the typedef_name to
|
|---|
| 510 | // alias union U. Currently, this is the only know attribute that must be moved from typedef to
|
|---|
| 511 | // alias.
|
|---|
| 512 | static void moveUnionAttribute( DeclarationNode * decl, DeclarationNode * unionDecl ) {
|
|---|
| 513 | assert( decl->type->kind == TypeData::Symbolic );
|
|---|
| 514 | assert( decl->type->symbolic.isTypedef );
|
|---|
| 515 | assert( unionDecl->type->kind == TypeData::Aggregate );
|
|---|
| 516 |
|
|---|
| 517 | if ( unionDecl->type->aggregate.kind != ast::AggregateDecl::Union ) return;
|
|---|
| 518 |
|
|---|
| 519 | // Ignore the Aggregate_t::attributes. Why did we add that before the rework?
|
|---|
| 520 | for ( auto attr = decl->attributes.begin() ; attr != decl->attributes.end() ; ) {
|
|---|
| 521 | if ( (*attr)->name == "transparent_union" || (*attr)->name == "__transparent_union__" ) {
|
|---|
| 522 | unionDecl->attributes.emplace_back( attr->release() );
|
|---|
| 523 | attr = decl->attributes.erase( attr );
|
|---|
| 524 | } else {
|
|---|
| 525 | ++attr;
|
|---|
| 526 | }
|
|---|
| 527 | }
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 | // Helper for addTypedef, handles the case where the typedef wraps an
|
|---|
| 531 | // aggregate declaration (not a type), returns a chain of nodes.
|
|---|
| 532 | static DeclarationNode * addTypedefAggr(
|
|---|
| 533 | DeclarationNode * olddecl, TypeData * newtype ) {
|
|---|
| 534 | TypeData *& oldaggr = olddecl->type->aggInst.aggregate;
|
|---|
| 535 |
|
|---|
| 536 | // Handle anonymous aggregates: typedef struct { int i; } foo
|
|---|
| 537 | // Give the typedefed type a consistent name across translation units.
|
|---|
| 538 | if ( oldaggr->aggregate.anon ) {
|
|---|
| 539 | delete oldaggr->aggregate.name;
|
|---|
| 540 | oldaggr->aggregate.name = new string( "__anonymous_" + *olddecl->name );
|
|---|
| 541 | oldaggr->aggregate.anon = false;
|
|---|
| 542 | oldaggr->qualifiers.reset();
|
|---|
| 543 | }
|
|---|
| 544 |
|
|---|
| 545 | // Replace the wrapped TypeData with a forward declaration.
|
|---|
| 546 | TypeData * newaggr = new TypeData( TypeData::Aggregate );
|
|---|
| 547 | newaggr->aggregate.kind = oldaggr->aggregate.kind;
|
|---|
| 548 | newaggr->aggregate.name = oldaggr->aggregate.name ? new string( *oldaggr->aggregate.name ) : nullptr;
|
|---|
| 549 | newaggr->aggregate.body = false;
|
|---|
| 550 | newaggr->aggregate.anon = oldaggr->aggregate.anon;
|
|---|
| 551 | newaggr->aggregate.tagged = oldaggr->aggregate.tagged;
|
|---|
| 552 | swap( newaggr, oldaggr );
|
|---|
| 553 |
|
|---|
| 554 | newtype->base = olddecl->type;
|
|---|
| 555 | olddecl->type = newtype;
|
|---|
| 556 | DeclarationNode * newdecl = new DeclarationNode;
|
|---|
| 557 | newdecl->type = newaggr;
|
|---|
| 558 | newdecl->next = olddecl;
|
|---|
| 559 |
|
|---|
| 560 | moveUnionAttribute( olddecl, newdecl );
|
|---|
| 561 |
|
|---|
| 562 | return newdecl;
|
|---|
| 563 | }
|
|---|
| 564 |
|
|---|
| 565 | // Helper for addTypedef, handles the case where the typedef wraps an
|
|---|
| 566 | // enumeration declaration (not a type), returns a chain of nodes.
|
|---|
| 567 | static DeclarationNode * addTypedefEnum(
|
|---|
| 568 | DeclarationNode * olddecl, TypeData * newtype ) {
|
|---|
| 569 | TypeData *& oldenum = olddecl->type->aggInst.aggregate;
|
|---|
| 570 |
|
|---|
| 571 | // Handle anonymous enumeration: typedef enum { A, B, C } foo
|
|---|
| 572 | // Give the typedefed type a consistent name across translation units.
|
|---|
| 573 | if ( oldenum->enumeration.anon ) {
|
|---|
| 574 | delete oldenum->enumeration.name;
|
|---|
| 575 | oldenum->enumeration.name = new string( "__anonymous_" + *olddecl->name );
|
|---|
| 576 | oldenum->enumeration.anon = false;
|
|---|
| 577 | oldenum->qualifiers.reset();
|
|---|
| 578 | }
|
|---|
| 579 |
|
|---|
| 580 | // Replace the wrapped TypeData with a forward declaration.
|
|---|
| 581 | TypeData * newenum = new TypeData( TypeData::Enum );
|
|---|
| 582 | newenum->enumeration.name = oldenum->enumeration.name ? new string( *oldenum->enumeration.name ) : nullptr;
|
|---|
| 583 | newenum->enumeration.body = false;
|
|---|
| 584 | newenum->enumeration.anon = oldenum->enumeration.anon;
|
|---|
| 585 | newenum->enumeration.typed = oldenum->enumeration.typed;
|
|---|
| 586 | newenum->enumeration.hiding = oldenum->enumeration.hiding;
|
|---|
| 587 | swap( newenum, oldenum );
|
|---|
| 588 |
|
|---|
| 589 | newtype->base = olddecl->type;
|
|---|
| 590 | olddecl->type = newtype;
|
|---|
| 591 | DeclarationNode * newdecl = new DeclarationNode;
|
|---|
| 592 | newdecl->type = newenum;
|
|---|
| 593 | newdecl->next = olddecl;
|
|---|
| 594 |
|
|---|
| 595 | return newdecl;
|
|---|
| 596 | }
|
|---|
| 597 |
|
|---|
| [ba7aa2d] | 598 | DeclarationNode * DeclarationNode::addTypedef() {
|
|---|
| 599 | TypeData * newtype = new TypeData( TypeData::Symbolic );
|
|---|
| [2298f728] | 600 | newtype->symbolic.params = nullptr;
|
|---|
| [8f6f47d7] | 601 | newtype->symbolic.isTypedef = true;
|
|---|
| [2298f728] | 602 | newtype->symbolic.name = name ? new string( *name ) : nullptr;
|
|---|
| [2583407] | 603 | // If this typedef is wrapping an aggregate, separate them out.
|
|---|
| 604 | if ( TypeData::AggregateInst == type->kind
|
|---|
| 605 | && TypeData::Aggregate == type->aggInst.aggregate->kind
|
|---|
| 606 | && type->aggInst.aggregate->aggregate.body ) {
|
|---|
| 607 | return addTypedefAggr( this, newtype );
|
|---|
| 608 | // If this typedef is wrapping an enumeration, separate them out.
|
|---|
| 609 | } else if ( TypeData::AggregateInst == type->kind
|
|---|
| 610 | && TypeData::Enum == type->aggInst.aggregate->kind
|
|---|
| 611 | && type->aggInst.aggregate->enumeration.body ) {
|
|---|
| 612 | return addTypedefEnum( this, newtype );
|
|---|
| 613 | // There is no internal declaration, just a type.
|
|---|
| 614 | } else {
|
|---|
| 615 | newtype->base = type;
|
|---|
| 616 | type = newtype;
|
|---|
| 617 | return this;
|
|---|
| 618 | }
|
|---|
| [3848e0e] | 619 | }
|
|---|
| 620 |
|
|---|
| [ba7aa2d] | 621 | DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) {
|
|---|
| [bb7422a] | 622 | if ( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS ) {
|
|---|
| [702e826] | 623 | if ( variable.assertions ) {
|
|---|
| [dc3fbe5] | 624 | variable.assertions->set_last( assertions );
|
|---|
| [702e826] | 625 | } else {
|
|---|
| 626 | variable.assertions = assertions;
|
|---|
| 627 | } // if
|
|---|
| 628 | return this;
|
|---|
| [2298f728] | 629 | } // if
|
|---|
| 630 |
|
|---|
| [b87a5ed] | 631 | assert( type );
|
|---|
| 632 | switch ( type->kind ) {
|
|---|
| [0d0931d] | 633 | case TypeData::Symbolic:
|
|---|
| [8f6f47d7] | 634 | if ( type->symbolic.assertions ) {
|
|---|
| [dc3fbe5] | 635 | type->symbolic.assertions->set_last( assertions );
|
|---|
| [b87a5ed] | 636 | } else {
|
|---|
| [8f6f47d7] | 637 | type->symbolic.assertions = assertions;
|
|---|
| [68cd1ce] | 638 | } // if
|
|---|
| [b87a5ed] | 639 | break;
|
|---|
| [0d0931d] | 640 | default:
|
|---|
| [b87a5ed] | 641 | assert( false );
|
|---|
| [68cd1ce] | 642 | } // switch
|
|---|
| [974906e2] | 643 |
|
|---|
| [b87a5ed] | 644 | return this;
|
|---|
| [51b73452] | 645 | }
|
|---|
| 646 |
|
|---|
| [fb114fa1] | 647 | DeclarationNode * DeclarationNode::addName( string * newname ) {
|
|---|
| [2298f728] | 648 | assert( ! name );
|
|---|
| 649 | name = newname;
|
|---|
| [b87a5ed] | 650 | return this;
|
|---|
| [51b73452] | 651 | }
|
|---|
| 652 |
|
|---|
| [c0aa336] | 653 | DeclarationNode * DeclarationNode::addAsmName( DeclarationNode * newname ) {
|
|---|
| [58dd019] | 654 | assert( ! asmName );
|
|---|
| [c0aa336] | 655 | asmName = newname ? newname->asmName : nullptr;
|
|---|
| 656 | return this->addQualifiers( newname );
|
|---|
| [58dd019] | 657 | }
|
|---|
| 658 |
|
|---|
| [ba7aa2d] | 659 | DeclarationNode * DeclarationNode::addBitfield( ExpressionNode * size ) {
|
|---|
| [b87a5ed] | 660 | bitfieldWidth = size;
|
|---|
| 661 | return this;
|
|---|
| [51b73452] | 662 | }
|
|---|
| 663 |
|
|---|
| [ba7aa2d] | 664 | DeclarationNode * DeclarationNode::addVarArgs() {
|
|---|
| [b87a5ed] | 665 | assert( type );
|
|---|
| 666 | hasEllipsis = true;
|
|---|
| 667 | return this;
|
|---|
| [51b73452] | 668 | }
|
|---|
| 669 |
|
|---|
| [c453ac4] | 670 | DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body, ExpressionNode * withExprs ) {
|
|---|
| [b87a5ed] | 671 | assert( type );
|
|---|
| 672 | assert( type->kind == TypeData::Function );
|
|---|
| [2298f728] | 673 | assert( ! type->function.body );
|
|---|
| [8f6f47d7] | 674 | type->function.body = body;
|
|---|
| [c453ac4] | 675 | type->function.withExprs = withExprs;
|
|---|
| [b87a5ed] | 676 | return this;
|
|---|
| [51b73452] | 677 | }
|
|---|
| 678 |
|
|---|
| [ba7aa2d] | 679 | DeclarationNode * DeclarationNode::addOldDeclList( DeclarationNode * list ) {
|
|---|
| [b87a5ed] | 680 | assert( type );
|
|---|
| 681 | assert( type->kind == TypeData::Function );
|
|---|
| [2298f728] | 682 | assert( ! type->function.oldDeclList );
|
|---|
| [8f6f47d7] | 683 | type->function.oldDeclList = list;
|
|---|
| [b87a5ed] | 684 | return this;
|
|---|
| [51b73452] | 685 | }
|
|---|
| 686 |
|
|---|
| [c0aa336] | 687 | DeclarationNode * DeclarationNode::setBase( TypeData * newType ) {
|
|---|
| [b87a5ed] | 688 | if ( type ) {
|
|---|
| [af60383] | 689 | type->setLastBase( newType );
|
|---|
| [b87a5ed] | 690 | } else {
|
|---|
| 691 | type = newType;
|
|---|
| [68cd1ce] | 692 | } // if
|
|---|
| [c0aa336] | 693 | return this;
|
|---|
| [3848e0e] | 694 | }
|
|---|
| 695 |
|
|---|
| [c0aa336] | 696 | DeclarationNode * DeclarationNode::copyAttribute( DeclarationNode * a ) {
|
|---|
| 697 | if ( a ) {
|
|---|
| [bb7422a] | 698 | spliceBegin( attributes, a->attributes );
|
|---|
| [c0aa336] | 699 | a->attributes.clear();
|
|---|
| 700 | } // if
|
|---|
| 701 | return this;
|
|---|
| 702 | } // copyAttribute
|
|---|
| 703 |
|
|---|
| [ba7aa2d] | 704 | DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) {
|
|---|
| [b87a5ed] | 705 | if ( p ) {
|
|---|
| [6926a6d] | 706 | assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference );
|
|---|
| [c0aa336] | 707 | setBase( p->type );
|
|---|
| [2298f728] | 708 | p->type = nullptr;
|
|---|
| [c0aa336] | 709 | copyAttribute( p );
|
|---|
| [b87a5ed] | 710 | delete p;
|
|---|
| [68cd1ce] | 711 | } // if
|
|---|
| [b87a5ed] | 712 | return this;
|
|---|
| [3848e0e] | 713 | }
|
|---|
| 714 |
|
|---|
| [ba7aa2d] | 715 | DeclarationNode * DeclarationNode::addArray( DeclarationNode * a ) {
|
|---|
| [b87a5ed] | 716 | if ( a ) {
|
|---|
| 717 | assert( a->type->kind == TypeData::Array );
|
|---|
| [c0aa336] | 718 | setBase( a->type );
|
|---|
| [2298f728] | 719 | a->type = nullptr;
|
|---|
| [c0aa336] | 720 | copyAttribute( a );
|
|---|
| [b87a5ed] | 721 | delete a;
|
|---|
| [68cd1ce] | 722 | } // if
|
|---|
| [b87a5ed] | 723 | return this;
|
|---|
| [51b73452] | 724 | }
|
|---|
| 725 |
|
|---|
| [ba7aa2d] | 726 | DeclarationNode * DeclarationNode::addNewPointer( DeclarationNode * p ) {
|
|---|
| [b87a5ed] | 727 | if ( p ) {
|
|---|
| [e6cee92] | 728 | assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference );
|
|---|
| [b87a5ed] | 729 | if ( type ) {
|
|---|
| [af60383] | 730 | p->type->base = makeNewBase( type );
|
|---|
| [2298f728] | 731 | type = nullptr;
|
|---|
| [68cd1ce] | 732 | } // if
|
|---|
| [b87a5ed] | 733 | delete this;
|
|---|
| 734 | return p;
|
|---|
| 735 | } else {
|
|---|
| 736 | return this;
|
|---|
| [68cd1ce] | 737 | } // if
|
|---|
| [51b73452] | 738 | }
|
|---|
| 739 |
|
|---|
| [ba7aa2d] | 740 | DeclarationNode * DeclarationNode::addNewArray( DeclarationNode * a ) {
|
|---|
| [0d0931d] | 741 | if ( ! a ) return this;
|
|---|
| [738e304] | 742 | assert( a->type->kind == TypeData::Array );
|
|---|
| 743 | if ( type ) {
|
|---|
| [af60383] | 744 | a->type->setLastBase( makeNewBase( type ) );
|
|---|
| [738e304] | 745 | type = nullptr;
|
|---|
| [68cd1ce] | 746 | } // if
|
|---|
| [738e304] | 747 | delete this;
|
|---|
| 748 | return a;
|
|---|
| [51b73452] | 749 | }
|
|---|
| [3848e0e] | 750 |
|
|---|
| [ba7aa2d] | 751 | DeclarationNode * DeclarationNode::addParamList( DeclarationNode * params ) {
|
|---|
| 752 | TypeData * ftype = new TypeData( TypeData::Function );
|
|---|
| [8f6f47d7] | 753 | ftype->function.params = params;
|
|---|
| [c0aa336] | 754 | setBase( ftype );
|
|---|
| [b87a5ed] | 755 | return this;
|
|---|
| [3848e0e] | 756 | }
|
|---|
| 757 |
|
|---|
| [ba7aa2d] | 758 | static TypeData * addIdListToType( TypeData * type, DeclarationNode * ids ) {
|
|---|
| [b87a5ed] | 759 | if ( type ) {
|
|---|
| 760 | if ( type->kind != TypeData::Function ) {
|
|---|
| 761 | type->base = addIdListToType( type->base, ids );
|
|---|
| 762 | } else {
|
|---|
| [8f6f47d7] | 763 | type->function.idList = ids;
|
|---|
| [68cd1ce] | 764 | } // if
|
|---|
| [b87a5ed] | 765 | return type;
|
|---|
| [3848e0e] | 766 | } else {
|
|---|
| [ba7aa2d] | 767 | TypeData * newtype = new TypeData( TypeData::Function );
|
|---|
| [8f6f47d7] | 768 | newtype->function.idList = ids;
|
|---|
| [b87a5ed] | 769 | return newtype;
|
|---|
| [68cd1ce] | 770 | } // if
|
|---|
| [2298f728] | 771 | } // addIdListToType
|
|---|
| [974906e2] | 772 |
|
|---|
| [ba7aa2d] | 773 | DeclarationNode * DeclarationNode::addIdList( DeclarationNode * ids ) {
|
|---|
| [b87a5ed] | 774 | type = addIdListToType( type, ids );
|
|---|
| 775 | return this;
|
|---|
| [3848e0e] | 776 | }
|
|---|
| 777 |
|
|---|
| [ba7aa2d] | 778 | DeclarationNode * DeclarationNode::addInitializer( InitializerNode * init ) {
|
|---|
| [b87a5ed] | 779 | initializer = init;
|
|---|
| 780 | return this;
|
|---|
| [3848e0e] | 781 | }
|
|---|
| 782 |
|
|---|
| [67cf18c] | 783 | DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) {
|
|---|
| [bb7422a] | 784 | assertf( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." );
|
|---|
| [67cf18c] | 785 | variable.initializer = init;
|
|---|
| 786 | return this;
|
|---|
| 787 | }
|
|---|
| 788 |
|
|---|
| [a46b69c] | 789 | DeclarationNode * DeclarationNode::cloneType( string * name ) {
|
|---|
| 790 | DeclarationNode * newnode = newName( name );
|
|---|
| [5bf685f] | 791 | newnode->type = maybeCopy( type );
|
|---|
| [a7c90d4] | 792 | newnode->copySpecifiers( this );
|
|---|
| [b87a5ed] | 793 | return newnode;
|
|---|
| [3848e0e] | 794 | }
|
|---|
| 795 |
|
|---|
| [4eb3a7c5] | 796 | DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o, bool copyattr ) {
|
|---|
| [2298f728] | 797 | if ( ! o ) return nullptr;
|
|---|
| [4eb3a7c5] | 798 | o->copySpecifiers( this, copyattr );
|
|---|
| [2298f728] | 799 | if ( type ) {
|
|---|
| [af60383] | 800 | o->type = ::cloneBaseType( type, o->type );
|
|---|
| [68cd1ce] | 801 | } // if
|
|---|
| [b87a5ed] | 802 | return o;
|
|---|
| [51b73452] | 803 | }
|
|---|
| 804 |
|
|---|
| [ba7aa2d] | 805 | DeclarationNode * DeclarationNode::extractAggregate() const {
|
|---|
| [b87a5ed] | 806 | if ( type ) {
|
|---|
| [ba7aa2d] | 807 | TypeData * ret = typeextractAggregate( type );
|
|---|
| [b87a5ed] | 808 | if ( ret ) {
|
|---|
| [ba7aa2d] | 809 | DeclarationNode * newnode = new DeclarationNode;
|
|---|
| [b87a5ed] | 810 | newnode->type = ret;
|
|---|
| [4eb3a7c5] | 811 | if ( ret->kind == TypeData::Aggregate ) {
|
|---|
| 812 | newnode->attributes.swap( ret->aggregate.attributes );
|
|---|
| 813 | } // if
|
|---|
| [b87a5ed] | 814 | return newnode;
|
|---|
| [843054c2] | 815 | } // if
|
|---|
| 816 | } // if
|
|---|
| [2298f728] | 817 | return nullptr;
|
|---|
| [3848e0e] | 818 | }
|
|---|
| 819 |
|
|---|
| [45e753c] | 820 | // Get the non-anonymous name of the instance type of the declaration,
|
|---|
| 821 | // if one exists.
|
|---|
| 822 | static const std::string * getInstTypeOfName( ast::Decl * decl ) {
|
|---|
| 823 | if ( auto dwt = dynamic_cast<ast::DeclWithType *>( decl ) ) {
|
|---|
| 824 | if ( auto aggr = dynamic_cast<ast::BaseInstType const *>( dwt->get_type() ) ) {
|
|---|
| 825 | if ( aggr->name.find("anonymous") == std::string::npos ) {
|
|---|
| 826 | return &aggr->name;
|
|---|
| 827 | }
|
|---|
| 828 | }
|
|---|
| 829 | }
|
|---|
| 830 | return nullptr;
|
|---|
| 831 | }
|
|---|
| 832 |
|
|---|
| [b38f6da] | 833 | void buildList( DeclarationNode * firstNode, std::vector<ast::ptr<ast::Decl>> & outputList ) {
|
|---|
| [a16764a6] | 834 | SemanticErrorException errors;
|
|---|
| [bb7422a] | 835 | std::back_insert_iterator<std::vector<ast::ptr<ast::Decl>>> out( outputList );
|
|---|
| [2298f728] | 836 |
|
|---|
| [dc3fbe5] | 837 | for ( const DeclarationNode * cur = firstNode ; cur ; cur = cur->next ) {
|
|---|
| [b87a5ed] | 838 | try {
|
|---|
| [45e753c] | 839 | bool extracted_named = false;
|
|---|
| [692c1cc] | 840 |
|
|---|
| [ba7aa2d] | 841 | if ( DeclarationNode * extr = cur->extractAggregate() ) {
|
|---|
| [78e2fca] | 842 | assert( cur->type );
|
|---|
| [692c1cc] | 843 |
|
|---|
| [45e753c] | 844 | if ( ast::Decl * decl = extr->build() ) {
|
|---|
| [692c1cc] | 845 | *out++ = decl;
|
|---|
| [3d7e53b] | 846 |
|
|---|
| 847 | // need to remember the cases where a declaration contains an anonymous aggregate definition
|
|---|
| 848 | assert( extr->type );
|
|---|
| 849 | if ( extr->type->kind == TypeData::Aggregate ) {
|
|---|
| [692c1cc] | 850 | // typedef struct { int A } B is the only case?
|
|---|
| [4eb3a7c5] | 851 | extracted_named = ! extr->type->aggregate.anon;
|
|---|
| [3d7e53b] | 852 | } else if ( extr->type->kind == TypeData::Enum ) {
|
|---|
| [692c1cc] | 853 | // typedef enum { A } B is the only case?
|
|---|
| [4eb3a7c5] | 854 | extracted_named = ! extr->type->enumeration.anon;
|
|---|
| [45e753c] | 855 | } else {
|
|---|
| 856 | extracted_named = true;
|
|---|
| [3d7e53b] | 857 | }
|
|---|
| [843054c2] | 858 | } // if
|
|---|
| [f39096c] | 859 | delete extr;
|
|---|
| [843054c2] | 860 | } // if
|
|---|
| [2298f728] | 861 |
|
|---|
| [45e753c] | 862 | if ( ast::Decl * decl = cur->build() ) {
|
|---|
| 863 | if ( "" == decl->name && !cur->get_inLine() ) {
|
|---|
| 864 | // Don't include anonymous declaration for named aggregates,
|
|---|
| 865 | // but do include them for anonymous aggregates, e.g.:
|
|---|
| 866 | // struct S {
|
|---|
| 867 | // struct T { int x; }; // no anonymous member
|
|---|
| 868 | // struct { int y; }; // anonymous member
|
|---|
| 869 | // struct T; // anonymous member
|
|---|
| 870 | // };
|
|---|
| 871 | if ( extracted_named ) {
|
|---|
| 872 | continue;
|
|---|
| 873 | }
|
|---|
| [692c1cc] | 874 |
|
|---|
| [45e753c] | 875 | if ( auto name = getInstTypeOfName( decl ) ) {
|
|---|
| 876 | // Temporary: warn about anonymous member declarations of named types, since
|
|---|
| 877 | // this conflicts with the syntax for the forward declaration of an anonymous type.
|
|---|
| 878 | SemanticWarning( cur->location, Warning::AggrForwardDecl, name->c_str() );
|
|---|
| 879 | }
|
|---|
| [e07caa2] | 880 | } // if
|
|---|
| [45e753c] | 881 | *out++ = decl;
|
|---|
| [843054c2] | 882 | } // if
|
|---|
| [45e753c] | 883 | } catch ( SemanticErrorException & e ) {
|
|---|
| [b87a5ed] | 884 | errors.append( e );
|
|---|
| [843054c2] | 885 | } // try
|
|---|
| [e07caa2] | 886 | } // for
|
|---|
| [2298f728] | 887 |
|
|---|
| [b87a5ed] | 888 | if ( ! errors.isEmpty() ) {
|
|---|
| 889 | throw errors;
|
|---|
| [843054c2] | 890 | } // if
|
|---|
| [2298f728] | 891 | } // buildList
|
|---|
| [3848e0e] | 892 |
|
|---|
| [3d7e53b] | 893 | // currently only builds assertions, function parameters, and return values
|
|---|
| [6611177] | 894 | void buildList( DeclarationNode * firstNode, std::vector<ast::ptr<ast::DeclWithType>> & outputList ) {
|
|---|
| [a16764a6] | 895 | SemanticErrorException errors;
|
|---|
| [bb7422a] | 896 | std::back_insert_iterator<std::vector<ast::ptr<ast::DeclWithType>>> out( outputList );
|
|---|
| [43c89a7] | 897 |
|
|---|
| [dc3fbe5] | 898 | for ( const DeclarationNode * cur = firstNode; cur; cur = cur->next ) {
|
|---|
| [b87a5ed] | 899 | try {
|
|---|
| [bb7422a] | 900 | ast::Decl * decl = cur->build();
|
|---|
| [45e753c] | 901 | assertf( decl, "buildList: build for ast::DeclWithType." );
|
|---|
| [bb7422a] | 902 | if ( ast::DeclWithType * dwt = dynamic_cast<ast::DeclWithType *>( decl ) ) {
|
|---|
| [47498bd] | 903 | dwt->location = cur->location;
|
|---|
| [3ca7ef3] | 904 | *out++ = dwt;
|
|---|
| [bb7422a] | 905 | } else if ( ast::StructDecl * agg = dynamic_cast<ast::StructDecl *>( decl ) ) {
|
|---|
| [3d7e53b] | 906 | // e.g., int foo(struct S) {}
|
|---|
| [bb7422a] | 907 | auto inst = new ast::StructInstType( agg->name );
|
|---|
| 908 | auto obj = new ast::ObjectDecl( cur->location, "", inst );
|
|---|
| 909 | obj->linkage = linkage;
|
|---|
| [3ca7ef3] | 910 | *out++ = obj;
|
|---|
| [47498bd] | 911 | delete agg;
|
|---|
| [bb7422a] | 912 | } else if ( ast::UnionDecl * agg = dynamic_cast<ast::UnionDecl *>( decl ) ) {
|
|---|
| [3d7e53b] | 913 | // e.g., int foo(union U) {}
|
|---|
| [bb7422a] | 914 | auto inst = new ast::UnionInstType( agg->name );
|
|---|
| 915 | auto obj = new ast::ObjectDecl( cur->location,
|
|---|
| 916 | "", inst, nullptr, ast::Storage::Classes(),
|
|---|
| 917 | linkage );
|
|---|
| [3ca7ef3] | 918 | *out++ = obj;
|
|---|
| [bb7422a] | 919 | } else if ( ast::EnumDecl * agg = dynamic_cast<ast::EnumDecl *>( decl ) ) {
|
|---|
| [3d7e53b] | 920 | // e.g., int foo(enum E) {}
|
|---|
| [bb7422a] | 921 | auto inst = new ast::EnumInstType( agg->name );
|
|---|
| 922 | auto obj = new ast::ObjectDecl( cur->location,
|
|---|
| 923 | "",
|
|---|
| 924 | inst,
|
|---|
| 925 | nullptr,
|
|---|
| 926 | ast::Storage::Classes(),
|
|---|
| 927 | linkage
|
|---|
| 928 | );
|
|---|
| [3ca7ef3] | 929 | *out++ = obj;
|
|---|
| [45e753c] | 930 | } else {
|
|---|
| 931 | assertf( false, "buildList: Could not convert to ast::DeclWithType." );
|
|---|
| [843054c2] | 932 | } // if
|
|---|
| [45e753c] | 933 | } catch ( SemanticErrorException & e ) {
|
|---|
| [b87a5ed] | 934 | errors.append( e );
|
|---|
| [843054c2] | 935 | } // try
|
|---|
| [3a5131ed] | 936 | } // for
|
|---|
| 937 |
|
|---|
| [b87a5ed] | 938 | if ( ! errors.isEmpty() ) {
|
|---|
| 939 | throw errors;
|
|---|
| [843054c2] | 940 | } // if
|
|---|
| [2298f728] | 941 | } // buildList
|
|---|
| [3848e0e] | 942 |
|
|---|
| [bb7422a] | 943 | void buildTypeList( const DeclarationNode * firstNode,
|
|---|
| 944 | std::vector<ast::ptr<ast::Type>> & outputList ) {
|
|---|
| [a16764a6] | 945 | SemanticErrorException errors;
|
|---|
| [bb7422a] | 946 | std::back_insert_iterator<std::vector<ast::ptr<ast::Type>>> out( outputList );
|
|---|
| [2298f728] | 947 |
|
|---|
| [dc3fbe5] | 948 | for ( const DeclarationNode * cur = firstNode ; cur ; cur = cur->next ) {
|
|---|
| [b87a5ed] | 949 | try {
|
|---|
| [ba7aa2d] | 950 | * out++ = cur->buildType();
|
|---|
| [45e753c] | 951 | } catch ( SemanticErrorException & e ) {
|
|---|
| [b87a5ed] | 952 | errors.append( e );
|
|---|
| [843054c2] | 953 | } // try
|
|---|
| [45e753c] | 954 | } // for
|
|---|
| [2298f728] | 955 |
|
|---|
| [b87a5ed] | 956 | if ( ! errors.isEmpty() ) {
|
|---|
| 957 | throw errors;
|
|---|
| [843054c2] | 958 | } // if
|
|---|
| [2298f728] | 959 | } // buildTypeList
|
|---|
| [51b73452] | 960 |
|
|---|
| [bb7422a] | 961 | ast::Decl * DeclarationNode::build() const {
|
|---|
| [a16764a6] | 962 | if ( ! error.empty() ) SemanticError( this, error + " in declaration of " );
|
|---|
| [2298f728] | 963 |
|
|---|
| [e994912] | 964 | if ( asmStmt ) {
|
|---|
| [bb7422a] | 965 | auto stmt = strict_dynamic_cast<ast::AsmStmt *>( asmStmt->build() );
|
|---|
| 966 | return new ast::AsmDecl( stmt->location, stmt );
|
|---|
| [e994912] | 967 | } // if
|
|---|
| [2d019af] | 968 | if ( directiveStmt ) {
|
|---|
| [bb7422a] | 969 | auto stmt = strict_dynamic_cast<ast::DirectiveStmt *>( directiveStmt->build() );
|
|---|
| 970 | return new ast::DirectiveDecl( stmt->location, stmt );
|
|---|
| [2d019af] | 971 | } // if
|
|---|
| [e994912] | 972 |
|
|---|
| [bb7422a] | 973 | if ( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS ) {
|
|---|
| [f0ecf9b] | 974 | // otype is internally converted to dtype + otype parameters
|
|---|
| [bb7422a] | 975 | static const ast::TypeDecl::Kind kindMap[] = { ast::TypeDecl::Dtype, ast::TypeDecl::Dtype, ast::TypeDecl::Dtype, ast::TypeDecl::Ftype, ast::TypeDecl::Ttype, ast::TypeDecl::Dimension };
|
|---|
| 976 | static_assert( sizeof(kindMap) / sizeof(kindMap[0]) == ast::TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." );
|
|---|
| [8f60f0b] | 977 | assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
|
|---|
| [bb7422a] | 978 | ast::TypeDecl * ret = new ast::TypeDecl( location,
|
|---|
| 979 | *name,
|
|---|
| 980 | ast::Storage::Classes(),
|
|---|
| 981 | (ast::Type *)nullptr,
|
|---|
| 982 | kindMap[ variable.tyClass ],
|
|---|
| 983 | variable.tyClass == ast::TypeDecl::Otype || variable.tyClass == ast::TypeDecl::DStype,
|
|---|
| 984 | variable.initializer ? variable.initializer->buildType() : nullptr
|
|---|
| 985 | );
|
|---|
| 986 | buildList( variable.assertions, ret->assertions );
|
|---|
| [2298f728] | 987 | return ret;
|
|---|
| 988 | } // if
|
|---|
| 989 |
|
|---|
| [843054c2] | 990 | if ( type ) {
|
|---|
| [dd020c0] | 991 | // Function specifiers can only appear on a function definition/declaration.
|
|---|
| 992 | //
|
|---|
| 993 | // inline _Noreturn int f(); // allowed
|
|---|
| 994 | // inline _Noreturn int g( int i ); // allowed
|
|---|
| 995 | // inline _Noreturn int i; // disallowed
|
|---|
| [fb04321] | 996 | if ( type->kind != TypeData::Function && funcSpecs.any() ) {
|
|---|
| [a16764a6] | 997 | SemanticError( this, "invalid function specifier for " );
|
|---|
| [dd020c0] | 998 | } // if
|
|---|
| [284da8c] | 999 | // Forall qualifier can only appear on a function/aggregate definition/declaration.
|
|---|
| 1000 | //
|
|---|
| 1001 | // forall int f(); // allowed
|
|---|
| 1002 | // forall int g( int i ); // allowed
|
|---|
| 1003 | // forall int i; // disallowed
|
|---|
| 1004 | if ( type->kind != TypeData::Function && type->forall ) {
|
|---|
| 1005 | SemanticError( this, "invalid type qualifier for " );
|
|---|
| 1006 | } // if
|
|---|
| [3ed994e] | 1007 | bool isDelete = initializer && initializer->get_isDelete();
|
|---|
| [bb7422a] | 1008 | ast::Decl * decl = buildDecl(
|
|---|
| 1009 | type,
|
|---|
| 1010 | name ? *name : string( "" ),
|
|---|
| 1011 | storageClasses,
|
|---|
| 1012 | maybeBuild( bitfieldWidth ),
|
|---|
| 1013 | funcSpecs,
|
|---|
| 1014 | linkage,
|
|---|
| 1015 | asmName,
|
|---|
| 1016 | isDelete ? nullptr : maybeBuild( initializer ),
|
|---|
| 1017 | copy( attributes )
|
|---|
| 1018 | )->set_extension( extension );
|
|---|
| [3ed994e] | 1019 | if ( isDelete ) {
|
|---|
| [bb7422a] | 1020 | auto dwt = strict_dynamic_cast<ast::DeclWithType *>( decl );
|
|---|
| [3ed994e] | 1021 | dwt->isDeleted = true;
|
|---|
| 1022 | }
|
|---|
| 1023 | return decl;
|
|---|
| [843054c2] | 1024 | } // if
|
|---|
| [2298f728] | 1025 |
|
|---|
| [f6e3e34] | 1026 | if ( assert.condition ) {
|
|---|
| [bb7422a] | 1027 | auto cond = maybeBuild( assert.condition );
|
|---|
| 1028 | auto msg = strict_dynamic_cast<ast::ConstantExpr *>( maybeCopy( assert.message ) );
|
|---|
| 1029 | return new ast::StaticAssertDecl( location, cond, msg );
|
|---|
| [f6e3e34] | 1030 | }
|
|---|
| 1031 |
|
|---|
| [dd020c0] | 1032 | // SUE's cannot have function specifiers, either
|
|---|
| 1033 | //
|
|---|
| [79aae15] | 1034 | // inline _Noreturn struct S { ... }; // disallowed
|
|---|
| 1035 | // inline _Noreturn enum E { ... }; // disallowed
|
|---|
| [fb04321] | 1036 | if ( funcSpecs.any() ) {
|
|---|
| [a16764a6] | 1037 | SemanticError( this, "invalid function specifier for " );
|
|---|
| [843054c2] | 1038 | } // if
|
|---|
| [e874605] | 1039 | if ( enumInLine ) {
|
|---|
| [bb7422a] | 1040 | return new ast::InlineMemberDecl( location,
|
|---|
| 1041 | *name, (ast::Type*)nullptr, storageClasses, linkage );
|
|---|
| [e874605] | 1042 | } // if
|
|---|
| [dd020c0] | 1043 | assertf( name, "ObjectDecl must a have name\n" );
|
|---|
| [bb7422a] | 1044 | auto ret = new ast::ObjectDecl( location,
|
|---|
| 1045 | *name,
|
|---|
| 1046 | (ast::Type*)nullptr,
|
|---|
| 1047 | maybeBuild( initializer ),
|
|---|
| 1048 | storageClasses,
|
|---|
| 1049 | linkage,
|
|---|
| 1050 | maybeBuild( bitfieldWidth )
|
|---|
| 1051 | );
|
|---|
| 1052 | ret->asmName = asmName;
|
|---|
| 1053 | ret->extension = extension;
|
|---|
| 1054 | return ret;
|
|---|
| [51b73452] | 1055 | }
|
|---|
| 1056 |
|
|---|
| [bb7422a] | 1057 | ast::Type * DeclarationNode::buildType() const {
|
|---|
| [b87a5ed] | 1058 | assert( type );
|
|---|
| [974906e2] | 1059 |
|
|---|
| [b87a5ed] | 1060 | switch ( type->kind ) {
|
|---|
| [0d0931d] | 1061 | case TypeData::Enum:
|
|---|
| 1062 | case TypeData::Aggregate: {
|
|---|
| [bb7422a] | 1063 | ast::BaseInstType * ret =
|
|---|
| 1064 | buildComAggInst( type, copy( attributes ), linkage );
|
|---|
| 1065 | buildList( type->aggregate.actuals, ret->params );
|
|---|
| [0d0931d] | 1066 | return ret;
|
|---|
| 1067 | }
|
|---|
| 1068 | case TypeData::Symbolic: {
|
|---|
| [bb7422a] | 1069 | ast::TypeInstType * ret = new ast::TypeInstType(
|
|---|
| 1070 | *type->symbolic.name,
|
|---|
| 1071 | // This is just a default, the true value is not known yet.
|
|---|
| 1072 | ast::TypeDecl::Dtype,
|
|---|
| 1073 | buildQualifiers( type ),
|
|---|
| 1074 | copy( attributes ) );
|
|---|
| 1075 | buildList( type->symbolic.actuals, ret->params );
|
|---|
| [0d0931d] | 1076 | return ret;
|
|---|
| 1077 | }
|
|---|
| 1078 | default:
|
|---|
| [bb7422a] | 1079 | ast::Type * simpletypes = typebuild( type );
|
|---|
| 1080 | // copy because member is const
|
|---|
| 1081 | simpletypes->attributes = attributes;
|
|---|
| [c0aa336] | 1082 | return simpletypes;
|
|---|
| [b87a5ed] | 1083 | } // switch
|
|---|
| [3848e0e] | 1084 | }
|
|---|
| 1085 |
|
|---|
| [b87a5ed] | 1086 | // Local Variables: //
|
|---|
| 1087 | // tab-width: 4 //
|
|---|
| 1088 | // mode: c++ //
|
|---|
| 1089 | // compile-command: "make install" //
|
|---|
| 1090 | // End: //
|
|---|