Changes in / [5c69a1e:38bfe05b]
- Location:
- src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r5c69a1e r38bfe05b 324 324 printDesignators( init->get_designators() ); 325 325 output << "{ "; 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 326 genCommaList( init->begin(), init->end() ); 332 327 output << " }"; 333 328 } -
src/Parser/DeclarationNode.cc
r5c69a1e r38bfe05b 57 57 variable.tyClass = NoTypeClass; 58 58 variable.assertions = nullptr; 59 variable.initializer = nullptr; 59 60 60 61 // attr.name = nullptr; … … 70 71 // delete variable.name; 71 72 delete variable.assertions; 73 delete variable.initializer; 72 74 73 75 delete type; … … 101 103 newnode->variable.tyClass = variable.tyClass; 102 104 newnode->variable.assertions = maybeClone( variable.assertions ); 105 newnode->variable.initializer = maybeClone( variable.initializer ); 103 106 104 107 // newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr; … … 857 860 } 858 861 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 859 868 DeclarationNode * DeclarationNode::cloneType( string * newName ) { 860 869 DeclarationNode * newnode = new DeclarationNode; … … 1014 1023 assertf( sizeof(kindMap)/sizeof(kindMap[0] == NoTypeClass-1), "DeclarationNode::build: kindMap is out of sync." ); 1015 1024 assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." ); 1016 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ] );1025 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.initializer ? variable.initializer->buildType() : nullptr ); 1017 1026 buildList( variable.assertions, ret->get_assertions() ); 1018 1027 return ret; -
src/Parser/ParseNode.h
r5c69a1e r38bfe05b 274 274 DeclarationNode * addIdList( DeclarationNode * list ); // old-style functions 275 275 DeclarationNode * addInitializer( InitializerNode * init ); 276 DeclarationNode * addTypeInitializer( DeclarationNode * init ); 276 277 277 278 DeclarationNode * cloneType( std::string * newName ); … … 301 302 DeclarationNode::TypeClass tyClass; 302 303 DeclarationNode * assertions; 304 DeclarationNode * initializer; 303 305 }; 304 306 Variable_t variable; -
src/Parser/parser.yy
r5c69a1e r38bfe05b 1606 1606 1607 1607 typegen_name: // CFA 1608 TYPEGENname '(' type_list ')' 1608 TYPEGENname '(' ')' 1609 { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); } 1610 | TYPEGENname '(' type_list ')' 1609 1611 { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); } 1610 1612 ; … … 1983 1985 1984 1986 type_parameter_list: // CFA 1985 type_parameter type_initializer_opt 1986 | type_parameter_list ',' type_parameter type_initializer_opt 1987 type_parameter 1988 { $$ = $1; } 1989 | type_parameter_list ',' type_parameter 1987 1990 { $$ = $1->appendList( $3 ); } 1988 1991 ; … … 1998 2001 type_class no_attr_identifier_or_type_name 1999 2002 { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); } 2000 assertion_list_opt2001 { $$ = DeclarationNode::newTypeParam( $1, $2 )->add Assertions( $4); }2003 type_initializer_opt assertion_list_opt 2004 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } 2002 2005 | type_specifier identifier_parameter_declarator 2003 2006 ; -
src/SymTab/Indexer.cc
r5c69a1e r38bfe05b 285 285 addType( typeDecl ); 286 286 acceptAll( typeDecl->get_assertions(), *this ); 287 acceptNewScope( typeDecl->get_init(), *this ); 287 288 } 288 289 -
src/SymTab/Validate.cc
r5c69a1e r38bfe05b 506 506 void LinkReferenceToTypes::visit( StructDecl *structDecl ) { 507 507 // 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) 508 509 Parent::visit( structDecl ); 509 510 if ( ! structDecl->get_members().empty() ) { … … 844 845 if ( params != NULL ) { 845 846 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 ); 846 872 if ( args.size() < params->size() ) throw SemanticError( "Too few type arguments in generic type ", inst ); 847 873 if ( args.size() > params->size() ) throw SemanticError( "Too many type arguments in generic type ", inst ); -
src/SynTree/Declaration.h
r5c69a1e r38bfe05b 194 194 }; 195 195 196 TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind );196 TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, Type * init = nullptr ); 197 197 TypeDecl( const TypeDecl &other ); 198 virtual ~TypeDecl(); 198 199 199 200 Kind get_kind() const { return kind; } 201 202 Type * get_init() const { return init; } 203 TypeDecl * set_init( Type * newValue ) { init = newValue; return this; } 200 204 201 205 bool isComplete() const { return kind == Any || sized; } … … 209 213 virtual void accept( Visitor &v ) { v.visit( this ); } 210 214 virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); } 215 virtual void print( std::ostream &os, int indent = 0 ) const; 216 211 217 private: 212 218 Kind kind; 219 Type * init; 213 220 bool sized; 214 221 }; -
src/SynTree/Mutator.cc
r5c69a1e r38bfe05b 77 77 TypeDecl *Mutator::mutate( TypeDecl *typeDecl ) { 78 78 handleNamedTypeDecl( typeDecl ); 79 typeDecl->set_init( maybeMutate( typeDecl->get_init(), *this ) ); 79 80 return typeDecl; 80 81 } -
src/SynTree/TypeDecl.cc
r5c69a1e r38bfe05b 18 18 #include "Common/utility.h" 19 19 20 TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind ) : Parent( name, scs, type ), kind( kind), sized( kind == Any || kind == Ttype ) {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 ) { 21 21 } 22 22 23 TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), kind( other.kind ), sized( other.sized ) { 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; 24 28 } 25 29 … … 34 38 } 35 39 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 36 49 std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ) { 37 50 return os << data.kind << ", " << data.isComplete; -
src/SynTree/Visitor.cc
r5c69a1e r38bfe05b 67 67 void Visitor::visit( TypeDecl *typeDecl ) { 68 68 handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) ); 69 maybeAccept( typeDecl->get_init(), *this ); 69 70 } 70 71 -
src/libcfa/containers/vector
r5c69a1e r38bfe05b 22 22 23 23 //------------------------------------------------------------------------------ 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 //------------------------------------------------------------------------------ 24 54 //Declaration 25 55 trait allocator_c(otype T, otype allocator_t) … … 29 59 }; 30 60 31 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))61 forall(otype T, otype allocator_t = heap_allocator(T) | allocator_c(T, allocator_t)) 32 62 struct vector; 33 63 … … 46 76 void ^?{}(vector(T, allocator_t)* this); 47 77 48 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))78 forall(otype T, otype allocator_t = heap_allocator(T) | allocator_c(T, allocator_t)) 49 79 struct vector 50 80 { … … 136 166 // } 137 167 138 //------------------------------------------------------------------------------139 //Allocator140 forall(otype T)141 struct heap_allocator142 {143 T* storage;144 size_t capacity;145 };146 147 forall(otype T)148 void ?{}(heap_allocator(T)* this);149 150 forall(otype T)151 void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs);152 153 forall(otype T)154 heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs);155 156 forall(otype T)157 void ^?{}(heap_allocator(T)* this);158 159 forall(otype T)160 void realloc_storage(heap_allocator(T)* this, size_t size);161 162 forall(otype T)163 static inline T* data(heap_allocator(T)* this)164 {165 return this->storage;166 }167 168 168 #endif // VECTOR_H 169 169 -
src/tests/libcfa_vector.c
r5c69a1e r38bfe05b 27 27 28 28 int main() { 29 vector( int , heap_allocator(int)) iv;29 vector( int ) iv; 30 30 31 31 assert( empty( &iv ) );
Note: See TracChangeset
for help on using the changeset viewer.