Changes in / [fd782b2:f006f01]
- Location:
- src
- Files:
-
- 1 deleted
- 24 edited
-
InitTweak/InitTweak.cc (modified) (1 diff)
-
Parser/DeclarationNode.cc (modified) (8 diffs)
-
Parser/ParseNode.h (modified) (16 diffs)
-
Parser/TypeData.h (modified) (2 diffs)
-
Parser/parser.cc (modified) (1 diff)
-
Parser/parser.yy (modified) (1 diff)
-
examples/gc_no_raii/bug-repro/field.c (modified) (2 diffs)
-
examples/gc_no_raii/bug-repro/oddtype.c (deleted)
-
examples/gc_no_raii/src/gcpointers.c (modified) (6 diffs)
-
examples/gc_no_raii/src/gcpointers.h (modified) (3 diffs)
-
examples/gc_no_raii/src/internal/card_table.h (modified) (4 diffs)
-
examples/gc_no_raii/src/internal/collector.c (modified) (6 diffs)
-
examples/gc_no_raii/src/internal/collector.h (modified) (1 diff)
-
examples/gc_no_raii/src/internal/memory_pool.c (modified) (10 diffs)
-
examples/gc_no_raii/src/internal/memory_pool.h (modified) (2 diffs)
-
examples/gc_no_raii/src/internal/object_header.c (modified) (11 diffs)
-
examples/gc_no_raii/src/internal/object_header.h (modified) (4 diffs)
-
examples/gc_no_raii/src/internal/state.c (modified) (7 diffs)
-
examples/gc_no_raii/src/internal/state.h (modified) (1 diff)
-
examples/gc_no_raii/src/tools/checks.h (modified) (3 diffs)
-
examples/gc_no_raii/src/tools/print.c (modified) (1 diff)
-
examples/gc_no_raii/src/tools/print.h (modified) (1 diff)
-
examples/gc_no_raii/test/badlll.c (modified) (3 diffs)
-
tests/.expect/declarationErrors.txt (modified) (1 diff)
-
tests/avltree/avl_test.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
rfd782b2 rf006f01 387 387 } else if ( MemberExpr * memberExpr = dynamic_cast< MemberExpr * >( func ) ) { 388 388 return memberExpr->get_member()->get_name(); 389 } else if ( UntypedMemberExpr * memberExpr = dynamic_cast< UntypedMemberExpr * > ( func ) ) {390 return funcName( memberExpr->get_member() );391 389 } else { 392 390 assertf( false, "Unexpected expression type being called as a function in call expression" ); -
src/Parser/DeclarationNode.cc
rfd782b2 rf006f01 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 11 09:24:11201613 // Update Count : 4 3812 // Last Modified On : Fri Sep 9 23:21:47 2016 13 // Update Count : 402 14 14 // 15 15 … … 31 31 32 32 // These must remain in the same order as the corresponding DeclarationNode enumerations. 33 const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", " NoStorageClass" };33 const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "" }; 34 34 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" }; 35 35 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary", }; … … 389 389 390 390 void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) { 391 TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization392 393 if ( (qsrc & qdst).any() ) { // common qualifier?391 TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; 392 393 if ( (qsrc & qdst).any() ) { // common bits between qualifier masks ? 394 394 for ( int i = 0; i < NoOfQualifier; i += 1 ) { // find common qualifiers 395 395 if ( qsrc[i] & qdst[i] ) { 396 if ( ! error.empty() ) error += ", "; // separator 397 error += string( "duplicate " ) + DeclarationNode::qualifierName[i]; 396 error += string(error.empty() ? "" : ", ") + "duplicate " + DeclarationNode::qualifierName[i]; 398 397 } // if 399 398 } // for 400 399 } // if 401 400 } // DeclarationNode::checkQualifiers 402 403 void DeclarationNode::checkStorageClasses( DeclarationNode *q ) {404 if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) {405 if ( ! error.empty() ) error += ", "; // separator406 if ( storageClass == q->storageClass ) { // duplicate qualifier407 error += string( "duplicate " ) + storageName[ storageClass ];408 } else { // only one storage class409 error += string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ];410 q->storageClass = storageClass; // FIX ERROR411 } // if412 if ( ! q->error.empty() ) error += ", " + q->error; // separator413 } else {414 if ( ! error.empty() ) {415 if ( ! q->error.empty() ) error += ", " + q->error; // separator416 } else if ( ! q->error.empty() ) error += q->error;417 } // if418 } // DeclarationNode::copyStorageClasses419 420 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {421 isInline = isInline | q->isInline;422 isNoreturn = isNoreturn | q->isNoreturn;423 // do not overwrite an existing value with NoStorageClass424 if ( q->storageClass != NoStorageClass ) {425 assert( storageClass == NoStorageClass || storageClass == q->storageClass );426 storageClass = q->storageClass;427 } // if428 return this;429 } // DeclarationNode::copyStorageClasses430 401 431 402 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 432 403 if ( q ) { 433 checkStorageClasses( q ); 434 copyStorageClasses( q ); 404 copyStorageClasses(q); 435 405 if ( q->type ) { 436 406 if ( ! type ) { … … 459 429 return this; 460 430 } 431 432 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 433 isInline = isInline || q->isInline; 434 isNoreturn = isNoreturn || q->isNoreturn; 435 if ( storageClass == NoStorageClass ) { 436 storageClass = q->storageClass; 437 } else if ( q->storageClass != NoStorageClass ) { 438 if ( storageClass == q->storageClass ) { 439 q->error += string( "duplicate " ) + storageName[ storageClass ]; 440 } else { // can only have one storage class 441 q->error += string( "multiple " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ]; 442 } // if 443 } // if 444 if ( ! q->error.empty() ) { 445 error += (! error.empty() ? ", " : "") + q->error; 446 } // if 447 return this; 448 } // DeclarationNode::copyStorageClasses 461 449 462 450 static void addTypeToType( TypeData *&src, TypeData *&dst ) { … … 516 504 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) { 517 505 if ( o ) { 518 checkStorageClasses( o );519 506 copyStorageClasses( o ); 520 507 if ( o->type ) { … … 764 751 } // if 765 752 newnode->type->forall = maybeClone( type->forall ); 766 assert( storageClass == NoStorageClass );767 753 newnode->copyStorageClasses( this ); 768 754 newnode->name = assign_strptr( newName ); … … 805 791 DeclarationNode *newnode = new DeclarationNode; 806 792 newnode->type = maybeClone( type ); 807 assert( storageClass == NoStorageClass );808 793 newnode->copyStorageClasses( this ); 809 794 newnode->name = assign_strptr( newName ); … … 813 798 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) { 814 799 if ( o ) { 815 assert( storageClass == NoStorageClass );816 800 o->copyStorageClasses( this ); 817 801 if ( type ) { -
src/Parser/ParseNode.h
rfd782b2 rf006f01 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Sep 10 17:14:37201613 // Update Count : 58 912 // Last Modified On : Thu Sep 8 21:58:06 2016 13 // Update Count : 587 14 14 // 15 15 … … 41 41 public: 42 42 ParseNode() {}; 43 ParseNode( const std::string * name ) : name( *name ) { assert( false ); delete name; }43 ParseNode( const std::string *name ) : name( *name ) { assert( false ); delete name; } 44 44 ParseNode( const std::string &name ) : name( name ) { assert( false ); } 45 45 virtual ~ParseNode() { delete next; }; 46 virtual ParseNode * clone() const = 0;47 48 ParseNode * get_next() const { return next; }49 ParseNode * set_next( ParseNode *newlink ) { next = newlink; return this; }50 ParseNode * get_last() {51 ParseNode * current;46 virtual ParseNode *clone() const = 0; 47 48 ParseNode *get_next() const { return next; } 49 ParseNode *set_next( ParseNode *newlink ) { next = newlink; return this; } 50 ParseNode *get_last() { 51 ParseNode *current; 52 52 for ( current = this; current->get_next() != 0; current = current->get_next() ); 53 53 return current; 54 54 } 55 ParseNode * set_last( ParseNode *newlast ) {55 ParseNode *set_last( ParseNode *newlast ) { 56 56 if ( newlast != 0 ) get_last()->set_next( newlast ); 57 57 return this; … … 66 66 static int indent_by; 67 67 68 ParseNode * next = nullptr;68 ParseNode *next = nullptr; 69 69 std::string name; 70 70 }; // ParseNode … … 74 74 class InitializerNode : public ParseNode { 75 75 public: 76 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = 0 );77 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = 0 );76 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 ); 77 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 ); 78 78 ~InitializerNode(); 79 virtual InitializerNode * clone() const { assert( false ); return nullptr; }80 81 ExpressionNode * get_expression() const { return expr; }82 83 InitializerNode * set_designators( ExpressionNode *des ) { designator = des; return this; }84 ExpressionNode * get_designators() const { return designator; }85 86 InitializerNode * set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }79 virtual InitializerNode *clone() const { assert( false ); return nullptr; } 80 81 ExpressionNode *get_expression() const { return expr; } 82 83 InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; } 84 ExpressionNode *get_designators() const { return designator; } 85 86 InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; } 87 87 bool get_maybeConstructed() const { return maybeConstructed; } 88 88 89 InitializerNode * next_init() const { return kids; }89 InitializerNode *next_init() const { return kids; } 90 90 91 91 void print( std::ostream &os, int indent = 0 ) const; 92 92 void printOneLine( std::ostream & ) const; 93 93 94 virtual Initializer * build() const;94 virtual Initializer *build() const; 95 95 private: 96 ExpressionNode * expr;96 ExpressionNode *expr; 97 97 bool aggregate; 98 ExpressionNode * designator;// may be list99 InitializerNode * kids;98 ExpressionNode *designator; // may be list 99 InitializerNode *kids; 100 100 bool maybeConstructed; 101 101 }; // InitializerNode … … 106 106 public: 107 107 ExpressionNode( Expression * expr = nullptr ) : expr( expr ) {} 108 ExpressionNode( Expression * expr, const std::string * name ) : ParseNode( name ), expr( expr ) {}108 ExpressionNode( Expression * expr, const std::string *name ) : ParseNode( name ), expr( expr ) {} 109 109 ExpressionNode( const ExpressionNode &other ); 110 110 virtual ~ExpressionNode() {} 111 virtual ExpressionNode * clone() const { return expr ? new ExpressionNode( expr->clone() ) : nullptr; }111 virtual ExpressionNode *clone() const { return expr ? new ExpressionNode( expr->clone() ) : nullptr; } 112 112 113 113 bool get_extension() const { return extension; } 114 ExpressionNode * set_extension( bool exten ) { extension = exten; return this; }114 ExpressionNode *set_extension( bool exten ) { extension = exten; return this; } 115 115 116 116 void print( std::ostream &os, int indent = 0 ) const {} … … 122 122 } 123 123 124 Expression * build() const { return const_cast<ExpressionNode*>(this)->expr.release(); }124 Expression *build() const { return const_cast<ExpressionNode*>(this)->expr.release(); } 125 125 private: 126 126 bool extension = false; … … 130 130 template< typename T > 131 131 struct maybeBuild_t< Expression, T > { 132 static inline Expression * doit( const T * orig ) {132 static inline Expression * doit( const T *orig ) { 133 133 if ( orig ) { 134 Expression * p = orig->build();134 Expression *p = orig->build(); 135 135 p->set_extension( orig->get_extension() ); 136 136 return p; … … 156 156 }; 157 157 158 Expression * build_constantInteger( const std::string &str );159 Expression * build_constantFloat( const std::string &str );160 Expression * build_constantChar( const std::string &str );161 ConstantExpr * build_constantStr( const std::string &str );162 163 NameExpr * build_varref( const std::string *name, bool labelp = false );164 Expression * build_typevalue( DeclarationNode *decl );165 166 Expression * build_cast( DeclarationNode * decl_node, ExpressionNode *expr_node );167 Expression * build_fieldSel( ExpressionNode * expr_node, Expression *member );168 Expression * build_pfieldSel( ExpressionNode * expr_node, Expression *member );169 Expression * build_addressOf( ExpressionNode *expr_node );170 Expression * build_sizeOfexpr( ExpressionNode *expr_node );171 Expression * build_sizeOftype( DeclarationNode *decl_node );172 Expression * build_alignOfexpr( ExpressionNode *expr_node );173 Expression * build_alignOftype( DeclarationNode *decl_node );174 Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr *member );175 Expression * build_and( ExpressionNode * expr_node1, ExpressionNode *expr_node2 );176 Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode *expr_node2, bool kind );177 Expression * build_unary_val( OperKinds op, ExpressionNode *expr_node );178 Expression * build_unary_ptr( OperKinds op, ExpressionNode *expr_node );179 Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode *expr_node2 );180 Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode *expr_node2 );181 Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode *expr_node3 );182 Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode *expr_node2 );183 Expression * build_attrexpr( NameExpr *var, ExpressionNode * expr_node );184 Expression * build_attrtype( NameExpr *var, DeclarationNode * decl_node );185 Expression * build_tuple( ExpressionNode * expr_node = 0 );186 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node );187 Expression * build_range( ExpressionNode * low, ExpressionNode *high );188 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode *operand );189 Expression * build_valexpr( StatementNode *s );190 Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode *kids );158 Expression *build_constantInteger( const std::string &str ); 159 Expression *build_constantFloat( const std::string &str ); 160 Expression *build_constantChar( const std::string &str ); 161 ConstantExpr *build_constantStr( const std::string &str ); 162 163 NameExpr *build_varref( const std::string *name, bool labelp = false ); 164 Expression *build_typevalue( DeclarationNode *decl ); 165 166 Expression *build_cast( DeclarationNode * decl_node, ExpressionNode *expr_node ); 167 Expression *build_fieldSel( ExpressionNode *expr_node, Expression *member ); 168 Expression *build_pfieldSel( ExpressionNode *expr_node, Expression *member ); 169 Expression *build_addressOf( ExpressionNode *expr_node ); 170 Expression *build_sizeOfexpr( ExpressionNode *expr_node ); 171 Expression *build_sizeOftype( DeclarationNode *decl_node ); 172 Expression *build_alignOfexpr( ExpressionNode *expr_node ); 173 Expression *build_alignOftype( DeclarationNode *decl_node ); 174 Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ); 175 Expression *build_and( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); 176 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ); 177 Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ); 178 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ); 179 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); 180 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); 181 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ); 182 Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); 183 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ); 184 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ); 185 Expression *build_tuple( ExpressionNode * expr_node = 0 ); 186 Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ); 187 Expression *build_range( ExpressionNode * low, ExpressionNode *high ); 188 Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ); 189 Expression *build_valexpr( StatementNode *s ); 190 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ); 191 191 192 192 //############################################################################## … … 204 204 enum BuiltinType { Valist }; 205 205 206 static const char * qualifierName[];207 static const char * storageName[];208 static const char * basicTypeName[];209 static const char * modifierName[];210 static const char * aggregateName[];211 static const char * typeClassName[];212 static const char * builtinTypeName[];213 214 static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode *body, bool newStyle = false );215 static DeclarationNode * newQualifier( Qualifier );216 static DeclarationNode * newForall( DeclarationNode *);217 static DeclarationNode * newStorageClass( StorageClass );218 static DeclarationNode * newBasicType( BasicType );219 static DeclarationNode * newModifier( Modifier );220 static DeclarationNode * newBuiltinType( BuiltinType );221 static DeclarationNode * newFromTypedef( std::string *);222 static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode *fields, bool body );223 static DeclarationNode * newEnum( std::string * name, DeclarationNode *constants );224 static DeclarationNode * newEnumConstant( std::string * name, ExpressionNode *constant );225 static DeclarationNode * newName( std::string *);226 static DeclarationNode * newFromTypeGen( std::string *, ExpressionNode *params );227 static DeclarationNode * newTypeParam( TypeClass, std::string *);228 static DeclarationNode * newTrait( std::string * name, DeclarationNode * params, DeclarationNode *asserts );229 static DeclarationNode * newTraitUse( std::string * name, ExpressionNode *params );230 static DeclarationNode * newTypeDecl( std::string * name, DeclarationNode *typeParams );231 static DeclarationNode * newPointer( DeclarationNode *qualifiers );232 static DeclarationNode * newArray( ExpressionNode * size, DeclarationNode *qualifiers, bool isStatic );233 static DeclarationNode * newVarArray( DeclarationNode *qualifiers );234 static DeclarationNode * newBitfield( ExpressionNode *size );235 static DeclarationNode * newTuple( DeclarationNode *members );236 static DeclarationNode * newTypeof( ExpressionNode *expr );237 static DeclarationNode * newAttr( std::string *, ExpressionNode *expr );238 static DeclarationNode * newAttr( std::string *, DeclarationNode *type );206 static const char *qualifierName[]; 207 static const char *storageName[]; 208 static const char *basicTypeName[]; 209 static const char *modifierName[]; 210 static const char *aggregateName[]; 211 static const char *typeClassName[]; 212 static const char *builtinTypeName[]; 213 214 static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle = false ); 215 static DeclarationNode *newQualifier( Qualifier ); 216 static DeclarationNode *newForall( DeclarationNode *); 217 static DeclarationNode *newStorageClass( StorageClass ); 218 static DeclarationNode *newBasicType( BasicType ); 219 static DeclarationNode *newModifier( Modifier ); 220 static DeclarationNode *newBuiltinType( BuiltinType ); 221 static DeclarationNode *newFromTypedef( std::string *); 222 static DeclarationNode *newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ); 223 static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants ); 224 static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant ); 225 static DeclarationNode *newName( std::string *); 226 static DeclarationNode *newFromTypeGen( std::string *, ExpressionNode *params ); 227 static DeclarationNode *newTypeParam( TypeClass, std::string *); 228 static DeclarationNode *newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ); 229 static DeclarationNode *newTraitUse( std::string *name, ExpressionNode *params ); 230 static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams ); 231 static DeclarationNode *newPointer( DeclarationNode *qualifiers ); 232 static DeclarationNode *newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ); 233 static DeclarationNode *newVarArray( DeclarationNode *qualifiers ); 234 static DeclarationNode *newBitfield( ExpressionNode *size ); 235 static DeclarationNode *newTuple( DeclarationNode *members ); 236 static DeclarationNode *newTypeof( ExpressionNode *expr ); 237 static DeclarationNode *newAttr( std::string *, ExpressionNode *expr ); 238 static DeclarationNode *newAttr( std::string *, DeclarationNode *type ); 239 239 240 240 DeclarationNode(); 241 241 ~DeclarationNode(); 242 DeclarationNode * clone() const;243 244 DeclarationNode * addQualifiers( DeclarationNode *);242 DeclarationNode *clone() const; 243 244 DeclarationNode *addQualifiers( DeclarationNode *); 245 245 void checkQualifiers( const TypeData *, const TypeData * ); 246 void checkStorageClasses( DeclarationNode *q ); 247 DeclarationNode * copyStorageClasses( DeclarationNode *); 248 DeclarationNode * addType( DeclarationNode *); 249 DeclarationNode * addTypedef(); 250 DeclarationNode * addAssertions( DeclarationNode *); 251 DeclarationNode * addName( std::string *); 252 DeclarationNode * addBitfield( ExpressionNode * size ); 253 DeclarationNode * addVarArgs(); 254 DeclarationNode * addFunctionBody( StatementNode * body ); 255 DeclarationNode * addOldDeclList( DeclarationNode * list ); 256 DeclarationNode * addPointer( DeclarationNode * qualifiers ); 257 DeclarationNode * addArray( DeclarationNode * array ); 258 DeclarationNode * addNewPointer( DeclarationNode * pointer ); 259 DeclarationNode * addNewArray( DeclarationNode * array ); 260 DeclarationNode * addParamList( DeclarationNode * list ); 261 DeclarationNode * addIdList( DeclarationNode * list ); // old-style functions 262 DeclarationNode * addInitializer( InitializerNode * init ); 263 264 DeclarationNode * cloneType( std::string * newName ); 265 DeclarationNode * cloneType( DeclarationNode * existing ); 266 DeclarationNode * cloneType( int ) { return cloneType( ( std::string *)0 ); } 267 DeclarationNode * cloneBaseType( std::string * newName ); 268 DeclarationNode * cloneBaseType( DeclarationNode * newdecl ); 269 270 DeclarationNode * appendList( DeclarationNode * node ) { 246 DeclarationNode *copyStorageClasses( DeclarationNode *); 247 DeclarationNode *addType( DeclarationNode *); 248 DeclarationNode *addTypedef(); 249 DeclarationNode *addAssertions( DeclarationNode *); 250 DeclarationNode *addName( std::string *); 251 DeclarationNode *addBitfield( ExpressionNode *size ); 252 DeclarationNode *addVarArgs(); 253 DeclarationNode *addFunctionBody( StatementNode *body ); 254 DeclarationNode *addOldDeclList( DeclarationNode *list ); 255 DeclarationNode *addPointer( DeclarationNode *qualifiers ); 256 DeclarationNode *addArray( DeclarationNode *array ); 257 DeclarationNode *addNewPointer( DeclarationNode *pointer ); 258 DeclarationNode *addNewArray( DeclarationNode *array ); 259 DeclarationNode *addParamList( DeclarationNode *list ); 260 DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions 261 DeclarationNode *addInitializer( InitializerNode *init ); 262 263 DeclarationNode *cloneType( std::string *newName ); 264 DeclarationNode *cloneType( DeclarationNode *existing ); 265 DeclarationNode *cloneType( int ) { return cloneType( ( std::string *)0 ); } 266 DeclarationNode *cloneBaseType( std::string *newName ); 267 DeclarationNode *cloneBaseType( DeclarationNode *newdecl ); 268 269 DeclarationNode *appendList( DeclarationNode *node ) { 271 270 return (DeclarationNode *)set_last( node ); 272 271 } … … 275 274 void printList( std::ostream &os, int indent = 0 ) const; 276 275 277 Declaration * build() const;278 ::Type * buildType() const;276 Declaration *build() const; 277 ::Type *buildType() const; 279 278 280 279 bool get_hasEllipsis() const; 281 280 const std::string &get_name() const { return name; } 282 281 LinkageSpec::Spec get_linkage() const { return linkage; } 283 DeclarationNode * extractAggregate() const;282 DeclarationNode *extractAggregate() const; 284 283 bool has_enumeratorValue() const { return (bool)enumeratorValue; } 285 ExpressionNode * consume_enumeratorValue() const { return const_cast<DeclarationNode*>(this)->enumeratorValue.release(); }284 ExpressionNode *consume_enumeratorValue() const { return const_cast<DeclarationNode*>(this)->enumeratorValue.release(); } 286 285 287 286 bool get_extension() const { return extension; } 288 DeclarationNode * set_extension( bool exten ) { extension = exten; return this; }287 DeclarationNode *set_extension( bool exten ) { extension = exten; return this; } 289 288 public: 290 289 // StorageClass buildStorageClass() const; … … 307 306 BuiltinType builtin; 308 307 309 TypeData * type;308 TypeData *type; 310 309 std::string name; 311 310 // std::list< StorageClass > storageClasses; … … 313 312 bool isInline, isNoreturn; 314 313 std::list< std::string > attributes; 315 ExpressionNode * bitfieldWidth;314 ExpressionNode *bitfieldWidth; 316 315 std::unique_ptr<ExpressionNode> enumeratorValue; 317 InitializerNode * initializer;316 InitializerNode *initializer; 318 317 bool hasEllipsis; 319 318 LinkageSpec::Spec linkage; … … 324 323 }; // DeclarationNode 325 324 326 Type * buildType( TypeData *type );325 Type *buildType( TypeData *type ); 327 326 //Type::Qualifiers buildQualifiers( const TypeData::Qualifiers & qualifiers ); 328 327 329 static inline Type * maybeMoveBuildType( const DeclarationNode * orig ) {328 static inline Type * maybeMoveBuildType( const DeclarationNode *orig ) { 330 329 Type* ret = orig ? orig->buildType() : nullptr; 331 330 delete orig; … … 338 337 public: 339 338 StatementNode() { stmt = nullptr; } 340 StatementNode( Statement * stmt ) : stmt( stmt ) {}341 StatementNode( DeclarationNode * decl );339 StatementNode( Statement *stmt ) : stmt( stmt ) {} 340 StatementNode( DeclarationNode *decl ); 342 341 virtual ~StatementNode() {} 343 342 344 virtual StatementNode * clone() const final { assert( false ); return nullptr; }345 Statement * build() const { return const_cast<StatementNode*>(this)->stmt.release(); }346 347 virtual StatementNode * add_label( const std::string * name ) {348 stmt->get_labels().emplace_back( * name );343 virtual StatementNode *clone() const final { assert( false ); return nullptr; } 344 Statement *build() const { return const_cast<StatementNode*>(this)->stmt.release(); } 345 346 virtual StatementNode *add_label( const std::string * name ) { 347 stmt->get_labels().emplace_back( *name ); 349 348 delete name; 350 349 return this; 351 350 } 352 351 353 virtual StatementNode * append_last_case( StatementNode * );352 virtual StatementNode *append_last_case( StatementNode * ); 354 353 355 354 virtual void print( std::ostream &os, int indent = 0 ) {} … … 359 358 }; // StatementNode 360 359 361 Statement * build_expr( ExpressionNode *ctl );360 Statement *build_expr( ExpressionNode *ctl ); 362 361 363 362 struct ForCtl { 364 ForCtl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode *change ) :363 ForCtl( ExpressionNode *expr, ExpressionNode *condition, ExpressionNode *change ) : 365 364 init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {} 366 ForCtl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode *change ) :365 ForCtl( DeclarationNode *decl, ExpressionNode *condition, ExpressionNode *change ) : 367 366 init( new StatementNode( decl ) ), condition( condition ), change( change ) {} 368 367 369 StatementNode * init;370 ExpressionNode * condition;371 ExpressionNode * change;368 StatementNode *init; 369 ExpressionNode *condition; 370 ExpressionNode *change; 372 371 }; 373 372 374 Statement * build_if( ExpressionNode * ctl, StatementNode * then_stmt, StatementNode *else_stmt );375 Statement * build_switch( ExpressionNode * ctl, StatementNode *stmt );376 Statement * build_case( ExpressionNode *ctl );377 Statement * build_default();378 Statement * build_while( ExpressionNode * ctl, StatementNode *stmt, bool kind = false );379 Statement * build_for( ForCtl * forctl, StatementNode *stmt );380 Statement * build_branch( BranchStmt::Type kind );381 Statement * build_branch( std::string *identifier, BranchStmt::Type kind );382 Statement * build_computedgoto( ExpressionNode *ctl );383 Statement * build_return( ExpressionNode *ctl );384 Statement * build_throw( ExpressionNode *ctl );385 Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode *finally_stmt );386 Statement * build_catch( DeclarationNode * decl, StatementNode *stmt, bool catchAny = false );387 Statement * build_finally( StatementNode *stmt );388 Statement * build_compound( StatementNode *first );389 Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = 0, ExpressionNode * input = 0, ExpressionNode * clobber = 0, LabelNode *gotolabels = 0 );373 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ); 374 Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ); 375 Statement *build_case( ExpressionNode *ctl ); 376 Statement *build_default(); 377 Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind = false ); 378 Statement *build_for( ForCtl *forctl, StatementNode *stmt ); 379 Statement *build_branch( BranchStmt::Type kind ); 380 Statement *build_branch( std::string *identifier, BranchStmt::Type kind ); 381 Statement *build_computedgoto( ExpressionNode *ctl ); 382 Statement *build_return( ExpressionNode *ctl ); 383 Statement *build_throw( ExpressionNode *ctl ); 384 Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ); 385 Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny = false ); 386 Statement *build_finally( StatementNode *stmt ); 387 Statement *build_compound( StatementNode *first ); 388 Statement *build_asmstmt( bool voltile, ConstantExpr *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ExpressionNode *clobber = 0, LabelNode *gotolabels = 0 ); 390 389 391 390 //############################################################################## 392 391 393 392 template< typename SynTreeType, typename NodeType > 394 void buildList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) {393 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) { 395 394 SemanticError errors; 396 395 std::back_insert_iterator< std::list< SynTreeType * > > out( outputList ); 397 const NodeType * cur = firstNode;396 const NodeType *cur = firstNode; 398 397 399 398 while ( cur ) { 400 399 try { 401 // SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type >( cur ) );402 SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) );400 // SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type >( cur ) ); 401 SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) ); 403 402 if ( result ) { 404 * out++ = result;403 *out++ = result; 405 404 } // if 406 405 } catch( SemanticError &e ) { … … 415 414 416 415 // in DeclarationNode.cc 417 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList );418 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList );419 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList );416 void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ); 417 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ); 418 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ); 420 419 421 420 template< typename SynTreeType, typename NodeType > 422 void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) {421 void buildMoveList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) { 423 422 buildList(firstNode, outputList); 424 423 delete firstNode; -
src/Parser/TypeData.h
rfd782b2 rf006f01 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Sep 10 09:42:54201613 // Update Count : 11 812 // Last Modified On : Fri Sep 9 23:20:55 2016 13 // Update Count : 117 14 14 // 15 15 … … 89 89 typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers; 90 90 Qualifiers qualifiers; 91 typedef std::bitset< DeclarationNode::NoStorageClass > StorageClasses;92 StorageClasses storageclasses;93 91 DeclarationNode * forall; 94 92 -
src/Parser/parser.cc
rfd782b2 rf006f01 5943 5943 /* Line 1806 of yacc.c */ 5944 5944 #line 831 "parser.yy" 5945 { (yyval.sn) = new StatementNode( build_while( (yyvsp[(5) - (7)].en), (yyvsp[(2) - (7)].sn) , true) ); }5945 { (yyval.sn) = new StatementNode( build_while( (yyvsp[(5) - (7)].en), (yyvsp[(2) - (7)].sn) ) ); } 5946 5946 break; 5947 5947 -
src/Parser/parser.yy
rfd782b2 rf006f01 829 829 { $$ = new StatementNode( build_while( $3, $5 ) ); } 830 830 | DO statement WHILE '(' comma_expression ')' ';' 831 { $$ = new StatementNode( build_while( $5, $2 , true) ); }831 { $$ = new StatementNode( build_while( $5, $2 ) ); } 832 832 | FOR '(' push for_control_expression ')' statement 833 833 { $$ = new StatementNode( build_for( $4, $6 ) ); } -
src/examples/gc_no_raii/bug-repro/field.c
rfd782b2 rf006f01 62 62 { 63 63 struct gc_object_header* object; 64 #if ndef NDEBUG64 #if _DEBUG 65 65 intptr_t lower_limit; 66 66 intptr_t upper_limit; … … 71 71 gc_pool_object_iterator* const this, 72 72 void* start_object 73 #if ndef NDEBUG73 #if _DEBUG 74 74 , intptr_t pool_start 75 75 , intptr_t pool_end -
src/examples/gc_no_raii/src/gcpointers.c
rfd782b2 rf006f01 14 14 gc_object_header* obj = gc_get_object_for_ref(gc_get_state(), (void*)this); 15 15 check(obj); 16 check( is_valid(obj));17 check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || !obj->type_chain);16 check(gc_obj_is_valide(obj)); 17 check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || obj->type_chain == NULL); 18 18 this->next = obj->type_chain; 19 19 obj->type_chain = this; 20 check( is_valid(obj));20 check(obj->is_valide()); 21 21 } 22 22 else … … 24 24 gc_object_header* obj = gc_get_object_ptr((void*)this->ptr); 25 25 check(obj); 26 check(is_valid(obj)); 27 check(!obj->root_chain || this->ptr == obj->root_chain->ptr); 28 check(!obj->root_chain || gc_is_managed(this) == gc_is_managed(obj->root_chain)); 26 check(gc_obj_is_valide(obj)); 27 check(gc_is_managed(this) == gc_is_managed(obj->root_chain) || obj->root_chain == NULL); 29 28 this->next = obj->root_chain; 30 29 obj->root_chain = this; 31 check( is_valid(obj));30 check(gc_obj_is_valide(obj)); 32 31 } 33 32 } … … 70 69 } 71 70 72 gcpointer_t ?=?(gcpointer_t* this, gcpointer_trhs)71 gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs) 73 72 { 74 unregister_ptr(this);75 this->ptr = rhs.ptr;76 register_ptr(this);73 if(this != rhs) 74 { 75 unregister_ptr(this); 77 76 78 return *this; 77 this->ptr = rhs->ptr; 78 79 register_ptr(this); 80 } 81 82 return this; 79 83 } 80 84 81 85 //Logical operators 82 bool gcpointer_equal( const gcpointer_t* this, constgcpointer_t* rhs)86 bool gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs) 83 87 { 84 88 return this->ptr == rhs->ptr; 85 89 } 86 90 87 bool gcpointer_not_equal( const gcpointer_t* this, constgcpointer_t* rhs)91 bool gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs) 88 92 { 89 93 return this->ptr != rhs->ptr; 90 94 } 91 95 92 bool gcpointer_null( constgcpointer_t* this)96 bool gcpointer_null(gcpointer_t* this) 93 97 { 94 98 return this->ptr == (intptr_t)NULL; 95 99 } 96 97 #ifndef NDEBUG98 bool is_valid(const gcpointer_t* this) {99 if(gcpointer_null(this)) return true;100 101 gc_object_header* obj = gc_get_object_ptr((void*)this->ptr);102 check(obj);103 check(is_valid(obj));104 check(!obj->root_chain || this->ptr == obj->root_chain->ptr);105 106 if( !gc_is_managed(this))107 {108 check( !(this->next) || this->ptr == this->next->ptr );109 }110 111 return true;112 }113 #endif114 100 115 101 forall(otype T) void ?{}(gcpointer(T)* this) { … … 121 107 } 122 108 123 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T) other) {124 (&this->internal) { other .internal };109 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other) { 110 (&this->internal) { other->internal }; 125 111 } 126 112 … … 129 115 } 130 116 131 forall(otype T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs) { 132 this->internal = rhs.internal; 133 return *this; 134 } 117 // forall(otype T) gcpointer(T) ?=?(gcpointer(T) this, gcpointer(T) rhs); 135 118 // 136 119 // forall(otype T) T *?(gcpointer(T) this); … … 141 124 // 142 125 // //Logical operators 143 forall(otype T) int ?!=?(gcpointer(T) this, int zero) {144 return this.internal.ptr != 0;145 }146 126 // forall(otype T) int ?!=?(gcpointer(T) this, gcpointer(T) rhs); 147 127 // forall(otype T) int ?==?(gcpointer(T) this, gcpointer(T) rhs); -
src/examples/gc_no_raii/src/gcpointers.h
rfd782b2 rf006f01 3 3 #include <stdbool.h> 4 4 #include <stdint.h> 5 6 forall(dtype T)7 struct gcpointer;8 5 9 6 struct gcpointer_t … … 17 14 void ?{}(gcpointer_t* this, gcpointer_t other); 18 15 void ^?{}(gcpointer_t* this); 19 gcpointer_t ?=?(gcpointer_t*this, gcpointer_t rhs);16 gcpointer_t* ?=?(gcpointer_t this, gcpointer_t rhs); 20 17 21 18 //Logical operators 22 19 bool gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs); 23 20 bool gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs); 24 bool gcpointer_null( constgcpointer_t* this);21 bool gcpointer_null(gcpointer_t* this); 25 22 26 27 #ifndef NDEBUG 28 bool is_valid(const gcpointer_t* this); 29 #endif 30 31 forall(dtype T) 23 forall(otype T) 32 24 struct gcpointer 33 25 { … … 38 30 forall(otype T) void ?{}(gcpointer(T)* this); 39 31 forall(otype T) void ?{}(gcpointer(T)* this, void* address); 40 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T) other);32 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other); 41 33 forall(otype T) void ^?{}(gcpointer(T)* this); 42 forall(otype T) gcpointer(T) ?=?(gcpointer(T) *this, gcpointer(T) rhs);34 forall(otype T) gcpointer(T) ?=?(gcpointer(T) this, gcpointer(T) rhs); 43 35 44 36 45 //forall(otype T) T *?(gcpointer(T) this);37 forall(otype T) T *?(gcpointer(T) this); 46 38 forall(otype T) T* get(gcpointer(T)* this); 47 39 48 40 //Logical operators 49 forall(otype T) int ?!=?(gcpointer(T) this, int zero);50 41 forall(otype T) int ?!=?(gcpointer(T) this, gcpointer(T) rhs); 51 42 forall(otype T) int ?==?(gcpointer(T) this, gcpointer(T) rhs); -
src/examples/gc_no_raii/src/internal/card_table.h
rfd782b2 rf006f01 1 1 #pragma once 2 3 #include <stdlib> 2 4 3 5 #include "globals.h" … … 7 9 { 8 10 size_t card = ( ((intptr_t)address) & CARDS_OFFSET_MASK ) >> CARDS_SIZE_EXP; 9 checkf(card < CARDS_COUNT, (const char*)"%lu %lu = (%lx & %lx) >> %lu\n", (size_t)CARDS_COUNT, (size_t)card, (size_t)address, (size_t)CARDS_OFFSET_MASK, (size_t)CARDS_SIZE_EXP);10 11 check(card < CARDS_COUNT); 11 12 return card; … … 18 19 }; 19 20 20 static inline void ctor _card(card_table_t* const this)21 static inline void ctor(card_table_t* const this) 21 22 { 22 23 this->count = 0; 23 24 } 24 25 25 static inline void dtor _card(card_table_t* const this)26 static inline void dtor(card_table_t* const this) 26 27 { 27 28 … … 47 48 else 48 49 { 49 check(card == this->count);50 check(card == count); 50 51 this->count++; 51 52 this->cards_start[card] = object; -
src/examples/gc_no_raii/src/internal/collector.c
rfd782b2 rf006f01 25 25 gc_object_header* obj = gc_get_object_ptr((void*)target->ptr); 26 26 27 check( is_valid(obj));27 check(gc_is_valide(obj)); 28 28 29 29 gcpointer_t** prev_next_ptr = managed ? &obj->type_chain : &obj->root_chain; … … 38 38 void* gc_allocate(size_t target_size) 39 39 { 40 //sout | "Allocating " | target_size | " bytes" | endl;40 sout | "Allocating " | target_size | " bytes" | endl; 41 41 42 42 size_t size = gc_compute_size(target_size + sizeof(gc_object_header)); 43 43 44 //sout | "Object header size: " | sizeof(gc_object_header) | " bytes" | endl;45 //sout | "Actual allocation size: " | size | " bytes" | endl;44 sout | "Object header size: " | sizeof(gc_object_header) | " bytes" | endl; 45 sout | "Actual allocation size: " | size | " bytes" | endl; 46 46 47 47 check(size < POOL_SIZE_BYTES); … … 60 60 if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size); 61 61 62 checkf( (int) 0, "ERROR: allocation in new pool failed");62 checkf(false, "ERROR: allocation in new pool failed"); 63 63 64 64 return NULL; … … 67 67 void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size) 68 68 { 69 intptr_t data = ((intptr_t)block) + sizeof(gc_object_header);69 void* data = (void*)(((intptr_t)block) + sizeof(gc_object_header)); 70 70 void* header = block; 71 71 72 check( data> ((intptr_t)block));73 check( data>= ((intptr_t)header));74 check( gc_is_aligned( (void*)data ));75 check( data + target_size <= ((intptr_t)block) + actual_size);72 check(((intptr_t)data) > ((intptr_t)block)); 73 check(((intptr_t)data) >= ((intptr_t)header)); 74 check(is_aligned(data)); 75 check(((intptr_t)data) + target_size <= ((intptr_t)block) + actual_size); 76 76 77 77 gc_object_header* obj = placement_ctor(header, actual_size); 78 78 79 79 (void)obj; //remove unsused warning since this is for debug 80 check(obj == g c_get_object_ptr( (void*)data));80 check(obj == get_object_ptr(data)); 81 81 82 82 gc_register_allocation(gc_get_state(), actual_size); 83 83 84 return (void*)data;84 return data; 85 85 } 86 86 … … 119 119 check(!ptr->forward); 120 120 check(!ptr->is_forwarded); 121 check(gc_ pool_is_from_space(gc_pool_of(ptr)));121 check(gc_is_from_space(gc_pool_of(ptr))); 122 122 123 123 gc_memory_pool* pool = gc_pool_of(ptr)->mirror; … … 143 143 check(((intptr_t)field) < ((intptr_t)((intptr_t)object) + object->size)); 144 144 145 check(gc_is_in_to_space(gc_get_state(), & field->ptr));145 check(gc_is_in_to_space(gc_get_state(), &type->ptr)); 146 146 147 147 intptr_t* ref = &field->ptr; -
src/examples/gc_no_raii/src/internal/collector.h
rfd782b2 rf006f01 1 1 #pragma once 2 2 3 #include <stdlib .h>3 #include <stdlib> 4 4 5 5 #include "tools.h" -
src/examples/gc_no_raii/src/internal/memory_pool.c
rfd782b2 rf006f01 1 1 #include "memory_pool.h" 2 2 3 extern "C" { 4 #include <stdlib.h> 5 #include <string.h> 6 } 3 #include <stdlib> 7 4 8 #include "collector.h"9 5 #include "object_header.h" 10 6 … … 19 15 card_table_t* new = (card_table_t*)malloc(sizeof(card_table_t)); 20 16 this->cards = new; 21 ctor _card(this->cards);17 ctor(this->cards); 22 18 23 19 this->end_p = ((uint8_t*)this) + size; 24 20 this->free_p = this->start_p; 25 21 26 check( gc_pool_of( (void*)this) == this);22 check(gc_pool_of(this) == this); 27 23 check(this->cards); 28 24 gc_reset_pool(this); … … 31 27 void dtor(gc_memory_pool *const this) 32 28 { 33 dtor _card(this->cards);29 dtor(this->cards); 34 30 free(this->cards); 35 31 } … … 38 34 { 39 35 this->free_p = this->start_p; 40 #if ndef NDEBUG41 memset(this->start_p, 0xCD, gc_pool_ size_total(this));36 #if _DEBUG 37 memset(this->start_p, 0xCD, gc_pool_total_size(this)); 42 38 #endif 43 39 … … 45 41 reset(this->cards); 46 42 47 check(gc_pool_size_left(this) == gc_pool_ size_total(this));43 check(gc_pool_size_left(this) == gc_pool_total_size(this)); 48 44 } 49 45 … … 62 58 } 63 59 64 void ?{}( gc_pool_object_iterator* this, 60 void ctor( 61 gc_pool_object_iterator* const this, 65 62 struct gc_object_header* start_object 66 #if ndef NDEBUG63 #if _DEBUG 67 64 , intptr_t pool_start 68 65 , intptr_t pool_end … … 71 68 { 72 69 this->object = start_object; 73 #if ndef NDEBUG70 #if _DEBUG 74 71 this->lower_limit = pool_start; 75 72 this->upper_limit = pool_end; 76 73 #endif 77 74 78 check( ((intptr_t)start_object) >= this->lower_limit );79 check( ((intptr_t)start_object) <= this->upper_limit );75 check( ((intptr_t)start_object) >= lower_limit ); 76 check( ((intptr_t)start_object) <= upper_limit ); 80 77 } 81 82 void ^?{}( gc_pool_object_iterator* this ) {}83 78 84 79 gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const this, void* member) … … 86 81 size_t card = card_of(member); 87 82 intptr_t member_add = (intptr_t)member; 88 intptr_t start_obj; 83 void* start_obj; 84 intptr_t start_obj_add; 89 85 90 86 do 91 87 { 92 88 check(card < CARDS_COUNT); 93 start_obj = (intptr_t)object_at(this->cards, card);89 start_obj = object_at(this->cards, card); 94 90 check(card != 0 || start_obj); 95 91 card--; 92 start_obj_add = (intptr_t)start_obj; 96 93 } 97 while(start_obj > member_add || !(start_obj));94 while(start_obj_add > member_add || start_obj_add != 0); 98 95 99 check( start_obj);100 96 check(start_obj); 97 101 98 struct gc_object_header* start_obj_typed = (struct gc_object_header*)start_obj; 102 99 103 return (gc_pool_object_iterator) { 104 start_obj_typed 105 #ifndef NDEBUG 100 gc_pool_object_iterator it; 101 ctor( &it, 102 start_obj_typed, 103 #if _DEBUG 106 104 , (intptr_t)this->start_p 107 105 , (intptr_t)this->free_p 108 106 #endif 109 }; 107 ); 108 return it; 110 109 } 111 110 … … 118 117 { 119 118 struct gc_object_header* start_obj = (struct gc_object_header*)this->start_p; 120 return (gc_pool_object_iterator) { 121 start_obj 122 #ifndef NDEBUG 119 gc_pool_object_iterator it; 120 ctor( &it, 121 start_obj, 122 #if _DEBUG 123 123 , (intptr_t)this->start_p 124 124 , (intptr_t)this->free_p 125 125 #endif 126 }; 126 ); 127 return it; 127 128 } 128 129 129 130 gc_pool_object_iterator end(gc_memory_pool* const this) 130 131 { 131 return (gc_pool_object_iterator) { 132 (struct gc_object_header*)this->free_p 133 #ifndef NDEBUG 132 gc_pool_object_iterator it; 133 ctor( &it, 134 (struct gc_object_header*)this->free_p, 135 #if _DEBUG 134 136 , (intptr_t)this->start_p 135 137 , (intptr_t)this->free_p 136 138 #endif 137 }; 139 ); 140 return it; 138 141 } 139 142 … … 142 145 struct gc_object_header* object = it->object; 143 146 intptr_t next_ptr = ((intptr_t)object) + object->size; 144 check(next_ptr > it->lower_limit);145 check(next_ptr <= it->upper_limit);147 check(next_ptr > lower_limit); 148 check(next_ptr <= upper_limit); 146 149 147 150 struct gc_object_header* next_obj = ((struct gc_object_header*)next_ptr); 148 check(next_ptr == it->upper_limit || is_valid(next_obj));151 check(next_ptr == upper_limit || is_valide(next_obj)); 149 152 150 153 it->object = next_obj; -
src/examples/gc_no_raii/src/internal/memory_pool.h
rfd782b2 rf006f01 39 39 { 40 40 struct gc_object_header* object; 41 #if ndef NDEBUG41 #if _DEBUG 42 42 intptr_t lower_limit; 43 43 intptr_t upper_limit; … … 46 46 47 47 48 void ?{}( gc_pool_object_iterator* this, 48 void ctor( 49 gc_pool_object_iterator* const this, 49 50 struct gc_object_header* start_object 50 #if ndef NDEBUG51 #if _DEBUG 51 52 , intptr_t pool_start 52 53 , intptr_t pool_end 53 54 #endif 54 55 ); 55 56 void ^?{}( gc_pool_object_iterator* this );57 56 58 57 bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs); -
src/examples/gc_no_raii/src/internal/object_header.c
rfd782b2 rf006f01 3 3 #include <stdint.h> 4 4 5 #include "collector.h"6 5 #include "globals.h" 7 6 #include "gcpointers.h" … … 9 8 void ctor(gc_object_header* const this, size_t inSize) 10 9 { 11 #if ndef NDEBUG10 #if _DEBUG 12 11 this->canary_start = CANARY_VALUE; 13 12 #endif … … 19 18 this->is_forwarded = false; 20 19 21 #if ndef NDEBUG20 #if _DEBUG 22 21 this->canary_end = CANARY_VALUE; 23 22 #endif … … 26 25 void copy_ctor(gc_object_header* const this, const gc_object_header* const other) 27 26 { 28 #if ndef NDEBUG27 #if _DEBUG 29 28 this->canary_start = CANARY_VALUE; 30 29 #endif … … 36 35 this->is_forwarded = false; 37 36 38 #if ndef NDEBUG37 #if _DEBUG 39 38 this->canary_end = CANARY_VALUE; 40 39 #endif … … 43 42 while(root) 44 43 { 45 check(g c_get_object_ptr( (void*)root->ptr) == other);44 check(get_object_ptr(root->ptr) == other); 46 45 root->ptr = ((intptr_t)this) + sizeof(gc_object_header); 47 46 48 check(g c_get_object_ptr( (void*)root->ptr) == this);47 check(get_object_ptr(root->ptr) == this); 49 48 root = root->next; 50 49 } … … 57 56 58 57 size_t offset = (intptr_t)type - (intptr_t)other; 59 check(offset < this->size);58 check(offset < size); 60 59 61 60 gcpointer_t* member_ptr = (gcpointer_t*)( (intptr_t)this + offset ); … … 64 63 65 64 size_t next_offset = type->next ? (intptr_t)type->next - (intptr_t)other : 0; 66 check(next_offset < this->size);65 check(next_offset < size); 67 66 68 67 gcpointer_t* next_ptr = type->next ? (gcpointer_t*)((intptr_t)this + next_offset) : NULL; … … 74 73 } 75 74 76 check(is_valid (this));75 check(is_valide(this)); 77 76 } 78 77 79 #if ndef NDEBUG80 bool is_valid (const gc_object_header* const this)78 #if _DEBUG 79 bool is_valide(const gc_object_header* const this) 81 80 { 82 check( (intptr_t)this->canary_start == (intptr_t)CANARY_VALUE);83 check( (intptr_t)this->canary_end == (intptr_t)CANARY_VALUE);81 check(this->canary_start == CANARY_VALUE); 82 check(this->canary_end == CANARY_VALUE); 84 83 85 check(this->is_forwarded == ( (intptr_t)this->forward != (intptr_t)NULL));84 check(this->is_forwarded == (this->forward != nullptr)); 86 85 87 86 check(this->size < POOL_SIZE_BYTES); … … 90 89 while(root) 91 90 { 92 check f(gc_get_object_ptr( (void*)root->ptr ) == this, (const char*)"Expected %lX got %lX\n", gc_get_object_ptr( (void*)root->ptr ),this);91 check(get_object_ptr(root->ptr) == this); 93 92 94 93 root = root->next; 95 94 } 96 95 97 gcpointer_t* type = t his->type_chain;96 gcpointer_t* type = type_chain; 98 97 while(type) 99 98 { 100 99 check((intptr_t)type > (intptr_t)this); 101 check((intptr_t)type < (intptr_t)(( (intptr_t)this) + this->size));100 check((intptr_t)type < (intptr_t)((intptr_t)this + size)); 102 101 103 102 type = type->next; … … 106 105 return true; 107 106 } 108 #else109 #error blarg110 107 #endif -
src/examples/gc_no_raii/src/internal/object_header.h
rfd782b2 rf006f01 7 7 #include "tools.h" 8 8 9 #if ndef NDEBUG10 static void* const CANARY_VALUE = (void*)0xCAFEBABACAFEBABA;9 #if DEBUG 10 static const long unsigned int CANARY_VALUE = 0xCAFEBABACAFEBABA; 11 11 #endif 12 12 … … 16 16 struct gc_object_header 17 17 { 18 #if ndef NDEBUG18 #if DEBUG 19 19 void* canary_start; 20 20 #endif … … 26 26 bool is_forwarded; 27 27 28 #if ndef NDEBUG28 #if DEBUG 29 29 void* canary_end; 30 30 #endif … … 47 47 return this; 48 48 } 49 50 #ifndef NDEBUG51 bool is_valid(const gc_object_header* const this);52 #endif -
src/examples/gc_no_raii/src/internal/state.c
rfd782b2 rf006f01 21 21 void gc_state_calc_usage(gc_state *const this); 22 22 23 #if ndef NDEBUG23 #if DEBUG 24 24 bool gc_state_roots_match(gc_state *const this); 25 25 bool gc_state_no_from_space_ref(gc_state *const this); … … 76 76 gc_object_header* gc_get_object_for_ref(gc_state* state, void* member) 77 77 { 78 volatile int stage = 0;79 78 intptr_t target = ((intptr_t)member); 80 79 if(!gc_is_in_heap(state, member)) return NULL; 81 stage++;82 80 83 81 gc_memory_pool* pool = gc_pool_of(member); 84 stage++;85 82 gc_pool_object_iterator it = gc_pool_iterator_for(pool, member); 86 stage++;87 83 gc_pool_object_iterator end = end(pool); 88 stage++;89 84 90 85 while(it != end) 91 86 { 92 87 gc_object_header* object = *it; 93 check(object);94 check( is_valid(object) );95 88 { 96 89 intptr_t start = ((intptr_t)object); … … 101 94 } 102 95 } 103 stage++;104 96 ++it; 105 97 } 106 98 107 checkf( (int) 0, "is_in_heap() and iterator_for() return inconsistent data");99 checkf(false, "is_in_heap() and iterator_for() return inconsistent data"); 108 100 abort(); 109 101 return NULL; … … 184 176 this->from_code = (~this->from_code) & 0x01; 185 177 186 #if ndef NDEBUG178 #if _DEBUG 187 179 { 188 180 gc_memory_pool* pool = this->from_space; … … 259 251 } 260 252 261 #if ndef NDEBUG253 #if _DEBUG 262 254 bool gc_state_roots_match(gc_state* const this) 263 255 { … … 273 265 size += object->size; 274 266 275 gcpointer_ t* ptr = object->root_chain;267 gcpointer_base* ptr = object->root_chain; 276 268 while(ptr) 277 269 { 278 check(g c_get_object_ptr( (void*)ptr->ptr) == object);279 ptr = ptr-> next;270 check(get_object_ptr(ptr->m_ptr) == object); 271 ptr = ptr->m_next; 280 272 } 281 273 } 282 274 283 checkf(size + gc_pool_size_left(pool) == gc_pool_size_total(pool), 284 (const char*)"expected %lu + %lu == %lu\n", 285 (size_t)size, 286 (size_t)gc_pool_size_left(pool), 287 (size_t)gc_pool_size_total(pool)); 275 check(size + gc_pool_size_used(pool) == gc_pool_size_total(pool)); 288 276 289 277 pool = pool->next; … … 298 286 while(pool) 299 287 { 300 void** potential_ref = (void**)pool-> start_p;301 while(potential_ref < (void**)pool-> free_p)288 void** potential_ref = (void**)pool->m_start; 289 while(potential_ref < (void**)pool->m_free) 302 290 { 303 291 check(!gc_is_in_heap(this, *potential_ref)); -
src/examples/gc_no_raii/src/internal/state.h
rfd782b2 rf006f01 38 38 static inline bool gc_needs_collect(gc_state* state) 39 39 { 40 //sout | "Used Space: " | state->used_space | " bytes" | endl;40 sout | "Used Space: " | state->used_space | " bytes" | endl; 41 41 return state->used_space * 2 > state->total_space; 42 42 } -
src/examples/gc_no_raii/src/tools/checks.h
rfd782b2 rf006f01 1 1 #pragma once 2 2 3 #ifdef NDEBUG 4 5 #define check(x) 6 7 #define checkf(x, format, ...) 8 9 #warning no debug checks 10 11 #else 3 #if _DEBUG 12 4 13 5 #include <stdlib.h> … … 18 10 printf("CHECK failed : %s at %s:%i\n", #x, __FILE__, __LINE__);\ 19 11 abort();\ 20 }}while( (int)0)\12 }}while(0)\ 21 13 22 14 #define checkf(x, ...) do {\ … … 25 17 printf(__VA_ARGS__);\ 26 18 abort();\ 27 }}while( (int)0 )\ 19 }}while(0)\ 20 21 #else 22 23 #define check(x) 24 25 #define checkf(x, format, ...) 28 26 29 27 #endif //NO_CHECKS -
src/examples/gc_no_raii/src/tools/print.c
rfd782b2 rf006f01 1 1 #include "tools.h" 2 2 3 #if ndef NDEBUG4 //ofstream *sout = ofstream_stdout();3 #if _DEBUG 4 ofstream *sout = ofstream_stdout(); 5 5 #endif -
src/examples/gc_no_raii/src/tools/print.h
rfd782b2 rf006f01 1 1 #pragma once 2 2 3 // #ifndef NDEBUG4 // 5 //#include <fstream>6 // 7 //#define DEBUG_OUT(x) sout | x | endl;8 // 9 //#else3 #if _DEBUG 4 5 #include <fstream> 6 7 #define DEBUG_OUT(x) sout | x | endl; 8 9 #else 10 10 11 11 #define DEBUG_OUT(x) 12 12 13 //#endif //NO_CHECKS13 #endif //NO_CHECKS -
src/examples/gc_no_raii/test/badlll.c
rfd782b2 rf006f01 1 1 #include "gc.h" 2 3 #include <stdio.h>4 2 5 3 struct List_t … … 9 7 }; 10 8 9 void ?{}(List_t* this); 10 List_t* ?=?(List_t* this, List_t* rhs); 11 11 12 typedef gcpointer(List_t) LLL; 12 13 13 #define MAX (1024 * 1 )14 #define MAX (1024 * 1024) 14 15 15 LLL buildLLL(int sz) 16 // LLL buildLLL(int sz) 17 void bla() 16 18 { 17 int i = 0; 18 LLL ll0; 19 20 gcmalloc( &ll0 ); 21 List_t* ll0_ptr = get( &ll0 ); 22 ll0_ptr->val = i; 23 LLL lll = ll0; 24 25 for (i = 1; i < sz; i++) 26 { 27 LLL llc; 28 gcmalloc( &llc ); 29 List_t* llc_ptr = get( &llc ); 30 llc_ptr->val = i; 31 List_t* lll_ptr = get( &lll ); 32 lll_ptr->next = llc; 33 34 lll = llc; 35 } 36 37 check(is_valid( &ll0.internal )); 38 39 return ll0; 19 int i; 20 // LLL ll0;//, lll, llc; 21 // 22 // ll0 = gcmalloc(); 23 // ll0->val = 0; 24 // lll = ll0; 25 // 26 // for (i = 1; i < sz; i++) 27 // { 28 // llc = gcmalloc(); 29 // llc->val = i; 30 // lll->next = llc; 31 // lll = llc; 32 // } 33 // 34 // return ll0; 40 35 } 41 42 void testLLL(LLL lll) 43 { 44 unsigned char *counted; 45 46 counted = (unsigned char *) calloc(MAX, sizeof(unsigned char)); 47 while (lll) 48 { 49 List_t* lll_ptr = get( &lll ); 50 counted[lll_ptr->val]++; 51 if (counted[lll_ptr->val] > 1) 52 { 53 fprintf(stderr, "ERROR! Encountered %d twice!\n", lll_ptr->val); 54 exit(1); 55 } 56 lll = lll_ptr->next; 57 } 58 59 return; 60 } 36 // 37 // void testLLL(LLL lll) 38 // { 39 // unsigned char *counted; 40 // 41 // counted = (unsigned char *) calloc(MAX, sizeof(unsigned char)); 42 // while (lll) 43 // { 44 // counted[lll->val]++; 45 // if (counted[lll->val] > 1) 46 // { 47 // fprintf(stderr, "ERROR! Encountered %d twice!\n", lll->val); 48 // exit(1); 49 // } 50 // lll = lll->next; 51 // } 52 // 53 // return; 54 // } 61 55 62 56 int main(void) … … 64 58 LLL mylll; 65 59 66 mylll = buildLLL(MAX);67 68 testLLL(mylll);60 // mylll = buildLLL(MAX); 61 // 62 // testLLL(mylll); 69 63 70 64 return 0; -
src/tests/.expect/declarationErrors.txt
rfd782b2 rf006f01 2 2 Error: duplicate static in declaration of x1: static const volatile short int 3 3 4 Error: conflictingextern & static in declaration of x2: extern const volatile short int4 Error: multiple extern & static in declaration of x2: extern const volatile short int 5 5 6 Error: conflicting extern & auto, conflicting extern & static, conflictingextern & static, duplicate extern in declaration of x3: extern const volatile short int6 Error: multiple extern & auto, multiple extern & static, multiple extern & static, duplicate extern in declaration of x3: extern const volatile short int 7 7 8 8 Error: duplicate static in declaration of x4: static const volatile instance of const volatile struct __anonymous0 -
src/tests/avltree/avl_test.c
rfd782b2 rf006f01 14 14 15 15 // int -> int 16 tree(int, int) * imap = create(-1, (int)0);16 tree(int, int) * imap = create(-1, 0); 17 17 insert(&imap, 12, 13); 18 18 insert(&imap, 2, 3);
Note:
See TracChangeset
for help on using the changeset viewer.