Changeset 630a82a for src/SynTree


Ignore:
Timestamp:
Apr 8, 2016, 5:22:29 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
3da470c
Parents:
3d9b5da
Message:

C99 compound literals now work, comment rational code, clean up hoisting AddVisit?

Location:
src/SynTree
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    r3d9b5da r630a82a  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Dec 09 14:10:29 2015
    13 // Update Count     : 34
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Apr  8 17:16:23 2016
     13// Update Count     : 40
    1414//
    1515
     
    2222
    2323#include "Type.h"
     24#include "Initializer.h"
    2425#include "Expression.h"
    2526#include "Declaration.h"
     
    443444
    444445
     446CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
     447        add_result( type->clone() );
     448}
     449
     450CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}
     451
     452CompoundLiteralExpr::~CompoundLiteralExpr() {
     453        delete initializer;
     454        delete type;
     455}
     456
     457void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
     458        os << "Compound Literal Expression: " << std::endl;
     459        if ( type ) type->print( os, indent + 2 );
     460        if ( initializer ) initializer->print( os, indent + 2 );
     461}
     462
    445463
    446464std::ostream & operator<<( std::ostream & out, Expression * expr ) {
  • src/SynTree/Expression.h

    r3d9b5da r630a82a  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Dec 09 14:10:21 2015
    13 // Update Count     : 19
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Apr  8 17:18:06 2016
     13// Update Count     : 21
    1414//
    1515
     
    557557};
    558558
     559/// CompoundLiteralExpr represents a C99 'compound literal'
     560class CompoundLiteralExpr : public Expression {
     561  public:
     562        CompoundLiteralExpr( Type * type, Initializer * initializer );
     563        CompoundLiteralExpr( const CompoundLiteralExpr &other );
     564        ~CompoundLiteralExpr();
     565
     566        Type * get_type() const { return type; }
     567        void set_type( Type * t ) { type = t; }
     568
     569        Initializer * get_initializer() const { return initializer; }
     570        void set_initializer( Initializer * i ) { initializer = i; }
     571
     572        virtual CompoundLiteralExpr *clone() const { return new CompoundLiteralExpr( *this ); }
     573        virtual void accept( Visitor &v ) { v.visit( this ); }
     574        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     575        virtual void print( std::ostream &os, int indent = 0 ) const;
     576  private:
     577        Type * type;
     578        Initializer * initializer;
     579};
     580
    559581std::ostream & operator<<( std::ostream & out, Expression * expr );
    560582
  • src/SynTree/Mutator.cc

    r3d9b5da r630a82a  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:28:20 2016
    13 // Update Count     : 12
     12// Last Modified On : Fri Apr  1 18:05:16 2016
     13// Update Count     : 16
    1414//
    1515
     
    336336}
    337337
     338Expression *Mutator::mutate( CompoundLiteralExpr *compLitExpr ) {
     339        mutateAll( compLitExpr->get_results(), *this );
     340        compLitExpr->set_type( maybeMutate( compLitExpr->get_type(), *this ) );
     341        compLitExpr->set_initializer( maybeMutate( compLitExpr->get_initializer(), *this ) );
     342        return compLitExpr;
     343}
     344
    338345Type *Mutator::mutate( VoidType *voidType ) {
    339346        mutateAll( voidType->get_forall(), *this );
  • src/SynTree/Mutator.h

    r3d9b5da r630a82a  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:33:11 2016
    13 // Update Count     : 9
     12// Last Modified On : Fri Apr  1 17:26:56 2016
     13// Update Count     : 10
    1414//
    1515#include <cassert>
     
    7676        virtual Expression* mutate( AsmExpr *asmExpr );
    7777        virtual Expression* mutate( UntypedValofExpr *valofExpr );
     78        virtual Expression* mutate( CompoundLiteralExpr *compLitExpr );
    7879
    7980        virtual Type* mutate( VoidType *basicType );
  • src/SynTree/SynTree.h

    r3d9b5da r630a82a  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:29:00 2016
    13 // Update Count     : 4
     12// Last Modified On : Fri Apr  1 16:47:44 2016
     13// Update Count     : 5
    1414//
    1515
     
    8181class AsmExpr;
    8282class UntypedValofExpr;
     83class CompoundLiteralExpr;
    8384
    8485class Type;
  • src/SynTree/Visitor.cc

    r3d9b5da r630a82a  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:29:23 2016
    13 // Update Count     : 16
     12// Last Modified On : Fri Apr  1 18:05:13 2016
     13// Update Count     : 18
    1414//
    1515
     
    284284}
    285285
     286void Visitor::visit( CompoundLiteralExpr *compLitExpr ) {
     287        acceptAll( compLitExpr->get_results(), *this );
     288        maybeAccept( compLitExpr->get_type(), *this );
     289        maybeAccept( compLitExpr->get_initializer(), *this );
     290}
     291
    286292void Visitor::visit( VoidType *voidType ) {
    287293        acceptAll( voidType->get_forall(), *this );
  • src/SynTree/Visitor.h

    r3d9b5da r630a82a  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:33:35 2016
    13 // Update Count     : 6
     12// Last Modified On : Fri Apr  1 17:26:55 2016
     13// Update Count     : 7
    1414//
    1515
     
    7676        virtual void visit( AsmExpr *asmExpr );
    7777        virtual void visit( UntypedValofExpr *valofExpr );
     78        virtual void visit( CompoundLiteralExpr *compLitExpr );
    7879
    7980        virtual void visit( VoidType *basicType );
Note: See TracChangeset for help on using the changeset viewer.