Changeset fc12f05 for src/AST


Ignore:
Timestamp:
Nov 13, 2023, 3:43:43 AM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
25f2798
Parents:
0030b508 (diff), 2174191 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/AST
Files:
2 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    r0030b508 rfc12f05  
    125125
    126126/// Object declaration `int foo()`
    127 class FunctionDecl : public DeclWithType {
     127class FunctionDecl final : public DeclWithType {
    128128public:
    129129        std::vector<ptr<TypeDecl>> type_params;
     
    314314class EnumDecl final : public AggregateDecl {
    315315public:
    316         bool isTyped; // isTyped indicated if the enum has a declaration like:
     316        // isTyped indicated if the enum has a declaration like:
    317317        // enum (type_optional) Name {...}
    318         ptr<Type> base; // if isTyped == true && base.get() == nullptr, it is a "void" type enum
     318        bool isTyped;
     319        // if isTyped == true && base.get() == nullptr, it is a "void" type enum
     320        ptr<Type> base;
    319321        enum class EnumHiding { Visible, Hide } hide;
    320322
     
    374376
    375377/// Assembly declaration: `asm ... ( "..." : ... )`
    376 class AsmDecl : public Decl {
     378class AsmDecl final : public Decl {
    377379public:
    378380        ptr<AsmStmt> stmt;
    379381
    380382        AsmDecl( const CodeLocation & loc, AsmStmt * stmt )
    381         : Decl( loc, "", {}, {} ), stmt(stmt) {}
     383        : Decl( loc, "", {}, Linkage::C ), stmt(stmt) {}
    382384
    383385        const AsmDecl * accept( Visitor & v ) const override { return v.visit( this ); }
     
    388390
    389391/// C-preprocessor directive `#...`
    390 class DirectiveDecl : public Decl {
     392class DirectiveDecl final : public Decl {
    391393public:
    392394        ptr<DirectiveStmt> stmt;
    393395
    394396        DirectiveDecl( const CodeLocation & loc, DirectiveStmt * stmt )
    395         : Decl( loc, "", {}, {} ), stmt(stmt) {}
     397        : Decl( loc, "", {}, Linkage::C ), stmt(stmt) {}
    396398
    397399        const DirectiveDecl * accept( Visitor & v ) const override { return v.visit( this ); }
     
    402404
    403405/// Static Assertion `_Static_assert( ... , ... );`
    404 class StaticAssertDecl : public Decl {
     406class StaticAssertDecl final : public Decl {
    405407public:
    406408        ptr<Expr> cond;
     
    408410
    409411        StaticAssertDecl( const CodeLocation & loc, const Expr * condition, const ConstantExpr * msg )
    410         : Decl( loc, "", {}, {} ), cond( condition ), msg( msg ) {}
     412        : Decl( loc, "", {}, Linkage::C ), cond( condition ), msg( msg ) {}
    411413
    412414        const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/AST/Fwd.hpp

    r0030b508 rfc12f05  
    6868class MutexStmt;
    6969class CorunStmt;
     70class CoforStmt;
    7071
    7172class Expr;
  • src/AST/Node.cpp

    r0030b508 rfc12f05  
    194194template class ast::ptr_base< ast::CorunStmt, ast::Node::ref_type::weak >;
    195195template class ast::ptr_base< ast::CorunStmt, ast::Node::ref_type::strong >;
     196template class ast::ptr_base< ast::CoforStmt, ast::Node::ref_type::weak >;
     197template class ast::ptr_base< ast::CoforStmt, ast::Node::ref_type::strong >;
    196198template class ast::ptr_base< ast::Expr, ast::Node::ref_type::weak >;
    197199template class ast::ptr_base< ast::Expr, ast::Node::ref_type::strong >;
  • src/AST/Pass.cpp

    r0030b508 rfc12f05  
    1919
    2020PassVisitorStats pass_visitor_stats;
     21// TODO: There was a counter for every syntax node created.
     22//   This has not been translated to the new ast.
    2123// Stats::Counters::SimpleCounter * BaseSyntaxNode::new_nodes = nullptr;
    2224
  • src/AST/Pass.hpp

    r0030b508 rfc12f05  
    172172        const ast::Stmt *             visit( const ast::MutexStmt            * ) override final;
    173173        const ast::Stmt *             visit( const ast::CorunStmt            * ) override final;
     174        const ast::Stmt *             visit( const ast::CoforStmt            * ) override final;
    174175        const ast::Expr *             visit( const ast::ApplicationExpr      * ) override final;
    175176        const ast::Expr *             visit( const ast::UntypedExpr          * ) override final;
  • src/AST/Pass.impl.hpp

    r0030b508 rfc12f05  
    11341134
    11351135//--------------------------------------------------------------------------
     1136// CoforStmt
     1137template< typename core_t >
     1138const ast::Stmt * ast::Pass< core_t >::visit( const ast::CoforStmt * node ) {
     1139        VISIT_START( node );
     1140
     1141        if ( __visit_children() ) {
     1142                // for statements introduce a level of scope (for the initialization)
     1143                guard_symtab guard { *this };
     1144                maybe_accept( node, &CoforStmt::inits );
     1145                maybe_accept_top( node, &CoforStmt::cond  );
     1146                maybe_accept_top( node, &CoforStmt::inc   );
     1147                maybe_accept_as_compound( node, &CoforStmt::body  );
     1148        }
     1149
     1150        VISIT_END( Stmt, node );
     1151}
     1152
     1153//--------------------------------------------------------------------------
    11361154// ApplicationExpr
    11371155template< typename core_t >
  • src/AST/Print.cpp

    r0030b508 rfc12f05  
    934934        }
    935935
     936        virtual const ast::Stmt * visit( const ast::CoforStmt * node ) override final {
     937                os << "Cofor Statement" << endl;
     938
     939                if ( ! node->inits.empty() ) {
     940                        os << indent << "... initialization:" << endl;
     941                        ++indent;
     942                        for ( const ast::Stmt * stmt : node->inits ) {
     943                                os << indent+1;
     944                                safe_print( stmt );
     945                        }
     946                        --indent;
     947                }
     948
     949                if ( node->cond ) {
     950                        os << indent << "... condition:" << endl;
     951                        ++indent;
     952                        os << indent;
     953                        node->cond->accept( *this );
     954                        --indent;
     955                }
     956
     957                if ( node->inc ) {
     958                        os << indent << "... increment:" << endl;
     959                        ++indent;
     960                        os << indent;
     961                        node->inc->accept( *this );
     962                        --indent;
     963                }
     964
     965                if ( node->body ) {
     966                        os << indent << "... with body:" << endl;
     967                        ++indent;
     968                        os << indent;
     969                        node->body->accept( *this );
     970                        --indent;
     971                }
     972                os << endl;
     973                print( node->labels );
     974
     975                return node;
     976        }
     977
    936978        virtual const ast::Expr * visit( const ast::ApplicationExpr * node ) override final {
    937979                ++indent;
  • src/AST/Stmt.hpp

    r0030b508 rfc12f05  
    2828// Must be included in *all* AST classes; should be #undef'd at the end of the file
    2929#define MUTATE_FRIEND                                                                                                   \
    30     template<typename node_t> friend node_t * mutate(const node_t * node); \
     30        template<typename node_t> friend node_t * mutate(const node_t * node); \
    3131        template<typename node_t> friend node_t * shallowCopy(const node_t * node);
    3232
     
    340340
    341341        CatchClause( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond,
    342                            const Stmt * body )
     342                        const Stmt * body )
    343343                : StmtClause(loc), decl(decl), cond(cond), body(body), kind(kind) {}
    344344
     
    380380// Base class of WaitFor/WaitUntil statements
    381381// form: KEYWORD(...) ... timeout(...) ... else ...
    382 class WaitStmt : public Stmt { 
    383   public:
    384     ptr<Expr> timeout_time;
     382class WaitStmt : public Stmt {
     383  public:
     384        ptr<Expr> timeout_time;
    385385        ptr<Stmt> timeout_stmt;
    386386        ptr<Expr> timeout_cond;
     
    388388        ptr<Expr> else_cond;
    389389
    390     WaitStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )
     390        WaitStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )
    391391                : Stmt(loc, std::move(labels)) {}
    392392
    393393  private:
    394     WaitStmt * clone() const override = 0;
     394        WaitStmt * clone() const override = 0;
    395395        MUTATE_FRIEND
    396396};
     
    444444class WaitUntilStmt final : public WaitStmt {
    445445  public:
    446     // Non-ast node used during compilation to store data needed to generate predicates
    447     //    and set initial status values for clauses
    448     // Used to create a tree corresponding to the structure of the clauses in a WaitUntil
    449     struct ClauseNode {
    450         enum Op { AND, OR, LEFT_OR, LEAF, ELSE, TIMEOUT } op; // operation/type tag
    451         // LEFT_OR used with TIMEOUT/ELSE to indicate that we ignore right hand side after parsing
    452 
    453         ClauseNode * left;
    454         ClauseNode * right;
    455         WhenClause * leaf;  // only set if this node is a leaf (points into vector of clauses)
    456 
    457         bool ambiguousWhen; // used to paint nodes of predicate tree based on when() clauses
    458         bool whenState;     // used to track if when_cond is toggled on or off for generating init values
    459         bool childOfAnd;      // true on leaf nodes that are children of AND, false otherwise
    460 
    461         ClauseNode( Op op, ClauseNode * left, ClauseNode * right )
    462             : op(op), left(left), right(right), leaf(nullptr),
    463             ambiguousWhen(false), whenState(true), childOfAnd(false) {}
    464         ClauseNode( Op op, WhenClause * leaf )
    465             : op(op), left(nullptr), right(nullptr), leaf(leaf),
    466             ambiguousWhen(false), whenState(true), childOfAnd(false) {}
    467         ClauseNode( WhenClause * leaf ) : ClauseNode(LEAF, leaf) {}
    468        
    469         ~ClauseNode() {
    470             if ( left ) delete left;
    471             if ( right ) delete right;
    472         }
    473     };
     446        // Non-ast node used during compilation to store data needed to generate predicates
     447        //    and set initial status values for clauses
     448        // Used to create a tree corresponding to the structure of the clauses in a WaitUntil
     449        struct ClauseNode {
     450                enum Op { AND, OR, LEFT_OR, LEAF, ELSE, TIMEOUT } op; // operation/type tag
     451                // LEFT_OR used with TIMEOUT/ELSE to indicate that we ignore right hand side after parsing
     452
     453                ClauseNode * left;
     454                ClauseNode * right;
     455                WhenClause * leaf;  // only set if this node is a leaf (points into vector of clauses)
     456
     457                bool ambiguousWhen; // used to paint nodes of predicate tree based on when() clauses
     458                bool whenState;     // used to track if when_cond is toggled on or off for generating init values
     459                bool childOfAnd;      // true on leaf nodes that are children of AND, false otherwise
     460
     461                ClauseNode( Op op, ClauseNode * left, ClauseNode * right )
     462                        : op(op), left(left), right(right), leaf(nullptr),
     463                        ambiguousWhen(false), whenState(true), childOfAnd(false) {}
     464                ClauseNode( Op op, WhenClause * leaf )
     465                        : op(op), left(nullptr), right(nullptr), leaf(leaf),
     466                        ambiguousWhen(false), whenState(true), childOfAnd(false) {}
     467                ClauseNode( WhenClause * leaf ) : ClauseNode(LEAF, leaf) {}
     468
     469                ~ClauseNode() {
     470                        if ( left ) delete left;
     471                        if ( right ) delete right;
     472                }
     473        };
    474474
    475475        std::vector<ptr<WhenClause>> clauses;
    476     ClauseNode * predicateTree;
     476        ClauseNode * predicateTree;
    477477
    478478        WaitUntilStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )
    479479                : WaitStmt(loc, std::move(labels)) {}
    480480
    481     ~WaitUntilStmt() { delete predicateTree; }
     481        ~WaitUntilStmt() { delete predicateTree; }
    482482
    483483        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     
    522522        std::vector<ptr<Expr>> mutexObjs;
    523523
    524         MutexStmt( const CodeLocation & loc, const Stmt * stmt, 
     524        MutexStmt( const CodeLocation & loc, const Stmt * stmt,
    525525                           const std::vector<ptr<Expr>> && mutexes, const std::vector<Label> && labels = {} )
    526526                : Stmt(loc, std::move(labels)), stmt(stmt), mutexObjs(std::move(mutexes)) {}
     
    543543  private:
    544544        CorunStmt * clone() const override { return new CorunStmt{ *this }; }
     545        MUTATE_FRIEND
     546};
     547
     548// Corun Statement
     549class CoforStmt final : public Stmt {
     550  public:
     551        std::vector<ptr<Stmt>> inits;
     552        ptr<Expr> cond;
     553        ptr<Expr> inc;
     554        ptr<Stmt> body;
     555
     556        CoforStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond,
     557                         const Expr * inc, const Stmt * body, const std::vector<Label> && label = {} )
     558                : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), body(body) {}
     559
     560        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     561  private:
     562        CoforStmt * clone() const override { return new CoforStmt{ *this }; }
    545563        MUTATE_FRIEND
    546564};
  • src/AST/Type.hpp

    r0030b508 rfc12f05  
    3434
    3535namespace ast {
    36 
    37 template< typename T > class Pass;
    3836
    3937class Type : public Node {
  • src/AST/Visitor.hpp

    r0030b508 rfc12f05  
    6060    virtual const ast::Stmt *             visit( const ast::MutexStmt            * ) = 0;
    6161    virtual const ast::Stmt *             visit( const ast::CorunStmt            * ) = 0;
     62    virtual const ast::Stmt *             visit( const ast::CoforStmt            * ) = 0;
    6263    virtual const ast::Expr *             visit( const ast::ApplicationExpr      * ) = 0;
    6364    virtual const ast::Expr *             visit( const ast::UntypedExpr          * ) = 0;
  • src/AST/module.mk

    r0030b508 rfc12f05  
    2020        AST/Bitfield.hpp \
    2121        AST/Chain.hpp \
    22         AST/Convert.cpp \
    23         AST/Convert.hpp \
    2422        AST/Copy.cpp \
    2523        AST/Copy.hpp \
Note: See TracChangeset for help on using the changeset viewer.