Changeset a5a71d0 for src/SynTree


Ignore:
Timestamp:
Apr 6, 2016, 5:11:32 PM (10 years ago)
Author:
Rob Schluntz <rschlunt@…>
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, with_gc
Children:
eab39cd
Parents:
39786813 (diff), 3aba311 (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 'fix-memory-error' into ctor

Conflicts:

src/CodeGen/CodeGenerator.cc
src/Makefile.in
src/Parser/DeclarationNode.cc
src/Parser/ParseNode.h
src/Parser/TypeData.cc
src/Parser/parser.cc
src/Parser/parser.yy
src/ResolvExpr/Resolver.cc
src/SymTab/Validate.cc
src/SynTree/Declaration.h
src/SynTree/Mutator.cc
src/SynTree/Mutator.h
src/SynTree/SynTree.h
src/SynTree/Visitor.cc
src/SynTree/Visitor.h
src/libcfa/prelude.cf

Location:
src/SynTree
Files:
2 deleted
18 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/AggregateDecl.cc

    r39786813 ra5a71d0  
    1010// Created On       : Sun May 17 23:56:39 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun 13 08:12:49 2015
    13 // Update Count     : 6
     12// Last Modified On : Wed Mar  2 17:28:00 2016
     13// Update Count     : 7
    1414//
    1515
     
    6464std::string EnumDecl::typeString() const { return "enum"; }
    6565
    66 std::string ContextDecl::typeString() const { return "context"; }
     66std::string TraitDecl::typeString() const { return "context"; }
    6767
    6868// Local Variables: //
  • src/SynTree/CommaExpr.cc

    r39786813 ra5a71d0  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // CommaExpr.cc -- 
     7// CommaExpr.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 08:09:58 2015
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Apr 06 17:07:54 2016
    1313// Update Count     : 1
    1414//
     
    2020CommaExpr::CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname )
    2121                : Expression( _aname ), arg1( arg1 ), arg2( arg2 ) {
     22        // xxx - result of a comma expression is never an lvalue, so should set lvalue
     23        // to false on all result types
    2224        cloneAll( arg2->get_results(), get_results() );
    2325}
  • src/SynTree/CompoundStmt.cc

    r39786813 ra5a71d0  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc -- 
     7// XXX.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jun 23 11:37:49 2015
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Apr 06 14:35:37 2016
    1313// Update Count     : 3
    1414//
     
    1818#include <algorithm>
    1919#include <functional>
     20#include "Expression.h"
     21#include "Declaration.h"
    2022
    2123using std::string;
    2224using std::endl;
     25
     26class VarExprReplacer : public Visitor {
     27public:
     28  typedef std::map< DeclarationWithType *, DeclarationWithType * > DeclMap;
     29private:
     30  const DeclMap & declMap;
     31public:
     32  VarExprReplacer( const DeclMap & declMap ) : declMap( declMap ) {}
     33
     34  // replace variable with new node from decl map
     35  virtual void visit( VariableExpr * varExpr ) {
     36    if ( declMap.count( varExpr->get_var() ) ) {
     37      varExpr->set_var( declMap.at( varExpr->get_var() ) );
     38    }
     39  }
     40};
     41
    2342
    2443CompoundStmt::CompoundStmt( std::list<Label> labels ) : Statement( labels ) {
     
    2746CompoundStmt::CompoundStmt( const CompoundStmt &other ) : Statement( other ) {
    2847        cloneAll( other.kids, kids );
     48
     49  // when cloning a compound statement, we may end up cloning declarations which
     50  // are referred to by VariableExprs throughout the block. Cloning a VariableExpr
     51  // does a shallow copy, so the VariableExpr will end up pointing to the original
     52  // declaration. If the original declaration is deleted, e.g. because the original
     53  // CompoundStmt is deleted, then we have a dangling pointer. To avoid this case,
     54  // find all DeclarationWithType nodes (since a VariableExpr must point to a
     55  // DeclarationWithType) in the original CompoundStmt and map them to the cloned
     56  // node in the new CompoundStmt ('this'), then replace the Declarations referred to
     57  // by each VariableExpr according to the constructed map. Note that only the declarations
     58  // in the current level are collected into the map, because child CompoundStmts will
     59  // recursively execute this routine. There may be more efficient ways of doing
     60  // this.
     61  VarExprReplacer::DeclMap declMap;
     62  std::list< Statement * >::const_iterator origit = other.kids.begin();
     63  for ( Statement * s : kids ) {
     64    assert( origit != other.kids.end() );
     65    if ( DeclStmt * declStmt = dynamic_cast< DeclStmt * >( s ) ) {
     66      DeclStmt * origDeclStmt = dynamic_cast< DeclStmt * >( *origit );
     67      assert( origDeclStmt );
     68      if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * > ( declStmt->get_decl() ) ) {
     69        DeclarationWithType * origdwt = dynamic_cast< DeclarationWithType * > ( origDeclStmt->get_decl() );
     70        assert( origdwt );
     71        declMap[ origdwt ] = dwt;
     72      }
     73    }
     74  }
     75  if ( ! declMap.empty() ) {
     76    VarExprReplacer replacer( declMap );
     77    accept( replacer );
     78  }
    2979}
    3080
  • src/SynTree/Constant.cc

    r39786813 ra5a71d0  
    1616#include <iostream>
    1717#include <list>
     18#include <string>
    1819
    1920#include "Constant.h"
     
    2829
    2930Constant::~Constant() { delete type; }
     31
     32Constant Constant::from( int i ) {
     33        return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ) );
     34}
     35
     36Constant Constant::from( unsigned long i ) {
     37        return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ) );
     38}
     39
     40Constant Constant::from( double d ) {
     41        return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ) );
     42}
    3043
    3144Constant *Constant::clone() const { assert( false ); return 0; }
  • src/SynTree/Constant.h

    r39786813 ra5a71d0  
    3232        void set_value( std::string newValue ) { value = newValue; }
    3333
     34        /// generates an integer constant of the given int
     35        static Constant from( int i );
     36        /// generates an integer constant of the given unsigned long int
     37        static Constant from( unsigned long i );
     38        /// generates a floating point constant of the given double
     39        static Constant from( double d );
     40
    3441        virtual Constant *clone() const;
    3542        virtual void accept( Visitor &v ) { v.visit( this ); }
  • src/SynTree/Declaration.h

    r39786813 ra5a71d0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jan 13 16:11:49 2016
     12// Last Modified On : Mon Apr 04 17:14:00 2016
    1313// Update Count     : 36
    1414//
     
    246246};
    247247
    248 class ContextDecl : public AggregateDecl {
    249         typedef AggregateDecl Parent;
    250   public:
    251         ContextDecl( const std::string &name ) : Parent( name ) {}
    252         ContextDecl( const ContextDecl &other ) : Parent( other ) {}
    253 
    254         virtual ContextDecl *clone() const { return new ContextDecl( *this ); }
     248class TraitDecl : public AggregateDecl {
     249        typedef AggregateDecl Parent;
     250  public:
     251        TraitDecl( const std::string &name ) : Parent( name ) {}
     252        TraitDecl( const TraitDecl &other ) : Parent( other ) {}
     253
     254        virtual TraitDecl *clone() const { return new TraitDecl( *this ); }
    255255        virtual void accept( Visitor &v ) { v.visit( this ); }
    256256        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
  • src/SynTree/Initializer.cc

    r39786813 ra5a71d0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Mar 30 13:58:32 2016
     12// Last Modified On : Wed Apr 06 16:15:32 2016
    1313// Update Count     : 28
    1414//
     
    3535}
    3636
    37 SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( other.value ) {
     37SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) {
    3838        cloneAll(other.designators, designators );
    3939}
  • src/SynTree/Mutator.cc

    r39786813 ra5a71d0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jan 13 15:32:29 2016
     12// Last Modified On : Mon Apr 04 17:14:20 2016
    1313// Update Count     : 15
    1414//
     
    6363}
    6464
    65 Declaration *Mutator::mutate( ContextDecl *aggregateDecl ) {
     65Declaration *Mutator::mutate( TraitDecl *aggregateDecl ) {
    6666        handleAggregateDecl( aggregateDecl );
    6767        return aggregateDecl;
     
    387387}
    388388
    389 Type *Mutator::mutate( ContextInstType *aggregateUseType ) {
     389Type *Mutator::mutate( TraitInstType *aggregateUseType ) {
    390390        handleReferenceToType( aggregateUseType );
    391391        mutateAll( aggregateUseType->get_members(), *this );
  • src/SynTree/Mutator.h

    r39786813 ra5a71d0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jan 13 15:24:26 2016
     12// Last Modified On : Mon Apr 04 17:14:44 2016
    1313// Update Count     : 9
    1414//
     
    3131        virtual Declaration* mutate( UnionDecl *aggregateDecl );
    3232        virtual Declaration* mutate( EnumDecl *aggregateDecl );
    33         virtual Declaration* mutate( ContextDecl *aggregateDecl );
     33        virtual Declaration* mutate( TraitDecl *aggregateDecl );
    3434        virtual TypeDecl* mutate( TypeDecl *typeDecl );
    3535        virtual Declaration* mutate( TypedefDecl *typeDecl );
     
    8585        virtual Type* mutate( UnionInstType *aggregateUseType );
    8686        virtual Type* mutate( EnumInstType *aggregateUseType );
    87         virtual Type* mutate( ContextInstType *aggregateUseType );
     87        virtual Type* mutate( TraitInstType *aggregateUseType );
    8888        virtual Type* mutate( TypeInstType *aggregateUseType );
    8989        virtual Type* mutate( TupleType *tupleType );
  • src/SynTree/ReferenceToType.cc

    r39786813 ra5a71d0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jun  7 08:31:48 2015
    13 // Update Count     : 4
     12// Last Modified On : Wed Mar  2 17:28:51 2016
     13// Update Count     : 5
    1414//
    1515
     
    8383std::string EnumInstType::typeString() const { return "enum"; }
    8484
    85 std::string ContextInstType::typeString() const { return "context"; }
     85std::string TraitInstType::typeString() const { return "context"; }
    8686
    87 ContextInstType::ContextInstType( const ContextInstType &other ) : Parent( other ) {
     87TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ) {
    8888        cloneAll( other.members, members );
    8989}
    9090
    91 ContextInstType::~ContextInstType() {
     91TraitInstType::~TraitInstType() {
    9292        deleteAll( members );
    9393}
  • src/SynTree/SynTree.h

    r39786813 ra5a71d0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jan 13 15:28:41 2016
     12// Last Modified On : Mon Apr 04 17:16:09 2016
    1313// Update Count     : 4
    1414//
     
    3030class UnionDecl;
    3131class EnumDecl;
    32 class ContextDecl;
     32class TraitDecl;
    3333class NamedTypeDecl;
    3434class TypeDecl;
     
    9292class UnionInstType;
    9393class EnumInstType;
    94 class ContextInstType;
     94class TraitInstType;
    9595class TypeInstType;
    9696class TupleType;
  • src/SynTree/Type.h

    r39786813 ra5a71d0  
    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 : Fri Dec 18 14:46:18 2015
    13 // Update Count     : 18
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Mar  2 17:29:08 2016
     13// Update Count     : 21
    1414//
    1515
     
    296296};
    297297
    298 class ContextInstType : public ReferenceToType {
     298class TraitInstType : public ReferenceToType {
    299299        typedef ReferenceToType Parent;
    300300  public:
    301         ContextInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
    302         ContextInstType( const ContextInstType &other );
    303         ~ContextInstType();
     301        TraitInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
     302        TraitInstType( const TraitInstType &other );
     303        ~TraitInstType();
    304304
    305305        std::list< Declaration* >& get_members() { return members; }
    306306
    307         virtual ContextInstType *clone() const { return new ContextInstType( *this ); }
     307        virtual TraitInstType *clone() const { return new TraitInstType( *this ); }
    308308        virtual void accept( Visitor &v ) { v.visit( this ); }
    309309        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     
    402402/// Represents the GCC built-in varargs type
    403403class VarArgsType : public Type {
     404  public:
    404405        VarArgsType();
     406        VarArgsType( Type::Qualifiers tq );
    405407
    406408        virtual VarArgsType *clone() const { return new VarArgsType( *this ); }
  • src/SynTree/TypeSubstitution.cc

    r39786813 ra5a71d0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 11:10:04 2015
    13 // Update Count     : 2
     12// Last Modified On : Wed Mar  2 17:29:15 2016
     13// Update Count     : 3
    1414//
    1515
     
    190190}
    191191
    192 Type * TypeSubstitution::mutate( ContextInstType *aggregateUseType ) {
     192Type * TypeSubstitution::mutate( TraitInstType *aggregateUseType ) {
    193193        return handleType( aggregateUseType );
    194194}
  • src/SynTree/TypeSubstitution.h

    r39786813 ra5a71d0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 11:12:30 2015
    13 // Update Count     : 1
     12// Last Modified On : Wed Mar  2 17:33:19 2016
     13// Update Count     : 2
    1414//
    1515
     
    7272        virtual Type* mutate(UnionInstType *aggregateUseType);
    7373        virtual Type* mutate(EnumInstType *aggregateUseType);
    74         virtual Type* mutate(ContextInstType *aggregateUseType);
     74        virtual Type* mutate(TraitInstType *aggregateUseType);
    7575        virtual Type* mutate(TupleType *tupleType);
    7676        virtual Type* mutate(VarArgsType *varArgsType);
  • src/SynTree/VarArgsType.cc

    r39786813 ra5a71d0  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu Feb 25 16:34:00 2016
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu Feb 25 16:34:00 2016
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Mar  2 17:10:40 2016
     13// Update Count     : 2
    1414//
    1515
     
    1717
    1818VarArgsType::VarArgsType() : Type( Type::Qualifiers() ) {}
     19
     20VarArgsType::VarArgsType( Type::Qualifiers tq ) : Type( tq ) {}
    1921
    2022void VarArgsType::print( std::ostream &os, int indent ) const {
  • src/SynTree/Visitor.cc

    r39786813 ra5a71d0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jan 13 15:27:23 2016
     12// Last Modified On : Mon Apr 04 17:16:25 2016
    1313// Update Count     : 18
    1414//
     
    5656}
    5757
    58 void Visitor::visit( ContextDecl *aggregateDecl ) {
     58void Visitor::visit( TraitDecl *aggregateDecl ) {
    5959        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
    6060}
     
    326326}
    327327
    328 void Visitor::visit( ContextInstType *aggregateUseType ) {
     328void Visitor::visit( TraitInstType *aggregateUseType ) {
    329329        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
    330330        acceptAll( aggregateUseType->get_members(), *this );
  • src/SynTree/Visitor.h

    r39786813 ra5a71d0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Feb 09 13:20:48 2016
     12// Last Modified On : Mon Apr 04 17:16:36 2016
    1313// Update Count     : 6
    1414//
     
    3131        virtual void visit( UnionDecl *aggregateDecl );
    3232        virtual void visit( EnumDecl *aggregateDecl );
    33         virtual void visit( ContextDecl *aggregateDecl );
     33        virtual void visit( TraitDecl *aggregateDecl );
    3434        virtual void visit( TypeDecl *typeDecl );
    3535        virtual void visit( TypedefDecl *typeDecl );
     
    8585        virtual void visit( UnionInstType *aggregateUseType );
    8686        virtual void visit( EnumInstType *aggregateUseType );
    87         virtual void visit( ContextInstType *aggregateUseType );
     87        virtual void visit( TraitInstType *aggregateUseType );
    8888        virtual void visit( TypeInstType *aggregateUseType );
    8989        virtual void visit( TupleType *tupleType );
  • src/SynTree/module.mk

    r39786813 ra5a71d0  
    4646       SynTree/Visitor.cc \
    4747       SynTree/Mutator.cc \
    48        SynTree/CodeGenVisitor.cc \
    4948       SynTree/TypeSubstitution.cc
    5049
Note: See TracChangeset for help on using the changeset viewer.