Changeset 7edd5c1


Ignore:
Timestamp:
May 9, 2022, 11:38:08 AM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
00675a1
Parents:
bd1d279
Message:

Assorted fixes to the AST, found while I was trying to add more invarant checks.

Location:
src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rbd1d279 r7edd5c1  
    9393        };
    9494
    95     template<typename T>
    96     Getter<T> get() {
    97         return Getter<T>{ *this };
    98     }
     95        template<typename T>
     96        Getter<T> get() {
     97                return Getter<T>{ *this };
     98        }
    9999
    100100        Label makeLabel(Statement * labelled, const ast::Label& label) {
     
    16511651                        // GET_ACCEPT_1(type, FunctionType),
    16521652                        std::move(forall),
     1653                        std::move(assertions),
    16531654                        std::move(paramVars),
    16541655                        std::move(returnVars),
     
    16641665                cache.emplace( old, decl );
    16651666
    1666                 decl->assertions = std::move(assertions);
    16671667                decl->withExprs = GET_ACCEPT_V(withExprs, Expr);
    16681668                decl->stmts = GET_ACCEPT_1(statements, CompoundStmt);
  • src/AST/Copy.cpp

    rbd1d279 r7edd5c1  
    1010// Created On       : Thr Nov 11  9:16:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Nov 11  9:28:00 2021
    13 // Update Count     : 0
     12// Last Modified On : Tue May  3 16:28:00 2022
     13// Update Count     : 1
    1414//
    1515
     
    7777        }
    7878
     79        void postvisit( const UniqueExpr * node ) {
     80                readonlyInsert( &node->object );
     81        }
     82
    7983        void postvisit( const MemberExpr * node ) {
    8084                readonlyInsert( &node->member );
  • src/AST/Decl.cpp

    rbd1d279 r7edd5c1  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 12 16:54:55 2021
    13 // Update Count     : 23
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu May  5 12:10:00 2022
     13// Update Count     : 24
    1414//
    1515
     
    5353// --- FunctionDecl
    5454
    55 FunctionDecl::FunctionDecl( const CodeLocation & loc, const std::string & name, 
     55FunctionDecl::FunctionDecl( const CodeLocation & loc, const std::string & name,
    5656        std::vector<ptr<TypeDecl>>&& forall,
    5757        std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
     
    7474        }
    7575        this->type = ftype;
     76}
     77
     78FunctionDecl::FunctionDecl( const CodeLocation & location, const std::string & name,
     79        std::vector<ptr<TypeDecl>>&& forall, std::vector<ptr<DeclWithType>>&& assertions,
     80        std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
     81        CompoundStmt * stmts, Storage::Classes storage, Linkage::Spec linkage,
     82        std::vector<ptr<Attribute>>&& attrs, Function::Specs fs, bool isVarArgs)
     83: DeclWithType( location, name, storage, linkage, std::move(attrs), fs ),
     84                params( std::move(params) ), returns( std::move(returns) ),
     85                type_params( std::move( forall) ), assertions( std::move( assertions ) ),
     86                type( nullptr ), stmts( stmts ) {
     87        FunctionType * type = new FunctionType( (isVarArgs) ? VariableArgs : FixedArgs );
     88        for ( auto & param : this->params ) {
     89                type->params.emplace_back( param->get_type() );
     90        }
     91        for ( auto & ret : this->returns ) {
     92                type->returns.emplace_back( ret->get_type() );
     93        }
     94        for ( auto & param : this->type_params ) {
     95                type->forall.emplace_back( new TypeInstType( param ) );
     96        }
     97        for ( auto & assertion : this->assertions ) {
     98                type->assertions.emplace_back(
     99                        new VariableExpr( assertion->location, assertion ) );
     100        }
     101        this->type = type;
    76102}
    77103
  • src/AST/Decl.hpp

    rbd1d279 r7edd5c1  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 12 18:25:05 2021
    13 // Update Count     : 32
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu May  5 12:09:00 2022
     13// Update Count     : 33
    1414//
    1515
     
    135135        std::vector< ptr<Expr> > withExprs;
    136136
     137        // The difference between the two constructors is in how they handle
     138        // assertions. The first constructor uses the assertions from the type
     139        // parameters, in the style of the old ast, and puts them on the type.
     140        // The second takes an explicite list of assertions and builds a list of
     141        // references to them on the type.
     142
    137143        FunctionDecl( const CodeLocation & loc, const std::string & name, std::vector<ptr<TypeDecl>>&& forall,
    138144                std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
    139145                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
    140146                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {}, bool isVarArgs = false);
    141         // : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), params(std::move(params)), returns(std::move(returns)),
    142         //  stmts( stmts ) {}
     147
     148        FunctionDecl( const CodeLocation & location, const std::string & name,
     149                std::vector<ptr<TypeDecl>>&& forall, std::vector<ptr<DeclWithType>>&& assertions,
     150                std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
     151                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
     152                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {}, bool isVarArgs = false);
    143153
    144154        const Type * get_type() const override;
  • src/AST/Expr.hpp

    rbd1d279 r7edd5c1  
    784784public:
    785785        ptr<Expr> expr;
    786         ptr<ObjectDecl> object;
     786        readonly<ObjectDecl> object;
    787787        ptr<VariableExpr> var;
    788788        unsigned long long id;
  • src/AST/Node.hpp

    rbd1d279 r7edd5c1  
    1010// Created On       : Wed May 8 10:27:04 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Mar 25 10:33:00 2022
    13 // Update Count     : 7
     12// Last Modified On : Mon May  9 10:20:00 2022
     13// Update Count     : 8
    1414//
    1515
     
    4949
    5050        bool unique() const { return strong_count == 1; }
    51         bool isManaged() const {return strong_count > 0; }
     51        bool isManaged() const { return strong_count > 0; }
     52        bool isReferenced() const { return weak_count > 0; }
    5253
    5354private:
  • src/AST/Stmt.cpp

    rbd1d279 r7edd5c1  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May  8 13:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  2 19:01:20 2022
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue May  3 15:18:20 2022
     13// Update Count     : 4
    1414//
    1515
    1616#include "Stmt.hpp"
    1717
    18 
     18#include "Copy.hpp"
    1919#include "DeclReplacer.hpp"
    2020#include "Type.hpp"
     
    2323
    2424// --- CompoundStmt
    25 CompoundStmt::CompoundStmt( const CompoundStmt& other ) : Stmt(other), kids(other.kids) {
     25CompoundStmt::CompoundStmt( const CompoundStmt& other ) : Stmt(other), kids() {
     26        // Statements can have weak references to them, if that happens inserting
     27        // the original node into the new list will put the original node in a
     28        // bad state, where it cannot be mutated. To avoid this, just perform an
     29        // additional shallow copy on the statement.
     30        for ( const Stmt * kid : other.kids ) {
     31                if ( kid->isReferenced() ) {
     32                        kids.emplace_back( ast::shallowCopy( kid ) );
     33                } else {
     34                        kids.emplace_back( kid );
     35                }
     36        }
     37
    2638        // when cloning a compound statement, we may end up cloning declarations which
    2739        // are referred to by VariableExprs throughout the block. Cloning a VariableExpr
  • src/Validate/Autogen.cpp

    rbd1d279 r7edd5c1  
    350350                name,
    351351                std::move( type_params ),
     352                std::move( assertions ),
    352353                std::move( params ),
    353354                std::move( returns ),
     
    360361                // Auto-generated routines are inline to avoid conflicts.
    361362                ast::Function::Specs( ast::Function::Inline ) );
    362         decl->assertions = std::move( assertions );
    363363        decl->fixUniqueId();
    364364        return decl;
Note: See TracChangeset for help on using the changeset viewer.