Changeset f6e3e34


Ignore:
Timestamp:
Apr 3, 2018, 11:13:10 AM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, 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, with_gc
Children:
92fea32
Parents:
3d2b7bc
Message:

Add StaticAssertDecl? node

Location:
src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r3d2b7bc rf6e3e34  
    6666        virtual void visit( TypedefDecl * typeDecl ) override final;
    6767        virtual void visit( AsmDecl * asmDecl ) override final;
     68        virtual void visit( StaticAssertDecl * assertDecl ) override final;
    6869
    6970        virtual void visit( CompoundStmt * compoundStmt ) override final;
     
    161162        virtual Declaration * mutate( TypedefDecl * typeDecl ) override final;
    162163        virtual AsmDecl * mutate( AsmDecl * asmDecl ) override final;
     164        virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) override final;
    163165
    164166        virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) override final;
  • src/Common/PassVisitor.impl.h

    r3d2b7bc rf6e3e34  
    685685
    686686//--------------------------------------------------------------------------
     687// StaticAssertDecl
     688template< typename pass_type >
     689void 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
     698template< typename pass_type >
     699StaticAssertDecl * 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//--------------------------------------------------------------------------
    687709// CompoundStmt
    688710template< typename pass_type >
     
    14901512        indexerScopedAccept( node->result, *this );
    14911513        maybeAccept_impl   ( node->type  , *this );
    1492         maybeAccept_impl   ( node->member, *this );
    14931514
    14941515        VISIT_END( node );
     
    15021523        indexerScopedMutate( node->result, *this );
    15031524        maybeMutate_impl   ( node->type  , *this );
    1504         maybeMutate_impl   ( node->member, *this );
    15051525
    15061526        MUTATE_END( Expression, node );
  • src/Parser/DeclarationNode.cc

    r3d2b7bc rf6e3e34  
    7171        attr.expr = nullptr;
    7272        attr.type = nullptr;
     73
     74        assert.condition = nullptr;
     75        assert.message = nullptr;
    7376}
    7477
     
    8891        // asmName, no delete, passed to next stage
    8992        delete initializer;
     93
     94        delete assert.condition;
     95        delete assert.message;
    9096}
    9197
     
    117123        newnode->attr.expr = maybeClone( attr.expr );
    118124        newnode->attr.type = maybeClone( attr.type );
     125
     126        newnode->assert.condition = maybeClone( assert.condition );
     127        newnode->assert.message = maybeClone( assert.message );
    119128        return newnode;
    120129} // DeclarationNode::clone
     
    434443        return newnode;
    435444}
     445
     446DeclarationNode * 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
    436453
    437454void appendError( string & dst, const string & src ) {
     
    10521069        } // if
    10531070
     1071        if ( assert.condition ) {
     1072                return new StaticAssertDecl( maybeBuild< Expression >( assert.condition ), strict_dynamic_cast< ConstantExpr * >( maybeClone( assert.message ) ) );
     1073        }
     1074
    10541075        // SUE's cannot have function specifiers, either
    10551076        //
  • src/Parser/ParseNode.h

    r3d2b7bc rf6e3e34  
    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 );
    248249
    249250        DeclarationNode();
     
    313314        Attr_t attr;
    314315
     316        struct StaticAssert_t {
     317                ExpressionNode * condition;
     318                Expression * message;
     319        };
     320        StaticAssert_t assert;
     321
    315322        BuiltinType builtin;
    316323
  • src/Parser/parser.yy

    r3d2b7bc rf6e3e34  
    13081308static_assert:
    13091309        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
    1310                 { SemanticError( yylloc, "Static assert is currently unimplemented." ); $$ = nullptr; } // FIX ME
     1310                { $$ = DeclarationNode::newStaticAssert( $3, $5 ); }
    13111311
    13121312// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
  • src/SynTree/Declaration.cc

    r3d2b7bc rf6e3e34  
    8181
    8282
     83StaticAssertDecl::StaticAssertDecl( Expression * condition, ConstantExpr * message ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), condition( condition ), message( message )  {
     84}
     85
     86StaticAssertDecl::StaticAssertDecl( const StaticAssertDecl & other ) : Declaration( other ), condition( maybeClone( other.condition ) ), message( maybeClone( other.message ) )  {
     87}
     88
     89StaticAssertDecl::~StaticAssertDecl() {
     90        delete condition;
     91        delete message;
     92}
     93
     94void 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 );
     99os << std::endl;
     100}
     101
     102void StaticAssertDecl::printShort( std::ostream &os, Indenter indent ) const {
     103        print( os, indent );
     104}
     105
    83106// Local Variables: //
    84107// tab-width: 4 //
  • src/SynTree/Declaration.h

    r3d2b7bc rf6e3e34  
    365365};
    366366
     367class StaticAssertDecl : public Declaration {
     368public:
     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
    367383std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data );
    368384
  • src/SynTree/Mutator.h

    r3d2b7bc rf6e3e34  
    3434        virtual Declaration * mutate( TypedefDecl * typeDecl ) = 0;
    3535        virtual AsmDecl * mutate( AsmDecl * asmDecl ) = 0;
     36        virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) = 0;
    3637
    3738        virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) = 0;
  • src/SynTree/SynTree.h

    r3d2b7bc rf6e3e34  
    3838class TypedefDecl;
    3939class AsmDecl;
     40class StaticAssertDecl;
    4041
    4142class Statement;
  • src/SynTree/Visitor.h

    r3d2b7bc rf6e3e34  
    3636        virtual void visit( TypedefDecl * typeDecl ) = 0;
    3737        virtual void visit( AsmDecl * asmDecl ) = 0;
     38        virtual void visit( StaticAssertDecl * assertDecl ) = 0;
    3839
    3940        virtual void visit( CompoundStmt * compoundStmt ) = 0;
Note: See TracChangeset for help on using the changeset viewer.