Changeset 2d019af


Ignore:
Timestamp:
Mar 12, 2021, 11:14:29 PM (7 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
41ca6fa, e867b44
Parents:
6083392
Message:

parser global pragmas, fixes #241

Location:
src
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r6083392 r2d019af  
    99// Author           : Thierry Delisle
    1010// Created On       : Thu May 09 15::37::05 2019
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Nov 12 10:07:00 2020
    13 // Update Count     : 34
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Mar 12 18:43:51 2021
     13// Update Count     : 36
    1414//
    1515
     
    327327        const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final {
    328328                auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) );
     329                declPostamble( decl, node );
     330                return nullptr;
     331        }
     332
     333        const ast::DirectiveDecl * visit( const ast::DirectiveDecl * node ) override final {
     334                auto decl = new DirectiveDecl( get<DirectiveStmt>().accept1( node->stmt ) );
    329335                declPostamble( decl, node );
    330336                return nullptr;
     
    17691775        }
    17701776
     1777        virtual void visit( const DirectiveDecl * old ) override final {
     1778                auto decl = new ast::DirectiveDecl{
     1779                        old->location,
     1780                        GET_ACCEPT_1(stmt, DirectiveStmt)
     1781                };
     1782                decl->extension  = old->extension;
     1783                decl->uniqueId   = old->uniqueId;
     1784                decl->storage    = { old->storageClasses.val };
     1785
     1786                this->node = decl;
     1787        }
     1788
    17711789        virtual void visit( const StaticAssertDecl * old ) override final {
    17721790                auto decl = new ast::StaticAssertDecl{
  • src/AST/Decl.hpp

    r6083392 r2d019af  
    1010// Created On       : Thu May 9 10:00:00 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 11 20:48:38 2021
    13 // Update Count     : 30
     12// Last Modified On : Fri Mar 12 18:25:05 2021
     13// Update Count     : 32
    1414//
    1515
     
    365365};
    366366
     367/// C-preprocessor directive `#...`
     368class DirectiveDecl : public Decl {
     369public:
     370        ptr<DirectiveStmt> stmt;
     371
     372        DirectiveDecl( const CodeLocation & loc, DirectiveStmt * stmt )
     373        : Decl( loc, "", {}, {} ), stmt(stmt) {}
     374
     375        const DirectiveDecl * accept( Visitor & v ) const override { return v.visit( this ); }
     376private:
     377        DirectiveDecl * clone() const override { return new DirectiveDecl( *this ); }
     378        MUTATE_FRIEND
     379};
     380
    367381class StaticAssertDecl : public Decl {
    368382public:
  • src/AST/Fwd.hpp

    r6083392 r2d019af  
    99// Author           : Andrew Beach
    1010// Created On       : Wed May  8 16:05:00 2019
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Jul 23 14:15:00 2020
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Mar 12 18:37:39 2021
     13// Update Count     : 4
    1414//
    1515
     
    3535class TypedefDecl;
    3636class AsmDecl;
     37class DirectiveDecl;
    3738class StaticAssertDecl;
    3839
  • src/AST/Node.cpp

    r6083392 r2d019af  
    99// Author           : Thierry Delisle
    1010// Created On       : Thu May 16 14:16:00 2019
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Jun  5 10:21:00 2020
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Mar 12 18:25:06 2021
     13// Update Count     : 2
    1414//
    1515
     
    130130template class ast::ptr_base< ast::AsmDecl, ast::Node::ref_type::weak >;
    131131template class ast::ptr_base< ast::AsmDecl, ast::Node::ref_type::strong >;
     132template class ast::ptr_base< ast::DirectiveDecl, ast::Node::ref_type::weak >;
     133template class ast::ptr_base< ast::DirectiveDecl, ast::Node::ref_type::strong >;
    132134template class ast::ptr_base< ast::StaticAssertDecl, ast::Node::ref_type::weak >;
    133135template class ast::ptr_base< ast::StaticAssertDecl, ast::Node::ref_type::strong >;
  • src/AST/Pass.hpp

    r6083392 r2d019af  
    139139        const ast::Decl *             visit( const ast::TypedefDecl          * ) override final;
    140140        const ast::AsmDecl *          visit( const ast::AsmDecl              * ) override final;
     141        const ast::DirectiveDecl *    visit( const ast::DirectiveDecl        * ) override final;
    141142        const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl     * ) override final;
    142143        const ast::CompoundStmt *     visit( const ast::CompoundStmt         * ) override final;
  • src/AST/Pass.impl.hpp

    r6083392 r2d019af  
    646646
    647647//--------------------------------------------------------------------------
     648// DirectiveDecl
     649template< typename core_t >
     650const ast::DirectiveDecl * ast::Pass< core_t >::visit( const ast::DirectiveDecl * node ) {
     651        VISIT_START( node );
     652
     653        VISIT(
     654                maybe_accept( node, &DirectiveDecl::stmt );
     655        )
     656
     657        VISIT_END( DirectiveDecl, node );
     658}
     659
     660//--------------------------------------------------------------------------
    648661// StaticAssertDecl
    649662template< typename core_t >
  • src/AST/Print.cpp

    r6083392 r2d019af  
    387387
    388388        virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final {
     389                safe_print( node->stmt );
     390                return node;
     391        }
     392
     393        virtual const ast::DirectiveDecl * visit( const ast::DirectiveDecl * node ) override final {
    389394                safe_print( node->stmt );
    390395                return node;
  • src/AST/Visitor.hpp

    r6083392 r2d019af  
    99// Author           : Andrew Beach
    1010// Created On       : Thr May 9 15:28:00 2019
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr May 9 15:33:00 2019
    13 // Update Count     : 0
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Mar 12 18:25:07 2021
     13// Update Count     : 1
    1414//
    1515
     
    3131    virtual const ast::Decl *             visit( const ast::TypedefDecl          * ) = 0;
    3232    virtual const ast::AsmDecl *          visit( const ast::AsmDecl              * ) = 0;
     33    virtual const ast::DirectiveDecl *    visit( const ast::DirectiveDecl        * ) = 0;
    3334    virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl     * ) = 0;
    3435    virtual const ast::CompoundStmt *     visit( const ast::CompoundStmt         * ) = 0;
  • src/CodeGen/CodeGenerator.cc

    r6083392 r2d019af  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Feb 16 08:32:48 2020
    13 // Update Count     : 532
     12// Last Modified On : Fri Mar 12 19:00:42 2021
     13// Update Count     : 536
    1414//
    1515#include "CodeGenerator.h"
     
    935935                if ( asmStmt->get_instruction() ) asmStmt->get_instruction()->accept( *visitor );
    936936                output << " )";
     937        }
     938
     939        void CodeGenerator::postvisit( DirectiveDecl * directiveDecl ) {
     940                output << endl << directiveDecl->get_stmt()->directive; // endl prevents spaces before directive
    937941        }
    938942
  • src/CodeGen/CodeGenerator.h

    r6083392 r2d019af  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Feb 16 03:58:31 2020
    13 // Update Count     : 62
     12// Last Modified On : Fri Mar 12 18:35:38 2021
     13// Update Count     : 63
    1414//
    1515
     
    105105                void postvisit( DirectiveStmt * );
    106106                void postvisit( AsmDecl * );                                    // special: statement in declaration context
     107                void postvisit( DirectiveDecl * );                              // special: statement in declaration context
    107108                void postvisit( IfStmt * );
    108109                void postvisit( SwitchStmt * );
  • src/Common/CodeLocationTools.cpp

    r6083392 r2d019af  
    99// Author           : Andrew Beach
    1010// Created On       : Fri Dec  4 15:42:00 2020
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Dec  9  9:42:00 2020
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Mar 12 18:35:37 2021
     13// Update Count     : 2
    1414//
    1515
     
    102102    macro(TypedefDecl, Decl) \
    103103    macro(AsmDecl, AsmDecl) \
     104    macro(DirectiveDecl, DirectiveDecl) \
    104105    macro(StaticAssertDecl, StaticAssertDecl) \
    105106    macro(CompoundStmt, CompoundStmt) \
  • src/Common/PassVisitor.h

    r6083392 r2d019af  
    7777        virtual void visit( AsmDecl * asmDecl ) override final;
    7878        virtual void visit( const AsmDecl * asmDecl ) override final;
     79        virtual void visit( DirectiveDecl * directiveDecl ) override final;
     80        virtual void visit( const DirectiveDecl * directiveDecl ) override final;
    7981        virtual void visit( StaticAssertDecl * assertDecl ) override final;
    8082        virtual void visit( const StaticAssertDecl * assertDecl ) override final;
     
    261263        virtual Declaration * mutate( TypedefDecl * typeDecl ) override final;
    262264        virtual AsmDecl * mutate( AsmDecl * asmDecl ) override final;
     265        virtual DirectiveDecl * mutate( DirectiveDecl * directiveDecl ) override final;
    263266        virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) override final;
    264267
  • src/Common/PassVisitor.impl.h

    r6083392 r2d019af  
    973973
    974974//--------------------------------------------------------------------------
     975// DirectiveDecl
     976template< typename pass_type >
     977void PassVisitor< pass_type >::visit( DirectiveDecl * node ) {
     978        VISIT_START( node );
     979
     980        maybeAccept_impl( node->stmt, *this );
     981
     982        VISIT_END( node );
     983}
     984
     985template< typename pass_type >
     986void PassVisitor< pass_type >::visit( const DirectiveDecl * node ) {
     987        VISIT_START( node );
     988
     989        maybeAccept_impl( node->stmt, *this );
     990
     991        VISIT_END( node );
     992}
     993
     994template< typename pass_type >
     995DirectiveDecl * PassVisitor< pass_type >::mutate( DirectiveDecl * node ) {
     996        MUTATE_START( node );
     997
     998        maybeMutate_impl( node->stmt, *this );
     999
     1000        MUTATE_END( DirectiveDecl, node );
     1001}
     1002
     1003//--------------------------------------------------------------------------
    9751004// StaticAssertDecl
    9761005template< typename pass_type >
  • src/Parser/DeclarationNode.cc

    r6083392 r2d019af  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 11 20:58:07 2021
    13 // Update Count     : 1137
     12// Last Modified On : Fri Mar 12 18:35:37 2021
     13// Update Count     : 1141
    1414//
    1515
     
    424424        newnode->attributes.push_back( new Attribute( *name, exprs ) );
    425425        delete name;
     426        return newnode;
     427}
     428
     429DeclarationNode * DeclarationNode::newDirectiveStmt( StatementNode * stmt ) {
     430        DeclarationNode * newnode = new DeclarationNode;
     431        newnode->directiveStmt = stmt;
    426432        return newnode;
    427433}
     
    10721078                return new AsmDecl( strict_dynamic_cast<AsmStmt *>( asmStmt->build() ) );
    10731079        } // if
     1080        if ( directiveStmt ) {
     1081                return new DirectiveDecl( strict_dynamic_cast<DirectiveStmt *>( directiveStmt->build() ) );
     1082        } // if
    10741083
    10751084        if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {
  • src/Parser/ParseNode.h

    r6083392 r2d019af  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan  3 18:23:01 2021
    13 // Update Count     : 896
     12// Last Modified On : Fri Mar 12 15:19:04 2021
     13// Update Count     : 897
    1414//
    1515
     
    249249        static DeclarationNode * newTypeof( ExpressionNode * expr, bool basetypeof = false );
    250250        static DeclarationNode * newAttribute( const std::string *, ExpressionNode * expr = nullptr ); // gcc attributes
     251        static DeclarationNode * newDirectiveStmt( StatementNode * stmt ); // gcc external directive statement
    251252        static DeclarationNode * newAsmStmt( StatementNode * stmt ); // gcc external asm statement
    252253        static DeclarationNode * newStaticAssert( ExpressionNode * condition, Expression * message );
     
    345346        std::string error;
    346347        StatementNode * asmStmt = nullptr;
     348        StatementNode * directiveStmt = nullptr;
    347349
    348350        static UniqueName anonymous;
  • src/Parser/parser.yy

    r6083392 r2d019af  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 09:03:07 2021
    13 // Update Count     : 4722
     12// Last Modified On : Fri Mar 12 15:21:02 2021
     13// Update Count     : 4728
    1414//
    1515
     
    26392639
    26402640external_definition:
    2641         declaration
     2641        DIRECTIVE
     2642                { $$ = DeclarationNode::newDirectiveStmt( new StatementNode( build_directive( $1 ) ) ); }
     2643        | declaration
    26422644        | external_function_definition
    26432645        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
  • src/SynTree/Declaration.cc

    r6083392 r2d019af  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 11 16:39:56 2019
    13 // Update Count     : 36
     12// Last Modified On : Fri Mar 12 18:35:39 2021
     13// Update Count     : 37
    1414//
    1515
     
    6666
    6767
     68DirectiveDecl::DirectiveDecl( DirectiveStmt *stmt ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), stmt( stmt ) {
     69}
     70
     71DirectiveDecl::DirectiveDecl( const DirectiveDecl &other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) {
     72}
     73
     74DirectiveDecl::~DirectiveDecl() {
     75        delete stmt;
     76}
     77
     78void DirectiveDecl::print( std::ostream &os, Indenter indent ) const {
     79        stmt->print( os, indent );
     80}
     81
     82void DirectiveDecl::printShort( std::ostream &os, Indenter indent ) const {
     83        stmt->print( os, indent );
     84}
     85
     86
    6887StaticAssertDecl::StaticAssertDecl( Expression * condition, ConstantExpr * message ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), condition( condition ), message( message )  {
    6988}
  • src/SynTree/Declaration.h

    r6083392 r2d019af  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 11 20:48:39 2021
    13 // Update Count     : 158
     12// Last Modified On : Fri Mar 12 18:35:36 2021
     13// Update Count     : 159
    1414//
    1515
     
    400400};
    401401
     402class DirectiveDecl : public Declaration {
     403  public:
     404        DirectiveStmt * stmt;
     405
     406        DirectiveDecl( DirectiveStmt * stmt );
     407        DirectiveDecl( const DirectiveDecl & other );
     408        virtual ~DirectiveDecl();
     409
     410        DirectiveStmt * get_stmt() { return stmt; }
     411        void set_stmt( DirectiveStmt * newValue ) { stmt = newValue; }
     412
     413        virtual DirectiveDecl * clone() const override { return new DirectiveDecl( *this ); }
     414        virtual void accept( Visitor & v ) override { v.visit( this ); }
     415        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     416        virtual DirectiveDecl * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     417        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     418        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
     419};
     420
    402421class StaticAssertDecl : public Declaration {
    403422public:
  • src/SynTree/Mutator.h

    r6083392 r2d019af  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 25 22:37:46 2019
    13 // Update Count     : 17
     12// Last Modified On : Fri Mar 12 18:35:36 2021
     13// Update Count     : 18
    1414//
    1515#pragma once
     
    3434        virtual Declaration * mutate( TypedefDecl * typeDecl ) = 0;
    3535        virtual AsmDecl * mutate( AsmDecl * asmDecl ) = 0;
     36        virtual DirectiveDecl * mutate( DirectiveDecl * directiveDecl ) = 0;
    3637        virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) = 0;
    3738
  • src/SynTree/SynTree.h

    r6083392 r2d019af  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 25 22:37:45 2019
    13 // Update Count     : 12
     12// Last Modified On : Fri Mar 12 18:56:44 2021
     13// Update Count     : 13
    1414//
    1515
     
    3636class TypedefDecl;
    3737class AsmDecl;
     38class DirectiveDecl;
    3839class StaticAssertDecl;
    3940
  • src/SynTree/Visitor.h

    r6083392 r2d019af  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 25 22:21:49 2019
    13 // Update Count     : 14
     12// Last Modified On : Fri Mar 12 18:35:35 2021
     13// Update Count     : 15
    1414//
    1515
     
    4545        virtual void visit( AsmDecl * node ) { visit( const_cast<const AsmDecl *>(node) ); }
    4646        virtual void visit( const AsmDecl * asmDecl ) = 0;
     47        virtual void visit( DirectiveDecl * node ) { visit( const_cast<const DirectiveDecl *>(node) ); }
     48        virtual void visit( const DirectiveDecl * directiveDecl ) = 0;
    4749        virtual void visit( StaticAssertDecl * node ) { visit( const_cast<const StaticAssertDecl *>(node) ); }
    4850        virtual void visit( const StaticAssertDecl * assertDecl ) = 0;
Note: See TracChangeset for help on using the changeset viewer.