Changeset cf32116 for src/AST


Ignore:
Timestamp:
Oct 4, 2019, 3:07:07 PM (5 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
3f3bfe5a
Parents:
90ce35aa
Message:

Implemented expression based lvalue resolution on new ast.

Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/AST/Expr.cpp

    r90ce35aa rcf32116  
    1010// Created On       : Wed May 15 17:00:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Created On       : Thr Jun 13 13:38:00 2019
    13 // Update Count     : 2
     12// Created On       : Thr Jun 26 12:12:00 2019
     13// Update Count     : 3
    1414//
    1515
     
    2323#include "Eval.hpp"                // for call
    2424#include "GenericSubstitution.hpp"
     25#include "LinkageSpec.hpp"
    2526#include "Stmt.hpp"
    2627#include "Type.hpp"
     
    2930#include "Common/SemanticError.h"
    3031#include "GenPoly/Lvalue.h"        // for referencesPermissable
    31 #include "InitTweak/InitTweak.h"   // for getPointerBase
     32#include "InitTweak/InitTweak.h"   // for getFunction, getPointerBase
    3233#include "ResolvExpr/typeops.h"    // for extractResultType
    3334#include "Tuples/Tuples.h"         // for makeTupleType
    3435
    3536namespace ast {
     37
     38namespace {
     39        std::set<std::string> const lvalueFunctionNames = {"*?", "?[?]"};
     40}
     41
     42// --- Expr
     43bool Expr::get_lvalue() const {
     44        return false;
     45}
    3646
    3747// --- ApplicationExpr
     
    4656        result = ResolvExpr::extractResultType( fn );
    4757        assert( result );
     58}
     59
     60bool ApplicationExpr::get_lvalue() const {
     61        if ( const DeclWithType * func = InitTweak::getFunction( this ) ) {
     62                return func->linkage == Linkage::Intrinsic && lvalueFunctionNames.count( func->name );
     63        }
     64        return false;
    4865}
    4966
     
    7188}
    7289
     90bool UntypedExpr::get_lvalue() const {
     91        std::string fname = InitTweak::getFunctionName( this );
     92        return lvalueFunctionNames.count( fname );
     93}
     94
    7395UntypedExpr * UntypedExpr::createAssign( const CodeLocation & loc, Expr * lhs, Expr * rhs ) {
    7496        assert( lhs && rhs );
     
    106128AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) : Expr( loc ), arg( a ) {
    107129        if ( arg->result ) {
    108                 if ( arg->result->is_lvalue() ) {
     130                if ( arg->get_lvalue() ) {
    109131                        // lvalue, retains all levels of reference, and gains a pointer inside the references
    110132                        Type * res = addrType( arg->result );
     
    137159: Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ) {}
    138160
     161bool CastExpr::get_lvalue() const {
     162        // This is actually wrong by C, but it works with our current set-up.
     163        return arg->get_lvalue();
     164}
     165
    139166// --- KeywordCastExpr
    140167
     
    150177}
    151178
     179// --- UntypedMemberExpr
     180
     181bool UntypedMemberExpr::get_lvalue() const {
     182        return aggregate->get_lvalue();
     183}
     184
    152185// --- MemberExpr
    153186
     
    210243}
    211244
     245bool MemberExpr::get_lvalue() const {
     246        // This is actually wrong by C, but it works with our current set-up.
     247        return true;
     248}
     249
    212250// --- VariableExpr
    213251
     
    222260        r->qualifiers |= CV::Lvalue;
    223261        result = r;
     262}
     263
     264bool VariableExpr::get_lvalue() const {
     265        // It isn't always an lvalue, but it is never an rvalue.
     266        return true;
    224267}
    225268
     
    308351: Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {}
    309352
     353// --- CommaExpr
     354bool CommaExpr::get_lvalue() const {
     355        // This is wrong by C, but the current implementation uses it.
     356        // (ex: Specialize, Lvalue and Box)
     357        return arg2->get_lvalue();
     358}
     359
    310360// --- ConstructorExpr
    311361
     
    329379}
    330380
     381bool CompoundLiteralExpr::get_lvalue() const {
     382        return true;
     383}
     384
    331385// --- TupleExpr
    332386
     
    344398        result = type->types[ index ];
    345399        add_qualifiers( result, CV::Lvalue );
     400}
     401
     402bool TupleIndexExpr::get_lvalue() const {
     403        return tuple->get_lvalue();
    346404}
    347405
  • TabularUnified src/AST/Expr.hpp

    r90ce35aa rcf32116  
    99// Author           : Aaron B. Moss
    1010// Created On       : Fri May 10 10:30:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Created On       : Fri May 10 10:30:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Andrew Beach
     12// Created On       : Thr Sep 26 12:51:00 2019
     13// Update Count     : 2
    1414//
    1515
     
    187187
    188188        Expr * set_extension( bool ex ) { extension = ex; return this; }
     189        virtual bool get_lvalue() const;
    189190
    190191        virtual const Expr * accept( Visitor & v ) const override = 0;
     
    203204        ApplicationExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as = {} );
    204205
     206        bool get_lvalue() const final;
     207
    205208        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    206209private:
     
    217220        UntypedExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as = {} )
    218221        : Expr( loc ), func( f ), args( std::move(as) ) {}
     222
     223        bool get_lvalue() const final;
    219224
    220225        /// Creates a new dereference expression
     
    293298        CastExpr( const Expr * a ) : CastExpr( a->location, a, GeneratedCast ) {}
    294299
     300        bool get_lvalue() const final;
     301
    295302        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    296303private:
     
    340347        : Expr( loc ), member( mem ), aggregate( agg ) { assert( aggregate ); }
    341348
     349        bool get_lvalue() const final;
     350
    342351        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    343352private:
     
    353362
    354363        MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg );
     364
     365        bool get_lvalue() const final;
    355366
    356367        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     
    374385        VariableExpr( const CodeLocation & loc );
    375386        VariableExpr( const CodeLocation & loc, const DeclWithType * v );
     387
     388        bool get_lvalue() const final;
    376389
    377390        /// generates a function pointer for a given function
     
    545558        }
    546559
     560        bool get_lvalue() const final;
     561
    547562        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    548563private:
     
    616631        CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i );
    617632
     633        bool get_lvalue() const final;
     634
    618635        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    619636private:
     
    671688
    672689        TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i );
     690
     691        bool get_lvalue() const final;
    673692
    674693        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
Note: See TracChangeset for help on using the changeset viewer.