Changeset 32cab5b for src/SynTree


Ignore:
Timestamp:
Apr 17, 2018, 12:01:09 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
3265399
Parents:
b2fe1c9 (diff), 81bb114 (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 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/SynTree
Files:
1 added
1 deleted
12 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/SynTree/CompoundStmt.cc

    rb2fe1c9 r32cab5b  
    2323#include "Statement.h"                // for CompoundStmt, Statement, DeclStmt
    2424#include "SynTree/Label.h"            // for Label
    25 #include "SynTree/VarExprReplacer.h"  // for VarExprReplacer, VarExprReplace...
     25#include "SynTree/DeclReplacer.h"     // for DeclReplacer
    2626
    2727using std::string;
     
    4949        // recursively execute this routine. There may be more efficient ways of doing
    5050        // this.
    51         VarExprReplacer::DeclMap declMap;
     51        DeclReplacer::DeclMap declMap;
    5252        std::list< Statement * >::const_iterator origit = other.kids.begin();
    5353        for ( Statement * s : kids ) {
     
    6464        }
    6565        if ( ! declMap.empty() ) {
    66                 VarExprReplacer::replace( this, declMap );
     66                DeclReplacer::replace( this, declMap );
    6767        }
    6868}
  • src/SynTree/DeclReplacer.h

    rb2fe1c9 r32cab5b  
    2323class VariableExpr;
    2424
    25 namespace VarExprReplacer {
     25namespace DeclReplacer {
    2626        typedef std::map< DeclarationWithType *, DeclarationWithType * > DeclMap;
     27        typedef std::map< TypeDecl *, TypeDecl * > TypeMap;
    2728
    2829        void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false );
     30        void replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false );
     31        void replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
    2932}
    3033
  • src/SynTree/Declaration.cc

    rb2fe1c9 r32cab5b  
    8181
    8282
     83StaticAssertDecl::StaticAssertDecl( Expression * condition, ConstantExpr * message ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), condition( condition ), message( message )  {
     84}
     85
     86StaticAssertDecl::StaticAssertDecl( const StaticAssertDecl & other ) : Declaration( other ), condition( maybeClone( other.condition ) ), message( maybeClone( other.message ) )  {
     87}
     88
     89StaticAssertDecl::~StaticAssertDecl() {
     90        delete condition;
     91        delete message;
     92}
     93
     94void StaticAssertDecl::print( std::ostream &os, Indenter indent ) const {
     95        os << "Static Assert with condition: ";
     96        condition->print( os, indent+1 );
     97        os << std::endl << indent << "and message: ";
     98        message->print( os, indent+1 );
     99os << std::endl;
     100}
     101
     102void StaticAssertDecl::printShort( std::ostream &os, Indenter indent ) const {
     103        print( os, indent );
     104}
     105
    83106// Local Variables: //
    84107// tab-width: 4 //
  • src/SynTree/Declaration.h

    rb2fe1c9 r32cab5b  
    365365};
    366366
     367class StaticAssertDecl : public Declaration {
     368public:
     369        Expression * condition;
     370        ConstantExpr * message;   // string literal
     371
     372        StaticAssertDecl( Expression * condition, ConstantExpr * message );
     373        StaticAssertDecl( const StaticAssertDecl & other );
     374        virtual ~StaticAssertDecl();
     375
     376        virtual StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
     377        virtual void accept( Visitor &v ) override { v.visit( this ); }
     378        virtual StaticAssertDecl * acceptMutator( Mutator &m )  override { return m.mutate( this ); }
     379        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     380        virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     381};
     382
    367383std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data );
    368384
  • src/SynTree/FunctionDecl.cc

    rb2fe1c9 r32cab5b  
    2626#include "Statement.h"           // for CompoundStmt
    2727#include "Type.h"                // for Type, FunctionType, Type::FuncSpecif...
    28 #include "VarExprReplacer.h"
     28#include "DeclReplacer.h"
    2929
    3030extern bool translation_unit_nomain;
     
    4141                : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
    4242
    43         VarExprReplacer::DeclMap declMap;
     43        DeclReplacer::DeclMap declMap;
    4444        for ( auto p : group_iterate( other.type->parameters, type->parameters ) ) {
    4545                declMap[ std::get<0>(p) ] = std::get<1>(p);
     
    4949        }
    5050        if ( ! declMap.empty() ) {
    51                 VarExprReplacer::replace( this, declMap );
     51                DeclReplacer::replace( this, declMap );
    5252        }
    5353        cloneAll( other.withExprs, withExprs );
  • src/SynTree/Mutator.h

    rb2fe1c9 r32cab5b  
    3434        virtual Declaration * mutate( TypedefDecl * typeDecl ) = 0;
    3535        virtual AsmDecl * mutate( AsmDecl * asmDecl ) = 0;
     36        virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) = 0;
    3637
    3738        virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) = 0;
  • src/SynTree/Statement.cc

    rb2fe1c9 r32cab5b  
    3434Statement::Statement( const std::list<Label> & labels ) : labels( labels ) {}
    3535
    36 void Statement::print( std::ostream & os, Indenter ) const {
     36void Statement::print( std::ostream & os, Indenter indent ) const {
    3737        if ( ! labels.empty() ) {
    38                 os << "Labels: {";
     38                os << indent << "... Labels: {";
    3939                for ( const Label & l : labels ) {
    4040                        os << l << ",";
     
    223223
    224224void CaseStmt::print( std::ostream &os, Indenter indent ) const {
    225         if ( isDefault() ) os << "Default ";
     225        if ( isDefault() ) os << indent << "Default ";
    226226        else {
    227                 os << "Case ";
     227                os << indent << "Case ";
    228228                condition->print( os, indent );
    229229        } // if
     
    231231
    232232        for ( Statement * stmt : stmts ) {
     233                os << indent+1;
    233234                stmt->print( os, indent+1 );
    234235        }
     
    478479}
    479480
    480 void NullStmt::print( std::ostream &os, Indenter ) const {
     481void NullStmt::print( std::ostream &os, Indenter indent ) const {
    481482        os << "Null Statement" << endl;
     483        Statement::print( os, indent );
    482484}
    483485
  • src/SynTree/Statement.h

    rb2fe1c9 r32cab5b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep  3 20:46:46 2017
    13 // Update Count     : 77
     12// Last Modified On : Thu Mar  8 14:53:02 2018
     13// Update Count     : 78
    1414//
    1515
     
    255255class BranchStmt : public Statement {
    256256  public:
    257         enum Type { Goto = 0, Break, Continue };
     257        enum Type { Goto = 0, Break, Continue, FallThrough, FallThroughDefault };
    258258
    259259        // originalTarget kept for error messages.
  • src/SynTree/SynTree.h

    rb2fe1c9 r32cab5b  
    3838class TypedefDecl;
    3939class AsmDecl;
     40class StaticAssertDecl;
    4041
    4142class Statement;
  • src/SynTree/TypeSubstitution.cc

    rb2fe1c9 r32cab5b  
    149149                return inst;
    150150        } else {
    151 ///         std::cerr << "found " << inst->get_name() << ", replacing with ";
    152 ///         i->second->print( std::cerr );
    153 ///         std::cerr << std::endl;
     151                // cut off infinite loop for the case where a type is bound to itself.
     152                // Note: this does not prevent cycles in the general case, so it may be necessary to do something more sophisticated here.
     153                // TODO: investigate preventing type variables from being bound to themselves in the first place.
     154                if ( TypeInstType * replacement = dynamic_cast< TypeInstType * >( i->second ) ) {
     155                        if ( inst->name == replacement->name ) {
     156                                return inst;
     157                        }
     158                }
     159                // std::cerr << "found " << inst->name << ", replacing with " << i->second << std::endl;
    154160                subCount++;
    155161                Type * newtype = i->second->clone();
    156162                newtype->get_qualifiers() |= inst->get_qualifiers();
    157163                delete inst;
    158                 return newtype;
     164                // Note: need to recursively apply substitution to the new type because normalize does not substitute bound vars, but bound vars must be substituted when not in freeOnly mode.
     165                return newtype->acceptMutator( *visitor );
    159166        } // if
    160167}
  • src/SynTree/TypeSubstitution.h

    rb2fe1c9 r32cab5b  
    129129
    130130// definitition must happen after PassVisitor is included so that WithGuards can be used
    131 struct TypeSubstitution::Substituter : public WithGuards {
     131struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> {
    132132                Substituter( TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
    133133
  • src/SynTree/Visitor.h

    rb2fe1c9 r32cab5b  
    3636        virtual void visit( TypedefDecl * typeDecl ) = 0;
    3737        virtual void visit( AsmDecl * asmDecl ) = 0;
     38        virtual void visit( StaticAssertDecl * assertDecl ) = 0;
    3839
    3940        virtual void visit( CompoundStmt * compoundStmt ) = 0;
  • src/SynTree/module.mk

    rb2fe1c9 r32cab5b  
    4848       SynTree/TypeSubstitution.cc \
    4949       SynTree/Attribute.cc \
    50        SynTree/VarExprReplacer.cc
     50       SynTree/DeclReplacer.cc
    5151
Note: See TracChangeset for help on using the changeset viewer.