Changeset a1da039


Ignore:
Timestamp:
Oct 24, 2023, 3:00:53 PM (14 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
dd7c2ce0
Parents:
d8a0e51
Message:

Make all new declarations have a properly defined LinkageSpec?. Also some general clean-up.

Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    rd8a0e51 ra1da039  
    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/Stmt.hpp

    rd8a0e51 ra1da039  
    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)) {}
Note: See TracChangeset for help on using the changeset viewer.