Changeset 81da3da4 for src/AST


Ignore:
Timestamp:
Dec 11, 2023, 4:18:13 AM (23 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
21ce2c7, 2554f24
Parents:
5ddb8bf (diff), 1c85ffc (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:
5 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Chain.hpp

    r5ddb8bf r81da3da4  
    3333        template<typename actual_node_t, typename child_t>
    3434        auto operator()( child_t actual_node_t::*child ) {
    35                 auto n = mutate(base.get());
     35                node_t * n = base.get_and_mutate();
    3636                actual_node_t * node = strict_dynamic_cast<actual_node_t *>(n);
    37                 base = node;
    3837                return _chain_mutator< typename std::remove_reference< decltype(node->*child) >::type >{node->*child};
    3938        }
    4039
    4140        node_t * operator->() {
    42                 auto n = mutate(base.get());
    43                 base = n;
    44                 return n;
     41                return base.get_and_mutate();
    4542        }
    4643};
  • src/AST/Decl.cpp

    r5ddb8bf r81da3da4  
    2121
    2222#include "Common/Eval.h"       // for eval
     23#include "Common/SemanticError.h"
    2324
    2425#include "Fwd.hpp"             // for UniqueId
     
    4142
    4243FunctionDecl::FunctionDecl( const CodeLocation & loc, const std::string & name,
    43         std::vector<ptr<TypeDecl>>&& forall,
    4444        std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
    4545        CompoundStmt * stmts, Storage::Classes storage, Linkage::Spec linkage,
    4646        std::vector<ptr<Attribute>>&& attrs, Function::Specs fs, ArgumentFlag isVarArgs )
    47 : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ),
    48         type_params(std::move(forall)), assertions(),
    49         params(std::move(params)), returns(std::move(returns)), stmts( stmts ) {
    50         FunctionType * ftype = new FunctionType( isVarArgs );
    51         for (auto & param : this->params) {
    52                 ftype->params.emplace_back(param->get_type());
    53         }
    54         for (auto & ret : this->returns) {
    55                 ftype->returns.emplace_back(ret->get_type());
    56         }
    57         for (auto & tp : this->type_params) {
    58                 ftype->forall.emplace_back(new TypeInstType(tp));
    59                 for (auto & ap: tp->assertions) {
    60                         ftype->assertions.emplace_back(new VariableExpr(loc, ap));
    61                 }
    62         }
    63         this->type = ftype;
     47: FunctionDecl( loc, name, {}, {}, std::move(params), std::move(returns),
     48                stmts, storage, linkage, std::move(attrs), fs, isVarArgs ) {
    6449}
    6550
  • src/AST/Decl.hpp

    r5ddb8bf r81da3da4  
    3030#include "Visitor.hpp"
    3131#include "Common/utility.h"
    32 #include "Common/SemanticError.h"                                               // error_str
    3332
    3433// Must be included in *all* AST classes; should be #undef'd at the end of the file
     
    135134        std::vector< ptr<Expr> > withExprs;
    136135
    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 
    143         FunctionDecl( const CodeLocation & loc, const std::string & name, std::vector<ptr<TypeDecl>>&& forall,
     136        /// Monomorphic Function Constructor:
     137        FunctionDecl( const CodeLocation & locaction, const std::string & name,
    144138                std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
    145139                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::Cforall,
    146140                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {}, ArgumentFlag isVarArgs = FixedArgs );
    147141
     142        /// Polymorphic Function Constructor:
    148143        FunctionDecl( const CodeLocation & location, const std::string & name,
    149144                std::vector<ptr<TypeDecl>>&& forall, std::vector<ptr<DeclWithType>>&& assertions,
  • src/AST/Expr.cpp

    r5ddb8bf r81da3da4  
    222222}
    223223
    224 MemberExpr::MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg,
    225     MemberExpr::NoOpConstruction overloadSelector )
    226 : Expr( loc ), member( mem ), aggregate( agg ) {
    227         assert( member );
    228         assert( aggregate );
    229         assert( aggregate->result );
    230         (void) overloadSelector;
    231 }
    232 
    233224bool MemberExpr::get_lvalue() const {
    234225        // This is actually wrong by C, but it works with our current set-up.
     
    388379        stmts.emplace_back( new ExprStmt{ loc, tupleExpr } );
    389380        stmtExpr = new StmtExpr{ loc, new CompoundStmt{ loc, std::move(stmts) } };
    390 }
    391 
    392 TupleAssignExpr::TupleAssignExpr(
    393         const CodeLocation & loc, const Type * result, const StmtExpr * s )
    394 : Expr( loc, result ), stmtExpr() {
    395         stmtExpr = s;
    396381}
    397382
  • src/AST/Expr.hpp

    r5ddb8bf r81da3da4  
    3535        template<typename node_t> friend node_t * shallowCopy(const node_t * node);
    3636
    37 
    38 class ConverterOldToNew;
    39 class ConverterNewToOld;
    40 
    4137namespace ast {
    4238
     
    439435        MemberExpr * clone() const override { return new MemberExpr{ *this }; }
    440436        MUTATE_FRIEND
    441 
    442         // Custructor overload meant only for AST conversion
    443         enum NoOpConstruction { NoOpConstructionChosen };
    444         MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg,
    445             NoOpConstruction overloadSelector );
    446         friend class ::ConverterOldToNew;
    447         friend class ::ConverterNewToOld;
    448437};
    449438
     
    458447        ConstantExpr(
    459448                const CodeLocation & loc, const Type * ty, const std::string & r,
    460                         std::optional<unsigned long long> i )
    461         : Expr( loc, ty ), rep( r ), ival( i ), underlyer(ty) {}
     449                        const std::optional<unsigned long long> & i )
     450        : Expr( loc, ty ), rep( r ), ival( i ) {}
    462451
    463452        /// Gets the integer value of this constant, if one is appropriate to its type.
     
    483472
    484473        std::optional<unsigned long long> ival;
    485 
    486         // Intended only for legacy support of roundtripping the old AST.
    487         // Captures the very-locally inferred type, before the resolver modifies the type of this ConstantExpression.
    488         // In the old AST it's constExpr->constant.type
    489         ptr<Type> underlyer;
    490         friend class ::ConverterOldToNew;
    491         friend class ::ConverterNewToOld;
    492474};
    493475
     
    779761        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    780762
    781         friend class ::ConverterOldToNew;
    782 
    783763private:
    784764        TupleAssignExpr * clone() const override { return new TupleAssignExpr{ *this }; }
    785     TupleAssignExpr( const CodeLocation & loc, const Type * result, const StmtExpr * s );
    786 
    787765        MUTATE_FRIEND
    788766};
Note: See TracChangeset for help on using the changeset viewer.