Changeset b0d9ff7 for src/SynTree


Ignore:
Timestamp:
Sep 1, 2022, 1:27:52 PM (20 months ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
12df6fe
Parents:
def751f
Message:

Fix up the QualifiedNameExpr?. It should now work on both old AST and new AST. There are some known bugs to fix so make all-tests will fail.

Location:
src/SynTree
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Declaration.h

    rdef751f rb0d9ff7  
    145145        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    146146
    147         // TODO: Move to the right place
    148147        void checkAssignedValue() const;
    149148};
     
    338337        typedef AggregateDecl Parent;
    339338  public:
     339        bool isTyped;
     340        Type * base;
     341
    340342        EnumDecl( const std::string & name,
    341343         const std::list< Attribute * > & attributes = std::list< class Attribute * >(),
    342           LinkageSpec::Spec linkage = LinkageSpec::Cforall,
    343           Type * baseType = nullptr ) : Parent( name, attributes, linkage ) , base( baseType ){}
    344         EnumDecl( const EnumDecl & other ) : Parent( other ), base( other.base ) {}
    345 
     344          bool isTyped = false, LinkageSpec::Spec linkage = LinkageSpec::Cforall,
     345          Type * baseType = nullptr )
     346          : Parent( name, attributes, linkage ),isTyped(isTyped), base( baseType ) {}
     347        EnumDecl( const EnumDecl & other )
     348          : Parent( other ), isTyped( other.isTyped), base( other.base ) {}
    346349        bool valueOf( Declaration * enumerator, long long int & value );
    347 
    348350        virtual EnumDecl * clone() const override { return new EnumDecl( *this ); }
    349351        virtual void accept( Visitor & v ) override { v.visit( this ); }
    350352        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    351353        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    352         Type * base;
    353         std::unordered_map< std::string, long long int > enumValues;
     354
     355        std::unordered_map< std::string, long long int > enumValues; // This attribute is unused
    354356        virtual void print( std::ostream & os, Indenter indent = {} ) const override final;
    355357  private:
  • src/SynTree/Expression.h

    rdef751f rb0d9ff7  
    166166class QualifiedNameExpr : public Expression {
    167167  public:
    168         Type * type; // Convert to [parent] QualifiedNameExpr
    169         std::string name; // Convert from NameExpr
    170 
    171         QualifiedNameExpr( Type * type, std::string name):
    172                 Expression(), type(type), name(name) {
    173                 std::cout << "Making QualifiedNameExpr" << std::endl;
    174                 print( std::cout );
    175         }
    176         QualifiedNameExpr( const QualifiedNameExpr & other): Expression(other), type(other.type), name(other.name) {
    177 
    178         }
     168        Declaration * type_decl;
     169        std::string name;
     170        DeclarationWithType * var;
     171
     172        QualifiedNameExpr( Declaration * decl, std::string name): Expression(), type_decl(decl), name(name) {}
     173        QualifiedNameExpr( const QualifiedNameExpr & other): Expression(other), type_decl(other.type_decl), name(other.name), var(other.var) {}
     174        DeclarationWithType * get_var() const { return var; }
     175        void set_var( DeclarationWithType * newValue ) { var = newValue; }
     176
    179177        virtual ~QualifiedNameExpr() {
    180                 delete type;
     178                delete var;
     179                delete type_decl;
    181180        }
    182181
     
    184183                return new QualifiedNameExpr( * this );
    185184        }
    186         virtual void accept( Visitor & v ) override { (void)v; }
    187         virtual void accept( Visitor & v ) const override { (void)v; }
    188         virtual Expression * acceptMutator( Mutator & m ) override { (void) m;return nullptr; }
     185        virtual void accept( Visitor & v ) override { v.visit(this); }
     186        virtual void accept( Visitor & v ) const override { v.visit(this); }
     187        virtual Expression * acceptMutator( Mutator & m ) override {
     188                return m.mutate( this );
     189        }
     190       
    189191        virtual void print( std::ostream & os, Indenter indent = {} ) const override {
    190                 type->print( os, indent );
    191                 std::cout << name << std::endl;
     192                type_decl->print( os, indent );
     193                os << name << std::endl;
    192194        }
    193195};
  • src/SynTree/Mutator.h

    rdef751f rb0d9ff7  
    9898        virtual Expression * mutate( DefaultArgExpr * argExpr ) = 0;
    9999        virtual Expression * mutate( GenericExpr * genExpr ) = 0;
     100        virtual Expression * mutate( QualifiedNameExpr * qualifiedNameExpr ) = 0;
    100101
    101102        virtual Type * mutate( VoidType * basicType ) = 0;
  • src/SynTree/Type.h

    rdef751f rb0d9ff7  
    342342        Type * parent;
    343343        Type * child;
    344 
    345344        QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child );
    346345        QualifiedType( const QualifiedType & tq );
  • src/SynTree/Visitor.h

    rdef751f rb0d9ff7  
    101101        virtual void visit( NameExpr * node ) { visit( const_cast<const NameExpr *>(node) ); }
    102102        virtual void visit( const NameExpr * nameExpr ) = 0;
     103        virtual void visit( QualifiedNameExpr * node ) { visit( const_cast<const QualifiedNameExpr*>(node) );}
     104        virtual void visit( const QualifiedNameExpr* qualifiednameExpr ) = 0;
    103105        virtual void visit( CastExpr * node ) { visit( const_cast<const CastExpr *>(node) ); }
    104106        virtual void visit( const CastExpr * castExpr ) = 0;
Note: See TracChangeset for help on using the changeset viewer.