Changes in / [38bfe05b:5c69a1e]


Ignore:
Location:
src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r38bfe05b r5c69a1e  
    324324                printDesignators( init->get_designators() );
    325325                output << "{ ";
    326                 genCommaList( init->begin(), init->end() );
     326                if ( init->begin() == init->end() ) {
     327                        // illegal to leave initializer list empty for scalar initializers, but always legal to have 0
     328                        output << "0";
     329                } else {
     330                        genCommaList( init->begin(), init->end() );
     331                } // if
    327332                output << " }";
    328333        }
  • src/Parser/DeclarationNode.cc

    r38bfe05b r5c69a1e  
    5757        variable.tyClass = NoTypeClass;
    5858        variable.assertions = nullptr;
    59         variable.initializer = nullptr;
    6059
    6160//      attr.name = nullptr;
     
    7170//      delete variable.name;
    7271        delete variable.assertions;
    73         delete variable.initializer;
    7472
    7573        delete type;
     
    103101        newnode->variable.tyClass = variable.tyClass;
    104102        newnode->variable.assertions = maybeClone( variable.assertions );
    105         newnode->variable.initializer = maybeClone( variable.initializer );
    106103
    107104//      newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr;
     
    860857}
    861858
    862 DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) {
    863         assertf( variable.tyClass != NoTypeClass, "Called addTypeInitializer on something that isn't a type variable." );
    864         variable.initializer = init;
    865         return this;
    866 }
    867 
    868859DeclarationNode * DeclarationNode::cloneType( string * newName ) {
    869860        DeclarationNode * newnode = new DeclarationNode;
     
    10231014                assertf( sizeof(kindMap)/sizeof(kindMap[0] == NoTypeClass-1), "DeclarationNode::build: kindMap is out of sync." );
    10241015                assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
    1025                 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.initializer ? variable.initializer->buildType() : nullptr );
     1016                TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ] );
    10261017                buildList( variable.assertions, ret->get_assertions() );
    10271018                return ret;
  • src/Parser/ParseNode.h

    r38bfe05b r5c69a1e  
    274274        DeclarationNode * addIdList( DeclarationNode * list ); // old-style functions
    275275        DeclarationNode * addInitializer( InitializerNode * init );
    276         DeclarationNode * addTypeInitializer( DeclarationNode * init );
    277276
    278277        DeclarationNode * cloneType( std::string * newName );
     
    302301                DeclarationNode::TypeClass tyClass;
    303302                DeclarationNode * assertions;
    304                 DeclarationNode * initializer;
    305303        };
    306304        Variable_t variable;
  • src/Parser/parser.yy

    r38bfe05b r5c69a1e  
    16061606
    16071607typegen_name:                                                                                   // CFA
    1608         TYPEGENname '(' ')'
    1609                 { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }
    1610         | TYPEGENname '(' type_list ')'
     1608        TYPEGENname '(' type_list ')'
    16111609                { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
    16121610        ;
     
    19851983
    19861984type_parameter_list:                                                                    // CFA
    1987         type_parameter
    1988                 { $$ = $1; }
    1989         | type_parameter_list ',' type_parameter
     1985        type_parameter type_initializer_opt
     1986        | type_parameter_list ',' type_parameter type_initializer_opt
    19901987                { $$ = $1->appendList( $3 ); }
    19911988        ;
     
    20011998        type_class no_attr_identifier_or_type_name
    20021999                { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }
    2003           type_initializer_opt assertion_list_opt
    2004                 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
     2000          assertion_list_opt
     2001                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addAssertions( $4 ); }
    20052002        | type_specifier identifier_parameter_declarator
    20062003        ;
  • src/SymTab/Indexer.cc

    r38bfe05b r5c69a1e  
    285285                addType( typeDecl );
    286286                acceptAll( typeDecl->get_assertions(), *this );
    287                 acceptNewScope( typeDecl->get_init(), *this );
    288287        }
    289288
  • src/SymTab/Validate.cc

    r38bfe05b r5c69a1e  
    506506        void LinkReferenceToTypes::visit( StructDecl *structDecl ) {
    507507                // visit struct members first so that the types of self-referencing members are updated properly
    508                 // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and and their defaults)
    509508                Parent::visit( structDecl );
    510509                if ( ! structDecl->get_members().empty() ) {
     
    845844                if ( params != NULL ) {
    846845                        std::list< Expression * > & args = inst->get_parameters();
    847 
    848                         // insert defaults arguments when a type argument is missing (currently only supports missing arguments at the end of the list).
    849                         // A substitution is used to ensure that defaults are replaced correctly, e.g.,
    850                         //   forall(otype T, otype alloc = heap_allocator(T)) struct vector;
    851                         //   vector(int) v;
    852                         // after insertion of default values becomes
    853                         //   vector(int, heap_allocator(T))
    854                         // and the substitution is built with T=int so that after substitution, the result is
    855                         //   vector(int, heap_allocator(int))
    856                         TypeSubstitution sub;
    857                         auto paramIter = params->begin();
    858                         for ( size_t i = 0; paramIter != params->end(); ++paramIter, ++i ) {
    859                                 if ( i < args.size() ) {
    860                                         TypeExpr * expr = safe_dynamic_cast< TypeExpr * >( *std::next( args.begin(), i ) );
    861                                         sub.add( (*paramIter)->get_name(), expr->get_type()->clone() );
    862                                 } else if ( i == args.size() ) {
    863                                         Type * defaultType = (*paramIter)->get_init();
    864                                         if ( defaultType ) {
    865                                                 args.push_back( new TypeExpr( defaultType->clone() ) );
    866                                                 sub.add( (*paramIter)->get_name(), defaultType->clone() );
    867                                         }
    868                                 }
    869                         }
    870 
    871                         sub.apply( inst );
    872846                        if ( args.size() < params->size() ) throw SemanticError( "Too few type arguments in generic type ", inst );
    873847                        if ( args.size() > params->size() ) throw SemanticError( "Too many type arguments in generic type ", inst );
  • src/SynTree/Declaration.h

    r38bfe05b r5c69a1e  
    194194        };
    195195
    196         TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, Type * init = nullptr );
     196        TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind );
    197197        TypeDecl( const TypeDecl &other );
    198         virtual ~TypeDecl();
    199198
    200199        Kind get_kind() const { return kind; }
    201 
    202         Type * get_init() const { return init; }
    203         TypeDecl * set_init( Type * newValue ) { init = newValue; return this; }
    204200
    205201        bool isComplete() const { return kind == Any || sized; }
     
    213209        virtual void accept( Visitor &v ) { v.visit( this ); }
    214210        virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    215         virtual void print( std::ostream &os, int indent = 0 ) const;
    216 
    217211  private:
    218212        Kind kind;
    219         Type * init;
    220213        bool sized;
    221214};
  • src/SynTree/Mutator.cc

    r38bfe05b r5c69a1e  
    7777TypeDecl *Mutator::mutate( TypeDecl *typeDecl ) {
    7878        handleNamedTypeDecl( typeDecl );
    79         typeDecl->set_init( maybeMutate( typeDecl->get_init(), *this ) );
    8079        return typeDecl;
    8180}
  • src/SynTree/TypeDecl.cc

    r38bfe05b r5c69a1e  
    1818#include "Common/utility.h"
    1919
    20 TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, Type * init ) : Parent( name, scs, type ), kind( kind ), init( init ), sized( kind == Any || kind == Ttype ) {
     20TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind ) : Parent( name, scs, type ), kind( kind ), sized( kind == Any || kind == Ttype ) {
    2121}
    2222
    23 TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), kind( other.kind ), init( maybeClone( other.init ) ), sized( other.sized ) {
    24 }
    25 
    26 TypeDecl::~TypeDecl() {
    27   delete init;
     23TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), kind( other.kind ), sized( other.sized ) {
    2824}
    2925
     
    3834}
    3935
    40 void TypeDecl::print( std::ostream &os, int indent ) const {
    41   NamedTypeDecl::print( os, indent );
    42   if ( init ) {
    43     os << std::endl << std::string( indent, ' ' ) << "with type initializer: ";
    44     init->print( os, indent + 2 );
    45   }
    46 }
    47 
    48 
    4936std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ) {
    5037  return os << data.kind << ", " << data.isComplete;
  • src/SynTree/Visitor.cc

    r38bfe05b r5c69a1e  
    6767void Visitor::visit( TypeDecl *typeDecl ) {
    6868        handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) );
    69         maybeAccept( typeDecl->get_init(), *this );
    7069}
    7170
  • src/libcfa/containers/vector

    r38bfe05b r5c69a1e  
    2222
    2323//------------------------------------------------------------------------------
    24 //Allocator
    25 forall(otype T)
    26 struct heap_allocator
    27 {
    28         T* storage;
    29         size_t capacity;
    30 };
    31 
    32 forall(otype T)
    33 void ?{}(heap_allocator(T)* this);
    34 
    35 forall(otype T)
    36 void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs);
    37 
    38 forall(otype T)
    39 heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs);
    40 
    41 forall(otype T)
    42 void ^?{}(heap_allocator(T)* this);
    43 
    44 forall(otype T)
    45 void realloc_storage(heap_allocator(T)* this, size_t size);
    46 
    47 forall(otype T)
    48 static inline T* data(heap_allocator(T)* this)
    49 {
    50         return this->storage;
    51 }
    52 
    53 //------------------------------------------------------------------------------
    5424//Declaration
    5525trait allocator_c(otype T, otype allocator_t)
     
    5929};
    6030
    61 forall(otype T, otype allocator_t = heap_allocator(T) | allocator_c(T, allocator_t))
     31forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    6232struct vector;
    6333
     
    7646void ^?{}(vector(T, allocator_t)* this);
    7747
    78 forall(otype T, otype allocator_t = heap_allocator(T) | allocator_c(T, allocator_t))
     48forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    7949struct vector
    8050{
     
    166136// }
    167137
     138//------------------------------------------------------------------------------
     139//Allocator
     140forall(otype T)
     141struct heap_allocator
     142{
     143        T* storage;
     144        size_t capacity;
     145};
     146
     147forall(otype T)
     148void ?{}(heap_allocator(T)* this);
     149
     150forall(otype T)
     151void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs);
     152
     153forall(otype T)
     154heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs);
     155
     156forall(otype T)
     157void ^?{}(heap_allocator(T)* this);
     158
     159forall(otype T)
     160void realloc_storage(heap_allocator(T)* this, size_t size);
     161
     162forall(otype T)
     163static inline T* data(heap_allocator(T)* this)
     164{
     165        return this->storage;
     166}
     167
    168168#endif // VECTOR_H
    169169
  • src/tests/libcfa_vector.c

    r38bfe05b r5c69a1e  
    2727
    2828int main() {
    29         vector( int ) iv;
     29        vector( int, heap_allocator(int) ) iv;
    3030
    3131        assert( empty( &iv ) );
Note: See TracChangeset for help on using the changeset viewer.