Changeset fd782b2


Ignore:
Timestamp:
Sep 15, 2016, 10:55:52 AM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
aa8f9df
Parents:
f006f01 (diff), 1eba452 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into tuples

Conflicts:

src/Parser/ParseNode.h

Location:
src
Files:
1 added
24 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/InitTweak.cc

    rf006f01 rfd782b2  
    387387                        } else if ( MemberExpr * memberExpr = dynamic_cast< MemberExpr * >( func ) ) {
    388388                                return memberExpr->get_member()->get_name();
     389                        } else if ( UntypedMemberExpr * memberExpr = dynamic_cast< UntypedMemberExpr * > ( func ) ) {
     390                                return funcName( memberExpr->get_member() );
    389391                        } else {
    390392                                assertf( false, "Unexpected expression type being called as a function in call expression" );
  • src/Parser/DeclarationNode.cc

    rf006f01 rfd782b2  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep  9 23:21:47 2016
    13 // Update Count     : 402
     12// Last Modified On : Sun Sep 11 09:24:11 2016
     13// Update Count     : 438
    1414//
    1515
     
    3131
    3232// 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", "" };
     33const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "NoStorageClass" };
    3434const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" };
    3535const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary",  };
     
    389389
    390390void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) {
    391         TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers;
    392 
    393         if ( (qsrc & qdst).any() ) {                                            // common bits between qualifier masks ?
     391        TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
     392
     393        if ( (qsrc & qdst).any() ) {                                            // common qualifier ?
    394394                for ( int i = 0; i < NoOfQualifier; i += 1 ) {  // find common qualifiers
    395395                        if ( qsrc[i] & qdst[i] ) {
    396                                 error += string(error.empty() ? "" : ", ") + "duplicate " + DeclarationNode::qualifierName[i];
     396                                if ( ! error.empty() ) error += ", ";   // separator
     397                                error += string( "duplicate " ) + DeclarationNode::qualifierName[i];
    397398                        } // if
    398399                } // for
    399400        } // if
    400401} // DeclarationNode::checkQualifiers
     402
     403void DeclarationNode::checkStorageClasses( DeclarationNode *q ) {
     404        if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) {
     405                if ( ! error.empty() ) error += ", ";                   // separator
     406                if ( storageClass == q->storageClass ) {                // duplicate qualifier
     407                        error += string( "duplicate " ) + storageName[ storageClass ];
     408                } else {                                                                                // only one storage class
     409                        error += string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ];
     410                        q->storageClass = storageClass;                         // FIX ERROR
     411                } // if
     412                if ( ! q->error.empty() ) error += ", " + q->error;     // separator
     413        } else {
     414                if ( ! error.empty() ) {
     415                        if ( ! q->error.empty() ) error += ", " + q->error; // separator
     416                } else if ( ! q->error.empty() ) error += q->error;
     417        } // if
     418} // DeclarationNode::copyStorageClasses
     419
     420DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {
     421        isInline = isInline | q->isInline;
     422        isNoreturn = isNoreturn | q->isNoreturn;
     423        // do not overwrite an existing value with NoStorageClass
     424        if ( q->storageClass != NoStorageClass ) {
     425                assert( storageClass == NoStorageClass || storageClass == q->storageClass );
     426                storageClass = q->storageClass;
     427        } // if
     428        return this;
     429} // DeclarationNode::copyStorageClasses
    401430
    402431DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    403432        if ( q ) {
    404                 copyStorageClasses(q);
     433                checkStorageClasses( q );
     434                copyStorageClasses( q );
    405435                if ( q->type ) {
    406436                        if ( ! type ) {
     
    429459        return this;
    430460}
    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
    449461
    450462static void addTypeToType( TypeData *&src, TypeData *&dst ) {
     
    504516DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) {
    505517        if ( o ) {
     518                checkStorageClasses( o );
    506519                copyStorageClasses( o );
    507520                if ( o->type ) {
     
    751764        } // if
    752765        newnode->type->forall = maybeClone( type->forall );
     766        assert( storageClass == NoStorageClass );
    753767        newnode->copyStorageClasses( this );
    754768        newnode->name = assign_strptr( newName );
     
    791805        DeclarationNode *newnode = new DeclarationNode;
    792806        newnode->type = maybeClone( type );
     807        assert( storageClass == NoStorageClass );
    793808        newnode->copyStorageClasses( this );
    794809        newnode->name = assign_strptr( newName );
     
    798813DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) {
    799814        if ( o ) {
     815                assert( storageClass == NoStorageClass );
    800816                o->copyStorageClasses( this );
    801817                if ( type ) {
  • src/Parser/ParseNode.h

    rf006f01 rfd782b2  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Sep  8 21:58:06 2016
    13 // Update Count     : 587
     12// Last Modified On : Sat Sep 10 17:14:37 2016
     13// Update Count     : 589
    1414//
    1515
     
    4141  public:
    4242        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; }
    4444        ParseNode( const std::string &name ) : name( name ) { assert( false ); }
    4545        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;
    5252                for ( current = this; current->get_next() != 0; current = current->get_next() );
    5353                return current;
    5454        }
    55         ParseNode *set_last( ParseNode *newlast ) {
     55        ParseNode * set_last( ParseNode * newlast ) {
    5656                if ( newlast != 0 ) get_last()->set_next( newlast );
    5757                return this;
     
    6666        static int indent_by;
    6767
    68         ParseNode *next = nullptr;
     68        ParseNode * next = nullptr;
    6969        std::string name;
    7070}; // ParseNode
     
    7474class InitializerNode : public ParseNode {
    7575  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 );
    7878        ~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; }
    8787        bool get_maybeConstructed() const { return maybeConstructed; }
    8888
    89         InitializerNode *next_init() const { return kids; }
     89        InitializerNode * next_init() const { return kids; }
    9090
    9191        void print( std::ostream &os, int indent = 0 ) const;
    9292        void printOneLine( std::ostream & ) const;
    9393
    94         virtual Initializer *build() const;
     94        virtual Initializer * build() const;
    9595  private:
    96         ExpressionNode *expr;
     96        ExpressionNode * expr;
    9797        bool aggregate;
    98         ExpressionNode *designator;                                                     // may be list
    99         InitializerNode *kids;
     98        ExpressionNode * designator;                                            // may be list
     99        InitializerNode * kids;
    100100        bool maybeConstructed;
    101101}; // InitializerNode
     
    106106  public:
    107107        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 ) {}
    109109        ExpressionNode( const ExpressionNode &other );
    110110        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; }
    112112
    113113        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; }
    115115
    116116        void print( std::ostream &os, int indent = 0 ) const {}
     
    122122        }
    123123
    124         Expression *build() const { return const_cast<ExpressionNode*>(this)->expr.release(); }
     124        Expression * build() const { return const_cast<ExpressionNode*>(this)->expr.release(); }
    125125  private:
    126126        bool extension = false;
     
    130130template< typename T >
    131131struct maybeBuild_t< Expression, T > {
    132         static inline Expression * doit( const T *orig ) {
     132        static inline Expression * doit( const T * orig ) {
    133133                if ( orig ) {
    134                         Expression *p = orig->build();
     134                        Expression * p = orig->build();
    135135                        p->set_extension( orig->get_extension() );
    136136                        return p;
     
    156156};
    157157
    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 );
     158Expression * build_constantInteger( const std::string &str );
     159Expression * build_constantFloat( const std::string &str );
     160Expression * build_constantChar( const std::string &str );
     161ConstantExpr * build_constantStr( const std::string &str );
     162
     163NameExpr * build_varref( const std::string * name, bool labelp = false );
     164Expression * build_typevalue( DeclarationNode * decl );
     165
     166Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node );
     167Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member );
     168Expression * build_pfieldSel( ExpressionNode * expr_node, Expression * member );
     169Expression * build_addressOf( ExpressionNode * expr_node );
     170Expression * build_sizeOfexpr( ExpressionNode * expr_node );
     171Expression * build_sizeOftype( DeclarationNode * decl_node );
     172Expression * build_alignOfexpr( ExpressionNode * expr_node );
     173Expression * build_alignOftype( DeclarationNode * decl_node );
     174Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member );
     175Expression * build_and( ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
     176Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind );
     177Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node );
     178Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node );
     179Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
     180Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
     181Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 );
     182Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
     183Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node );
     184Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node );
     185Expression * build_tuple( ExpressionNode * expr_node = 0 );
     186Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node );
     187Expression * build_range( ExpressionNode * low, ExpressionNode * high );
     188Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand );
     189Expression * build_valexpr( StatementNode * s );
     190Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids );
    191191
    192192//##############################################################################
     
    204204        enum BuiltinType { Valist };
    205205
    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 );
    239239
    240240        DeclarationNode();
    241241        ~DeclarationNode();
    242         DeclarationNode *clone() const;
    243 
    244         DeclarationNode *addQualifiers( DeclarationNode *);
     242        DeclarationNode * clone() const;
     243
     244        DeclarationNode * addQualifiers( DeclarationNode *);
    245245        void checkQualifiers( const TypeData *, const TypeData * );
    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 ) {
     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 ) {
    270271                return (DeclarationNode *)set_last( node );
    271272        }
     
    274275        void printList( std::ostream &os, int indent = 0 ) const;
    275276
    276         Declaration *build() const;
    277         ::Type *buildType() const;
     277        Declaration * build() const;
     278        ::Type * buildType() const;
    278279
    279280        bool get_hasEllipsis() const;
    280281        const std::string &get_name() const { return name; }
    281282        LinkageSpec::Spec get_linkage() const { return linkage; }
    282         DeclarationNode *extractAggregate() const;
     283        DeclarationNode * extractAggregate() const;
    283284        bool has_enumeratorValue() const { return (bool)enumeratorValue; }
    284         ExpressionNode *consume_enumeratorValue() const { return const_cast<DeclarationNode*>(this)->enumeratorValue.release(); }
     285        ExpressionNode * consume_enumeratorValue() const { return const_cast<DeclarationNode*>(this)->enumeratorValue.release(); }
    285286
    286287        bool get_extension() const { return extension; }
    287         DeclarationNode *set_extension( bool exten ) { extension = exten; return this; }
     288        DeclarationNode * set_extension( bool exten ) { extension = exten; return this; }
    288289  public:
    289290        // StorageClass buildStorageClass() const;
     
    306307        BuiltinType builtin;
    307308
    308         TypeData *type;
     309        TypeData * type;
    309310        std::string name;
    310311        // std::list< StorageClass > storageClasses;
     
    312313        bool isInline, isNoreturn;
    313314        std::list< std::string > attributes;
    314         ExpressionNode *bitfieldWidth;
     315        ExpressionNode * bitfieldWidth;
    315316        std::unique_ptr<ExpressionNode> enumeratorValue;
    316         InitializerNode *initializer;
     317        InitializerNode * initializer;
    317318        bool hasEllipsis;
    318319        LinkageSpec::Spec linkage;
     
    323324}; // DeclarationNode
    324325
    325 Type *buildType( TypeData *type );
     326Type * buildType( TypeData * type );
    326327//Type::Qualifiers buildQualifiers( const TypeData::Qualifiers & qualifiers );
    327328
    328 static inline Type * maybeMoveBuildType( const DeclarationNode *orig ) {
     329static inline Type * maybeMoveBuildType( const DeclarationNode * orig ) {
    329330        Type* ret = orig ? orig->buildType() : nullptr;
    330331        delete orig;
     
    337338  public:
    338339        StatementNode() { stmt = nullptr; }
    339         StatementNode( Statement *stmt ) : stmt( stmt ) {}
    340         StatementNode( DeclarationNode *decl );
     340        StatementNode( Statement * stmt ) : stmt( stmt ) {}
     341        StatementNode( DeclarationNode * decl );
    341342        virtual ~StatementNode() {}
    342343
    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 );
     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 );
    348349                delete name;
    349350                return this;
    350351        }
    351352
    352         virtual StatementNode *append_last_case( StatementNode * );
     353        virtual StatementNode * append_last_case( StatementNode * );
    353354
    354355        virtual void print( std::ostream &os, int indent = 0 ) {}
     
    358359}; // StatementNode
    359360
    360 Statement *build_expr( ExpressionNode *ctl );
     361Statement * build_expr( ExpressionNode * ctl );
    361362
    362363struct ForCtl {
    363         ForCtl( ExpressionNode *expr, ExpressionNode *condition, ExpressionNode *change ) :
     364        ForCtl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :
    364365                init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {}
    365         ForCtl( DeclarationNode *decl, ExpressionNode *condition, ExpressionNode *change ) :
     366        ForCtl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) :
    366367                init( new StatementNode( decl ) ), condition( condition ), change( change ) {}
    367368
    368         StatementNode *init;
    369         ExpressionNode *condition;
    370         ExpressionNode *change;
     369        StatementNode * init;
     370        ExpressionNode * condition;
     371        ExpressionNode * change;
    371372};
    372373
    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 );
     374Statement * build_if( ExpressionNode * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
     375Statement * build_switch( ExpressionNode * ctl, StatementNode * stmt );
     376Statement * build_case( ExpressionNode * ctl );
     377Statement * build_default();
     378Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind = false );
     379Statement * build_for( ForCtl * forctl, StatementNode * stmt );
     380Statement * build_branch( BranchStmt::Type kind );
     381Statement * build_branch( std::string * identifier, BranchStmt::Type kind );
     382Statement * build_computedgoto( ExpressionNode * ctl );
     383Statement * build_return( ExpressionNode * ctl );
     384Statement * build_throw( ExpressionNode * ctl );
     385Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt );
     386Statement * build_catch( DeclarationNode * decl, StatementNode * stmt, bool catchAny = false );
     387Statement * build_finally( StatementNode * stmt );
     388Statement * build_compound( StatementNode * first );
     389Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = 0, ExpressionNode * input = 0, ExpressionNode * clobber = 0, LabelNode * gotolabels = 0 );
    389390
    390391//##############################################################################
    391392
    392393template< typename SynTreeType, typename NodeType >
    393 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {
     394void buildList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) {
    394395        SemanticError errors;
    395396        std::back_insert_iterator< std::list< SynTreeType * > > out( outputList );
    396         const NodeType *cur = firstNode;
     397        const NodeType * cur = firstNode;
    397398
    398399        while ( cur ) {
    399400                try {
    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 ) );
     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 ) );
    402403                        if ( result ) {
    403                                 *out++ = result;
     404                                * out++ = result;
    404405                        } // if
    405406                } catch( SemanticError &e ) {
     
    414415
    415416// in DeclarationNode.cc
    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 );
     417void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList );
     418void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList );
     419void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList );
    419420
    420421template< typename SynTreeType, typename NodeType >
    421 void buildMoveList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {
     422void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) {
    422423        buildList(firstNode, outputList);
    423424        delete firstNode;
  • src/Parser/TypeData.h

    rf006f01 rfd782b2  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep  9 23:20:55 2016
    13 // Update Count     : 117
     12// Last Modified On : Sat Sep 10 09:42:54 2016
     13// Update Count     : 118
    1414//
    1515
     
    8989        typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers;
    9090        Qualifiers qualifiers;
     91        typedef std::bitset< DeclarationNode::NoStorageClass > StorageClasses;
     92        StorageClasses storageclasses;
    9193        DeclarationNode * forall;
    9294
  • src/Parser/parser.cc

    rf006f01 rfd782b2  
    59435943/* Line 1806 of yacc.c  */
    59445944#line 831 "parser.yy"
    5945     { (yyval.sn) = new StatementNode( build_while( (yyvsp[(5) - (7)].en), (yyvsp[(2) - (7)].sn) ) ); }
     5945    { (yyval.sn) = new StatementNode( build_while( (yyvsp[(5) - (7)].en), (yyvsp[(2) - (7)].sn), true ) ); }
    59465946    break;
    59475947
  • src/Parser/parser.yy

    rf006f01 rfd782b2  
    829829                { $$ = new StatementNode( build_while( $3, $5 ) ); }
    830830        | DO statement WHILE '(' comma_expression ')' ';'
    831                 { $$ = new StatementNode( build_while( $5, $2 ) ); }
     831                { $$ = new StatementNode( build_while( $5, $2, true ) ); }
    832832        | FOR '(' push for_control_expression ')' statement
    833833                { $$ = new StatementNode( build_for( $4, $6 ) ); }
  • src/examples/gc_no_raii/bug-repro/field.c

    rf006f01 rfd782b2  
    6262{
    6363        struct gc_object_header* object;
    64         #if _DEBUG
     64        #ifndef NDEBUG
    6565                intptr_t lower_limit;
    6666                intptr_t upper_limit;
     
    7171                gc_pool_object_iterator* const this,
    7272                void* start_object
    73                 #if _DEBUG
     73                #ifndef NDEBUG
    7474                        , intptr_t pool_start
    7575                        , intptr_t pool_end
  • src/examples/gc_no_raii/src/gcpointers.c

    rf006f01 rfd782b2  
    1414                gc_object_header* obj = gc_get_object_for_ref(gc_get_state(), (void*)this);
    1515                check(obj);
    16                 check(gc_obj_is_valide(obj));
    17                 check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || obj->type_chain == NULL);
     16                check(is_valid(obj));
     17                check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || !obj->type_chain);
    1818                this->next = obj->type_chain;
    1919                obj->type_chain = this;
    20                 check(obj->is_valide());
     20                check(is_valid(obj));
    2121        }
    2222        else
     
    2424                gc_object_header* obj = gc_get_object_ptr((void*)this->ptr);
    2525                check(obj);
    26                 check(gc_obj_is_valide(obj));
    27                 check(gc_is_managed(this) == gc_is_managed(obj->root_chain) || obj->root_chain == NULL);
     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));
    2829                this->next = obj->root_chain;
    2930                obj->root_chain = this;
    30                 check(gc_obj_is_valide(obj));
     31                check(is_valid(obj));
    3132        }
    3233}
     
    6970}
    7071
    71 gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs)
     72gcpointer_t ?=?(gcpointer_t* this, gcpointer_t rhs)
    7273{
    73         if(this != rhs)
    74         {
    75                 unregister_ptr(this);
     74        unregister_ptr(this);
     75        this->ptr = rhs.ptr;
     76        register_ptr(this);
    7677
    77                 this->ptr = rhs->ptr;
    78 
    79                 register_ptr(this);
    80         }
    81 
    82         return this;
     78        return *this;
    8379}
    8480
    8581//Logical operators
    86 bool gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs)
     82bool gcpointer_equal(const gcpointer_t* this, const gcpointer_t* rhs)
    8783{
    8884        return this->ptr == rhs->ptr;
    8985}
    9086
    91 bool gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs)
     87bool gcpointer_not_equal(const gcpointer_t* this, const gcpointer_t* rhs)
    9288{
    9389        return this->ptr != rhs->ptr;
    9490}
    9591
    96 bool gcpointer_null(gcpointer_t* this)
     92bool gcpointer_null(const gcpointer_t* this)
    9793{
    9894        return this->ptr == (intptr_t)NULL;
    9995}
     96
     97#ifndef NDEBUG
     98        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#endif
    100114
    101115forall(otype T) void ?{}(gcpointer(T)* this) {
     
    107121}
    108122
    109 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other) {
    110         (&this->internal) { other->internal };
     123forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T) other) {
     124        (&this->internal) { other.internal };
    111125}
    112126
     
    115129}
    116130
    117 // forall(otype T) gcpointer(T) ?=?(gcpointer(T) this, gcpointer(T) rhs);
     131forall(otype T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs) {
     132        this->internal = rhs.internal;
     133        return *this;
     134}
    118135//
    119136// forall(otype T) T *?(gcpointer(T) this);
     
    124141//
    125142// //Logical operators
     143forall(otype T) int ?!=?(gcpointer(T) this, int zero) {
     144        return this.internal.ptr != 0;
     145}
    126146// forall(otype T) int ?!=?(gcpointer(T) this, gcpointer(T) rhs);
    127147// forall(otype T) int ?==?(gcpointer(T) this, gcpointer(T) rhs);
  • src/examples/gc_no_raii/src/gcpointers.h

    rf006f01 rfd782b2  
    33#include <stdbool.h>
    44#include <stdint.h>
     5
     6forall(dtype T)
     7struct gcpointer;
    58
    69struct gcpointer_t
     
    1417void ?{}(gcpointer_t* this, gcpointer_t other);
    1518void ^?{}(gcpointer_t* this);
    16 gcpointer_t* ?=?(gcpointer_t this, gcpointer_t rhs);
     19gcpointer_t ?=?(gcpointer_t* this, gcpointer_t rhs);
    1720
    1821//Logical operators
    1922bool gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs);
    2023bool gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs);
    21 bool gcpointer_null(gcpointer_t* this);
     24bool gcpointer_null(const gcpointer_t* this);
    2225
    23 forall(otype T)
     26
     27#ifndef NDEBUG
     28        bool is_valid(const gcpointer_t* this);
     29#endif
     30
     31forall(dtype T)
    2432struct gcpointer
    2533{
     
    3038forall(otype T) void ?{}(gcpointer(T)* this);
    3139forall(otype T) void ?{}(gcpointer(T)* this, void* address);
    32 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other);
     40forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T) other);
    3341forall(otype T) void ^?{}(gcpointer(T)* this);
    34 forall(otype T) gcpointer(T) ?=?(gcpointer(T) this, gcpointer(T) rhs);
     42forall(otype T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs);
    3543
    3644
    37 forall(otype T) T *?(gcpointer(T) this);
     45// forall(otype T) T *?(gcpointer(T) this);
    3846forall(otype T) T* get(gcpointer(T)* this);
    3947
    4048//Logical operators
     49forall(otype T) int ?!=?(gcpointer(T) this, int zero);
    4150forall(otype T) int ?!=?(gcpointer(T) this, gcpointer(T) rhs);
    4251forall(otype T) int ?==?(gcpointer(T) this, gcpointer(T) rhs);
  • src/examples/gc_no_raii/src/internal/card_table.h

    rf006f01 rfd782b2  
    11#pragma once
    2 
    3 #include <stdlib>
    42
    53#include "globals.h"
     
    97{
    108        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);
    1110        check(card < CARDS_COUNT);
    1211        return card;
     
    1918};
    2019
    21 static inline void ctor(card_table_t* const this)
     20static inline void ctor_card(card_table_t* const this)
    2221{
    2322        this->count = 0;
    2423}
    2524
    26 static inline void dtor(card_table_t* const this)
     25static inline void dtor_card(card_table_t* const this)
    2726{
    2827
     
    4847        else
    4948        {
    50                 check(card == count);
     49                check(card == this->count);
    5150                this->count++;
    5251                this->cards_start[card] = object;
  • src/examples/gc_no_raii/src/internal/collector.c

    rf006f01 rfd782b2  
    2525        gc_object_header* obj = gc_get_object_ptr((void*)target->ptr);
    2626
    27         check(gc_is_valide(obj));
     27        check(is_valid(obj));
    2828
    2929        gcpointer_t** prev_next_ptr = managed ? &obj->type_chain : &obj->root_chain;
     
    3838void* gc_allocate(size_t target_size)
    3939{
    40         sout | "Allocating " | target_size | " bytes" | endl;
     40        // sout | "Allocating " | target_size | " bytes" | endl;
    4141
    4242        size_t size = gc_compute_size(target_size + sizeof(gc_object_header));
    4343
    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;
    4646
    4747        check(size < POOL_SIZE_BYTES);
     
    6060        if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
    6161
    62         checkf(false, "ERROR: allocation in new pool failed");
     62        checkf( (int) 0, "ERROR: allocation in new pool failed");
    6363
    6464        return NULL;
     
    6767void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size)
    6868{
    69         void* data = (void*)(((intptr_t)block) + sizeof(gc_object_header));
     69        intptr_t data = ((intptr_t)block) + sizeof(gc_object_header);
    7070        void* header = block;
    7171
    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);
     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 );
    7676
    7777        gc_object_header* obj = placement_ctor(header, actual_size);
    7878
    7979        (void)obj; //remove unsused warning since this is for debug
    80         check(obj == get_object_ptr(data));
     80        check(obj == gc_get_object_ptr( (void*)data ));
    8181
    8282        gc_register_allocation(gc_get_state(), actual_size);
    8383
    84         return data;
     84        return (void*)data;
    8585}
    8686
     
    119119        check(!ptr->forward);
    120120        check(!ptr->is_forwarded);
    121         check(gc_is_from_space(gc_pool_of(ptr)));
     121        check(gc_pool_is_from_space(gc_pool_of(ptr)));
    122122
    123123        gc_memory_pool* pool = gc_pool_of(ptr)->mirror;
     
    143143                check(((intptr_t)field) < ((intptr_t)((intptr_t)object) + object->size));
    144144
    145                 check(gc_is_in_to_space(gc_get_state(), &type->ptr));
     145                check(gc_is_in_to_space(gc_get_state(), &field->ptr));
    146146
    147147                intptr_t* ref = &field->ptr;
  • src/examples/gc_no_raii/src/internal/collector.h

    rf006f01 rfd782b2  
    11#pragma once
    22
    3 #include <stdlib>
     3#include <stdlib.h>
    44
    55#include "tools.h"
  • src/examples/gc_no_raii/src/internal/memory_pool.c

    rf006f01 rfd782b2  
    11#include "memory_pool.h"
    22
    3 #include <stdlib>
     3extern "C" {
     4        #include <stdlib.h>
     5        #include <string.h>
     6}
    47
     8#include "collector.h"
    59#include "object_header.h"
    610
     
    1519        card_table_t* new = (card_table_t*)malloc(sizeof(card_table_t));
    1620        this->cards = new;
    17         ctor(this->cards);
     21        ctor_card(this->cards);
    1822
    1923        this->end_p = ((uint8_t*)this) + size;
    2024        this->free_p = this->start_p;
    2125
    22         check(gc_pool_of(this) == this);
     26        check( gc_pool_of( (void*)this ) == this);
    2327        check(this->cards);
    2428        gc_reset_pool(this);
     
    2731void dtor(gc_memory_pool *const this)
    2832{
    29         dtor(this->cards);
     33        dtor_card(this->cards);
    3034        free(this->cards);
    3135}
     
    3438{
    3539        this->free_p = this->start_p;
    36         #if _DEBUG
    37                 memset(this->start_p, 0xCD, gc_pool_total_size(this));
     40        #ifndef NDEBUG
     41                memset(this->start_p, 0xCD, gc_pool_size_total(this));
    3842        #endif
    3943
     
    4145        reset(this->cards);
    4246
    43         check(gc_pool_size_left(this) == gc_pool_total_size(this));
     47        check(gc_pool_size_left(this) == gc_pool_size_total(this));
    4448}
    4549
     
    5862}
    5963
    60 void ctor(
    61                 gc_pool_object_iterator* const this,
     64void ?{}(       gc_pool_object_iterator* this,
    6265                struct gc_object_header* start_object
    63                 #if _DEBUG
     66                #ifndef NDEBUG
    6467                        , intptr_t pool_start
    6568                        , intptr_t pool_end
     
    6871{
    6972        this->object = start_object;
    70         #if _DEBUG
     73        #ifndef NDEBUG
    7174                this->lower_limit = pool_start;
    7275                this->upper_limit = pool_end;
    7376        #endif
    7477
    75         check( ((intptr_t)start_object) >= lower_limit );
    76         check( ((intptr_t)start_object) <= upper_limit );
     78        check( ((intptr_t)start_object) >= this->lower_limit );
     79        check( ((intptr_t)start_object) <= this->upper_limit );
    7780}
     81
     82void ^?{}( gc_pool_object_iterator* this ) {}
    7883
    7984gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const this, void* member)
     
    8186        size_t card = card_of(member);
    8287        intptr_t member_add = (intptr_t)member;
    83         void* start_obj;
    84         intptr_t start_obj_add;
     88        intptr_t start_obj;
    8589
    8690        do
    8791        {
    8892                check(card < CARDS_COUNT);
    89                 start_obj = object_at(this->cards, card);
     93                start_obj = (intptr_t)object_at(this->cards, card);
    9094                check(card != 0 || start_obj);
    9195                card--;
    92                 start_obj_add = (intptr_t)start_obj;
    9396        }
    94         while(start_obj_add > member_add || start_obj_add != 0);
     97        while(start_obj > member_add || !(start_obj));
    9598
    96         check(start_obj);
    97        
     99        check( start_obj );
     100
    98101        struct gc_object_header* start_obj_typed = (struct gc_object_header*)start_obj;
    99102
    100         gc_pool_object_iterator it;
    101         ctor( &it,
    102                 start_obj_typed,
    103                 #if _DEBUG
     103        return (gc_pool_object_iterator) {
     104                start_obj_typed
     105                #ifndef NDEBUG
    104106                        , (intptr_t)this->start_p
    105107                        , (intptr_t)this->free_p
    106108                #endif
    107         );
    108         return it;
     109        };
    109110}
    110111
     
    117118{
    118119        struct gc_object_header* start_obj = (struct gc_object_header*)this->start_p;
    119         gc_pool_object_iterator it;
    120         ctor( &it,
    121                 start_obj,
    122                 #if _DEBUG
     120        return (gc_pool_object_iterator) {
     121                start_obj
     122                #ifndef NDEBUG
    123123                        , (intptr_t)this->start_p
    124124                        , (intptr_t)this->free_p
    125125                #endif
    126         );
    127         return it;
     126        };
    128127}
    129128
    130129gc_pool_object_iterator end(gc_memory_pool* const this)
    131130{
    132         gc_pool_object_iterator it;
    133         ctor( &it,
    134                 (struct gc_object_header*)this->free_p,
    135                 #if _DEBUG
     131        return (gc_pool_object_iterator) {
     132                (struct gc_object_header*)this->free_p
     133                #ifndef NDEBUG
    136134                        , (intptr_t)this->start_p
    137135                        , (intptr_t)this->free_p
    138136                #endif
    139         );
    140         return it;
     137        };
    141138}
    142139
     
    145142        struct gc_object_header* object = it->object;
    146143        intptr_t next_ptr = ((intptr_t)object) + object->size;
    147         check(next_ptr > lower_limit);
    148         check(next_ptr <= upper_limit);
     144        check(next_ptr > it->lower_limit);
     145        check(next_ptr <= it->upper_limit);
    149146
    150147        struct gc_object_header* next_obj = ((struct gc_object_header*)next_ptr);
    151         check(next_ptr == upper_limit || is_valide(next_obj));
     148        check(next_ptr == it->upper_limit || is_valid(next_obj));
    152149
    153150        it->object = next_obj;
  • src/examples/gc_no_raii/src/internal/memory_pool.h

    rf006f01 rfd782b2  
    3939{
    4040        struct gc_object_header* object;
    41         #if _DEBUG
     41        #ifndef NDEBUG
    4242                intptr_t lower_limit;
    4343                intptr_t upper_limit;
     
    4646
    4747
    48 void ctor(
    49                 gc_pool_object_iterator* const this,
     48void ?{}(       gc_pool_object_iterator* this,
    5049                struct gc_object_header* start_object
    51                 #if _DEBUG
     50                #ifndef NDEBUG
    5251                        , intptr_t pool_start
    5352                        , intptr_t pool_end
    5453                #endif
    5554        );
     55
     56void ^?{}( gc_pool_object_iterator* this );
    5657
    5758bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs);
  • src/examples/gc_no_raii/src/internal/object_header.c

    rf006f01 rfd782b2  
    33#include <stdint.h>
    44
     5#include "collector.h"
    56#include "globals.h"
    67#include "gcpointers.h"
     
    89void ctor(gc_object_header* const this, size_t inSize)
    910{
    10         #if _DEBUG
     11        #ifndef NDEBUG
    1112                this->canary_start = CANARY_VALUE;
    1213        #endif
     
    1819        this->is_forwarded = false;
    1920
    20         #if _DEBUG
     21        #ifndef NDEBUG
    2122                this->canary_end = CANARY_VALUE;
    2223        #endif
     
    2526void copy_ctor(gc_object_header* const this, const gc_object_header* const other)
    2627{
    27         #if _DEBUG
     28        #ifndef NDEBUG
    2829                this->canary_start = CANARY_VALUE;
    2930        #endif
     
    3536        this->is_forwarded = false;
    3637
    37         #if _DEBUG
     38        #ifndef NDEBUG
    3839                this->canary_end = CANARY_VALUE;
    3940        #endif
     
    4243        while(root)
    4344        {
    44                 check(get_object_ptr(root->ptr) == other);
     45                check(gc_get_object_ptr( (void*)root->ptr ) == other);
    4546                root->ptr = ((intptr_t)this) + sizeof(gc_object_header);
    4647
    47                 check(get_object_ptr(root->ptr) == this);
     48                check(gc_get_object_ptr( (void*)root->ptr ) == this);
    4849                root = root->next;
    4950        }
     
    5657
    5758                size_t offset = (intptr_t)type - (intptr_t)other;
    58                 check(offset < size);
     59                check(offset < this->size);
    5960
    6061                gcpointer_t* member_ptr = (gcpointer_t*)( (intptr_t)this + offset );
     
    6364
    6465                size_t next_offset = type->next ? (intptr_t)type->next - (intptr_t)other : 0;
    65                 check(next_offset < size);
     66                check(next_offset < this->size);
    6667
    6768                gcpointer_t* next_ptr = type->next ? (gcpointer_t*)((intptr_t)this + next_offset) : NULL;
     
    7374        }
    7475
    75         check(is_valide(this));
     76        check(is_valid(this));
    7677}
    7778
    78 #if _DEBUG
    79         bool is_valide(const gc_object_header* const this)
     79#ifndef NDEBUG
     80        bool is_valid(const gc_object_header* const this)
    8081        {
    81                 check(this->canary_start == CANARY_VALUE);
    82                 check(this->canary_end == CANARY_VALUE);
     82                check((intptr_t)this->canary_start == (intptr_t)CANARY_VALUE);
     83                check((intptr_t)this->canary_end == (intptr_t)CANARY_VALUE);
    8384
    84                 check(this->is_forwarded == (this->forward != nullptr));
     85                check(this->is_forwarded == ( (intptr_t)this->forward != (intptr_t)NULL));
    8586
    8687                check(this->size < POOL_SIZE_BYTES);
     
    8990                while(root)
    9091                {
    91                         check(get_object_ptr(root->ptr) == this);
     92                        checkf(gc_get_object_ptr( (void*)root->ptr ) == this, (const char*)"Expected %lX got %lX\n", gc_get_object_ptr( (void*)root->ptr ), this);
    9293
    9394                        root = root->next;
    9495                }
    9596
    96                 gcpointer_t* type = type_chain;
     97                gcpointer_t* type = this->type_chain;
    9798                while(type)
    9899                {
    99100                        check((intptr_t)type > (intptr_t)this);
    100                         check((intptr_t)type < (intptr_t)((intptr_t)this + size));
     101                        check((intptr_t)type < (intptr_t)(((intptr_t)this) + this->size));
    101102
    102103                        type = type->next;
     
    105106                return true;
    106107        }
     108        #else
     109        #error blarg
    107110#endif
  • src/examples/gc_no_raii/src/internal/object_header.h

    rf006f01 rfd782b2  
    77#include "tools.h"
    88
    9 #if DEBUG
    10         static const long unsigned int CANARY_VALUE = 0xCAFEBABACAFEBABA;
     9#ifndef NDEBUG
     10        static void* const CANARY_VALUE = (void*)0xCAFEBABACAFEBABA;
    1111#endif
    1212
     
    1616struct gc_object_header
    1717{
    18         #if DEBUG
     18        #ifndef NDEBUG
    1919                void* canary_start;
    2020        #endif
     
    2626        bool                    is_forwarded;
    2727
    28         #if DEBUG
     28        #ifndef NDEBUG
    2929                void* canary_end;
    3030        #endif
     
    4747        return this;
    4848}
     49
     50#ifndef NDEBUG
     51        bool is_valid(const gc_object_header* const this);
     52#endif
  • src/examples/gc_no_raii/src/internal/state.c

    rf006f01 rfd782b2  
    2121void gc_state_calc_usage(gc_state *const this);
    2222
    23 #if DEBUG
     23#ifndef NDEBUG
    2424        bool gc_state_roots_match(gc_state *const this);
    2525        bool gc_state_no_from_space_ref(gc_state *const this);
     
    7676gc_object_header* gc_get_object_for_ref(gc_state* state, void* member)
    7777{
     78        volatile int stage = 0;
    7879        intptr_t target = ((intptr_t)member);
    7980        if(!gc_is_in_heap(state, member)) return NULL;
     81        stage++;
    8082
    8183        gc_memory_pool* pool = gc_pool_of(member);
     84        stage++;
    8285        gc_pool_object_iterator it = gc_pool_iterator_for(pool, member);
     86        stage++;
    8387        gc_pool_object_iterator end = end(pool);
     88        stage++;
    8489
    8590        while(it != end)
    8691        {
    8792                gc_object_header* object = *it;
     93                check(object);
     94                check( is_valid(object) );
    8895                {
    8996                        intptr_t start = ((intptr_t)object);
     
    94101                        }
    95102                }
     103                stage++;
    96104                ++it;
    97105        }
    98106
    99         checkf(false, "is_in_heap() and iterator_for() return inconsistent data");
     107        checkf( (int) 0, "is_in_heap() and iterator_for() return inconsistent data");
    100108        abort();
    101109        return NULL;
     
    176184        this->from_code = (~this->from_code) & 0x01;
    177185
    178         #if _DEBUG
     186        #ifndef NDEBUG
    179187                {
    180188                        gc_memory_pool* pool = this->from_space;
     
    251259}
    252260
    253 #if _DEBUG
     261#ifndef NDEBUG
    254262        bool gc_state_roots_match(gc_state* const this)
    255263        {
     
    265273                                size += object->size;
    266274
    267                                 gcpointer_base* ptr = object->root_chain;
     275                                gcpointer_t* ptr = object->root_chain;
    268276                                while(ptr)
    269277                                {
    270                                         check(get_object_ptr(ptr->m_ptr) == object);
    271                                         ptr = ptr->m_next;
     278                                        check(gc_get_object_ptr( (void*)ptr->ptr ) == object);
     279                                        ptr = ptr->next;
    272280                                }
    273281                        }
    274282
    275                         check(size + gc_pool_size_used(pool) == gc_pool_size_total(pool));
     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));
    276288
    277289                        pool = pool->next;
     
    286298                while(pool)
    287299                {
    288                         void** potential_ref = (void**)pool->m_start;
    289                         while(potential_ref < (void**)pool->m_free)
     300                        void** potential_ref = (void**)pool->start_p;
     301                        while(potential_ref < (void**)pool->free_p)
    290302                        {
    291303                                check(!gc_is_in_heap(this, *potential_ref));
  • src/examples/gc_no_raii/src/internal/state.h

    rf006f01 rfd782b2  
    3838static inline bool gc_needs_collect(gc_state* state)
    3939{
    40         sout | "Used Space: " | state->used_space | " bytes" | endl;
     40        // sout | "Used Space: " | state->used_space | " bytes" | endl;
    4141        return state->used_space * 2 > state->total_space;
    4242}
  • src/examples/gc_no_raii/src/tools/checks.h

    rf006f01 rfd782b2  
    11#pragma once
    22
    3 #if _DEBUG
     3#ifdef NDEBUG
     4
     5#define check(x)
     6
     7#define checkf(x, format, ...)
     8
     9#warning no debug checks
     10
     11#else
    412
    513#include <stdlib.h>
     
    1018                printf("CHECK failed : %s at %s:%i\n", #x, __FILE__, __LINE__);\
    1119                abort();\
    12         }}while(0)\
     20        }}while( (int)0 )\
    1321
    1422#define checkf(x, ...) do {\
     
    1725                printf(__VA_ARGS__);\
    1826                abort();\
    19         }}while(0)\
    20 
    21 #else
    22 
    23 #define check(x)
    24 
    25 #define checkf(x, format, ...)
     27        }}while( (int)0 )\
    2628
    2729#endif //NO_CHECKS
  • src/examples/gc_no_raii/src/tools/print.c

    rf006f01 rfd782b2  
    11#include "tools.h"
    22
    3 #if _DEBUG
    4         ofstream *sout = ofstream_stdout();
     3#ifndef NDEBUG
     4        // ofstream *sout = ofstream_stdout();
    55#endif
  • src/examples/gc_no_raii/src/tools/print.h

    rf006f01 rfd782b2  
    11#pragma once
    22
    3 #if _DEBUG
    4 
    5 #include <fstream>
    6 
    7 #define DEBUG_OUT(x) sout | x | endl;
    8 
    9 #else
     3// #ifndef NDEBUG
     4//
     5// #include <fstream>
     6//
     7// #define DEBUG_OUT(x) sout | x | endl;
     8//
     9// #else
    1010
    1111#define DEBUG_OUT(x)
    1212
    13 #endif //NO_CHECKS
     13// #endif //NO_CHECKS
  • src/examples/gc_no_raii/test/badlll.c

    rf006f01 rfd782b2  
    11#include "gc.h"
     2
     3#include <stdio.h>
    24
    35struct List_t
     
    79};
    810
    9 void ?{}(List_t* this);
    10 List_t* ?=?(List_t* this, List_t* rhs);
    11 
    1211typedef gcpointer(List_t) LLL;
    1312
    14 #define MAX (1024 * 1024)
     13#define MAX (1024 * 1)
    1514
    16 // LLL buildLLL(int sz)
    17 void bla()
     15LLL buildLLL(int sz)
    1816{
    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;
     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;
    3540}
    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 // }
     41
     42void 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}
    5561
    5662int main(void)
     
    5864        LLL mylll;
    5965
    60         // mylll = buildLLL(MAX);
    61         //
    62         // testLLL(mylll);
     66        mylll = buildLLL(MAX);
     67
     68        testLLL(mylll);
    6369
    6470        return 0;
  • src/tests/.expect/declarationErrors.txt

    rf006f01 rfd782b2  
    22Error: duplicate static in declaration of x1: static const volatile short int
    33
    4 Error: multiple extern & static in declaration of x2: extern const volatile short int
     4Error: conflicting extern & static in declaration of x2: extern const volatile short int
    55
    6 Error: multiple extern & auto, multiple extern & static, multiple extern & static, duplicate extern in declaration of x3: extern const volatile short int
     6Error: conflicting extern & auto, conflicting extern & static, conflicting extern & static, duplicate extern in declaration of x3: extern const volatile short int
    77
    88Error: duplicate static in declaration of x4: static const volatile instance of const volatile struct __anonymous0
  • src/tests/avltree/avl_test.c

    rf006f01 rfd782b2  
    1414
    1515  // int -> int
    16   tree(int, int) * imap = create(-1, 0);
     16  tree(int, int) * imap = create(-1, (int)0);
    1717  insert(&imap, 12, 13);
    1818  insert(&imap, 2, 3);
Note: See TracChangeset for help on using the changeset viewer.