Changes in / [ca37445:8ad6533]


Ignore:
Location:
src
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rca37445 r8ad6533  
    203203
    204204        void CodeGenerator::handleAggregate( AggregateDecl * aggDecl, const std::string & kind ) {
     205                genAttributes( aggDecl->get_attributes() );
     206
    205207                if( ! aggDecl->get_parameters().empty() && ! genC ) {
    206208                        // assertf( ! genC, "Aggregate type parameters should not reach code generation." );
     
    211213                }
    212214
    213                 output << kind;
    214                 genAttributes( aggDecl->get_attributes() );
    215                 output << aggDecl->get_name();
     215                output << kind << aggDecl->get_name();
    216216
    217217                if ( aggDecl->has_body() ) {
     
    298298                        output << " }";
    299299                }
    300         }
    301 
    302         void CodeGenerator::postvisit( StaticAssertDecl * assertDecl ) {
    303                 output << "_Static_assert(";
    304                 assertDecl->condition->accept( *visitor );
    305                 output << ", ";
    306                 assertDecl->message->accept( *visitor );
    307                 output << ")";
    308300        }
    309301
  • src/CodeGen/CodeGenerator.h

    rca37445 r8ad6533  
    4242                void postvisit( FunctionDecl * );
    4343                void postvisit( ObjectDecl * );
    44                 void postvisit( UnionDecl * aggregateDecl );
    45                 void postvisit( EnumDecl * aggregateDecl );
    46                 void postvisit( TraitDecl * aggregateDecl );
    47                 void postvisit( TypedefDecl * typeDecl );
    48                 void postvisit( TypeDecl * typeDecl );
    49                 void postvisit( StaticAssertDecl * assertDecl );
     44                void postvisit( UnionDecl *aggregateDecl );
     45                void postvisit( EnumDecl *aggregateDecl );
     46                void postvisit( TraitDecl *aggregateDecl );
     47                void postvisit( TypedefDecl *typeDecl );
     48                void postvisit( TypeDecl *typeDecl );
    5049
    5150                //*** Initializer
  • src/CodeGen/OperatorTable.cc

    rca37445 r8ad6533  
    7979        } // namespace
    8080
    81         bool operatorLookup( const std::string & funcName, OperatorInfo & info ) {
     81        bool operatorLookup( std::string funcName, OperatorInfo &info ) {
    8282                static bool init = false;
    8383                if ( ! init ) {
     
    100100                        return true;
    101101                } // if
    102         }
    103 
    104         bool isOperator( const std::string & funcName ) {
    105                 OperatorInfo info;
    106                 return operatorLookup( funcName, info );
    107102        }
    108103
  • src/CodeGen/OperatorTable.h

    rca37445 r8ad6533  
    4141        };
    4242
    43         bool isOperator( const std::string & funcName );
    44         bool operatorLookup( const std::string & funcName, OperatorInfo & info );
     43        bool operatorLookup( std::string funcName, OperatorInfo &info );
    4544
    4645        bool isConstructor( const std::string & );
  • src/Common/Debug.h

    rca37445 r8ad6533  
    2828namespace Debug {
    2929        /// debug codegen a translation unit
    30         static inline void codeGen( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, __attribute__((unused)) LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) {
     30        static inline void codeGen( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) {
    3131        #ifdef DEBUG
    3232                std::list< Declaration * > decls;
     
    4141        } // dump
    4242
    43         static inline void treeDump( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, __attribute__((unused)) LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) {
     43        static inline void treeDump( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) {
    4444        #ifdef DEBUG
    4545                std::list< Declaration * > decls;
  • src/Common/ErrorObjects.h

    rca37445 r8ad6533  
    3535class SemanticErrorException : public std::exception {
    3636  public:
    37         SemanticErrorException() = default;
     37        SemanticErrorException() = default;
    3838        SemanticErrorException( CodeLocation location, std::string error );
    3939        ~SemanticErrorException() throw() {}
  • src/Common/PassVisitor.h

    rca37445 r8ad6533  
    6666        virtual void visit( TypedefDecl * typeDecl ) override final;
    6767        virtual void visit( AsmDecl * asmDecl ) override final;
    68         virtual void visit( StaticAssertDecl * assertDecl ) override final;
    6968
    7069        virtual void visit( CompoundStmt * compoundStmt ) override final;
     
    162161        virtual Declaration * mutate( TypedefDecl * typeDecl ) override final;
    163162        virtual AsmDecl * mutate( AsmDecl * asmDecl ) override final;
    164         virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) override final;
    165163
    166164        virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) override final;
  • src/Common/PassVisitor.impl.h

    rca37445 r8ad6533  
    685685
    686686//--------------------------------------------------------------------------
    687 // StaticAssertDecl
    688 template< typename pass_type >
    689 void PassVisitor< pass_type >::visit( StaticAssertDecl * node ) {
    690         VISIT_START( node );
    691 
    692         maybeAccept_impl( node->condition, *this );
    693         maybeAccept_impl( node->message  , *this );
    694 
    695         VISIT_END( node );
    696 }
    697 
    698 template< typename pass_type >
    699 StaticAssertDecl * PassVisitor< pass_type >::mutate( StaticAssertDecl * node ) {
    700         MUTATE_START( node );
    701 
    702         maybeMutate_impl( node->condition, *this );
    703         maybeMutate_impl( node->message  , *this );
    704 
    705         MUTATE_END( StaticAssertDecl, node );
    706 }
    707 
    708 //--------------------------------------------------------------------------
    709687// CompoundStmt
    710688template< typename pass_type >
     
    15121490        indexerScopedAccept( node->result, *this );
    15131491        maybeAccept_impl   ( node->type  , *this );
     1492        maybeAccept_impl   ( node->member, *this );
    15141493
    15151494        VISIT_END( node );
     
    15231502        indexerScopedMutate( node->result, *this );
    15241503        maybeMutate_impl   ( node->type  , *this );
     1504        maybeMutate_impl   ( node->member, *this );
    15251505
    15261506        MUTATE_END( Expression, node );
  • src/GenPoly/Lvalue.cc

    rca37445 r8ad6533  
    4545                Expression * mkDeref( Expression * arg ) {
    4646                        if ( SymTab::dereferenceOperator ) {
    47                                 // note: reference depth can be arbitrarily deep here, so peel off the outermost pointer/reference, not just pointer because they are effecitvely equivalent in this pass
    4847                                VariableExpr * deref = new VariableExpr( SymTab::dereferenceOperator );
    4948                                deref->result = new PointerType( Type::Qualifiers(), deref->result );
     
    198197                                        PRINT(
    199198                                                std::cerr << "pair<0>: " << arg << std::endl;
    200                                                 std::cerr << " -- " << arg->result << std::endl;
    201199                                                std::cerr << "pair<1>: " << formal << std::endl;
    202200                                        )
    203201                                        if ( dynamic_cast<ReferenceType*>( formal ) ) {
    204                                                 PRINT(
    205                                                         std::cerr << "===formal is reference" << std::endl;
    206                                                 )
    207                                                 // TODO: it's likely that the second condition should be ... && ! isIntrinsicReference( arg ), but this requires investigation.
    208                                                 if ( function->get_linkage() != LinkageSpec::Intrinsic && isIntrinsicReference( arg ) ) {
    209                                                         // if argument is dereference or array subscript, the result isn't REALLY a reference, but non-intrinsic functions expect a reference: take address
    210                                                         PRINT(
    211                                                                 std::cerr << "===is intrinsic arg in non-intrinsic call - adding address" << std::endl;
    212                                                         )
    213                                                         arg = new AddressExpr( arg );
    214                                                 } else if ( function->get_linkage() == LinkageSpec::Intrinsic && arg->result->referenceDepth() != 0 ) {
    215                                                         // argument is a 'real' reference, but function expects a C lvalue: add a dereference to the reference-typed argument
    216                                                         PRINT(
    217                                                                 std::cerr << "===is non-intrinsic arg in intrinsic call - adding deref to arg" << std::endl;
    218                                                         )
     202                                                if ( isIntrinsicReference( arg ) ) { // do not combine conditions, because that changes the meaning of the else if
     203                                                        if ( function->get_linkage() != LinkageSpec::Intrinsic ) { // intrinsic functions that turn pointers into references
     204                                                                // if argument is dereference or array subscript, the result isn't REALLY a reference, so it's not necessary to fix the argument
     205                                                                PRINT(
     206                                                                        std::cerr << "===is intrinsic arg in non-intrinsic call - adding address" << std::endl;
     207                                                                )
     208                                                                arg = new AddressExpr( arg );
     209                                                        }
     210                                                } else if ( function->get_linkage() == LinkageSpec::Intrinsic ) {
     211                                                        // std::cerr << "===adding deref to arg" << std::endl;
     212                                                        // if the parameter is a reference, add a dereference to the reference-typed argument.
    219213                                                        Type * baseType = InitTweak::getPointerBase( arg->result );
    220214                                                        assertf( baseType, "parameter is reference, arg must be pointer or reference: %s", toString( arg->result ).c_str() );
     
    223217                                                        arg->set_result( ptrType );
    224218                                                        arg = mkDeref( arg );
    225                                                         assertf( arg->result->referenceDepth() == 0, "Reference types should have been eliminated from intrinsic function calls, but weren't: %s", toCString( arg->result ) );
    226219                                                }
    227220                                        }
  • src/Parser/DeclarationNode.cc

    rca37445 r8ad6533  
    7171        attr.expr = nullptr;
    7272        attr.type = nullptr;
    73 
    74         assert.condition = nullptr;
    75         assert.message = nullptr;
    7673}
    7774
     
    9188        // asmName, no delete, passed to next stage
    9289        delete initializer;
    93 
    94         delete assert.condition;
    95         delete assert.message;
    9690}
    9791
     
    123117        newnode->attr.expr = maybeClone( attr.expr );
    124118        newnode->attr.type = maybeClone( attr.type );
    125 
    126         newnode->assert.condition = maybeClone( assert.condition );
    127         newnode->assert.message = maybeClone( assert.message );
    128119        return newnode;
    129120} // DeclarationNode::clone
     
    443434        return newnode;
    444435}
    445 
    446 DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, Expression * message ) {
    447         DeclarationNode * newnode = new DeclarationNode;
    448         newnode->assert.condition = condition;
    449         newnode->assert.message = message;
    450         return newnode;
    451 }
    452 
    453436
    454437void appendError( string & dst, const string & src ) {
     
    10691052        } // if
    10701053
    1071         if ( assert.condition ) {
    1072                 return new StaticAssertDecl( maybeBuild< Expression >( assert.condition ), strict_dynamic_cast< ConstantExpr * >( maybeClone( assert.message ) ) );
    1073         }
    1074 
    10751054        // SUE's cannot have function specifiers, either
    10761055        //
  • src/Parser/ParseNode.h

    rca37445 r8ad6533  
    246246        static DeclarationNode * newAttribute( std::string *, ExpressionNode * expr = nullptr ); // gcc attributes
    247247        static DeclarationNode * newAsmStmt( StatementNode * stmt ); // gcc external asm statement
    248         static DeclarationNode * newStaticAssert( ExpressionNode * condition, Expression * message );
    249248
    250249        DeclarationNode();
     
    314313        Attr_t attr;
    315314
    316         struct StaticAssert_t {
    317                 ExpressionNode * condition;
    318                 Expression * message;
    319         };
    320         StaticAssert_t assert;
    321 
    322315        BuiltinType builtin;
    323316
  • src/Parser/parser.yy

    rca37445 r8ad6533  
    13141314static_assert:
    13151315        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
    1316                 { $$ = DeclarationNode::newStaticAssert( $3, $5 ); }
     1316                { SemanticError( yylloc, "Static assert is currently unimplemented." ); $$ = nullptr; }
    13171317
    13181318// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
  • src/ResolvExpr/CommonType.cc

    rca37445 r8ad6533  
    2727#include "typeops.h"                     // for isFtype
    2828
    29 #define DEBUG
    30 #ifdef DEBUG
    31 #define PRINT(x) x
    32 #else
    33 #define PRINT(x)
    34 #endif
     29// #define DEBUG
    3530
    3631namespace ResolvExpr {
     
    7570                // need unify to bind type variables
    7671                if ( unify( t1, t2, env, have, need, newOpen, indexer, common ) ) {
    77                         PRINT(
    78                                 std::cerr << "unify success: " << widenFirst << " " << widenSecond << std::endl;
    79                         )
     72                        // std::cerr << "unify success: " << widenFirst << " " << widenSecond << std::endl;
    8073                        if ( (widenFirst || t2->get_qualifiers() <= t1->get_qualifiers()) && (widenSecond || t1->get_qualifiers() <= t2->get_qualifiers()) ) {
    81                                 PRINT(
    82                                         std::cerr << "widen okay" << std::endl;
    83                                 )
     74                                // std::cerr << "widen okay" << std::endl;
    8475                                common->get_qualifiers() |= t1->get_qualifiers();
    8576                                common->get_qualifiers() |= t2->get_qualifiers();
     
    8778                        }
    8879                }
    89                 PRINT(
    90                         std::cerr << "exact unify failed: " << t1 << " " << t2 << std::endl;
    91                 )
     80                // std::cerr << "exact unify failed: " << t1 << " " << t2 << std::endl;
    9281                return nullptr;
    9382        }
     
    10594                        // special case where one type has a reference depth of 1 larger than the other
    10695                        if ( diff > 0 || diff < 0 ) {
    107                                 PRINT(
    108                                         std::cerr << "reference depth diff: " << diff << std::endl;
    109                                 )
     96                                // std::cerr << "reference depth diff: " << diff << std::endl;
    11097                                Type * result = nullptr;
    11198                                ReferenceType * ref1 = dynamic_cast< ReferenceType * >( type1 );
     
    122109                                if ( result && ref1 ) {
    123110                                        // formal is reference, so result should be reference
    124                                         PRINT(
    125                                                 std::cerr << "formal is reference; result should be reference" << std::endl;
    126                                         )
     111                                        // std::cerr << "formal is reference; result should be reference" << std::endl;
    127112                                        result = new ReferenceType( ref1->get_qualifiers(), result );
    128113                                }
    129                                 PRINT(
    130                                         std::cerr << "common type of reference [" << type1 << "] and [" << type2 << "] is [" << result << "]" << std::endl;
    131                                 )
     114                                // std::cerr << "common type of reference [" << type1 << "] and [" << type2 << "] is [" << result << "]" << std::endl;
    132115                                return result;
    133116                        }
  • src/ResolvExpr/Resolver.cc

    rca37445 r8ad6533  
    5959                void previsit( TypeDecl *typeDecl );
    6060                void previsit( EnumDecl * enumDecl );
    61                 void previsit( StaticAssertDecl * assertDecl );
    6261
    6362                void previsit( ArrayType * at );
     
    362361                GuardValue( inEnumDecl );
    363362                inEnumDecl = true;
    364         }
    365 
    366         void Resolver::previsit( StaticAssertDecl * assertDecl ) {
    367                 findIntegralExpression( assertDecl->condition, indexer );
    368363        }
    369364
  • src/SymTab/Validate.cc

    rca37445 r8ad6533  
    8989                void previsit( StructDecl * aggregateDecl );
    9090                void previsit( UnionDecl * aggregateDecl );
    91                 void previsit( StaticAssertDecl * assertDecl );
    9291
    9392          private:
     
    297296        }
    298297
    299         bool shouldHoist( Declaration *decl ) {
    300                 return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl ) || dynamic_cast< StaticAssertDecl * >( decl );
     298        bool isStructOrUnion( Declaration *decl ) {
     299                return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl );
    301300        }
    302301
     
    311310                } // if
    312311                // Always remove the hoisted aggregate from the inner structure.
    313                 GuardAction( [aggregateDecl]() { filter( aggregateDecl->members, shouldHoist, false ); } );
     312                GuardAction( [aggregateDecl]() { filter( aggregateDecl->members, isStructOrUnion, false ); } );
    314313        }
    315314
     
    329328                if ( inst->baseUnion ) {
    330329                        declsToAddBefore.push_front( inst->baseUnion );
    331                 }
    332         }
    333 
    334         void HoistStruct::previsit( StaticAssertDecl * assertDecl ) {
    335                 if ( parentAggr ) {
    336                         declsToAddBefore.push_back( assertDecl );
    337330                }
    338331        }
     
    637630                        forallFixer( pointer->base->forall, object );
    638631                } // if
    639                 // ensure that operator names only apply to functions or function pointers
    640                 if ( CodeGen::isOperator( object->name ) && ! dynamic_cast< FunctionType * >( object->type->stripDeclarator() ) ) {
    641                         SemanticError( object->location, toCString( "operator ", object->name.c_str(), " is not a function or function pointer." )  );
    642                 }
    643632                object->fixUniqueId();
    644633        }
  • src/SynTree/Declaration.cc

    rca37445 r8ad6533  
    8181
    8282
    83 StaticAssertDecl::StaticAssertDecl( Expression * condition, ConstantExpr * message ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), condition( condition ), message( message )  {
    84 }
    85 
    86 StaticAssertDecl::StaticAssertDecl( const StaticAssertDecl & other ) : Declaration( other ), condition( maybeClone( other.condition ) ), message( maybeClone( other.message ) )  {
    87 }
    88 
    89 StaticAssertDecl::~StaticAssertDecl() {
    90         delete condition;
    91         delete message;
    92 }
    93 
    94 void StaticAssertDecl::print( std::ostream &os, Indenter indent ) const {
    95         os << "Static Assert with condition: ";
    96         condition->print( os, indent+1 );
    97         os << std::endl << indent << "and message: ";
    98         message->print( os, indent+1 );
    99 os << std::endl;
    100 }
    101 
    102 void StaticAssertDecl::printShort( std::ostream &os, Indenter indent ) const {
    103         print( os, indent );
    104 }
    105 
    10683// Local Variables: //
    10784// tab-width: 4 //
  • src/SynTree/Declaration.h

    rca37445 r8ad6533  
    365365};
    366366
    367 class StaticAssertDecl : public Declaration {
    368 public:
    369         Expression * condition;
    370         ConstantExpr * message;   // string literal
    371 
    372         StaticAssertDecl( Expression * condition, ConstantExpr * message );
    373         StaticAssertDecl( const StaticAssertDecl & other );
    374         virtual ~StaticAssertDecl();
    375 
    376         virtual StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
    377         virtual void accept( Visitor &v ) override { v.visit( this ); }
    378         virtual StaticAssertDecl * acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    379         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    380         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
    381 };
    382 
    383367std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data );
    384368
  • src/SynTree/Mutator.h

    rca37445 r8ad6533  
    3434        virtual Declaration * mutate( TypedefDecl * typeDecl ) = 0;
    3535        virtual AsmDecl * mutate( AsmDecl * asmDecl ) = 0;
    36         virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) = 0;
    3736
    3837        virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) = 0;
  • src/SynTree/SynTree.h

    rca37445 r8ad6533  
    3838class TypedefDecl;
    3939class AsmDecl;
    40 class StaticAssertDecl;
    4140
    4241class Statement;
  • src/SynTree/Visitor.h

    rca37445 r8ad6533  
    3636        virtual void visit( TypedefDecl * typeDecl ) = 0;
    3737        virtual void visit( AsmDecl * asmDecl ) = 0;
    38         virtual void visit( StaticAssertDecl * assertDecl ) = 0;
    3938
    4039        virtual void visit( CompoundStmt * compoundStmt ) = 0;
  • src/tests/.expect/references.txt

    rca37445 r8ad6533  
    4413 1 12
    5514 14
    6 x = 6 ; x2 = 789
    7 x = 6 ; x2 = 999
    8 x = 12345 ; x2 = 999
    9 x = 22222 ; x2 = 999
    106Default constructing a Y
    117Copy constructing a Y
  • src/tests/operators.c

    rca37445 r8ad6533  
    2727        a(b);
    2828        a + b;
     29        struct accumulator ?+?; // why not, eh?
     30        a + b;
    2931}
    3032
  • src/tests/references.c

    rca37445 r8ad6533  
    4646
    4747int main() {
    48         int x = 123456, x2 = 789, *p1 = &x, **p2 = &p1, ***p3 = &p2,
     48        int x = 123456, *p1 = &x, **p2 = &p1, ***p3 = &p2,
    4949                &r1 = x,    &&r2 = r1,   &&&r3 = r2;
    5050        ***p3 = 3;                          // change x
     51        // ((int&)r3 = 3;                      // change x, ***r3
    5152        **p3 = &x;                          // change p1
     53        // ((int*&)&r3) = &x;                  // change r1, (&*)**r3
    5254        *p3 = &p1;                          // change p2
     55        // ((int**&)&&r3) = &p2;               // change r2, (&(&*)*)*r3
     56        // ((int***&)&&&r3) = p3;              // change r3 to p3, (&(&(&*)*)*)r3
    5357        int y = 0, z = 11, & ar[3] = { x, y, z };    // initialize array of references
    5458        // &ar[1] = &z;                        // change reference array element
     
    5862        // sizeof( &ar[1] ) == sizeof( int *); // is true, i.e., the size of a reference
    5963
    60         ((int*&)&r3) = &x;                  // change r1, (&*)**r3
    61         x = 3;
    6264        // test that basic reference properties are true - r1 should be an alias for x
    6365        printf("%d %d %d\n", x, r1, &x == &r1);
     
    7476        changeRef( r1 );
    7577        printf("%d %d\n", r1, x);
    76 
    77         ((int&)r3) = 6;                       // change x, ***r3
    78         printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
    79         ((int*&)&r3) = &x2;                   // change r1 to refer to x2, (&*)**r3
    80         ((int&)r3) = 999;                     // modify x2
    81         printf("x = %d ; x2 = %d\n", x, x2);  // check that x2 was changed
    82         ((int**&)&&r3) = p2;                  // change r2, (&(&*)*)*r3
    83         ((int&)r3) = 12345;                   // modify x
    84         printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
    85         ((int***&)&&&r3) = p3;                // change r3 to p3, (&(&(&*)*)*)r3
    86         ((int&)r3) = 22222;                   // modify x
    87         printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
    8878
    8979        // test that reference members are not implicitly constructed/destructed/assigned
Note: See TracChangeset for help on using the changeset viewer.