Changeset e7d6968 for src


Ignore:
Timestamp:
Oct 23, 2020, 9:08:09 PM (2 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
arm-eh, 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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc into master

Location:
src
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r37b7d95 re7d6968  
    102102        }
    103103        return ret;
     104}
     105
     106// --- VariableExpr
     107
     108VariableExpr::VariableExpr( const CodeLocation & loc )
     109: Expr( loc ), var( nullptr ) {}
     110
     111VariableExpr::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
     118bool VariableExpr::get_lvalue() const {
     119        // It isn't always an lvalue, but it is never an rvalue.
     120        return true;
     121}
     122
     123VariableExpr * 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;
    104129}
    105130
     
    238263}
    239264
    240 // --- VariableExpr
    241 
    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 pointer
    260         VariableExpr * funcExpr = new VariableExpr{ loc, decl };
    261         funcExpr->result = new PointerType{ funcExpr->result };
    262         return funcExpr;
    263 }
    264 
    265265// --- ConstantExpr
    266266
  • src/AST/Expr.hpp

    r37b7d95 re7d6968  
    250250};
    251251
     252/// A reference to a named variable.
     253class VariableExpr final : public Expr {
     254public:
     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 ); }
     266private:
     267        VariableExpr * clone() const override { return new VariableExpr{ *this }; }
     268        MUTATE_FRIEND
     269};
     270
    252271/// Address-of expression `&e`
    253272class AddressExpr final : public Expr {
     
    390409        friend class ::ConverterOldToNew;
    391410        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 function
    405         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_FRIEND
    411411};
    412412
  • src/AST/Type.cpp

    r37b7d95 re7d6968  
    157157
    158158template<typename decl_t>
     159SueInstType<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
     164template<typename decl_t>
    159165bool SueInstType<decl_t>::isComplete() const {
    160166        return base ? base->body : false;
  • src/AST/Type.hpp

    r37b7d95 re7d6968  
    302302class FunctionType final : public ParameterizedType {
    303303public:
    304 //      std::vector<ptr<DeclWithType>> returns;
    305 //      std::vector<ptr<DeclWithType>> params;
    306 
    307304        std::vector<ptr<Type>> returns;
    308305        std::vector<ptr<Type>> params;
     
    345342        : ParameterizedType(q, std::move(as)), params(), name(n) {}
    346343
     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
    347349        BaseInstType( const BaseInstType & o );
    348350
     
    369371
    370372        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 = {} );
    372378
    373379        bool isComplete() const override;
  • src/AST/porting.md

    r37b7d95 re7d6968  
    3030  * Base nodes now override `const Node * accept( Visitor & v ) const = 0` with, e.g. `const Stmt * accept( Visitor & v ) const override = 0`
    3131* `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`
    3236
    3337## Structural Changes ##
     
    146150  * allows `newObject` as just default settings
    147151
     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
    148157`NamedTypeDecl`
    149158* `parameters` => `params`
     
    154163`AggregateDecl`
    155164* `parameters` => `params`
     165
     166`StructDecl`
     167* `makeInst` replaced by better constructor on `StructInstType`.
    156168
    157169`Expr`
     
    245257* **TODO** move `kind`, `typeNames` into code generator
    246258
    247 `ReferenceToType`
     259`ReferenceToType` => `BaseInstType`
    248260* deleted `get_baseParameters()` from children
    249261  * replace with `aggr() ? aggr()->params : nullptr`
     
    261273* `returnVals` => `returns`
    262274* `parameters` => `params`
     275  * Both now just point at types.
    263276* `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`
    264281
    265282`TypeInstType`
  • src/Concurrency/Keywords.cc

    r37b7d95 re7d6968  
    6666                        bool needs_main, AggregateDecl::Aggregate cast_target ) :
    6767                  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 ) ),
    6970                  needs_main( needs_main ), cast_target( cast_target ) {}
    7071
     
    8990                const std::string getter_name;
    9091                const std::string context_error;
     92                const std::string exception_name;
    9193                const std::string vtable_name;
    9294                bool needs_main;
     
    9597                StructDecl   * type_decl = nullptr;
    9698                FunctionDecl * dtor_decl = nullptr;
     99                StructDecl * except_decl = nullptr;
    97100                StructDecl * vtable_decl = nullptr;
    98101        };
     
    376379                else if ( is_target(decl) ) {
    377380                        handle( decl );
     381                }
     382                else if ( !except_decl && exception_name == decl->name && decl->body ) {
     383                        except_decl = decl;
    378384                }
    379385                else if ( !vtable_decl && vtable_name == decl->name && decl->body ) {
     
    398404                        assert( struct_type );
    399405
    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                        ) );
    403413                }
    404414
     
    434444        void ConcurrentSueKeyword::addVtableForward( StructDecl * decl ) {
    435445                if ( vtable_decl ) {
    436                         declsToAddBefore.push_back( Virtual::makeVtableForward( vtable_decl, {
     446                        std::list< Expression * > poly_args = {
    437447                                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 ) ) ) );
    439455                // Its only an error if we want a vtable and don't have one.
    440456                } else if ( ! vtable_name.empty() ) {
  • src/InitTweak/FixGlobalInit.cc

    r37b7d95 re7d6968  
    153153                        } // if
    154154                        if ( Statement * ctor = ctorInit->ctor ) {
     155                                addDataSectonAttribute( objDecl );
    155156                                initStatements.push_back( ctor );
    156157                                objDecl->init = nullptr;
  • src/InitTweak/FixInit.cc

    r37b7d95 re7d6968  
    802802                                if ( Statement * ctor = ctorInit->get_ctor() ) {
    803803                                        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
    804810                                                // originally wanted to take advantage of gcc nested functions, but
    805811                                                // we get memory errors with this approach. To remedy this, the static
  • src/InitTweak/InitTweak.cc

    r37b7d95 re7d6968  
    11031103                return isCopyFunction( decl, "?{}" );
    11041104        }
     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
    11051115}
  • src/InitTweak/InitTweak.h

    r37b7d95 re7d6968  
    108108        bool isConstExpr( Initializer * init );
    109109
     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
    110121        class InitExpander_old {
    111122        public:
  • src/Parser/DeclarationNode.cc

    r37b7d95 re7d6968  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jun  9 20:26:55 2020
    13 // Update Count     : 1134
     12// Last Modified On : Thu Oct  8 08:03:38 2020
     13// Update Count     : 1135
    1414//
    1515
     
    10161016                        if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    10171017                                dwt->location = cur->location;
    1018                                 * out++ = dwt;
     1018                                *out++ = dwt;
    10191019                        } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
    10201020                                // e.g., int foo(struct S) {}
     
    10221022                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    10231023                                obj->location = cur->location;
    1024                                 * out++ = obj;
     1024                                *out++ = obj;
    10251025                                delete agg;
    10261026                        } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
     
    10291029                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    10301030                                obj->location = cur->location;
    1031                                 * out++ = obj;
     1031                                *out++ = obj;
    10321032                        } else if ( EnumDecl * agg = dynamic_cast< EnumDecl * >( decl ) ) {
    10331033                                // e.g., int foo(enum E) {}
     
    10351035                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    10361036                                obj->location = cur->location;
    1037                                 * out++ = obj;
     1037                                *out++ = obj;
    10381038                        } // if
    10391039                } catch( SemanticErrorException & e ) {
  • src/Parser/parser.yy

    r37b7d95 re7d6968  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Oct  6 18:24:18 2020
    13 // Update Count     : 4610
     12// Last Modified On : Fri Oct  9 18:09:09 2020
     13// Update Count     : 4614
    1414//
    1515
     
    204204                        return forCtrl( type, new string( identifier->name ), start, compop, comp, inc );
    205205                } 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;
    207207                } // if
    208208        } 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;
    210210        } // if
    211211} // forCtrl
     
    24122412// Overloading: function, data, and operator identifiers may be overloaded.
    24132413//
    2414 // Type declarations: "type" is used to generate new types for declaring objects. Similarly, "dtype" is used for object
     2414// Type declarations: "otype" is used to generate new types for declaring objects. Similarly, "dtype" is used for object
    24152415//     and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide
    24162416//     definitions of new types. Type declarations with storage class "extern" provide opaque types.
     
    24412441        type_class identifier_or_type_name
    24422442                { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
    2443           type_initializer_opt assertion_list_opt
     2443        type_initializer_opt assertion_list_opt
    24442444                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    24452445        | type_specifier identifier_parameter_declarator
     
    24682468        assertion
    24692469        | assertion_list assertion
    2470                 { $$ = $1 ? $1->appendList( $2 ) : $2; }
     2470                { $$ = $1->appendList( $2 ); }
    24712471        ;
    24722472
  • src/SynTree/AggregateDecl.cc

    r37b7d95 re7d6968  
    2121#include "Common/utility.h"      // for printAll, cloneAll, deleteAll
    2222#include "Declaration.h"         // for AggregateDecl, TypeDecl, Declaration
     23#include "Expression.h"
    2324#include "Initializer.h"
    2425#include "LinkageSpec.h"         // for Spec, linkageName, Cforall
     
    8889const char * StructDecl::typeString() const { return aggrString( kind ); }
    8990
     91StructInstType * 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
     97StructInstType * 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
    90104const char * UnionDecl::typeString() const { return aggrString( Union ); }
    91105
  • src/SynTree/Declaration.h

    r37b7d95 re7d6968  
    306306        bool is_thread   () { return kind == Thread   ; }
    307307
     308        // Make a type instance of this declaration.
     309        StructInstType * makeInst( std::list< Expression * > const & parameters );
     310        StructInstType * makeInst( std::list< Expression * > && parameters );
     311
    308312        virtual StructDecl * clone() const override { return new StructDecl( *this ); }
    309313        virtual void accept( Visitor & v ) override { v.visit( this ); }
  • src/SynTree/Expression.h

    r37b7d95 re7d6968  
    163163};
    164164
     165/// VariableExpr represents an expression that simply refers to the value of a named variable.
     166/// Does not take ownership of var.
     167class 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
    165190// The following classes are used to represent expression types that cannot be converted into
    166191// function-call format.
     
    329354};
    330355
    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 
    356356/// ConstantExpr represents an expression that simply refers to the value of a constant
    357357class ConstantExpr : public Expression {
  • src/SynTree/TypeDecl.cc

    r37b7d95 re7d6968  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 15:26:14 2019
    13 // Update Count     : 21
     12// Last Modified On : Thu Oct  8 18:18:55 2020
     13// Update Count     : 22
    1414//
    1515
     
    2121#include "Type.h"            // for Type, Type::StorageClasses
    2222
    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 ) {
     23TypeDecl::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 ) {
    2425}
    2526
  • src/Virtual/Tables.cc

    r37b7d95 re7d6968  
    1414//
    1515
     16#include <SynTree/Attribute.h>
    1617#include <SynTree/Declaration.h>
    1718#include <SynTree/Expression.h>
     19#include <SynTree/Statement.h>
    1820#include <SynTree/Type.h>
    1921
     
    3840}
    3941
    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 
    5042static ObjectDecl * makeVtableDeclaration(
    5143                StructInstType * type, Initializer * init ) {
     
    6658
    6759ObjectDecl * makeVtableForward( StructInstType * type ) {
     60        assert( type );
    6861        return makeVtableDeclaration( type, nullptr );
    6962}
    7063
    71 ObjectDecl * makeVtableForward(
    72                 StructDecl * polyDecl, std::list< Expression * > && parameters ) {
    73         return makeVtableForward( vtableInstType( polyDecl, std::move( parameters ) ) );
    74 }
    75 
    7664ObjectDecl * makeVtableInstance(
    77                 StructInstType * vtableType, Type * vobject_type, Initializer * init ) {
     65                StructInstType * vtableType, Type * objectType, Initializer * init ) {
     66        assert( vtableType );
     67        assert( objectType );
    7868        StructDecl * vtableStruct = vtableType->baseStruct;
    7969        // Build the initialization
     
    9282                                                new SingleInit( new AddressExpr( new NameExpr( parentInstance ) ) ) );
    9383                        } 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() ) ) );
    9585                        } 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() ) ) );
    9787                        } else {
    9888                                inits.push_back( new SingleInit( new NameExpr( field->name ) ) );
     
    10898}
    10999
    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 );
     100namespace {
     101        std::string const functionName = "get_exception_vtable";
     102}
     103
     104FunctionDecl * 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
     137FunctionDecl * 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;
    115147}
    116148
  • src/Virtual/Tables.h

    r37b7d95 re7d6968  
    2727bool isVTableInstanceName( std::string const & name );
    2828
    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.
     29ObjectDecl * makeVtableForward( StructInstType * vtableType );
     30/* Create a forward declaration of a vtable of the given type.
     31 * vtableType node is consumed.
    3832 */
    3933
    40 ObjectDecl * makeVtableInstance( StructInstType *, Type *, Initializer * );
    41 ObjectDecl * makeVtableInstance(
    42         StructDecl *, std::list< Expression * > &&, Type *, Initializer * );
     34ObjectDecl * makeVtableInstance( StructInstType * vtableType, Type * objectType,
     35        Initializer * init = nullptr );
    4336/* 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.
     41FunctionDecl * 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
     46FunctionDecl * makeGetExceptionFunction(
     47        ObjectDecl * vtableInstance, Type * exceptType );
     48/* Create the definition of the exception virtual function.
     49 * exceptType node is consumed.
    5050 */
    5151
  • src/main.cc

    r37b7d95 re7d6968  
    99// Author           : Peter Buhr and Rob Schluntz
    1010// Created On       : Fri May 15 23:12:02 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue May 19 12:03:00 2020
    13 // Update Count     : 634
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Oct  8 18:17:46 2020
     13// Update Count     : 637
    1414//
    1515
     
    458458
    459459
    460 static const char optstring[] = ":c:ghlLmNnpdP:S:twW:D:";
     460static const char optstring[] = ":c:ghlLmNnpdOAP:S:twW:D:";
    461461
    462462enum { PreludeDir = 128 };
     
    485485
    486486static const char * description[] = {
    487         "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
     487        "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
    495495        "generate prototypes for prelude functions",            // -p
    496         "don't print output that isn't deterministic",        // -d
    497         "Use the old-ast",                                    // -O
    498         "Use the new-ast",                                    // -A
    499         "print",                                              // -P
     496        "only print deterministic output",                  // -d
     497        "Use the old-ast",                                                                      // -O
     498        "Use the new-ast",                                                                      // -A
     499        "print",                                                                                        // -P
    500500        "<directory> prelude directory for debug/nodebug",      // no flag
    501501        "<option-list> enable profiling information:\n          counters,heap,time,all,none", // -S
    502         "building cfa standard lib",                          // -t
    503         "",                                                   // -w
    504         "",                                                   // -W
    505         "",                                                   // -D
     502        "building cfa standard lib",                                            // -t
     503        "",                                                                                                     // -w
     504        "",                                                                                                     // -W
     505        "",                                                                                                     // -D
    506506}; // description
    507507
Note: See TracChangeset for help on using the changeset viewer.