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