Changeset cf32116 for src/AST/Expr.cpp


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.