- Timestamp:
- Oct 23, 2020, 9:08:09 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c532847
- Parents:
- 37b7d95 (diff), 3aec25f (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. - Location:
- src
- Files:
-
- 19 edited
-
AST/Expr.cpp (modified) (2 diffs)
-
AST/Expr.hpp (modified) (2 diffs)
-
AST/Type.cpp (modified) (1 diff)
-
AST/Type.hpp (modified) (3 diffs)
-
AST/porting.md (modified) (5 diffs)
-
Concurrency/Keywords.cc (modified) (6 diffs)
-
InitTweak/FixGlobalInit.cc (modified) (1 diff)
-
InitTweak/FixInit.cc (modified) (1 diff)
-
InitTweak/InitTweak.cc (modified) (1 diff)
-
InitTweak/InitTweak.h (modified) (1 diff)
-
Parser/DeclarationNode.cc (modified) (5 diffs)
-
Parser/parser.yy (modified) (5 diffs)
-
SynTree/AggregateDecl.cc (modified) (2 diffs)
-
SynTree/Declaration.h (modified) (1 diff)
-
SynTree/Expression.h (modified) (2 diffs)
-
SynTree/TypeDecl.cc (modified) (2 diffs)
-
Virtual/Tables.cc (modified) (5 diffs)
-
Virtual/Tables.h (modified) (1 diff)
-
main.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Expr.cpp
r37b7d95 re7d6968 102 102 } 103 103 return ret; 104 } 105 106 // --- VariableExpr 107 108 VariableExpr::VariableExpr( const CodeLocation & loc ) 109 : Expr( loc ), var( nullptr ) {} 110 111 VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v ) 112 : Expr( loc ), var( v ) { 113 assert( var ); 114 assert( var->get_type() ); 115 result = shallowCopy( var->get_type() ); 116 } 117 118 bool VariableExpr::get_lvalue() const { 119 // It isn't always an lvalue, but it is never an rvalue. 120 return true; 121 } 122 123 VariableExpr * VariableExpr::functionPointer( 124 const CodeLocation & loc, const FunctionDecl * decl ) { 125 // wrap usually-determined result type in a pointer 126 VariableExpr * funcExpr = new VariableExpr{ loc, decl }; 127 funcExpr->result = new PointerType{ funcExpr->result }; 128 return funcExpr; 104 129 } 105 130 … … 238 263 } 239 264 240 // --- VariableExpr241 242 VariableExpr::VariableExpr( const CodeLocation & loc )243 : Expr( loc ), var( nullptr ) {}244 245 VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v )246 : Expr( loc ), var( v ) {247 assert( var );248 assert( var->get_type() );249 result = shallowCopy( var->get_type() );250 }251 252 bool VariableExpr::get_lvalue() const {253 // It isn't always an lvalue, but it is never an rvalue.254 return true;255 }256 257 VariableExpr * VariableExpr::functionPointer(258 const CodeLocation & loc, const FunctionDecl * decl ) {259 // wrap usually-determined result type in a pointer260 VariableExpr * funcExpr = new VariableExpr{ loc, decl };261 funcExpr->result = new PointerType{ funcExpr->result };262 return funcExpr;263 }264 265 265 // --- ConstantExpr 266 266 -
src/AST/Expr.hpp
r37b7d95 re7d6968 250 250 }; 251 251 252 /// A reference to a named variable. 253 class VariableExpr final : public Expr { 254 public: 255 readonly<DeclWithType> var; 256 257 VariableExpr( const CodeLocation & loc ); 258 VariableExpr( const CodeLocation & loc, const DeclWithType * v ); 259 260 bool get_lvalue() const final; 261 262 /// generates a function pointer for a given function 263 static VariableExpr * functionPointer( const CodeLocation & loc, const FunctionDecl * decl ); 264 265 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 266 private: 267 VariableExpr * clone() const override { return new VariableExpr{ *this }; } 268 MUTATE_FRIEND 269 }; 270 252 271 /// Address-of expression `&e` 253 272 class AddressExpr final : public Expr { … … 390 409 friend class ::ConverterOldToNew; 391 410 friend class ::ConverterNewToOld; 392 };393 394 /// A reference to a named variable.395 class VariableExpr final : public Expr {396 public:397 readonly<DeclWithType> var;398 399 VariableExpr( const CodeLocation & loc );400 VariableExpr( const CodeLocation & loc, const DeclWithType * v );401 402 bool get_lvalue() const final;403 404 /// generates a function pointer for a given function405 static VariableExpr * functionPointer( const CodeLocation & loc, const FunctionDecl * decl );406 407 const Expr * accept( Visitor & v ) const override { return v.visit( this ); }408 private:409 VariableExpr * clone() const override { return new VariableExpr{ *this }; }410 MUTATE_FRIEND411 411 }; 412 412 -
src/AST/Type.cpp
r37b7d95 re7d6968 157 157 158 158 template<typename decl_t> 159 SueInstType<decl_t>::SueInstType( 160 const base_type * b, std::vector<ptr<Expr>> && params, 161 CV::Qualifiers q, std::vector<ptr<Attribute>> && as ) 162 : BaseInstType( b->name, std::move(params), q, std::move(as) ), base( b ) {} 163 164 template<typename decl_t> 159 165 bool SueInstType<decl_t>::isComplete() const { 160 166 return base ? base->body : false; -
src/AST/Type.hpp
r37b7d95 re7d6968 302 302 class FunctionType final : public ParameterizedType { 303 303 public: 304 // std::vector<ptr<DeclWithType>> returns;305 // std::vector<ptr<DeclWithType>> params;306 307 304 std::vector<ptr<Type>> returns; 308 305 std::vector<ptr<Type>> params; … … 345 342 : ParameterizedType(q, std::move(as)), params(), name(n) {} 346 343 344 BaseInstType( 345 const std::string& n, std::vector<ptr<Expr>> && params, 346 CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ) 347 : ParameterizedType(q, std::move(as)), params(std::move(params)), name(n) {} 348 347 349 BaseInstType( const BaseInstType & o ); 348 350 … … 369 371 370 372 SueInstType( 371 const decl_t * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ); 373 const base_type * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ); 374 375 SueInstType( 376 const base_type * b, std::vector<ptr<Expr>> && params, 377 CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ); 372 378 373 379 bool isComplete() const override; -
src/AST/porting.md
r37b7d95 re7d6968 30 30 * Base nodes now override `const Node * accept( Visitor & v ) const = 0` with, e.g. `const Stmt * accept( Visitor & v ) const override = 0` 31 31 * `PassVisitor` is replaced with `ast::Pass` 32 * Most one shot uses can use `ast::Pass::run` and `ast::Pass::read`. 33 34 `WithConstTypeSubstitution` 35 * `env` => `typeSubs` 32 36 33 37 ## Structural Changes ## … … 146 150 * allows `newObject` as just default settings 147 151 152 `FunctionDecl` 153 * `params` and `returns` added. 154 * Contain the declarations of the parameters and return variables. 155 * Types should match (even be shared with) the fields of `type`. 156 148 157 `NamedTypeDecl` 149 158 * `parameters` => `params` … … 154 163 `AggregateDecl` 155 164 * `parameters` => `params` 165 166 `StructDecl` 167 * `makeInst` replaced by better constructor on `StructInstType`. 156 168 157 169 `Expr` … … 245 257 * **TODO** move `kind`, `typeNames` into code generator 246 258 247 `ReferenceToType` 259 `ReferenceToType` => `BaseInstType` 248 260 * deleted `get_baseParameters()` from children 249 261 * replace with `aggr() ? aggr()->params : nullptr` … … 261 273 * `returnVals` => `returns` 262 274 * `parameters` => `params` 275 * Both now just point at types. 263 276 * `bool isVarArgs;` => `enum ArgumentFlag { FixedArgs, VariableArgs }; ArgumentFlag isVarArgs;` 277 278 `SueInstType` 279 * Template class, with specializations and using to implement some other types: 280 * `StructInstType`, `UnionInstType` & `EnumInstType` 264 281 265 282 `TypeInstType` -
src/Concurrency/Keywords.cc
r37b7d95 re7d6968 66 66 bool needs_main, AggregateDecl::Aggregate cast_target ) : 67 67 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), 68 context_error( context_error ), vtable_name( getVTableName( exception_name ) ), 68 context_error( context_error ), exception_name( exception_name ), 69 vtable_name( getVTableName( exception_name ) ), 69 70 needs_main( needs_main ), cast_target( cast_target ) {} 70 71 … … 89 90 const std::string getter_name; 90 91 const std::string context_error; 92 const std::string exception_name; 91 93 const std::string vtable_name; 92 94 bool needs_main; … … 95 97 StructDecl * type_decl = nullptr; 96 98 FunctionDecl * dtor_decl = nullptr; 99 StructDecl * except_decl = nullptr; 97 100 StructDecl * vtable_decl = nullptr; 98 101 }; … … 376 379 else if ( is_target(decl) ) { 377 380 handle( decl ); 381 } 382 else if ( !except_decl && exception_name == decl->name && decl->body ) { 383 except_decl = decl; 378 384 } 379 385 else if ( !vtable_decl && vtable_name == decl->name && decl->body ) { … … 398 404 assert( struct_type ); 399 405 400 declsToAddAfter.push_back( Virtual::makeVtableInstance( vtable_decl, { 401 new TypeExpr( struct_type->clone() ), 402 }, struct_type, nullptr ) ); 406 std::list< Expression * > poly_args = { new TypeExpr( struct_type->clone() ) }; 407 ObjectDecl * vtable_object = Virtual::makeVtableInstance( 408 vtable_decl->makeInst( poly_args ), struct_type, nullptr ); 409 declsToAddAfter.push_back( vtable_object ); 410 declsToAddAfter.push_back( Virtual::makeGetExceptionFunction( 411 vtable_object, except_decl->makeInst( std::move( poly_args ) ) 412 ) ); 403 413 } 404 414 … … 434 444 void ConcurrentSueKeyword::addVtableForward( StructDecl * decl ) { 435 445 if ( vtable_decl ) { 436 declsToAddBefore.push_back( Virtual::makeVtableForward( vtable_decl,{446 std::list< Expression * > poly_args = { 437 447 new TypeExpr( new StructInstType( noQualifiers, decl ) ), 438 } ) ); 448 }; 449 declsToAddBefore.push_back( Virtual::makeGetExceptionForward( 450 vtable_decl->makeInst( poly_args ), 451 except_decl->makeInst( poly_args ) 452 ) ); 453 declsToAddBefore.push_back( Virtual::makeVtableForward( 454 vtable_decl->makeInst( move( poly_args ) ) ) ); 439 455 // Its only an error if we want a vtable and don't have one. 440 456 } else if ( ! vtable_name.empty() ) { -
src/InitTweak/FixGlobalInit.cc
r37b7d95 re7d6968 153 153 } // if 154 154 if ( Statement * ctor = ctorInit->ctor ) { 155 addDataSectonAttribute( objDecl ); 155 156 initStatements.push_back( ctor ); 156 157 objDecl->init = nullptr; -
src/InitTweak/FixInit.cc
r37b7d95 re7d6968 802 802 if ( Statement * ctor = ctorInit->get_ctor() ) { 803 803 if ( objDecl->get_storageClasses().is_static ) { 804 805 // The ojbect needs to go in the data section, regardless of dtor complexity below. 806 // The attribute works, and is meant to apply, both for leaving the static local alone, 807 // and for hoisting it out as a static global. 808 addDataSectonAttribute( objDecl ); 809 804 810 // originally wanted to take advantage of gcc nested functions, but 805 811 // we get memory errors with this approach. To remedy this, the static -
src/InitTweak/InitTweak.cc
r37b7d95 re7d6968 1103 1103 return isCopyFunction( decl, "?{}" ); 1104 1104 } 1105 1106 void addDataSectonAttribute( ObjectDecl * objDecl ) { 1107 Type *strLitT = new PointerType( Type::Qualifiers( ), 1108 new BasicType( Type::Qualifiers( ), BasicType::Char ) ); 1109 std::list< Expression * > attr_params; 1110 attr_params.push_back( 1111 new ConstantExpr( Constant( strLitT, "\".data#\"", std::nullopt ) ) ); 1112 objDecl->attributes.push_back(new Attribute("section", attr_params)); 1113 } 1114 1105 1115 } -
src/InitTweak/InitTweak.h
r37b7d95 re7d6968 108 108 bool isConstExpr( Initializer * init ); 109 109 110 /// Modifies objDecl to have: 111 /// __attribute__((section (".data#"))) 112 /// which makes gcc put the declared variable in the data section, 113 /// which is helpful for global constants on newer gcc versions, 114 /// so that CFA's generated initialization won't segfault when writing it via a const cast. 115 /// The trailing # is an injected assembly comment, to suppress the "a" in 116 /// .section .data,"a" 117 /// .section .data#,"a" 118 /// to avoid assembler warning "ignoring changed section attributes for .data" 119 void addDataSectonAttribute( ObjectDecl * objDecl ); 120 110 121 class InitExpander_old { 111 122 public: -
src/Parser/DeclarationNode.cc
r37b7d95 re7d6968 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Jun 9 20:26:55202013 // Update Count : 113 412 // Last Modified On : Thu Oct 8 08:03:38 2020 13 // Update Count : 1135 14 14 // 15 15 … … 1016 1016 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) { 1017 1017 dwt->location = cur->location; 1018 * out++ = dwt;1018 *out++ = dwt; 1019 1019 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) { 1020 1020 // e.g., int foo(struct S) {} … … 1022 1022 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr ); 1023 1023 obj->location = cur->location; 1024 * out++ = obj;1024 *out++ = obj; 1025 1025 delete agg; 1026 1026 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) { … … 1029 1029 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr ); 1030 1030 obj->location = cur->location; 1031 * out++ = obj;1031 *out++ = obj; 1032 1032 } else if ( EnumDecl * agg = dynamic_cast< EnumDecl * >( decl ) ) { 1033 1033 // e.g., int foo(enum E) {} … … 1035 1035 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr ); 1036 1036 obj->location = cur->location; 1037 * out++ = obj;1037 *out++ = obj; 1038 1038 } // if 1039 1039 } catch( SemanticErrorException & e ) { -
src/Parser/parser.yy
r37b7d95 re7d6968 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Oct 6 18:24:18202013 // Update Count : 461 012 // Last Modified On : Fri Oct 9 18:09:09 2020 13 // Update Count : 4614 14 14 // 15 15 … … 204 204 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc ); 205 205 } else { 206 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed " ); return nullptr;206 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr; 207 207 } // if 208 208 } else { 209 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed " ); return nullptr;209 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr; 210 210 } // if 211 211 } // forCtrl … … 2412 2412 // Overloading: function, data, and operator identifiers may be overloaded. 2413 2413 // 2414 // Type declarations: " type" is used to generate new types for declaring objects. Similarly, "dtype" is used for object2414 // Type declarations: "otype" is used to generate new types for declaring objects. Similarly, "dtype" is used for object 2415 2415 // and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide 2416 2416 // definitions of new types. Type declarations with storage class "extern" provide opaque types. … … 2441 2441 type_class identifier_or_type_name 2442 2442 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); } 2443 type_initializer_opt assertion_list_opt2443 type_initializer_opt assertion_list_opt 2444 2444 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } 2445 2445 | type_specifier identifier_parameter_declarator … … 2468 2468 assertion 2469 2469 | assertion_list assertion 2470 { $$ = $1 ? $1->appendList( $2 ) : $2; }2470 { $$ = $1->appendList( $2 ); } 2471 2471 ; 2472 2472 -
src/SynTree/AggregateDecl.cc
r37b7d95 re7d6968 21 21 #include "Common/utility.h" // for printAll, cloneAll, deleteAll 22 22 #include "Declaration.h" // for AggregateDecl, TypeDecl, Declaration 23 #include "Expression.h" 23 24 #include "Initializer.h" 24 25 #include "LinkageSpec.h" // for Spec, linkageName, Cforall … … 88 89 const char * StructDecl::typeString() const { return aggrString( kind ); } 89 90 91 StructInstType * StructDecl::makeInst( std::list< Expression * > const & new_parameters ) { 92 std::list< Expression * > copy_parameters; 93 cloneAll( new_parameters, copy_parameters ); 94 return makeInst( move( copy( copy_parameters ) ) ); 95 } 96 97 StructInstType * StructDecl::makeInst( std::list< Expression * > && new_parameters ) { 98 assert( parameters.size() == new_parameters.size() ); 99 StructInstType * type = new StructInstType( noQualifiers, this ); 100 type->parameters = std::move( new_parameters ); 101 return type; 102 } 103 90 104 const char * UnionDecl::typeString() const { return aggrString( Union ); } 91 105 -
src/SynTree/Declaration.h
r37b7d95 re7d6968 306 306 bool is_thread () { return kind == Thread ; } 307 307 308 // Make a type instance of this declaration. 309 StructInstType * makeInst( std::list< Expression * > const & parameters ); 310 StructInstType * makeInst( std::list< Expression * > && parameters ); 311 308 312 virtual StructDecl * clone() const override { return new StructDecl( *this ); } 309 313 virtual void accept( Visitor & v ) override { v.visit( this ); } -
src/SynTree/Expression.h
r37b7d95 re7d6968 163 163 }; 164 164 165 /// VariableExpr represents an expression that simply refers to the value of a named variable. 166 /// Does not take ownership of var. 167 class VariableExpr : public Expression { 168 public: 169 DeclarationWithType * var; 170 171 VariableExpr(); 172 VariableExpr( DeclarationWithType * var ); 173 VariableExpr( const VariableExpr & other ); 174 virtual ~VariableExpr(); 175 176 bool get_lvalue() const final; 177 178 DeclarationWithType * get_var() const { return var; } 179 void set_var( DeclarationWithType * newValue ) { var = newValue; } 180 181 static VariableExpr * functionPointer( FunctionDecl * decl ); 182 183 virtual VariableExpr * clone() const override { return new VariableExpr( * this ); } 184 virtual void accept( Visitor & v ) override { v.visit( this ); } 185 virtual void accept( Visitor & v ) const override { v.visit( this ); } 186 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 187 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 188 }; 189 165 190 // The following classes are used to represent expression types that cannot be converted into 166 191 // function-call format. … … 329 354 }; 330 355 331 /// VariableExpr represents an expression that simply refers to the value of a named variable.332 /// Does not take ownership of var.333 class VariableExpr : public Expression {334 public:335 DeclarationWithType * var;336 337 VariableExpr();338 VariableExpr( DeclarationWithType * var );339 VariableExpr( const VariableExpr & other );340 virtual ~VariableExpr();341 342 bool get_lvalue() const final;343 344 DeclarationWithType * get_var() const { return var; }345 void set_var( DeclarationWithType * newValue ) { var = newValue; }346 347 static VariableExpr * functionPointer( FunctionDecl * decl );348 349 virtual VariableExpr * clone() const override { return new VariableExpr( * this ); }350 virtual void accept( Visitor & v ) override { v.visit( this ); }351 virtual void accept( Visitor & v ) const override { v.visit( this ); }352 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }353 virtual void print( std::ostream & os, Indenter indent = {} ) const override;354 };355 356 356 /// ConstantExpr represents an expression that simply refers to the value of a constant 357 357 class ConstantExpr : public Expression { -
src/SynTree/TypeDecl.cc
r37b7d95 re7d6968 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 15:26:14 201913 // Update Count : 2 112 // Last Modified On : Thu Oct 8 18:18:55 2020 13 // Update Count : 22 14 14 // 15 15 … … 21 21 #include "Type.h" // for Type, Type::StorageClasses 22 22 23 TypeDecl::TypeDecl( const std::string & name, Type::StorageClasses scs, Type * type, Kind kind, bool sized, Type * init ) : Parent( name, scs, type ), kind( kind ), sized( kind == Ttype || sized ), init( init ) { 23 TypeDecl::TypeDecl( const std::string & name, Type::StorageClasses scs, Type * type, Kind kind, bool sized, Type * init ) : 24 Parent( name, scs, type ), kind( kind ), sized( kind == Ttype || sized ), init( init ) { 24 25 } 25 26 -
src/Virtual/Tables.cc
r37b7d95 re7d6968 14 14 // 15 15 16 #include <SynTree/Attribute.h> 16 17 #include <SynTree/Declaration.h> 17 18 #include <SynTree/Expression.h> 19 #include <SynTree/Statement.h> 18 20 #include <SynTree/Type.h> 19 21 … … 38 40 } 39 41 40 // Fuse base polymorphic declaration and forall arguments into a new type.41 static StructInstType * vtableInstType(42 StructDecl * polyDecl, std::list< Expression * > && parameters ) {43 assert( parameters.size() == polyDecl->parameters.size() );44 StructInstType * type = new StructInstType(45 Type::Qualifiers( /* Type::Const */ ), polyDecl );46 type->parameters = std::move( parameters );47 return type;48 }49 50 42 static ObjectDecl * makeVtableDeclaration( 51 43 StructInstType * type, Initializer * init ) { … … 66 58 67 59 ObjectDecl * makeVtableForward( StructInstType * type ) { 60 assert( type ); 68 61 return makeVtableDeclaration( type, nullptr ); 69 62 } 70 63 71 ObjectDecl * makeVtableForward(72 StructDecl * polyDecl, std::list< Expression * > && parameters ) {73 return makeVtableForward( vtableInstType( polyDecl, std::move( parameters ) ) );74 }75 76 64 ObjectDecl * makeVtableInstance( 77 StructInstType * vtableType, Type * vobject_type, Initializer * init ) { 65 StructInstType * vtableType, Type * objectType, Initializer * init ) { 66 assert( vtableType ); 67 assert( objectType ); 78 68 StructDecl * vtableStruct = vtableType->baseStruct; 79 69 // Build the initialization … … 92 82 new SingleInit( new AddressExpr( new NameExpr( parentInstance ) ) ) ); 93 83 } else if ( std::string( "size" ) == field->name ) { 94 inits.push_back( new SingleInit( new SizeofExpr( vobject_type->clone() ) ) );84 inits.push_back( new SingleInit( new SizeofExpr( objectType->clone() ) ) ); 95 85 } else if ( std::string( "align" ) == field->name ) { 96 inits.push_back( new SingleInit( new AlignofExpr( vobject_type->clone() ) ) );86 inits.push_back( new SingleInit( new AlignofExpr( objectType->clone() ) ) ); 97 87 } else { 98 88 inits.push_back( new SingleInit( new NameExpr( field->name ) ) ); … … 108 98 } 109 99 110 ObjectDecl * makeVtableInstance( 111 StructDecl * polyDecl, std::list< Expression * > && parameters, 112 Type * vobject, Initializer * init ) { 113 return makeVtableInstance( 114 vtableInstType( polyDecl, std::move( parameters ) ), vobject, init ); 100 namespace { 101 std::string const functionName = "get_exception_vtable"; 102 } 103 104 FunctionDecl * makeGetExceptionForward( 105 Type * vtableType, Type * exceptType ) { 106 assert( vtableType ); 107 assert( exceptType ); 108 FunctionType * type = new FunctionType( noQualifiers, false ); 109 vtableType->tq.is_const = true; 110 type->returnVals.push_back( new ObjectDecl( 111 "_retvalue", 112 noStorageClasses, 113 LinkageSpec::Cforall, 114 nullptr, 115 new ReferenceType( noQualifiers, vtableType ), 116 nullptr, 117 { new Attribute("unused") } 118 ) ); 119 type->parameters.push_back( new ObjectDecl( 120 "__unused", 121 noStorageClasses, 122 LinkageSpec::Cforall, 123 nullptr, 124 new PointerType( noQualifiers, exceptType ), 125 nullptr, 126 { new Attribute("unused") } 127 ) ); 128 return new FunctionDecl( 129 functionName, 130 noStorageClasses, 131 LinkageSpec::Cforall, 132 type, 133 nullptr 134 ); 135 } 136 137 FunctionDecl * makeGetExceptionFunction( 138 ObjectDecl * vtableInstance, Type * exceptType ) { 139 assert( vtableInstance ); 140 assert( exceptType ); 141 FunctionDecl * func = makeGetExceptionForward( 142 vtableInstance->type->clone(), exceptType ); 143 func->statements = new CompoundStmt( { 144 new ReturnStmt( new VariableExpr( vtableInstance ) ), 145 } ); 146 return func; 115 147 } 116 148 -
src/Virtual/Tables.h
r37b7d95 re7d6968 27 27 bool isVTableInstanceName( std::string const & name ); 28 28 29 /// Converts exceptions into regular structures. 30 //void ( std::list< Declaration * > & translationUnit ); 31 32 ObjectDecl * makeVtableForward( StructInstType * ); 33 ObjectDecl * makeVtableForward( StructDecl *, std::list< Expression * > && ); 34 /* Create a forward definition of a vtable of the given type. 35 * 36 * Instead of the virtual table type you may provide the declaration and all 37 * the forall parameters. 29 ObjectDecl * makeVtableForward( StructInstType * vtableType ); 30 /* Create a forward declaration of a vtable of the given type. 31 * vtableType node is consumed. 38 32 */ 39 33 40 ObjectDecl * makeVtableInstance( StructInstType *, Type *, Initializer * ); 41 ObjectDecl * makeVtableInstance( 42 StructDecl *, std::list< Expression * > &&, Type *, Initializer * ); 34 ObjectDecl * makeVtableInstance( StructInstType * vtableType, Type * objectType, 35 Initializer * init = nullptr ); 43 36 /* Create an initialized definition of a vtable. 44 * 45 * The parameters are the virtual table type (or the base declaration and the 46 * forall parameters), the object type and optionally an initializer. 47 * 48 * Instead of the virtual table type you may provide the declaration and all 49 * the forall parameters. 37 * vtableType and init (if provided) nodes are consumed. 38 */ 39 40 // Some special code for how exceptions interact with virtual tables. 41 FunctionDecl * makeGetExceptionForward( Type * vtableType, Type * exceptType ); 42 /* Create a forward declaration of the exception virtual function 43 * linking the vtableType to the exceptType. Both nodes are consumed. 44 */ 45 46 FunctionDecl * makeGetExceptionFunction( 47 ObjectDecl * vtableInstance, Type * exceptType ); 48 /* Create the definition of the exception virtual function. 49 * exceptType node is consumed. 50 50 */ 51 51 -
src/main.cc
r37b7d95 re7d6968 9 9 // Author : Peter Buhr and Rob Schluntz 10 10 // Created On : Fri May 15 23:12:02 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : T ue May 19 12:03:00202013 // Update Count : 63 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Oct 8 18:17:46 2020 13 // Update Count : 637 14 14 // 15 15 … … 458 458 459 459 460 static const char optstring[] = ":c:ghlLmNnpd P:S:twW:D:";460 static const char optstring[] = ":c:ghlLmNnpdOAP:S:twW:D:"; 461 461 462 462 enum { PreludeDir = 128 }; … … 485 485 486 486 static const char * description[] = { 487 "diagnostic color: never, always, or auto.", // -c488 "wait for gdb to attach", // -g489 "print help message", // -h490 "generate libcfa.c", // -l491 "generate line marks", // -L492 "do not replace main", // -m493 "do not generate line marks", // -N494 "do not read prelude", // -n487 "diagnostic color: never, always, or auto.", // -c 488 "wait for gdb to attach", // -g 489 "print help message", // -h 490 "generate libcfa.c", // -l 491 "generate line marks", // -L 492 "do not replace main", // -m 493 "do not generate line marks", // -N 494 "do not read prelude", // -n 495 495 "generate prototypes for prelude functions", // -p 496 " don't print output that isn't deterministic",// -d497 "Use the old-ast", // -O498 "Use the new-ast", // -A499 "print", // -P496 "only print deterministic output", // -d 497 "Use the old-ast", // -O 498 "Use the new-ast", // -A 499 "print", // -P 500 500 "<directory> prelude directory for debug/nodebug", // no flag 501 501 "<option-list> enable profiling information:\n counters,heap,time,all,none", // -S 502 "building cfa standard lib", // -t503 "", // -w504 "", // -W505 "", // -D502 "building cfa standard lib", // -t 503 "", // -w 504 "", // -W 505 "", // -D 506 506 }; // description 507 507
Note:
See TracChangeset
for help on using the changeset viewer.