Changeset 0dd3a2f


Ignore:
Timestamp:
May 18, 2015, 11:20:23 AM (10 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:
51587aa
Parents:
a32b204
Message:

licencing: third groups of files

Location:
translator
Files:
60 edited

Legend:

Unmodified
Added
Removed
  • translator/SymTab/AddVisit.h

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: AddVisit.h,v 1.2 2005/08/29 20:14:17 rcbilson Exp $
    5  *
    6  */
    7 
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// AddVisit.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 16:14:32 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 16:16:38 2015
     13// Update Count     : 3
     14//
    815
    916namespace SymTab {
     17        void addDecls( std::list< Declaration* > &declsToAdd, std::list< Statement* > &statements, std::list< Statement* >::iterator i );
    1018
    11 void addDecls( std::list< Declaration* > &declsToAdd, std::list< Statement* > &statements, std::list< Statement* >::iterator i );
     19        template< typename Visitor >
     20        inline void addVisitStatementList( std::list< Statement* > &statements, Visitor &visitor ) {
     21                for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
     22                        addDecls( visitor.get_declsToAdd(), statements, i );
     23                        (*i)->accept( visitor );
     24                } // for
     25                addDecls( visitor.get_declsToAdd(), statements, statements.end() );
     26        }
    1227
    13 template< typename Visitor >
    14 inline void
    15 addVisitStatementList( std::list< Statement* > &statements, Visitor &visitor )
    16 {
    17   for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
    18     addDecls( visitor.get_declsToAdd(), statements, i );
    19     (*i)->accept( visitor );
    20   }
    21   addDecls( visitor.get_declsToAdd(), statements, statements.end() );
    22 }
    23 
    24 template< typename Visitor >
    25 inline void
    26 addVisitStatement( Statement *stmt, Visitor &visitor )
    27 {
    28   maybeAccept( stmt, visitor );
     28        template< typename Visitor >
     29        inline void addVisitStatement( Statement *stmt, Visitor &visitor ) {
     30                maybeAccept( stmt, visitor );
    2931///   if ( ! declsToAdd.empty() ) {
    3032///     CompoundStmt *compound = new CompoundStmt( noLabels );
     
    3234///     addDecls( declsToAdd, compound->get_kids(), compound->get_kids().end() );
    3335///   }
    34 }
     36        }
    3537
    36 template< typename Visitor >
    37 inline void
    38 addVisit(CompoundStmt *compoundStmt, Visitor &visitor)
    39 {
    40   addVisitStatementList( compoundStmt->get_kids(), visitor );
    41 }
     38        template< typename Visitor >
     39        inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) {
     40                addVisitStatementList( compoundStmt->get_kids(), visitor );
     41        }
    4242
    43 template< typename Visitor >
    44 inline void
    45 addVisit(IfStmt *ifStmt, Visitor &visitor)
    46 {
    47   addVisitStatement( ifStmt->get_thenPart(), visitor );
    48   addVisitStatement( ifStmt->get_elsePart(), visitor );
    49   maybeAccept( ifStmt->get_condition(), visitor );
    50 }
     43        template< typename Visitor >
     44        inline void addVisit(IfStmt *ifStmt, Visitor &visitor) {
     45                addVisitStatement( ifStmt->get_thenPart(), visitor );
     46                addVisitStatement( ifStmt->get_elsePart(), visitor );
     47                maybeAccept( ifStmt->get_condition(), visitor );
     48        }
    5149
    52 template< typename Visitor >
    53 inline void
    54 addVisit(WhileStmt *whileStmt, Visitor &visitor)
    55 {
    56   addVisitStatement( whileStmt->get_body(), visitor );
    57   maybeAccept( whileStmt->get_condition(), visitor );
    58 }
     50        template< typename Visitor >
     51        inline void addVisit(WhileStmt *whileStmt, Visitor &visitor) {
     52                addVisitStatement( whileStmt->get_body(), visitor );
     53                maybeAccept( whileStmt->get_condition(), visitor );
     54        }
    5955
    60 template< typename Visitor >
    61 inline void
    62 addVisit(ForStmt *forStmt, Visitor &visitor)
    63 {
    64   addVisitStatement( forStmt->get_body(), visitor );
    65   maybeAccept( forStmt->get_initialization(), visitor );
    66   maybeAccept( forStmt->get_condition(), visitor );
    67   maybeAccept( forStmt->get_increment(), visitor );
    68 }
     56        template< typename Visitor >
     57        inline void addVisit(ForStmt *forStmt, Visitor &visitor) {
     58                addVisitStatement( forStmt->get_body(), visitor );
     59                maybeAccept( forStmt->get_initialization(), visitor );
     60                maybeAccept( forStmt->get_condition(), visitor );
     61                maybeAccept( forStmt->get_increment(), visitor );
     62        }
    6963
    70 template< typename Visitor >
    71 inline void
    72 addVisit(SwitchStmt *switchStmt, Visitor &visitor)
    73 {
    74   addVisitStatementList( switchStmt->get_branches(), visitor );
    75   maybeAccept( switchStmt->get_condition(), visitor );
    76 }
     64        template< typename Visitor >
     65        inline void addVisit(SwitchStmt *switchStmt, Visitor &visitor) {
     66                addVisitStatementList( switchStmt->get_branches(), visitor );
     67                maybeAccept( switchStmt->get_condition(), visitor );
     68        }
    7769
    78 template< typename Visitor >
    79 inline void
    80 addVisit(ChooseStmt *switchStmt, Visitor &visitor)
    81 {
    82   addVisitStatementList( switchStmt->get_branches(), visitor );
    83   maybeAccept( switchStmt->get_condition(), visitor );
    84 }
     70        template< typename Visitor >
     71        inline void addVisit(ChooseStmt *switchStmt, Visitor &visitor) {
     72                addVisitStatementList( switchStmt->get_branches(), visitor );
     73                maybeAccept( switchStmt->get_condition(), visitor );
     74        }
    8575
    86 template< typename Visitor >
    87 inline void
    88 addVisit(CaseStmt *caseStmt, Visitor &visitor)
    89 {
    90   addVisitStatementList( caseStmt->get_statements(), visitor );
    91   maybeAccept( caseStmt->get_condition(), visitor );
    92 }
     76        template< typename Visitor >
     77        inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) {
     78                addVisitStatementList( caseStmt->get_statements(), visitor );
     79                maybeAccept( caseStmt->get_condition(), visitor );
     80        }
    9381
    94 template< typename Visitor >
    95 inline void
    96 addVisit(CatchStmt *cathStmt, Visitor &visitor)
    97 {
    98   addVisitStatement( cathStmt->get_body(), visitor );
    99   maybeAccept( cathStmt->get_decl(), visitor );
    100 }
     82        template< typename Visitor >
     83        inline void addVisit(CatchStmt *cathStmt, Visitor &visitor) {
     84                addVisitStatement( cathStmt->get_body(), visitor );
     85                maybeAccept( cathStmt->get_decl(), visitor );
     86        }
     87} // namespace SymTab
    10188
    102 } // namespace SymTab
     89// Local Variables: //
     90// tab-width: 4 //
     91// mode: c++ //
     92// compile-command: "make install" //
     93// End: //
  • translator/SymTab/AggregateTable.h

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: AggregateTable.h,v 1.4 2005/08/29 20:14:17 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// AggregateTable.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 16:17:26 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 16:19:29 2015
     13// Update Count     : 4
     14//
    715
    8 #ifndef SYMTAB_AGGREGATETABLE_H
    9 #define SYMTAB_AGGREGATETABLE_H
     16#ifndef AGGREGATETABLE_H
     17#define AGGREGATETABLE_H
    1018
    1119#include <map>
     
    1826
    1927namespace SymTab {
     28        template< class AggregateDeclClass >
     29        class AggregateTableConflictFunction : public std::binary_function< AggregateDeclClass *, AggregateDeclClass *, AggregateDeclClass *> {
     30          public:
     31                AggregateDeclClass *operator()( AggregateDeclClass *existing, AggregateDeclClass *added ) {
     32                        if ( existing->get_members().empty() ) {
     33                                return added;
     34                        } else if ( ! added->get_members().empty() ) {
     35                                throw SemanticError( "redeclaration of ", added );
     36                        } // if
     37                        return existing;
     38                }
     39        };
    2040
    21 template< class AggregateDeclClass >
    22 class AggregateTableConflictFunction : public std::binary_function< AggregateDeclClass*, AggregateDeclClass*, AggregateDeclClass* >
    23 {
    24 public:
    25   AggregateDeclClass *operator()( AggregateDeclClass *existing, AggregateDeclClass *added )
    26   {
    27     if ( existing->get_members().empty() ) {
    28       return added;
    29     } else if ( ! added->get_members().empty() ) {
    30       throw SemanticError( "redeclaration of ", added );
    31     }
    32     return existing;
    33   }
    34  
    35 };
    36 
    37 typedef StackTable< StructDecl, AggregateTableConflictFunction< StructDecl > > StructTable;
    38 typedef StackTable< EnumDecl, AggregateTableConflictFunction< EnumDecl > > EnumTable;
    39 typedef StackTable< UnionDecl, AggregateTableConflictFunction< UnionDecl > > UnionTable;
    40 typedef StackTable< ContextDecl, AggregateTableConflictFunction< ContextDecl > > ContextTable;
    41 
     41        typedef StackTable< StructDecl, AggregateTableConflictFunction< StructDecl > > StructTable;
     42        typedef StackTable< EnumDecl, AggregateTableConflictFunction< EnumDecl > > EnumTable;
     43        typedef StackTable< UnionDecl, AggregateTableConflictFunction< UnionDecl > > UnionTable;
     44        typedef StackTable< ContextDecl, AggregateTableConflictFunction< ContextDecl > > ContextTable;
    4245} // namespace SymTab
    4346
    44 #endif /* #ifndef SYMTAB_AGGREGATETABLE_H */
     47#endif // AGGREGATETABLE_H
     48
     49// Local Variables: //
     50// tab-width: 4 //
     51// mode: c++ //
     52// compile-command: "make install" //
     53// End: //
  • translator/SymTab/FixFunction.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// FixFunction.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 16:19:49 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 16:22:54 2015
     13// Update Count     : 2
     14//
     15
    116#include "FixFunction.h"
    217#include "SynTree/Declaration.h"
     
    621
    722namespace SymTab {
     23        FixFunction::FixFunction() : isVoid( false ) {
     24        }
    825
    9 FixFunction::FixFunction()
    10   : isVoid( false )
    11 {
    12 }
     26        DeclarationWithType * FixFunction::mutate(FunctionDecl *functionDecl) {
     27                ObjectDecl *pointer = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClass(), functionDecl->get_linkage(), 0, new PointerType( Type::Qualifiers(), functionDecl->get_type()->clone() ), 0 );
     28                delete functionDecl;
     29                return pointer;
     30        }
    1331
    14 DeclarationWithType*
    15 FixFunction::mutate(FunctionDecl *functionDecl)
    16 {
    17   ObjectDecl *pointer = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClass(), functionDecl->get_linkage(), 0, new PointerType( Type::Qualifiers(), functionDecl->get_type()->clone() ), 0 );
    18   delete functionDecl;
    19   return pointer;
    20 }
     32        Type * FixFunction::mutate(VoidType *voidType) {
     33                isVoid = true;
     34                return voidType;
     35        }
    2136
    22 Type*
    23 FixFunction::mutate(VoidType *voidType)
    24 {
    25   isVoid = true;
    26   return voidType;
    27 }
     37        Type * FixFunction::mutate(BasicType *basicType) {
     38                return basicType;
     39        }
    2840
    29 Type*
    30 FixFunction::mutate(BasicType *basicType)
    31 {
    32   return basicType;
    33 }
     41        Type * FixFunction::mutate(PointerType *pointerType) {
     42                return pointerType;
     43        }
    3444
    35 Type*
    36 FixFunction::mutate(PointerType *pointerType)
    37 {
    38   return pointerType;
    39 }
     45        Type * FixFunction::mutate(ArrayType *arrayType) {
     46                PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), maybeClone( arrayType->get_base()->clone() ), maybeClone( arrayType->get_dimension() ), arrayType->get_isVarLen(), arrayType->get_isStatic() );
     47                delete arrayType;
     48                return pointerType;
     49        }
    4050
    41 Type*
    42 FixFunction::mutate(ArrayType *arrayType)
    43 {
    44   PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), maybeClone( arrayType->get_base()->clone() ), maybeClone( arrayType->get_dimension() ), arrayType->get_isVarLen(), arrayType->get_isStatic() );
    45   delete arrayType;
    46   return pointerType;
    47 }
     51        Type * FixFunction::mutate(StructInstType *aggregateUseType) {
     52                return aggregateUseType;
     53        }
    4854
    49 Type*
    50 FixFunction::mutate(StructInstType *aggregateUseType)
    51 {
    52   return aggregateUseType;
    53 }
     55        Type * FixFunction::mutate(UnionInstType *aggregateUseType) {
     56                return aggregateUseType;
     57        }
    5458
    55 Type*
    56 FixFunction::mutate(UnionInstType *aggregateUseType)
    57 {
    58   return aggregateUseType;
    59 }
     59        Type * FixFunction::mutate(EnumInstType *aggregateUseType) {
     60                return aggregateUseType;
     61        }
    6062
    61 Type*
    62 FixFunction::mutate(EnumInstType *aggregateUseType)
    63 {
    64   return aggregateUseType;
    65 }
     63        Type * FixFunction::mutate(ContextInstType *aggregateUseType) {
     64                return aggregateUseType;
     65        }
    6666
    67 Type*
    68 FixFunction::mutate(ContextInstType *aggregateUseType)
    69 {
    70   return aggregateUseType;
    71 }
     67        Type * FixFunction::mutate(TypeInstType *aggregateUseType) {
     68                return aggregateUseType;
     69        }
    7270
    73 Type*
    74 FixFunction::mutate(TypeInstType *aggregateUseType)
    75 {
    76   return aggregateUseType;
    77 }
     71        Type * FixFunction::mutate(TupleType *tupleType) {
     72                return tupleType;
     73        }
     74} // namespace SymTab
    7875
    79 Type*
    80 FixFunction::mutate(TupleType *tupleType)
    81 {
    82   return tupleType;
    83 }
    84 
    85 
    86 } // namespace SymTab
     76// Local Variables: //
     77// tab-width: 4 //
     78// mode: c++ //
     79// compile-command: "make install" //
     80// End: //
  • translator/SymTab/FixFunction.h

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: FixFunction.h,v 1.3 2005/08/29 20:14:17 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// FixFunction.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 17:02:08 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 17:03:43 2015
     13// Update Count     : 2
     14//
    715
    8 #ifndef SYMTAB_FIXFUNCTION_H
    9 #define SYMTAB_FIXFUNCTION_H
     16#ifndef FIXFUNCTION_H
     17#define FIXFUNCTION_H
    1018
    1119#include "SynTree/Mutator.h"
    1220
    1321namespace SymTab {
     22        class FixFunction : public Mutator {
     23                typedef Mutator Parent;
     24          public:
     25                FixFunction();
    1426
    15 class FixFunction : public Mutator
    16 {
    17   typedef Mutator Parent;
     27                bool get_isVoid() const { return isVoid; }
     28                void set_isVoid( bool newValue ) { isVoid = newValue; }
     29          private:
     30                virtual DeclarationWithType* mutate(FunctionDecl *functionDecl);
    1831
    19 public:
    20   FixFunction();
    21 
    22   bool get_isVoid() const { return isVoid; }
    23   void set_isVoid( bool newValue ) { isVoid = newValue; }
    24 
    25 private:
    26   virtual DeclarationWithType* mutate(FunctionDecl *functionDecl);
    27 
    28   virtual Type* mutate(VoidType *voidType);
    29   virtual Type* mutate(BasicType *basicType);
    30   virtual Type* mutate(PointerType *pointerType);
    31   virtual Type* mutate(ArrayType *arrayType);
    32   virtual Type* mutate(StructInstType *aggregateUseType);
    33   virtual Type* mutate(UnionInstType *aggregateUseType);
    34   virtual Type* mutate(EnumInstType *aggregateUseType);
    35   virtual Type* mutate(ContextInstType *aggregateUseType);
    36   virtual Type* mutate(TypeInstType *aggregateUseType);
    37   virtual Type* mutate(TupleType *tupleType);
     32                virtual Type* mutate(VoidType *voidType);
     33                virtual Type* mutate(BasicType *basicType);
     34                virtual Type* mutate(PointerType *pointerType);
     35                virtual Type* mutate(ArrayType *arrayType);
     36                virtual Type* mutate(StructInstType *aggregateUseType);
     37                virtual Type* mutate(UnionInstType *aggregateUseType);
     38                virtual Type* mutate(EnumInstType *aggregateUseType);
     39                virtual Type* mutate(ContextInstType *aggregateUseType);
     40                virtual Type* mutate(TypeInstType *aggregateUseType);
     41                virtual Type* mutate(TupleType *tupleType);
    3842 
    39   bool isVoid;
    40 };
    41 
     43                bool isVoid;
     44        };
    4245} // namespace SymTab
    4346
    44 #endif /* #ifndef SYMTAB_FIXFUNCTION_H */
     47#endif // FIXFUNCTION_H
     48
     49// Local Variables: //
     50// tab-width: 4 //
     51// mode: c++ //
     52// compile-command: "make install" //
     53// End: //
  • translator/SymTab/IdTable.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: IdTable.cc,v 1.6 2005/08/29 20:14:17 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// IdTable.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 17:04:02 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 17:07:43 2015
     13// Update Count     : 3
     14//
    715
    816#include <cassert>
     
    1826
    1927namespace SymTab {
     28        IdTable::IdTable() : scopeLevel( 0 ) {
     29        }
    2030
    21 IdTable::IdTable()
    22   : scopeLevel( 0 )
    23 {
    24 }
     31        void IdTable::enterScope() {
     32                scopeLevel++;
     33        }
    2534
    26 void
    27 IdTable::enterScope()
    28 {
    29   scopeLevel++;
    30 }
     35        void IdTable::leaveScope() {
     36                for ( OuterTableType::iterator outer = table.begin(); outer != table.end(); ++outer ) {
     37                        for ( InnerTableType::iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) {
     38                                std::stack< DeclEntry >& entry = inner->second;
     39                                if ( ! entry.empty() && entry.top().second == scopeLevel ) {
     40                                        entry.pop();
     41                                } // if
     42                        } // for
     43                } // for
    3144
    32 void
    33 IdTable::leaveScope()
    34 {
    35   for ( OuterTableType::iterator outer = table.begin(); outer != table.end(); ++outer ) {
    36     for ( InnerTableType::iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) {
    37       std::stack< DeclEntry >& entry = inner->second;
    38       if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    39         entry.pop();
    40       }
    41     }
    42   }
    43      
    44   scopeLevel--;
    45   assert( scopeLevel >= 0 );
    46 }
     45                scopeLevel--;
     46                assert( scopeLevel >= 0 );
     47        }
    4748
    48 void
    49 IdTable::addDecl( DeclarationWithType *decl )
    50 {
    51   const string &name = decl->get_name();
    52   string manglename;
    53   if ( decl->get_linkage() == LinkageSpec::C ) {
    54     manglename = name;
    55   } else {
    56     manglename = Mangler::mangle( decl );
    57   }
    58   InnerTableType &declTable = table[ name ];
    59   InnerTableType::iterator it = declTable.find( manglename );
    60   if ( it == declTable.end() ) {
    61     declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
    62   } else {
    63     std::stack< DeclEntry >& entry = it->second;
    64     if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    65       if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) {
    66         FunctionDecl *newentry = dynamic_cast< FunctionDecl* >( decl );
    67         FunctionDecl *old = dynamic_cast< FunctionDecl* >( entry.top().first );
    68         if ( newentry && old && newentry->get_statements() && old->get_statements() ) {
    69           throw SemanticError( "duplicate function definition for ", decl );
    70         } else {
    71           ObjectDecl *newobj = dynamic_cast< ObjectDecl* >( decl );
    72           ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( entry.top().first );
    73           if ( newobj && oldobj && newobj->get_init() && oldobj->get_init() ) {
    74             throw SemanticError( "duplicate definition for ", decl );
    75           }
    76         }
    77       } else {
    78         throw SemanticError( "duplicate definition for ", decl );
    79       }
    80     } else {
    81       declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
    82     }
    83   }
    84   // ensure the set of routines with C linkage cannot be overloaded
    85   for ( InnerTableType::iterator i = declTable.begin(); i != declTable.end(); ++i ) {
    86     if ( ! i->second.empty() && i->second.top().first->get_linkage() == LinkageSpec::C && declTable.size() > 1 ) {
    87         InnerTableType::iterator j = i;
    88         for ( j++; j != declTable.end(); ++j ) {
    89           if ( ! j->second.empty() && j->second.top().first->get_linkage() == LinkageSpec::C ) {
    90             throw SemanticError( "invalid overload of C function " );
    91           }
     49        void IdTable::addDecl( DeclarationWithType *decl ) {
     50                const string &name = decl->get_name();
     51                string manglename;
     52                if ( decl->get_linkage() == LinkageSpec::C ) {
     53                        manglename = name;
     54                } else {
     55                        manglename = Mangler::mangle( decl );
     56                } // if
     57
     58                InnerTableType &declTable = table[ name ];
     59                InnerTableType::iterator it = declTable.find( manglename );
     60
     61                if ( it == declTable.end() ) {
     62                        declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
     63                } else {
     64                        std::stack< DeclEntry >& entry = it->second;
     65                        if ( ! entry.empty() && entry.top().second == scopeLevel ) {
     66                                if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) {
     67                                        FunctionDecl *newentry = dynamic_cast< FunctionDecl* >( decl );
     68                                        FunctionDecl *old = dynamic_cast< FunctionDecl* >( entry.top().first );
     69                                        if ( newentry && old && newentry->get_statements() && old->get_statements() ) {
     70                                                throw SemanticError( "duplicate function definition for ", decl );
     71                                        } else {
     72                                                ObjectDecl *newobj = dynamic_cast< ObjectDecl* >( decl );
     73                                                ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( entry.top().first );
     74                                                if ( newobj && oldobj && newobj->get_init() && oldobj->get_init() ) {
     75                                                        throw SemanticError( "duplicate definition for ", decl );
     76                                                } // if
     77                                        } // if
     78                                } else {
     79                                        throw SemanticError( "duplicate definition for ", decl );
     80                                } // if
     81                        } else {
     82                                declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
     83                        } // if
     84                } // if
     85                // ensure the set of routines with C linkage cannot be overloaded
     86                for ( InnerTableType::iterator i = declTable.begin(); i != declTable.end(); ++i ) {
     87                        if ( ! i->second.empty() && i->second.top().first->get_linkage() == LinkageSpec::C && declTable.size() > 1 ) {
     88                                InnerTableType::iterator j = i;
     89                                for ( j++; j != declTable.end(); ++j ) {
     90                                        if ( ! j->second.empty() && j->second.top().first->get_linkage() == LinkageSpec::C ) {
     91                                                throw SemanticError( "invalid overload of C function " );
     92                                        } // if
     93                                } // for
     94                        } // if
     95                } // for
    9296        }
    93     }
    94   }
    95 }
    9697
    97 void
    98 IdTable::lookupId( const std::string &id, std::list< DeclarationWithType* >& decls ) const
    99 {
    100   OuterTableType::const_iterator outer = table.find( id );
    101   if ( outer == table.end() ) return;
    102   const InnerTableType &declTable = outer->second;
    103   for ( InnerTableType::const_iterator it = declTable.begin(); it != declTable.end(); ++it ) {
    104     const std::stack< DeclEntry >& entry = it->second;
    105     if ( ! entry.empty() ) {
    106       decls.push_back( entry.top().first );
    107     }
    108   }
    109 }
     98        void IdTable::lookupId( const std::string &id, std::list< DeclarationWithType* >& decls ) const {
     99                OuterTableType::const_iterator outer = table.find( id );
     100                if ( outer == table.end() ) return;
     101                const InnerTableType &declTable = outer->second;
     102                for ( InnerTableType::const_iterator it = declTable.begin(); it != declTable.end(); ++it ) {
     103                        const std::stack< DeclEntry >& entry = it->second;
     104                        if ( ! entry.empty() ) {
     105                                decls.push_back( entry.top().first );
     106                        } // if
     107                } // for
     108        }
    110109
    111 DeclarationWithType* IdTable::lookupId( const std::string &id) const {
    112    DeclarationWithType* result = 0;
    113    int depth = -1;
     110        DeclarationWithType * IdTable::lookupId( const std::string &id) const {
     111                DeclarationWithType* result = 0;
     112                int depth = -1;
    114113
    115    OuterTableType::const_iterator outer = table.find( id );
    116    if ( outer == table.end() ) return 0;
    117    const InnerTableType &declTable = outer->second;
    118    for ( InnerTableType::const_iterator it = declTable.begin(); it != declTable.end(); ++it ) {
    119      const std::stack< DeclEntry >& entry = it->second;
    120      if ( ! entry.empty() && entry.top().second > depth ) {
    121        result = entry.top().first;
    122        depth = entry.top().second;
    123      }
    124    }
    125    return result;
    126 }
     114                OuterTableType::const_iterator outer = table.find( id );
     115                if ( outer == table.end() ) return 0;
     116                const InnerTableType &declTable = outer->second;
     117                for ( InnerTableType::const_iterator it = declTable.begin(); it != declTable.end(); ++it ) {
     118                        const std::stack< DeclEntry >& entry = it->second;
     119                        if ( ! entry.empty() && entry.top().second > depth ) {
     120                                result = entry.top().first;
     121                                depth = entry.top().second;
     122                        } // if
     123                } // for
     124                return result;
     125        }
    127126
    128 void
    129 IdTable::dump( std::ostream &os ) const
    130 {
    131   for ( OuterTableType::const_iterator outer = table.begin(); outer != table.end(); ++outer ) {
    132     for ( InnerTableType::const_iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) {
     127        void IdTable::dump( std::ostream &os ) const {
     128                for ( OuterTableType::const_iterator outer = table.begin(); outer != table.end(); ++outer ) {
     129                        for ( InnerTableType::const_iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) {
    133130#if 0
    134       const std::stack< DeclEntry >& entry = inner->second;
    135       if ( ! entry.empty() ) { // && entry.top().second == scopeLevel ) {
    136         os << outer->first << " (" << inner->first << ") (" << entry.top().second << ")" << std::endl;
    137       } else {
    138         os << outer->first << " (" << inner->first << ") ( entry-empty)" << std::endl;
    139       }
     131                                const std::stack< DeclEntry >& entry = inner->second;
     132                                if ( ! entry.empty() ) { // && entry.top().second == scopeLevel ) {
     133                                        os << outer->first << " (" << inner->first << ") (" << entry.top().second << ")" << std::endl;
     134                                } else {
     135                                        os << outer->first << " (" << inner->first << ") ( entry-empty)" << std::endl;
     136                                } // if
    140137#endif
    141138#if 0
    142       std::stack<DeclEntry> stack = inner->second;
    143       os << "dumping a stack" << std::endl;
    144       while (! stack.empty()) {
    145         DeclEntry d = stack.top();
    146         os << outer->first << " (" << inner->first << ") (" << d.second << ") " << std::endl;
    147         stack.pop();
    148       }
     139                                std::stack<DeclEntry> stack = inner->second;
     140                                os << "dumping a stack" << std::endl;
     141                                while (! stack.empty()) {
     142                                        DeclEntry d = stack.top();
     143                                        os << outer->first << " (" << inner->first << ") (" << d.second << ") " << std::endl;
     144                                        stack.pop();
     145                                } // while
    149146#endif
    150     }
    151   }
     147                        } // for
     148                } // for
    152149#if 0
    153   for ( OuterTableType::const_iterator outer = table.begin(); outer != table.end(); ++outer ) {
    154     for ( InnerTableType::const_iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) {
    155       const std::stack< DeclEntry >& entry = inner->second;
    156       if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    157         os << outer->first << " (" << inner->first << ") (" << scopeLevel << ")" << std::endl;
    158       }
    159     }
    160   }
     150                for ( OuterTableType::const_iterator outer = table.begin(); outer != table.end(); ++outer ) {
     151                        for ( InnerTableType::const_iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) {
     152                                const std::stack< DeclEntry >& entry = inner->second;
     153                                if ( ! entry.empty() && entry.top().second == scopeLevel ) {
     154                                        os << outer->first << " (" << inner->first << ") (" << scopeLevel << ")" << std::endl;
     155                                } // if
     156                        } // for
     157                } // for
    161158#endif
    162 }
     159        }
     160} // namespace SymTab
    163161
    164 
    165 } // namespace SymTab
     162// Local Variables: //
     163// tab-width: 4 //
     164// mode: c++ //
     165// compile-command: "make install" //
     166// End: //
  • translator/SymTab/IdTable.h

    ra32b204 r0dd3a2f  
    1 #ifndef SYMTAB_IDTABLE_H
    2 #define SYMTAB_IDTABLE_H
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// IdTable.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 21:30:02 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 21:31:45 2015
     13// Update Count     : 3
     14//
     15
     16#ifndef IDTABLE_H
     17#define IDTABLE_H
    318
    419#include <iostream>
     
    1227    class IdTable {
    1328      public:
    14         IdTable();
     29                IdTable();
    1530 
    16         void enterScope();
    17         void leaveScope();
    18         void addDecl( DeclarationWithType *decl );
    19         void lookupId( const std::string &id, std::list< DeclarationWithType* >& decls ) const;
    20         DeclarationWithType* lookupId( const std::string &id) const;
     31                void enterScope();
     32                void leaveScope();
     33                void addDecl( DeclarationWithType *decl );
     34                void lookupId( const std::string &id, std::list< DeclarationWithType* >& decls ) const;
     35                DeclarationWithType* lookupId( const std::string &id) const;
    2136 
    22         void dump( std::ostream &os ) const; // debugging
     37                void dump( std::ostream &os ) const;                    // debugging
     38      private:
     39                typedef std::pair< DeclarationWithType*, int > DeclEntry;
     40                typedef std::map< std::string, std::stack< DeclEntry > > InnerTableType;
     41                typedef std::map< std::string, InnerTableType > OuterTableType;
    2342
    24       private:
    25         typedef std::pair< DeclarationWithType*, int > DeclEntry;
    26         typedef std::map< std::string, std::stack< DeclEntry > > InnerTableType;
    27         typedef std::map< std::string, InnerTableType > OuterTableType;
    28 
    29         OuterTableType table;
    30         int scopeLevel;
     43                OuterTableType table;
     44                int scopeLevel;
    3145    };
    3246} // namespace SymTab
    3347
    34 #endif // SYMTAB_IDTABLE_H
     48#endif // IDTABLE_H
     49
     50// Local Variables: //
     51// tab-width: 4 //
     52// mode: c++ //
     53// compile-command: "make install" //
     54// End: //
  • translator/SymTab/ImplementationType.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: ImplementationType.cc,v 1.4 2005/08/29 20:14:17 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// ImplementationType.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 21:32:01 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 21:34:40 2015
     13// Update Count     : 2
     14//
    715
    816#include "ImplementationType.h"
     
    1523
    1624namespace SymTab {
     25        class ImplementationType : public Visitor {
     26          public:
     27                ImplementationType( const SymTab::Indexer &indexer );
    1728
    18 class ImplementationType : public Visitor
    19 {
    20 public:
    21   ImplementationType( const SymTab::Indexer &indexer );
    22  
    23   Type *get_result() { return result; }
     29                Type *get_result() { return result; }
     30          private:
     31                virtual void visit(VoidType *voidType);
     32                virtual void visit(BasicType *basicType);
     33                virtual void visit(PointerType *pointerType);
     34                virtual void visit(ArrayType *arrayType);
     35                virtual void visit(FunctionType *functionType);
     36                virtual void visit(StructInstType *aggregateUseType);
     37                virtual void visit(UnionInstType *aggregateUseType);
     38                virtual void visit(EnumInstType *aggregateUseType);
     39                virtual void visit(ContextInstType *aggregateUseType);
     40                virtual void visit(TypeInstType *aggregateUseType);
     41                virtual void visit(TupleType *tupleType);
    2442
    25 private:
    26   virtual void visit(VoidType *voidType);
    27   virtual void visit(BasicType *basicType);
    28   virtual void visit(PointerType *pointerType);
    29   virtual void visit(ArrayType *arrayType);
    30   virtual void visit(FunctionType *functionType);
    31   virtual void visit(StructInstType *aggregateUseType);
    32   virtual void visit(UnionInstType *aggregateUseType);
    33   virtual void visit(EnumInstType *aggregateUseType);
    34   virtual void visit(ContextInstType *aggregateUseType);
    35   virtual void visit(TypeInstType *aggregateUseType);
    36   virtual void visit(TupleType *tupleType);
     43                Type *result;                   // synthesized
     44                const SymTab::Indexer &indexer;
     45        };
    3746
    38   Type *result;                 // synthesized
    39   const SymTab::Indexer &indexer;
    40 };
     47        Type * implementationType( Type *type, const SymTab::Indexer& indexer ) {
     48                ImplementationType implementor( indexer );
     49                type->accept( implementor );
     50                if ( implementor.get_result() == 0 ) {
     51                        return type->clone();
     52                } else {
     53                        return implementor.get_result();
     54                } // if
     55        }
    4156
    42 Type*
    43 implementationType( Type *type, const SymTab::Indexer& indexer )
    44 {
    45   ImplementationType implementor( indexer );
    46   type->accept( implementor );
    47   if ( implementor.get_result() == 0 ) {
    48     return type->clone();
    49   } else {
    50     return implementor.get_result();
    51   }
    52 }
     57        ImplementationType::ImplementationType( const SymTab::Indexer &indexer ) : result( 0 ), indexer( indexer ) {
     58        }
    5359
    54 ImplementationType::ImplementationType( const SymTab::Indexer &indexer )
    55   : result( 0 ), indexer( indexer )
    56 {
    57 }
     60        void ImplementationType::visit(VoidType *voidType) {
     61        }
    5862
    59 void
    60 ImplementationType::visit(VoidType *voidType)
    61 {
    62 }
     63        void ImplementationType::visit(BasicType *basicType) {
     64        }
    6365
    64 void
    65 ImplementationType::visit(BasicType *basicType)
    66 {
    67 }
     66        void ImplementationType::visit(PointerType *pointerType) {
     67                PointerType *newType = pointerType->clone();
     68                newType->set_base( implementationType( pointerType->get_base(), indexer ) );
     69                result = newType;
     70        }
    6871
    69 void
    70 ImplementationType::visit(PointerType *pointerType)
    71 {
    72   PointerType *newType = pointerType->clone();
    73   newType->set_base( implementationType( pointerType->get_base(), indexer ) );
    74   result = newType;
    75 }
     72        void ImplementationType::visit(ArrayType *arrayType) {
     73                ArrayType *newType = arrayType->clone();
     74                newType->set_base( implementationType( arrayType->get_base(), indexer ) );
     75                result = newType;
     76        }
    7677
    77 void
    78 ImplementationType::visit(ArrayType *arrayType)
    79 {
    80   ArrayType *newType = arrayType->clone();
    81   newType->set_base( implementationType( arrayType->get_base(), indexer ) );
    82   result = newType;
    83 }
    84 
    85 void
    86 ImplementationType::visit(FunctionType *functionType)
    87 {
     78        void ImplementationType::visit(FunctionType *functionType) {
    8879///   FunctionType *newType = functionType->clone();
    8980///   for ( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) {
     
    9384///     i->set_type( implementationType( i->get_type(), indexer ) );
    9485///   }
    95 }
     86        }
    9687
    97 void
    98 ImplementationType::visit(StructInstType *aggregateUseType)
    99 {
    100 }
     88        void ImplementationType::visit(StructInstType *aggregateUseType) {
     89        }
    10190
    102 void
    103 ImplementationType::visit(UnionInstType *aggregateUseType)
    104 {
    105 }
     91        void ImplementationType::visit(UnionInstType *aggregateUseType) {
     92        }
    10693
    107 void
    108 ImplementationType::visit(EnumInstType *aggregateUseType)
    109 {
    110 }
     94        void ImplementationType::visit(EnumInstType *aggregateUseType) {
     95        }
    11196
    112 void
    113 ImplementationType::visit(ContextInstType *aggregateUseType)
    114 {
    115 }
     97        void ImplementationType::visit(ContextInstType *aggregateUseType) {
     98        }
    11699
    117 void
    118 ImplementationType::visit(TypeInstType *inst)
    119 {
    120   NamedTypeDecl *typeDecl = indexer.lookupType( inst->get_name() );
    121   if ( typeDecl && typeDecl->get_base() ) {
    122     Type *base = implementationType( typeDecl->get_base(), indexer );
    123     base->get_qualifiers() += inst->get_qualifiers();
    124     result = base;
    125   }
    126 }
     100        void ImplementationType::visit(TypeInstType *inst) {
     101                NamedTypeDecl *typeDecl = indexer.lookupType( inst->get_name() );
     102                if ( typeDecl && typeDecl->get_base() ) {
     103                        Type *base = implementationType( typeDecl->get_base(), indexer );
     104                        base->get_qualifiers() += inst->get_qualifiers();
     105                        result = base;
     106                } // if
     107        }
    127108
    128 void
    129 ImplementationType::visit(TupleType *tupleType)
    130 {
    131   TupleType *newType = new TupleType( Type::Qualifiers() );
    132   for ( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) {
    133     Type *implType = implementationType( *i, indexer );
    134     implType->get_qualifiers() += tupleType->get_qualifiers();
    135     newType->get_types().push_back( implType );
    136   }
    137   result = newType;
    138 }
     109        void ImplementationType::visit(TupleType *tupleType) {
     110                TupleType *newType = new TupleType( Type::Qualifiers() );
     111                for ( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) {
     112                        Type *implType = implementationType( *i, indexer );
     113                        implType->get_qualifiers() += tupleType->get_qualifiers();
     114                        newType->get_types().push_back( implType );
     115                } // for
     116                result = newType;
     117        }
     118} // namespace SymTab
    139119
    140 } // namespace SymTab
     120// Local Variables: //
     121// tab-width: 4 //
     122// mode: c++ //
     123// compile-command: "make install" //
     124// End: //
  • translator/SymTab/ImplementationType.h

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: ImplementationType.h,v 1.3 2005/08/29 20:14:17 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// ImplementationType.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 21:35:41 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 21:37:15 2015
     13// Update Count     : 2
     14//
    715
    8 #ifndef SYMTAB_IMPLEMENTATIONTYPE_H
    9 #define SYMTAB_IMPLEMENTATIONTYPE_H
     16#ifndef IMPLEMENTATIONTYPE_H
     17#define IMPLEMENTATIONTYPE_H
    1018
    1119#include "SynTree/SynTree.h"
     
    1321
    1422namespace SymTab {
     23        Type *implementationType( Type *, const SymTab::Indexer &indexer );
    1524
    16 Type *implementationType( Type *, const SymTab::Indexer &indexer );
    17 
    18 template< typename InputIterator, typename OutputIterator >
    19 void
    20 implementationTypeList( InputIterator begin, InputIterator end, OutputIterator out, const SymTab::Indexer &indexer )
    21 {
    22   while ( begin != end ) {
    23     *out++ = implementationType( *begin++, indexer );
    24   }
    25 }
    26 
     25        template< typename InputIterator, typename OutputIterator >
     26        void implementationTypeList( InputIterator begin, InputIterator end, OutputIterator out, const SymTab::Indexer &indexer ) {
     27                while ( begin != end ) {
     28                        *out++ = implementationType( *begin++, indexer );
     29                } // while
     30        }
    2731} // namespace SymTab
    2832
    29 #endif /* #ifndef SYMTAB_IMPLEMENTATIONTYPE_H */
     33#endif // IMPLEMENTATIONTYPE_H
     34
     35// Local Variables: //
     36// tab-width: 4 //
     37// mode: c++ //
     38// compile-command: "make install" //
     39// End: //
  • translator/SymTab/Indexer.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Indexer.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 21:37:33 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 21:38:44 2015
     13// Update Count     : 2
     14//
     15
    116#include "SynTree/Declaration.h"
    217#include "SynTree/Type.h"
     
    1631
    1732    void Indexer::visit( ObjectDecl *objectDecl ) {
    18         maybeAccept( objectDecl->get_type(), *this );
    19         maybeAccept( objectDecl->get_init(), *this );
    20         maybeAccept( objectDecl->get_bitfieldWidth(), *this );
    21         if ( objectDecl->get_name() != "" ) {
    22             debugPrint( "Adding object " << objectDecl->get_name() << std::endl );
    23             idTable.addDecl( objectDecl );
    24         }
     33                maybeAccept( objectDecl->get_type(), *this );
     34                maybeAccept( objectDecl->get_init(), *this );
     35                maybeAccept( objectDecl->get_bitfieldWidth(), *this );
     36                if ( objectDecl->get_name() != "" ) {
     37                        debugPrint( "Adding object " << objectDecl->get_name() << std::endl );
     38                        idTable.addDecl( objectDecl );
     39                } // if
    2540    }
    2641
    2742    void Indexer::visit( FunctionDecl *functionDecl ) {
    28         if ( functionDecl->get_name() == "" ) return;
    29         debugPrint( "Adding function " << functionDecl->get_name() << std::endl );
    30         idTable.addDecl( functionDecl );
    31         enterScope();
    32         maybeAccept( functionDecl->get_functionType(), *this );
    33         acceptAll( functionDecl->get_oldDecls(), *this );
    34         maybeAccept( functionDecl->get_statements(), *this );
    35         leaveScope();
     43                if ( functionDecl->get_name() == "" ) return;
     44                debugPrint( "Adding function " << functionDecl->get_name() << std::endl );
     45                idTable.addDecl( functionDecl );
     46                enterScope();
     47                maybeAccept( functionDecl->get_functionType(), *this );
     48                acceptAll( functionDecl->get_oldDecls(), *this );
     49                maybeAccept( functionDecl->get_statements(), *this );
     50                leaveScope();
    3651    }
    3752
     
    5671
    5772    void Indexer::visit( TypeDecl *typeDecl ) {
    58         // see A NOTE ON THE ORDER OF TRAVERSAL, above
    59         // note that assertions come after the type is added to the symtab, since they aren't part
    60         // of the type proper and may depend on the type itself
    61         enterScope();
    62         acceptAll( typeDecl->get_parameters(), *this );
    63         maybeAccept( typeDecl->get_base(), *this );
    64         leaveScope();
    65         debugPrint( "Adding type " << typeDecl->get_name() << std::endl );
    66         typeTable.add( typeDecl );
    67         acceptAll( typeDecl->get_assertions(), *this );
     73                // see A NOTE ON THE ORDER OF TRAVERSAL, above
     74                // note that assertions come after the type is added to the symtab, since they aren't part
     75                // of the type proper and may depend on the type itself
     76                enterScope();
     77                acceptAll( typeDecl->get_parameters(), *this );
     78                maybeAccept( typeDecl->get_base(), *this );
     79                leaveScope();
     80                debugPrint( "Adding type " << typeDecl->get_name() << std::endl );
     81                typeTable.add( typeDecl );
     82                acceptAll( typeDecl->get_assertions(), *this );
    6883    }
    6984
    7085    void Indexer::visit( TypedefDecl *typeDecl ) {
    71         enterScope();
    72         acceptAll( typeDecl->get_parameters(), *this );
    73         maybeAccept( typeDecl->get_base(), *this );
    74         leaveScope();
    75         debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl );
    76         typeTable.add( typeDecl );
     86                enterScope();
     87                acceptAll( typeDecl->get_parameters(), *this );
     88                maybeAccept( typeDecl->get_base(), *this );
     89                leaveScope();
     90                debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl );
     91                typeTable.add( typeDecl );
    7792    }
    7893
    7994    void Indexer::visit( StructDecl *aggregateDecl ) {
    80         // make up a forward declaration and add it before processing the members
    81         StructDecl fwdDecl( aggregateDecl->get_name() );
    82         cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
    83         debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl );
    84         structTable.add( &fwdDecl );
    85  
    86         enterScope();
    87         acceptAll( aggregateDecl->get_parameters(), *this );
    88         acceptAll( aggregateDecl->get_members(), *this );
    89         leaveScope();
    90  
    91         debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl );
    92         // this addition replaces the forward declaration
    93         structTable.add( aggregateDecl );
     95                // make up a forward declaration and add it before processing the members
     96                StructDecl fwdDecl( aggregateDecl->get_name() );
     97                cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
     98                debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl );
     99                structTable.add( &fwdDecl );
     100 
     101                enterScope();
     102                acceptAll( aggregateDecl->get_parameters(), *this );
     103                acceptAll( aggregateDecl->get_members(), *this );
     104                leaveScope();
     105 
     106                debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl );
     107                // this addition replaces the forward declaration
     108                structTable.add( aggregateDecl );
    94109    }
    95110
    96111    void Indexer::visit( UnionDecl *aggregateDecl ) {
    97         // make up a forward declaration and add it before processing the members
    98         UnionDecl fwdDecl( aggregateDecl->get_name() );
    99         cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
    100         debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl );
    101         unionTable.add( &fwdDecl );
    102  
    103         enterScope();
    104         acceptAll( aggregateDecl->get_parameters(), *this );
    105         acceptAll( aggregateDecl->get_members(), *this );
    106         leaveScope();
    107  
    108         debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl );
    109         unionTable.add( aggregateDecl );
     112                // make up a forward declaration and add it before processing the members
     113                UnionDecl fwdDecl( aggregateDecl->get_name() );
     114                cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
     115                debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl );
     116                unionTable.add( &fwdDecl );
     117 
     118                enterScope();
     119                acceptAll( aggregateDecl->get_parameters(), *this );
     120                acceptAll( aggregateDecl->get_members(), *this );
     121                leaveScope();
     122 
     123                debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl );
     124                unionTable.add( aggregateDecl );
    110125    }
    111126
    112127    void Indexer::visit( EnumDecl *aggregateDecl ) {
    113         debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl );
    114         enumTable.add( aggregateDecl );
    115         // unlike structs, contexts, and unions, enums inject their members into the global scope
    116         acceptAll( aggregateDecl->get_members(), *this );
     128                debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl );
     129                enumTable.add( aggregateDecl );
     130                // unlike structs, contexts, and unions, enums inject their members into the global scope
     131                acceptAll( aggregateDecl->get_members(), *this );
    117132    }
    118133
    119134    void Indexer::visit( ContextDecl *aggregateDecl ) {
    120         enterScope();
    121         acceptAll( aggregateDecl->get_parameters(), *this );
    122         acceptAll( aggregateDecl->get_members(), *this );
    123         leaveScope();
    124  
    125         debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl );
    126         contextTable.add( aggregateDecl );
     135                enterScope();
     136                acceptAll( aggregateDecl->get_parameters(), *this );
     137                acceptAll( aggregateDecl->get_members(), *this );
     138                leaveScope();
     139 
     140                debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl );
     141                contextTable.add( aggregateDecl );
    127142    }
    128143
    129144    void Indexer::visit( CompoundStmt *compoundStmt ) {
    130         enterScope();
    131         acceptAll( compoundStmt->get_kids(), *this );
    132         leaveScope();
     145                enterScope();
     146                acceptAll( compoundStmt->get_kids(), *this );
     147                leaveScope();
    133148    }
    134149
    135150    void Indexer::visit( ContextInstType *contextInst ) {
    136         acceptAll( contextInst->get_parameters(), *this );
    137         acceptAll( contextInst->get_members(), *this );
     151                acceptAll( contextInst->get_parameters(), *this );
     152                acceptAll( contextInst->get_members(), *this );
    138153    }
    139154
    140155    void Indexer::visit( StructInstType *structInst ) {
    141         if ( ! structTable.lookup( structInst->get_name() ) ) {
    142             debugPrint( "Adding struct " << structInst->get_name() << " from implicit forward declaration" << std::endl );
    143             structTable.add( structInst->get_name() );
    144         }
    145         enterScope();
    146         acceptAll( structInst->get_parameters(), *this );
    147         leaveScope();
     156                if ( ! structTable.lookup( structInst->get_name() ) ) {
     157                        debugPrint( "Adding struct " << structInst->get_name() << " from implicit forward declaration" << std::endl );
     158                        structTable.add( structInst->get_name() );
     159                }
     160                enterScope();
     161                acceptAll( structInst->get_parameters(), *this );
     162                leaveScope();
    148163    }
    149164
    150165    void Indexer::visit( UnionInstType *unionInst ) {
    151         if ( ! unionTable.lookup( unionInst->get_name() ) ) {
    152             debugPrint( "Adding union " << unionInst->get_name() << " from implicit forward declaration" << std::endl );
    153             unionTable.add( unionInst->get_name() );
    154         }
    155         enterScope();
    156         acceptAll( unionInst->get_parameters(), *this );
    157         leaveScope();
     166                if ( ! unionTable.lookup( unionInst->get_name() ) ) {
     167                        debugPrint( "Adding union " << unionInst->get_name() << " from implicit forward declaration" << std::endl );
     168                        unionTable.add( unionInst->get_name() );
     169                }
     170                enterScope();
     171                acceptAll( unionInst->get_parameters(), *this );
     172                leaveScope();
    158173    }
    159174
     
    167182
    168183    void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const {
    169         idTable.lookupId( id, list );
     184                idTable.lookupId( id, list );
    170185    }
    171186
    172187    DeclarationWithType* Indexer::lookupId( const std::string &id) const {
    173         return idTable.lookupId(id);
     188                return idTable.lookupId(id);
    174189    }
    175190
    176191    NamedTypeDecl *Indexer::lookupType( const std::string &id ) const {
    177         return typeTable.lookup( id );
     192                return typeTable.lookup( id );
    178193    }
    179194
    180195    StructDecl *Indexer::lookupStruct( const std::string &id ) const {
    181         return structTable.lookup( id );
     196                return structTable.lookup( id );
    182197    }
    183198
    184199    EnumDecl *Indexer::lookupEnum( const std::string &id ) const {
    185         return enumTable.lookup( id );
     200                return enumTable.lookup( id );
    186201    }
    187202
    188203    UnionDecl *Indexer::lookupUnion( const std::string &id ) const {
    189         return unionTable.lookup( id );
     204                return unionTable.lookup( id );
    190205    }
    191206
    192207    ContextDecl  * Indexer::lookupContext( const std::string &id ) const {
    193         return contextTable.lookup( id );
     208                return contextTable.lookup( id );
    194209    }
    195210
    196211    void Indexer::enterScope() {
    197         if ( doDebug ) {
    198             std::cout << "--- Entering scope" << std::endl;
    199         }
    200         idTable.enterScope();
    201         typeTable.enterScope();
    202         structTable.enterScope();
    203         enumTable.enterScope();
    204         unionTable.enterScope();
    205         contextTable.enterScope();
     212                if ( doDebug ) {
     213                        std::cout << "--- Entering scope" << std::endl;
     214                }
     215                idTable.enterScope();
     216                typeTable.enterScope();
     217                structTable.enterScope();
     218                enumTable.enterScope();
     219                unionTable.enterScope();
     220                contextTable.enterScope();
    206221    }
    207222
    208223    void Indexer::leaveScope() {
    209         using std::cout;
    210         using std::endl;
    211  
    212         if ( doDebug ) {
    213             cout << "--- Leaving scope containing" << endl;
    214             idTable.dump( cout );
    215             typeTable.dump( cout );
    216             structTable.dump( cout );
    217             enumTable.dump( cout );
    218             unionTable.dump( cout );
    219             contextTable.dump( cout );
    220         }
    221         idTable.leaveScope();
    222         typeTable.leaveScope();
    223         structTable.leaveScope();
    224         enumTable.leaveScope();
    225         unionTable.leaveScope();
    226         contextTable.leaveScope();
     224                using std::cout;
     225                using std::endl;
     226 
     227                if ( doDebug ) {
     228                        cout << "--- Leaving scope containing" << endl;
     229                        idTable.dump( cout );
     230                        typeTable.dump( cout );
     231                        structTable.dump( cout );
     232                        enumTable.dump( cout );
     233                        unionTable.dump( cout );
     234                        contextTable.dump( cout );
     235                }
     236                idTable.leaveScope();
     237                typeTable.leaveScope();
     238                structTable.leaveScope();
     239                enumTable.leaveScope();
     240                unionTable.leaveScope();
     241                contextTable.leaveScope();
    227242    }
    228243
     
    244259        contextTable.dump( os );
    245260#if 0
    246         idTable.dump( os );
    247         typeTable.dump( os );
    248         structTable.dump( os );
    249         enumTable.dump( os );
    250         unionTable.dump( os );
    251         contextTable.dump( os );
     261                idTable.dump( os );
     262                typeTable.dump( os );
     263                structTable.dump( os );
     264                enumTable.dump( os );
     265                unionTable.dump( os );
     266                contextTable.dump( os );
    252267#endif
    253268    }
    254269} // namespace SymTab
     270
     271// Local Variables: //
     272// tab-width: 4 //
     273// mode: c++ //
     274// compile-command: "make install" //
     275// End: //
  • translator/SymTab/Indexer.h

    ra32b204 r0dd3a2f  
    1 #ifndef SYMTAB_INDEXER_H
    2 #define SYMTAB_INDEXER_H
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Indexer.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 21:38:55 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 21:40:17 2015
     13// Update Count     : 2
     14//
     15
     16#ifndef INDEXER_H
     17#define INDEXER_H
    318
    419#include <list>
     
    6176} // namespace SymTab
    6277
    63 #endif // SYMTAB_INDEXER_H
     78#endif // INDEXER_H
     79
     80// Local Variables: //
     81// tab-width: 4 //
     82// mode: c++ //
     83// compile-command: "make install" //
     84// End: //
  • translator/SymTab/Mangler.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Mangler.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 21:40:29 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 21:43:49 2015
     13// Update Count     : 2
     14//
     15
    116#include <cassert>
    217#include <string>
     
    1530
    1631namespace SymTab {
    17     Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true )
    18     {}
     32    Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true ) {
     33        }
    1934
    2035//Mangler::Mangler( const Mangler & )
     
    2338//}
    2439    Mangler::Mangler( const Mangler &rhs ) : mangleName() {
    25         varNums = rhs.varNums;
    26         nextVarNum = rhs.nextVarNum;
    27         isTopLevel = rhs.isTopLevel;
     40                varNums = rhs.varNums;
     41                nextVarNum = rhs.nextVarNum;
     42                isTopLevel = rhs.isTopLevel;
    2843    }
    2944
    3045    void Mangler::mangleDecl( DeclarationWithType *declaration ) {
    31         bool wasTopLevel = isTopLevel;
    32         if ( isTopLevel ) {
    33             varNums.clear();
    34             nextVarNum = 0;
    35             isTopLevel = false;
    36         }
    37         mangleName << "__";
    38         CodeGen::OperatorInfo opInfo;
    39         if ( operatorLookup( declaration->get_name(), opInfo ) ) {
    40             mangleName << opInfo.outputName;
    41         } else {
    42             mangleName << declaration->get_name();
    43         }
    44         mangleName << "__";
    45         maybeAccept( declaration->get_type(), *this );
    46         isTopLevel = wasTopLevel;
     46                bool wasTopLevel = isTopLevel;
     47                if ( isTopLevel ) {
     48                        varNums.clear();
     49                        nextVarNum = 0;
     50                        isTopLevel = false;
     51                } // if
     52                mangleName << "__";
     53                CodeGen::OperatorInfo opInfo;
     54                if ( operatorLookup( declaration->get_name(), opInfo ) ) {
     55                        mangleName << opInfo.outputName;
     56                } else {
     57                        mangleName << declaration->get_name();
     58                } // if
     59                mangleName << "__";
     60                maybeAccept( declaration->get_type(), *this );
     61                isTopLevel = wasTopLevel;
    4762    }
    4863
    4964    void Mangler::visit( ObjectDecl *declaration ) {
    50         mangleDecl( declaration );
     65                mangleDecl( declaration );
    5166    }
    5267
    5368    void Mangler::visit( FunctionDecl *declaration ) {
    54         mangleDecl( declaration );
     69                mangleDecl( declaration );
    5570    }
    5671
    5772    void Mangler::visit( VoidType *voidType ) {
    58         printQualifiers( voidType );
    59         mangleName << "v";
     73                printQualifiers( voidType );
     74                mangleName << "v";
    6075    }
    6176
    6277    void Mangler::visit( BasicType *basicType ) {
    63         static const char *btLetter[] = {
    64             "b",        // Bool
    65             "c",        // Char
    66             "Sc",       // SignedChar
    67             "Uc",       // UnsignedChar
    68             "s",        // ShortSignedInt
    69             "Us",       // ShortUnsignedInt
    70             "i",        // SignedInt
    71             "Ui",       // UnsignedInt
    72             "l",        // LongSignedInt
    73             "Ul",       // LongUnsignedInt
    74             "q",        // LongLongSignedInt
    75             "Uq",       // LongLongUnsignedInt
    76             "f",        // Float
    77             "d",        // Double
    78             "r",        // LongDouble
    79             "Xf",       // FloatComplex
    80             "Xd",       // DoubleComplex
    81             "Xr",       // LongDoubleComplex
    82             "If",       // FloatImaginary
    83             "Id",       // DoubleImaginary
    84             "Ir",       // LongDoubleImaginary
    85         };
     78                static const char *btLetter[] = {
     79                        "b",    // Bool
     80                        "c",    // Char
     81                        "Sc",   // SignedChar
     82                        "Uc",   // UnsignedChar
     83                        "s",    // ShortSignedInt
     84                        "Us",   // ShortUnsignedInt
     85                        "i",    // SignedInt
     86                        "Ui",   // UnsignedInt
     87                        "l",    // LongSignedInt
     88                        "Ul",   // LongUnsignedInt
     89                        "q",    // LongLongSignedInt
     90                        "Uq",   // LongLongUnsignedInt
     91                        "f",    // Float
     92                        "d",    // Double
     93                        "r",    // LongDouble
     94                        "Xf",   // FloatComplex
     95                        "Xd",   // DoubleComplex
     96                        "Xr",   // LongDoubleComplex
     97                        "If",   // FloatImaginary
     98                        "Id",   // DoubleImaginary
     99                        "Ir",   // LongDoubleImaginary
     100                };
    86101 
    87         printQualifiers( basicType );
    88         mangleName << btLetter[ basicType->get_kind() ];
     102                printQualifiers( basicType );
     103                mangleName << btLetter[ basicType->get_kind() ];
    89104    }
    90105
    91106    void Mangler::visit( PointerType *pointerType ) {
    92         printQualifiers( pointerType );
    93         mangleName << "P";
    94         maybeAccept( pointerType->get_base(), *this );
     107                printQualifiers( pointerType );
     108                mangleName << "P";
     109                maybeAccept( pointerType->get_base(), *this );
    95110    }
    96111
    97112    void Mangler::visit( ArrayType *arrayType ) {
    98         // TODO: encode dimension
    99         printQualifiers( arrayType );
    100         mangleName << "A0";
    101         maybeAccept( arrayType->get_base(), *this );
     113                // TODO: encode dimension
     114                printQualifiers( arrayType );
     115                mangleName << "A0";
     116                maybeAccept( arrayType->get_base(), *this );
    102117    }
    103118
    104119    namespace {
    105         inline std::list< Type* >
    106         getTypes( const std::list< DeclarationWithType* > decls )
    107         {
    108             std::list< Type* > ret;
    109             std::transform( decls.begin(), decls.end(), std::back_inserter( ret ),
    110                             std::mem_fun( &DeclarationWithType::get_type ) );
    111             return ret;
    112         }
     120                inline std::list< Type* > getTypes( const std::list< DeclarationWithType* > decls ) {
     121                        std::list< Type* > ret;
     122                        std::transform( decls.begin(), decls.end(), std::back_inserter( ret ),
     123                                                        std::mem_fun( &DeclarationWithType::get_type ) );
     124                        return ret;
     125                }
    113126    }
    114127
    115128    void Mangler::visit( FunctionType *functionType ) {
    116         printQualifiers( functionType );
    117         mangleName << "F";
    118         std::list< Type* > returnTypes = getTypes( functionType->get_returnVals() );
    119         acceptAll( returnTypes, *this );
    120         mangleName << "_";
    121         std::list< Type* > paramTypes = getTypes( functionType->get_parameters() );
    122         acceptAll( paramTypes, *this );
    123         mangleName << "_";
     129                printQualifiers( functionType );
     130                mangleName << "F";
     131                std::list< Type* > returnTypes = getTypes( functionType->get_returnVals() );
     132                acceptAll( returnTypes, *this );
     133                mangleName << "_";
     134                std::list< Type* > paramTypes = getTypes( functionType->get_parameters() );
     135                acceptAll( paramTypes, *this );
     136                mangleName << "_";
    124137    }
    125138
    126139    void Mangler::mangleRef( ReferenceToType *refType, std::string prefix ) {
    127         printQualifiers( refType );
    128         mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name();
     140                printQualifiers( refType );
     141                mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name();
    129142    }
    130143
    131144    void Mangler::visit( StructInstType *aggregateUseType ) {
    132         mangleRef( aggregateUseType, "s" );
     145                mangleRef( aggregateUseType, "s" );
    133146    }
    134147
    135148    void Mangler::visit( UnionInstType *aggregateUseType ) {
    136         mangleRef( aggregateUseType, "u" );
     149                mangleRef( aggregateUseType, "u" );
    137150    }
    138151
    139152    void Mangler::visit( EnumInstType *aggregateUseType ) {
    140         mangleRef( aggregateUseType, "e" );
     153                mangleRef( aggregateUseType, "e" );
    141154    }
    142155
    143156    void Mangler::visit( TypeInstType *typeInst ) {
    144         VarMapType::iterator varNum = varNums.find( typeInst->get_name() );
    145         if ( varNum == varNums.end() ) {
    146             mangleRef( typeInst, "t" );
    147         } else {
    148             printQualifiers( typeInst );
    149             std::ostrstream numStream;
    150             numStream << varNum->second.first;
    151             mangleName << (numStream.pcount() + 1);
    152             switch ( (TypeDecl::Kind )varNum->second.second ) {
    153               case TypeDecl::Any:
    154                 mangleName << "t";
    155                 break;
    156               case TypeDecl::Dtype:
    157                 mangleName << "d";
    158                 break;
    159               case TypeDecl::Ftype:
    160                 mangleName << "f";
    161                 break;
    162             }
    163             mangleName << std::string( numStream.str(), numStream.pcount() );
    164         }
     157                VarMapType::iterator varNum = varNums.find( typeInst->get_name() );
     158                if ( varNum == varNums.end() ) {
     159                        mangleRef( typeInst, "t" );
     160                } else {
     161                        printQualifiers( typeInst );
     162                        std::ostrstream numStream;
     163                        numStream << varNum->second.first;
     164                        mangleName << (numStream.pcount() + 1);
     165                        switch ( (TypeDecl::Kind )varNum->second.second ) {
     166                          case TypeDecl::Any:
     167                                mangleName << "t";
     168                                break;
     169                          case TypeDecl::Dtype:
     170                                mangleName << "d";
     171                                break;
     172                          case TypeDecl::Ftype:
     173                                mangleName << "f";
     174                                break;
     175                        } // switch
     176                        mangleName << std::string( numStream.str(), numStream.pcount() );
     177                } // if
    165178    }
    166179
    167180    void Mangler::visit( TupleType *tupleType ) {
    168         printQualifiers( tupleType );
    169         mangleName << "T";
    170         acceptAll( tupleType->get_types(), *this );
    171         mangleName << "_";
     181                printQualifiers( tupleType );
     182                mangleName << "T";
     183                acceptAll( tupleType->get_types(), *this );
     184                mangleName << "_";
    172185    }
    173186
    174187    void Mangler::visit( TypeDecl *decl ) {
    175         static const char *typePrefix[] = { "BT", "BD", "BF" };
    176         mangleName << typePrefix[ decl->get_kind() ] << ( decl->get_name().length() + 1 ) << decl->get_name();
     188                static const char *typePrefix[] = { "BT", "BD", "BF" };
     189                mangleName << typePrefix[ decl->get_kind() ] << ( decl->get_name().length() + 1 ) << decl->get_name();
    177190    }
    178191
    179192    void printVarMap( const std::map< std::string, std::pair< int, int > > &varMap, std::ostream &os ) {
    180         for ( std::map< std::string, std::pair< int, int > >::const_iterator i = varMap.begin(); i != varMap.end(); ++i ) {
    181             os << i->first << "(" << i->second.first << "/" << i->second.second << ")" << std::endl;
    182         }
     193                for ( std::map< std::string, std::pair< int, int > >::const_iterator i = varMap.begin(); i != varMap.end(); ++i ) {
     194                        os << i->first << "(" << i->second.first << "/" << i->second.second << ")" << std::endl;
     195                } // for
    183196    }
    184197
    185198    void Mangler::printQualifiers( Type *type ) {
    186         if ( ! type->get_forall().empty() ) {
    187             std::list< std::string > assertionNames;
    188             int tcount = 0, dcount = 0, fcount = 0;
    189             mangleName << "A";
    190             for ( std::list< TypeDecl* >::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
    191                 switch ( (*i)->get_kind() ) {
    192                   case TypeDecl::Any:
    193                     tcount++;
    194                     break;
    195                   case TypeDecl::Dtype:
    196                     dcount++;
    197                     break;
    198                   case TypeDecl::Ftype:
    199                     fcount++;
    200                     break;
    201                 }
    202                 varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() );
    203                 for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
    204                     Mangler sub_mangler;
    205                     sub_mangler.nextVarNum = nextVarNum;
    206                     sub_mangler.isTopLevel = false;
    207                     sub_mangler.varNums = varNums;
    208                     (*assert)->accept( sub_mangler );
    209                     assertionNames.push_back( std::string( sub_mangler.mangleName.str(), sub_mangler.mangleName.pcount() ) );
    210                 }
    211             }
    212             mangleName << tcount << "_" << dcount << "_" << fcount << "_";
    213             std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) );
    214             mangleName << "_";
    215         }
    216         if ( type->get_isConst() ) {
    217             mangleName << "C";
    218         }
    219         if ( type->get_isVolatile() ) {
    220             mangleName << "V";
    221         }
    222         if ( type->get_isRestrict() ) {
    223             mangleName << "R";
    224         }
    225         if ( type->get_isLvalue() ) {
    226             mangleName << "L";
    227         }
    228         if ( type->get_isAtomic() ) {
    229             mangleName << "A";
    230         }
    231     }
    232 } // SymTab
     199                if ( ! type->get_forall().empty() ) {
     200                        std::list< std::string > assertionNames;
     201                        int tcount = 0, dcount = 0, fcount = 0;
     202                        mangleName << "A";
     203                        for ( std::list< TypeDecl* >::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
     204                                switch ( (*i)->get_kind() ) {
     205                                  case TypeDecl::Any:
     206                                        tcount++;
     207                                        break;
     208                                  case TypeDecl::Dtype:
     209                                        dcount++;
     210                                        break;
     211                                  case TypeDecl::Ftype:
     212                                        fcount++;
     213                                        break;
     214                                } // switch
     215                                varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() );
     216                                for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
     217                                        Mangler sub_mangler;
     218                                        sub_mangler.nextVarNum = nextVarNum;
     219                                        sub_mangler.isTopLevel = false;
     220                                        sub_mangler.varNums = varNums;
     221                                        (*assert)->accept( sub_mangler );
     222                                        assertionNames.push_back( std::string( sub_mangler.mangleName.str(), sub_mangler.mangleName.pcount() ) );
     223                                } // for
     224                        } // for
     225                        mangleName << tcount << "_" << dcount << "_" << fcount << "_";
     226                        std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) );
     227                        mangleName << "_";
     228                } // if
     229                if ( type->get_isConst() ) {
     230                        mangleName << "C";
     231                } // if
     232                if ( type->get_isVolatile() ) {
     233                        mangleName << "V";
     234                } // if
     235                if ( type->get_isRestrict() ) {
     236                        mangleName << "R";
     237                } // if
     238                if ( type->get_isLvalue() ) {
     239                        mangleName << "L";
     240                } // if
     241                if ( type->get_isAtomic() ) {
     242                        mangleName << "A";
     243                } // if
     244    }
     245} // namespace SymTab
     246
     247// Local Variables: //
     248// tab-width: 4 //
     249// mode: c++ //
     250// compile-command: "make install" //
     251// End: //
  • translator/SymTab/Mangler.h

    ra32b204 r0dd3a2f  
    1 #ifndef SYMTAB_MANGLER_H
    2 #define SYMTAB_MANGLER_H
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Mangler.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 21:44:03 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 21:45:05 2015
     13// Update Count     : 2
     14//
     15
     16#ifndef MANGLER_H
     17#define MANGLER_H
    318
    419#include <strstream>
     
    924    class Mangler : public Visitor {
    1025      public:
    11         template< typename SynTreeClass >
     26                template< typename SynTreeClass >
    1227            static std::string mangle( SynTreeClass *decl ); // interface to clients
    1328
    1429///   using Visitor::visit;
    15         virtual void visit( ObjectDecl *declaration );
    16         virtual void visit( FunctionDecl *declaration );
    17         virtual void visit( TypeDecl *declaration );
     30                virtual void visit( ObjectDecl *declaration );
     31                virtual void visit( FunctionDecl *declaration );
     32                virtual void visit( TypeDecl *declaration );
    1833
    19         virtual void visit( VoidType *voidType );
    20         virtual void visit( BasicType *basicType );
    21         virtual void visit( PointerType *pointerType );
    22         virtual void visit( ArrayType *arrayType );
    23         virtual void visit( FunctionType *functionType );
    24         virtual void visit( StructInstType *aggregateUseType );
    25         virtual void visit( UnionInstType *aggregateUseType );
    26         virtual void visit( EnumInstType *aggregateUseType );
    27         virtual void visit( TypeInstType *aggregateUseType );
    28         virtual void visit( TupleType *tupleType );
     34                virtual void visit( VoidType *voidType );
     35                virtual void visit( BasicType *basicType );
     36                virtual void visit( PointerType *pointerType );
     37                virtual void visit( ArrayType *arrayType );
     38                virtual void visit( FunctionType *functionType );
     39                virtual void visit( StructInstType *aggregateUseType );
     40                virtual void visit( UnionInstType *aggregateUseType );
     41                virtual void visit( EnumInstType *aggregateUseType );
     42                virtual void visit( TypeInstType *aggregateUseType );
     43                virtual void visit( TupleType *tupleType );
    2944 
    30         std::string get_mangleName() { return std::string( mangleName.str(), mangleName.pcount() ); }
     45                std::string get_mangleName() { return std::string( mangleName.str(), mangleName.pcount() ); }
    3146      private:
    32         std::ostrstream mangleName;
    33         typedef std::map< std::string, std::pair< int, int > > VarMapType;
    34         VarMapType varNums;
    35         int nextVarNum;
    36         bool isTopLevel;
     47                std::ostrstream mangleName;
     48                typedef std::map< std::string, std::pair< int, int > > VarMapType;
     49                VarMapType varNums;
     50                int nextVarNum;
     51                bool isTopLevel;
    3752 
    38         Mangler();
    39         Mangler( const Mangler & );
     53                Mangler();
     54                Mangler( const Mangler & );
    4055 
    41         void mangleDecl( DeclarationWithType *declaration );
    42         void mangleRef( ReferenceToType *refType, std::string prefix );
     56                void mangleDecl( DeclarationWithType *declaration );
     57                void mangleRef( ReferenceToType *refType, std::string prefix );
    4358 
    44         void printQualifiers( Type *type );
     59                void printQualifiers( Type *type );
    4560    }; // Mangler
    4661
    4762    template< typename SynTreeClass >
    4863    std::string Mangler::mangle( SynTreeClass *decl ) {
    49         Mangler mangler;
    50         maybeAccept( decl, mangler );
    51         return mangler.get_mangleName();
     64                Mangler mangler;
     65                maybeAccept( decl, mangler );
     66                return mangler.get_mangleName();
    5267    }
    5368} // SymTab
    5469
    55 #endif // SYMTAB_MANGLER_H
     70#endif // MANGLER_H
     71
     72// Local Variables: //
     73// tab-width: 4 //
     74// mode: c++ //
     75// compile-command: "make install" //
     76// End: //
  • translator/SymTab/StackTable.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// StackTable.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 21:45:15 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 21:46:59 2015
     13// Update Count     : 2
     14//
     15
    116#include <cassert>
    217
     
    520namespace SymTab {
    621    template< typename Element, typename ConflictFunction >
    7     StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 )
    8     {}
     22    StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) {
     23        }
    924
    1025    template< typename Element, typename ConflictFunction >
    1126    void StackTable< Element, ConflictFunction >::enterScope() {
    12         scopeLevel++;
     27                scopeLevel++;
    1328    }
    1429
    1530    template< typename Element, typename ConflictFunction >
    1631    void StackTable< Element, ConflictFunction >::leaveScope() {
    17         for ( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) {
    18             std::stack< Entry >& entry = it->second;
    19             if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    20                 entry.pop();
    21             }
    22         }
    23         scopeLevel--;
    24         assert( scopeLevel >= 0 );
     32                for ( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) {
     33                        std::stack< Entry >& entry = it->second;
     34                        if ( ! entry.empty() && entry.top().second == scopeLevel ) {
     35                                entry.pop();
     36                        } // if
     37                } // for
     38                scopeLevel--;
     39                assert( scopeLevel >= 0 );
    2540    }
    2641
    2742    template< typename Element, typename ConflictFunction >
    2843    void StackTable< Element, ConflictFunction >::add( Element *type ) {
    29         std::stack< Entry >& entry = table[ type->get_name() ];
    30         if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    31             entry.top().first = conflictFunction( entry.top().first, type );
    32         } else {
    33             entry.push( Entry( type, scopeLevel ) );
    34         }
     44                std::stack< Entry >& entry = table[ type->get_name() ];
     45                if ( ! entry.empty() && entry.top().second == scopeLevel ) {
     46                        entry.top().first = conflictFunction( entry.top().first, type );
     47                } else {
     48                        entry.push( Entry( type, scopeLevel ) );
     49                } // if
    3550    }
    3651
    3752    template< typename Element, typename ConflictFunction >
    3853    void StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) {
    39         add( new Element( fwdDeclName ) );
     54                add( new Element( fwdDeclName ) );
    4055    }
    4156
    4257    template< typename Element, typename ConflictFunction >
    4358    Element *StackTable< Element, ConflictFunction >::lookup( std::string id ) const {
    44         typename TableType::const_iterator it = table.find( id );
    45         if ( it == table.end() ) {
    46             return 0;
    47         } else if ( ! it->second.empty() ) {
    48             return it->second.top().first;
    49         } else {
    50             return 0;
    51         }
     59                typename TableType::const_iterator it = table.find( id );
     60                if ( it == table.end() ) {
     61                        return 0;
     62                } else if ( ! it->second.empty() ) {
     63                        return it->second.top().first;
     64                } else {
     65                        return 0;
     66                } // if
    5267    }
    5368
    5469    template< typename Element, typename ConflictFunction >
    5570    void StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const {
    56         for ( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) {
    57             const std::stack< Entry >& entry = it->second;
    58             if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    59                 os << it->first << std::endl;
    60             }
    61         }
     71                for ( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) {
     72                        const std::stack< Entry >& entry = it->second;
     73                        if ( ! entry.empty() && entry.top().second == scopeLevel ) {
     74                                os << it->first << std::endl;
     75                        } // if
     76                } // for
    6277    }
    63 } // SymTab
     78} // namespace SymTab
     79
     80// Local Variables: //
     81// tab-width: 4 //
     82// mode: c++ //
     83// compile-command: "make install" //
     84// End: //
  • translator/SymTab/StackTable.h

    ra32b204 r0dd3a2f  
    1 #ifndef SYMTAB_STACKTABLE_H
    2 #define SYMTAB_STACKTABLE_H
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// StackTable.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 21:47:10 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 21:48:15 2015
     13// Update Count     : 3
     14//
     15
     16#ifndef STACKTABLE_H
     17#define STACKTABLE_H
    318
    419#include <map>
     
    1126        class StackTable {
    1227      public:
    13         StackTable();
     28                StackTable();
    1429
    15         void enterScope();
    16         void leaveScope();
    17         void add( Element *type );
    18         void add( std::string fwdDeclName );
    19         Element *lookup( std::string id ) const;
     30                void enterScope();
     31                void leaveScope();
     32                void add( Element *type );
     33                void add( std::string fwdDeclName );
     34                Element *lookup( std::string id ) const;
    2035
    21         void dump( std::ostream &os ) const; // debugging
     36                void dump( std::ostream &os ) const;                    // debugging
    2237      private:
    23         typedef std::pair< Element*, int > Entry;
    24         typedef std::map< std::string, std::stack< Entry > > TableType;
     38                typedef std::pair< Element*, int > Entry;
     39                typedef std::map< std::string, std::stack< Entry > > TableType;
    2540 
    26         ConflictFunction conflictFunction;
    27         TableType table;
    28         int scopeLevel;
     41                ConflictFunction conflictFunction;
     42                TableType table;
     43                int scopeLevel;
    2944    };
    3045} // SymTab
     
    3247#include "StackTable.cc"
    3348
    34 #endif // SYMTAB_STACKTABLE_H
     49#endif // STACKTABLE_H
     50
     51// Local Variables: //
     52// tab-width: 4 //
     53// mode: c++ //
     54// compile-command: "make install" //
     55// End: //
  • translator/SymTab/TypeTable.h

    ra32b204 r0dd3a2f  
    1 #ifndef SYMTAB_TYPETABLE_H
    2 #define SYMTAB_TYPETABLE_H
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// TypeTable.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 21:48:32 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 21:49:49 2015
     13// Update Count     : 2
     14//
     15
     16#ifndef TYPETABLE_H
     17#define TYPETABLE_H
    318
    419#include <cassert>
     
    1429    class TypeTableConflictFunction : public std::binary_function< NamedTypeDecl *, NamedTypeDecl *, NamedTypeDecl * > {
    1530      public:
    16         NamedTypeDecl *operator()( NamedTypeDecl *existing, NamedTypeDecl *added ) {
    17             if ( existing->get_base() == 0 ) {
    18                 return added;
    19             } else if ( added->get_base() == 0 ) {
    20                 return existing;
    21             } else {
    22                 throw SemanticError( "redeclaration of ", added );
    23             }
    24             assert( false );
    25             return 0;
    26         }
     31                NamedTypeDecl *operator()( NamedTypeDecl *existing, NamedTypeDecl *added ) {
     32                        if ( existing->get_base() == 0 ) {
     33                                return added;
     34                        } else if ( added->get_base() == 0 ) {
     35                                return existing;
     36                        } else {
     37                                throw SemanticError( "redeclaration of ", added );
     38                        } // if
     39                        assert( false );
     40                        return 0;
     41                }
    2742    };
    2843
    2944    typedef StackTable< NamedTypeDecl, TypeTableConflictFunction > TypeTable;
    30 } // SymTab
     45} // namespace SymTab
    3146
    32 #endif // SYMTAB_TYPETABLE_H
     47#endif // TYPETABLE_H
     48
     49// Local Variables: //
     50// tab-width: 4 //
     51// mode: c++ //
     52// compile-command: "make install" //
     53// End: //
  • translator/SymTab/Validate.cc

    ra32b204 r0dd3a2f  
    1 /*
    2   The "validate" phase of translation is used to take a syntax tree and convert it into a standard form that aims to be
    3   as regular in structure as possible.  Some assumptions can be made regarding the state of the tree after this pass is
    4   complete, including:
    5 
    6   - No nested structure or union definitions; any in the input are "hoisted" to the level of the containing struct or
    7     union.
    8 
    9   - All enumeration constants have type EnumInstType.
    10 
    11   - The type "void" never occurs in lists of function parameter or return types; neither do tuple types.  A function
    12     taking no arguments has no argument types, and tuples are flattened.
    13 
    14   - No context instances exist; they are all replaced by the set of declarations signified by the context, instantiated
    15     by the particular set of type arguments.
    16 
    17   - Every declaration is assigned a unique id.
    18 
    19   - No typedef declarations or instances exist; the actual type is substituted for each instance.
    20 
    21   - Each type, struct, and union definition is followed by an appropriate assignment operator.
    22 
    23   - Each use of a struct or union is connected to a complete definition of that struct or union, even if that definition
    24     occurs later in the input.
    25 */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Validate.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 21:50:04 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 21:53:16 2015
     13// Update Count     : 2
     14//
     15
     16// The "validate" phase of translation is used to take a syntax tree and convert it into a standard form that aims to be
     17// as regular in structure as possible.  Some assumptions can be made regarding the state of the tree after this pass is
     18// complete, including:
     19//
     20// - No nested structure or union definitions; any in the input are "hoisted" to the level of the containing struct or
     21//   union.
     22//
     23// - All enumeration constants have type EnumInstType.
     24//
     25// - The type "void" never occurs in lists of function parameter or return types; neither do tuple types.  A function
     26//   taking no arguments has no argument types, and tuples are flattened.
     27//
     28// - No context instances exist; they are all replaced by the set of declarations signified by the context, instantiated
     29//   by the particular set of type arguments.
     30//
     31// - Every declaration is assigned a unique id.
     32//
     33// - No typedef declarations or instances exist; the actual type is substituted for each instance.
     34//
     35// - Each type, struct, and union definition is followed by an appropriate assignment operator.
     36//
     37// - Each use of a struct or union is connected to a complete definition of that struct or union, even if that
     38//   definition occurs later in the input.
    2639
    2740#include <list>
     
    4659    class HoistStruct : public Visitor {
    4760      public:
    48         static void hoistStruct( std::list< Declaration * > &translationUnit );
    49  
    50         std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
    51  
    52         virtual void visit( StructDecl *aggregateDecl );
    53         virtual void visit( UnionDecl *aggregateDecl );
    54 
    55         virtual void visit( CompoundStmt *compoundStmt );
    56         virtual void visit( IfStmt *ifStmt );
    57         virtual void visit( WhileStmt *whileStmt );
    58         virtual void visit( ForStmt *forStmt );
    59         virtual void visit( SwitchStmt *switchStmt );
    60         virtual void visit( ChooseStmt *chooseStmt );
    61         virtual void visit( CaseStmt *caseStmt );
    62         virtual void visit( CatchStmt *catchStmt );
     61                static void hoistStruct( std::list< Declaration * > &translationUnit );
     62 
     63                std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
     64 
     65                virtual void visit( StructDecl *aggregateDecl );
     66                virtual void visit( UnionDecl *aggregateDecl );
     67
     68                virtual void visit( CompoundStmt *compoundStmt );
     69                virtual void visit( IfStmt *ifStmt );
     70                virtual void visit( WhileStmt *whileStmt );
     71                virtual void visit( ForStmt *forStmt );
     72                virtual void visit( SwitchStmt *switchStmt );
     73                virtual void visit( ChooseStmt *chooseStmt );
     74                virtual void visit( CaseStmt *caseStmt );
     75                virtual void visit( CatchStmt *catchStmt );
    6376      private:
    64         HoistStruct();
    65 
    66         template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );
    67 
    68         std::list< Declaration * > declsToAdd;
    69         bool inStruct;
     77                HoistStruct();
     78
     79                template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );
     80
     81                std::list< Declaration * > declsToAdd;
     82                bool inStruct;
    7083    };
    7184
    7285    class Pass1 : public Visitor {
    73         typedef Visitor Parent;
    74         virtual void visit( EnumDecl *aggregateDecl );
    75         virtual void visit( FunctionType *func );
     86                typedef Visitor Parent;
     87                virtual void visit( EnumDecl *aggregateDecl );
     88                virtual void visit( FunctionType *func );
    7689    };
    7790 
    7891    class Pass2 : public Indexer {
    79         typedef Indexer Parent;
     92                typedef Indexer Parent;
    8093      public:
    81         Pass2( bool doDebug, const Indexer *indexer );
     94                Pass2( bool doDebug, const Indexer *indexer );
    8295      private:
    83         virtual void visit( StructInstType *structInst );
    84         virtual void visit( UnionInstType *unionInst );
    85         virtual void visit( ContextInstType *contextInst );
    86         virtual void visit( StructDecl *structDecl );
    87         virtual void visit( UnionDecl *unionDecl );
    88         virtual void visit( TypeInstType *typeInst );
    89 
    90         const Indexer *indexer;
    91  
    92         typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType;
    93         typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType;
    94         ForwardStructsType forwardStructs;
    95         ForwardUnionsType forwardUnions;
     96                virtual void visit( StructInstType *structInst );
     97                virtual void visit( UnionInstType *unionInst );
     98                virtual void visit( ContextInstType *contextInst );
     99                virtual void visit( StructDecl *structDecl );
     100                virtual void visit( UnionDecl *unionDecl );
     101                virtual void visit( TypeInstType *typeInst );
     102
     103                const Indexer *indexer;
     104 
     105                typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType;
     106                typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType;
     107                ForwardStructsType forwardStructs;
     108                ForwardUnionsType forwardUnions;
    96109    };
    97110
    98111    class Pass3 : public Indexer {
    99         typedef Indexer Parent;
     112                typedef Indexer Parent;
    100113      public:
    101         Pass3( const Indexer *indexer );
     114                Pass3( const Indexer *indexer );
    102115      private:
    103         virtual void visit( ObjectDecl *object );
    104         virtual void visit( FunctionDecl *func );
    105 
    106         const Indexer *indexer;
     116                virtual void visit( ObjectDecl *object );
     117                virtual void visit( FunctionDecl *func );
     118
     119                const Indexer *indexer;
    107120    };
    108121
    109122    class AddStructAssignment : public Visitor {
    110123      public:
    111         static void addStructAssignment( std::list< Declaration * > &translationUnit );
    112 
    113         std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
    114  
    115         virtual void visit( StructDecl *structDecl );
    116         virtual void visit( UnionDecl *structDecl );
    117         virtual void visit( TypeDecl *typeDecl );
    118         virtual void visit( ContextDecl *ctxDecl );
    119         virtual void visit( FunctionDecl *functionDecl );
    120 
    121         virtual void visit( FunctionType *ftype );
    122         virtual void visit( PointerType *ftype );
    123  
    124         virtual void visit( CompoundStmt *compoundStmt );
    125         virtual void visit( IfStmt *ifStmt );
    126         virtual void visit( WhileStmt *whileStmt );
    127         virtual void visit( ForStmt *forStmt );
    128         virtual void visit( SwitchStmt *switchStmt );
    129         virtual void visit( ChooseStmt *chooseStmt );
    130         virtual void visit( CaseStmt *caseStmt );
    131         virtual void visit( CatchStmt *catchStmt );
    132 
    133         AddStructAssignment() : functionNesting( 0 ) {}
     124                static void addStructAssignment( std::list< Declaration * > &translationUnit );
     125
     126                std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
     127 
     128                virtual void visit( StructDecl *structDecl );
     129                virtual void visit( UnionDecl *structDecl );
     130                virtual void visit( TypeDecl *typeDecl );
     131                virtual void visit( ContextDecl *ctxDecl );
     132                virtual void visit( FunctionDecl *functionDecl );
     133
     134                virtual void visit( FunctionType *ftype );
     135                virtual void visit( PointerType *ftype );
     136 
     137                virtual void visit( CompoundStmt *compoundStmt );
     138                virtual void visit( IfStmt *ifStmt );
     139                virtual void visit( WhileStmt *whileStmt );
     140                virtual void visit( ForStmt *forStmt );
     141                virtual void visit( SwitchStmt *switchStmt );
     142                virtual void visit( ChooseStmt *chooseStmt );
     143                virtual void visit( CaseStmt *caseStmt );
     144                virtual void visit( CatchStmt *catchStmt );
     145
     146                AddStructAssignment() : functionNesting( 0 ) {}
    134147      private:
    135         template< typename StmtClass > void visitStatement( StmtClass *stmt );
    136  
    137         std::list< Declaration * > declsToAdd;
    138         std::set< std::string > structsDone;
    139         unsigned int functionNesting;                   // current level of nested functions
     148                template< typename StmtClass > void visitStatement( StmtClass *stmt );
     149 
     150                std::list< Declaration * > declsToAdd;
     151                std::set< std::string > structsDone;
     152                unsigned int functionNesting;                   // current level of nested functions
    140153    };
    141154
    142155    class EliminateTypedef : public Mutator {
    143156      public:
    144         static void eliminateTypedef( std::list< Declaration * > &translationUnit );
     157                static void eliminateTypedef( std::list< Declaration * > &translationUnit );
    145158      private:
    146         virtual Declaration *mutate( TypedefDecl *typeDecl );
    147         virtual TypeDecl *mutate( TypeDecl *typeDecl );
    148         virtual DeclarationWithType *mutate( FunctionDecl *funcDecl );
    149         virtual ObjectDecl *mutate( ObjectDecl *objDecl );
    150         virtual CompoundStmt *mutate( CompoundStmt *compoundStmt );
    151         virtual Type *mutate( TypeInstType *aggregateUseType );
    152         virtual Expression *mutate( CastExpr *castExpr );
    153  
    154         std::map< std::string, TypedefDecl * > typedefNames;
     159                virtual Declaration *mutate( TypedefDecl *typeDecl );
     160                virtual TypeDecl *mutate( TypeDecl *typeDecl );
     161                virtual DeclarationWithType *mutate( FunctionDecl *funcDecl );
     162                virtual ObjectDecl *mutate( ObjectDecl *objDecl );
     163                virtual CompoundStmt *mutate( CompoundStmt *compoundStmt );
     164                virtual Type *mutate( TypeInstType *aggregateUseType );
     165                virtual Expression *mutate( CastExpr *castExpr );
     166 
     167                std::map< std::string, TypedefDecl * > typedefNames;
    155168    };
    156169
    157170    void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    158         Pass1 pass1;
    159         Pass2 pass2( doDebug, 0 );
    160         Pass3 pass3( 0 );
    161         EliminateTypedef::eliminateTypedef( translationUnit );
    162         HoistStruct::hoistStruct( translationUnit );
    163         acceptAll( translationUnit, pass1 );
    164         acceptAll( translationUnit, pass2 );
    165         AddStructAssignment::addStructAssignment( translationUnit );
    166         acceptAll( translationUnit, pass3 );
     171                Pass1 pass1;
     172                Pass2 pass2( doDebug, 0 );
     173                Pass3 pass3( 0 );
     174                EliminateTypedef::eliminateTypedef( translationUnit );
     175                HoistStruct::hoistStruct( translationUnit );
     176                acceptAll( translationUnit, pass1 );
     177                acceptAll( translationUnit, pass2 );
     178                AddStructAssignment::addStructAssignment( translationUnit );
     179                acceptAll( translationUnit, pass3 );
    167180    }
    168181   
    169182    void validateType( Type *type, const Indexer *indexer ) {
    170         Pass1 pass1;
    171         Pass2 pass2( false, indexer );
    172         Pass3 pass3( indexer );
    173         type->accept( pass1 );
    174         type->accept( pass2 );
    175         type->accept( pass3 );
     183                Pass1 pass1;
     184                Pass2 pass2( false, indexer );
     185                Pass3 pass3( indexer );
     186                type->accept( pass1 );
     187                type->accept( pass2 );
     188                type->accept( pass3 );
    176189    }
    177190
    178191    template< typename Visitor >
    179192    void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) {
    180         std::list< Declaration * >::iterator i = translationUnit.begin();
    181         while ( i != translationUnit.end() ) {
    182             (*i)->accept( visitor );
    183             std::list< Declaration * >::iterator next = i;
    184             next++;
    185             if ( ! visitor.get_declsToAdd().empty() ) {
    186                 translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() );
    187             } // if
    188             i = next;
    189         } // while
     193                std::list< Declaration * >::iterator i = translationUnit.begin();
     194                while ( i != translationUnit.end() ) {
     195                        (*i)->accept( visitor );
     196                        std::list< Declaration * >::iterator next = i;
     197                        next++;
     198                        if ( ! visitor.get_declsToAdd().empty() ) {
     199                                translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() );
     200                        } // if
     201                        i = next;
     202                } // while
    190203    }
    191204
    192205    void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) {
    193         HoistStruct hoister;
    194         acceptAndAdd( translationUnit, hoister, true );
     206                HoistStruct hoister;
     207                acceptAndAdd( translationUnit, hoister, true );
    195208    }
    196209
     
    199212
    200213    void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) {
    201         std::list< Declaration * >::iterator i = declList.begin();
    202         while ( i != declList.end() ) {
    203             std::list< Declaration * >::iterator next = i;
    204             ++next;
    205             if ( pred( *i ) ) {
    206                 if ( doDelete ) {
    207                     delete *i;
    208                 } // if
    209                 declList.erase( i );
    210             } // if
    211             i = next;
    212         } // while
     214                std::list< Declaration * >::iterator i = declList.begin();
     215                while ( i != declList.end() ) {
     216                        std::list< Declaration * >::iterator next = i;
     217                        ++next;
     218                        if ( pred( *i ) ) {
     219                                if ( doDelete ) {
     220                                        delete *i;
     221                                } // if
     222                                declList.erase( i );
     223                        } // if
     224                        i = next;
     225                } // while
    213226    }
    214227
    215228    bool isStructOrUnion( Declaration *decl ) {
    216         return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl );
     229                return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl );
    217230    }
    218231
    219232    template< typename AggDecl >
    220233    void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) {
    221         if ( inStruct ) {
    222             // Add elements in stack order corresponding to nesting structure.
    223             declsToAdd.push_front( aggregateDecl );
    224             Visitor::visit( aggregateDecl );
    225         } else {
    226             inStruct = true;
    227             Visitor::visit( aggregateDecl );
    228             inStruct = false;
    229         } // if
    230         // Always remove the hoisted aggregate from the inner structure.
    231         filter( aggregateDecl->get_members(), isStructOrUnion, false );
     234                if ( inStruct ) {
     235                        // Add elements in stack order corresponding to nesting structure.
     236                        declsToAdd.push_front( aggregateDecl );
     237                        Visitor::visit( aggregateDecl );
     238                } else {
     239                        inStruct = true;
     240                        Visitor::visit( aggregateDecl );
     241                        inStruct = false;
     242                } // if
     243                // Always remove the hoisted aggregate from the inner structure.
     244                filter( aggregateDecl->get_members(), isStructOrUnion, false );
    232245    }
    233246
    234247    void HoistStruct::visit( StructDecl *aggregateDecl ) {
    235         handleAggregate( aggregateDecl );
     248                handleAggregate( aggregateDecl );
    236249    }
    237250
    238251    void HoistStruct::visit( UnionDecl *aggregateDecl ) {
    239         handleAggregate( aggregateDecl );
     252                handleAggregate( aggregateDecl );
    240253    }
    241254
    242255    void HoistStruct::visit( CompoundStmt *compoundStmt ) {
    243         addVisit( compoundStmt, *this );
     256                addVisit( compoundStmt, *this );
    244257    }
    245258
    246259    void HoistStruct::visit( IfStmt *ifStmt ) {
    247         addVisit( ifStmt, *this );
     260                addVisit( ifStmt, *this );
    248261    }
    249262
    250263    void HoistStruct::visit( WhileStmt *whileStmt ) {
    251         addVisit( whileStmt, *this );
     264                addVisit( whileStmt, *this );
    252265    }
    253266
    254267    void HoistStruct::visit( ForStmt *forStmt ) {
    255         addVisit( forStmt, *this );
     268                addVisit( forStmt, *this );
    256269    }
    257270
    258271    void HoistStruct::visit( SwitchStmt *switchStmt ) {
    259         addVisit( switchStmt, *this );
     272                addVisit( switchStmt, *this );
    260273    }
    261274
    262275    void HoistStruct::visit( ChooseStmt *switchStmt ) {
    263         addVisit( switchStmt, *this );
     276                addVisit( switchStmt, *this );
    264277    }
    265278
    266279    void HoistStruct::visit( CaseStmt *caseStmt ) {
    267         addVisit( caseStmt, *this );
     280                addVisit( caseStmt, *this );
    268281    }
    269282
    270283    void HoistStruct::visit( CatchStmt *cathStmt ) {
    271         addVisit( cathStmt, *this );
     284                addVisit( cathStmt, *this );
    272285    }
    273286
    274287    void Pass1::visit( EnumDecl *enumDecl ) {
    275         // Set the type of each member of the enumeration to be EnumConstant
    276  
    277         for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
    278             ObjectDecl *obj = dynamic_cast< ObjectDecl * >( *i );
    279             assert( obj );
    280             obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false, false, false ), enumDecl->get_name() ) );
    281         } // for
    282         Parent::visit( enumDecl );
     288                // Set the type of each member of the enumeration to be EnumConstant
     289 
     290                for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
     291                        ObjectDecl *obj = dynamic_cast< ObjectDecl * >( *i );
     292                        assert( obj );
     293                        obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false, false, false ), enumDecl->get_name() ) );
     294                } // for
     295                Parent::visit( enumDecl );
    283296    }
    284297
    285298    namespace {
    286         template< typename DWTIterator >
    287         void fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func ) {
    288             // the only case in which "void" is valid is where it is the only one in the list; then
    289             // it should be removed entirely
    290             // other fix ups are handled by the FixFunction class
    291             if ( begin == end ) return;
    292             FixFunction fixer;
    293             DWTIterator i = begin;
    294             *i = (*i )->acceptMutator( fixer );
    295             if ( fixer.get_isVoid() ) {
    296                 DWTIterator j = i;
    297                 ++i;
    298                 func->get_parameters().erase( j );
    299                 if ( i != end ) {
    300                     throw SemanticError( "invalid type void in function type ", func );
    301                 } // if
    302             } else {
    303                 ++i;
    304                 for ( ; i != end; ++i ) {
    305                     FixFunction fixer;
    306                     *i = (*i )->acceptMutator( fixer );
    307                     if ( fixer.get_isVoid() ) {
    308                         throw SemanticError( "invalid type void in function type ", func );
    309                     } // if
     299                template< typename DWTIterator >
     300                void fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func ) {
     301                        // the only case in which "void" is valid is where it is the only one in the list; then it should be removed
     302                        // entirely other fix ups are handled by the FixFunction class
     303                        if ( begin == end ) return;
     304                        FixFunction fixer;
     305                        DWTIterator i = begin;
     306                        *i = (*i )->acceptMutator( fixer );
     307                        if ( fixer.get_isVoid() ) {
     308                                DWTIterator j = i;
     309                                ++i;
     310                                func->get_parameters().erase( j );
     311                                if ( i != end ) {
     312                                        throw SemanticError( "invalid type void in function type ", func );
     313                                } // if
     314                        } else {
     315                                ++i;
     316                                for ( ; i != end; ++i ) {
     317                                        FixFunction fixer;
     318                                        *i = (*i )->acceptMutator( fixer );
     319                                        if ( fixer.get_isVoid() ) {
     320                                                throw SemanticError( "invalid type void in function type ", func );
     321                                        } // if
     322                                } // for
     323                        } // if
     324                }
     325    }
     326
     327    void Pass1::visit( FunctionType *func ) {
     328                // Fix up parameters and return types
     329                fixFunctionList( func->get_parameters().begin(), func->get_parameters().end(), func );
     330                fixFunctionList( func->get_returnVals().begin(), func->get_returnVals().end(), func );
     331                Visitor::visit( func );
     332    }
     333
     334    Pass2::Pass2( bool doDebug, const Indexer *other_indexer ) : Indexer( doDebug ) {
     335                if ( other_indexer ) {
     336                        indexer = other_indexer;
     337                } else {
     338                        indexer = this;
     339                } // if
     340    }
     341
     342    void Pass2::visit( StructInstType *structInst ) {
     343                Parent::visit( structInst );
     344                StructDecl *st = indexer->lookupStruct( structInst->get_name() );
     345                // it's not a semantic error if the struct is not found, just an implicit forward declaration
     346                if ( st ) {
     347                        assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() );
     348                        structInst->set_baseStruct( st );
     349                } // if
     350                if ( ! st || st->get_members().empty() ) {
     351                        // use of forward declaration
     352                        forwardStructs[ structInst->get_name() ].push_back( structInst );
     353                } // if
     354    }
     355
     356    void Pass2::visit( UnionInstType *unionInst ) {
     357                Parent::visit( unionInst );
     358                UnionDecl *un = indexer->lookupUnion( unionInst->get_name() );
     359                // it's not a semantic error if the union is not found, just an implicit forward declaration
     360                if ( un ) {
     361                        unionInst->set_baseUnion( un );
     362                } // if
     363                if ( ! un || un->get_members().empty() ) {
     364                        // use of forward declaration
     365                        forwardUnions[ unionInst->get_name() ].push_back( unionInst );
     366                } // if
     367    }
     368
     369    void Pass2::visit( ContextInstType *contextInst ) {
     370                Parent::visit( contextInst );
     371                ContextDecl *ctx = indexer->lookupContext( contextInst->get_name() );
     372                if ( ! ctx ) {
     373                        throw SemanticError( "use of undeclared context " + contextInst->get_name() );
     374                } // if
     375                for ( std::list< TypeDecl * >::const_iterator i = ctx->get_parameters().begin(); i != ctx->get_parameters().end(); ++i ) {
     376                        for ( std::list< DeclarationWithType * >::const_iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
     377                                if ( ContextInstType *otherCtx = dynamic_cast< ContextInstType * >(*assert ) ) {
     378                                        cloneAll( otherCtx->get_members(), contextInst->get_members() );
     379                                } else {
     380                                        contextInst->get_members().push_back( (*assert )->clone() );
     381                                } // if
     382                        } // for
    310383                } // for
    311             } // if
    312         }
    313     }
    314 
    315     void Pass1::visit( FunctionType *func ) {
    316         // Fix up parameters and return types
    317         fixFunctionList( func->get_parameters().begin(), func->get_parameters().end(), func );
    318         fixFunctionList( func->get_returnVals().begin(), func->get_returnVals().end(), func );
    319         Visitor::visit( func );
    320     }
    321 
    322     Pass2::Pass2( bool doDebug, const Indexer *other_indexer ) : Indexer( doDebug ) {
    323         if ( other_indexer ) {
    324             indexer = other_indexer;
    325         } else {
    326             indexer = this;
    327         } // if
    328     }
    329 
    330     void Pass2::visit( StructInstType *structInst ) {
    331         Parent::visit( structInst );
    332         StructDecl *st = indexer->lookupStruct( structInst->get_name() );
    333         // it's not a semantic error if the struct is not found, just an implicit forward declaration
    334         if ( st ) {
    335             assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() );
    336             structInst->set_baseStruct( st );
    337         } // if
    338         if ( ! st || st->get_members().empty() ) {
    339             // use of forward declaration
    340             forwardStructs[ structInst->get_name() ].push_back( structInst );
    341         } // if
    342     }
    343 
    344     void Pass2::visit( UnionInstType *unionInst ) {
    345         Parent::visit( unionInst );
    346         UnionDecl *un = indexer->lookupUnion( unionInst->get_name() );
    347         // it's not a semantic error if the union is not found, just an implicit forward declaration
    348         if ( un ) {
    349             unionInst->set_baseUnion( un );
    350         } // if
    351         if ( ! un || un->get_members().empty() ) {
    352             // use of forward declaration
    353             forwardUnions[ unionInst->get_name() ].push_back( unionInst );
    354         } // if
    355     }
    356 
    357     void Pass2::visit( ContextInstType *contextInst ) {
    358         Parent::visit( contextInst );
    359         ContextDecl *ctx = indexer->lookupContext( contextInst->get_name() );
    360         if ( ! ctx ) {
    361             throw SemanticError( "use of undeclared context " + contextInst->get_name() );
    362         } // if
    363         for ( std::list< TypeDecl * >::const_iterator i = ctx->get_parameters().begin(); i != ctx->get_parameters().end(); ++i ) {
    364             for ( std::list< DeclarationWithType * >::const_iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
    365                 if ( ContextInstType *otherCtx = dynamic_cast< ContextInstType * >(*assert ) ) {
    366                     cloneAll( otherCtx->get_members(), contextInst->get_members() );
     384                applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) );
     385    }
     386
     387    void Pass2::visit( StructDecl *structDecl ) {
     388                if ( ! structDecl->get_members().empty() ) {
     389                        ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() );
     390                        if ( fwds != forwardStructs.end() ) {
     391                                for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
     392                                        (*inst )->set_baseStruct( structDecl );
     393                                } // for
     394                                forwardStructs.erase( fwds );
     395                        } // if
     396                } // if
     397                Indexer::visit( structDecl );
     398    }
     399
     400    void Pass2::visit( UnionDecl *unionDecl ) {
     401                if ( ! unionDecl->get_members().empty() ) {
     402                        ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() );
     403                        if ( fwds != forwardUnions.end() ) {
     404                                for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
     405                                        (*inst )->set_baseUnion( unionDecl );
     406                                } // for
     407                                forwardUnions.erase( fwds );
     408                        } // if
     409                } // if
     410                Indexer::visit( unionDecl );
     411    }
     412
     413    void Pass2::visit( TypeInstType *typeInst ) {
     414                if ( NamedTypeDecl *namedTypeDecl = lookupType( typeInst->get_name() ) ) {
     415                        if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
     416                                typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype );
     417                        } // if
     418                } // if
     419    }
     420
     421    Pass3::Pass3( const Indexer *other_indexer ) :  Indexer( false ) {
     422                if ( other_indexer ) {
     423                        indexer = other_indexer;
    367424                } else {
    368                     contextInst->get_members().push_back( (*assert )->clone() );
    369                 } // if
    370             } // for
    371         } // for
    372         applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) );
    373     }
    374 
    375     void Pass2::visit( StructDecl *structDecl ) {
    376         if ( ! structDecl->get_members().empty() ) {
    377             ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() );
    378             if ( fwds != forwardStructs.end() ) {
    379                 for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    380                     (*inst )->set_baseStruct( structDecl );
     425                        indexer = this;
     426                } // if
     427    }
     428
     429    void forallFixer( Type *func ) {
     430                // Fix up assertions
     431                for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) {
     432                        std::list< DeclarationWithType * > toBeDone, nextRound;
     433                        toBeDone.splice( toBeDone.end(), (*type )->get_assertions() );
     434                        while ( ! toBeDone.empty() ) {
     435                                for ( std::list< DeclarationWithType * >::iterator assertion = toBeDone.begin(); assertion != toBeDone.end(); ++assertion ) {
     436                                        if ( ContextInstType *ctx = dynamic_cast< ContextInstType * >( (*assertion )->get_type() ) ) {
     437                                                for ( std::list< Declaration * >::const_iterator i = ctx->get_members().begin(); i != ctx->get_members().end(); ++i ) {
     438                                                        DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *i );
     439                                                        assert( dwt );
     440                                                        nextRound.push_back( dwt->clone() );
     441                                                }
     442                                                delete ctx;
     443                                        } else {
     444                                                FixFunction fixer;
     445                                                *assertion = (*assertion )->acceptMutator( fixer );
     446                                                if ( fixer.get_isVoid() ) {
     447                                                        throw SemanticError( "invalid type void in assertion of function ", func );
     448                                                }
     449                                                (*type )->get_assertions().push_back( *assertion );
     450                                        } // if
     451                                } // for
     452                                toBeDone.clear();
     453                                toBeDone.splice( toBeDone.end(), nextRound );
     454                        } // while
    381455                } // for
    382                 forwardStructs.erase( fwds );
    383             } // if
    384         } // if
    385         Indexer::visit( structDecl );
    386     }
    387 
    388     void Pass2::visit( UnionDecl *unionDecl ) {
    389         if ( ! unionDecl->get_members().empty() ) {
    390             ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() );
    391             if ( fwds != forwardUnions.end() ) {
    392                 for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    393                     (*inst )->set_baseUnion( unionDecl );
    394                 } // for
    395                 forwardUnions.erase( fwds );
    396             } // if
    397         } // if
    398         Indexer::visit( unionDecl );
    399     }
    400 
    401     void Pass2::visit( TypeInstType *typeInst ) {
    402         if ( NamedTypeDecl *namedTypeDecl = lookupType( typeInst->get_name() ) ) {
    403             if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
    404                 typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype );
    405             } // if
    406         } // if
    407     }
    408 
    409     Pass3::Pass3( const Indexer *other_indexer ) :  Indexer( false ) {
    410         if ( other_indexer ) {
    411             indexer = other_indexer;
    412         } else {
    413             indexer = this;
    414         } // if
    415     }
    416 
    417     void forallFixer( Type *func ) {
    418         // Fix up assertions
    419         for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) {
    420             std::list< DeclarationWithType * > toBeDone, nextRound;
    421             toBeDone.splice( toBeDone.end(), (*type )->get_assertions() );
    422             while ( ! toBeDone.empty() ) {
    423                 for ( std::list< DeclarationWithType * >::iterator assertion = toBeDone.begin(); assertion != toBeDone.end(); ++assertion ) {
    424                     if ( ContextInstType *ctx = dynamic_cast< ContextInstType * >( (*assertion )->get_type() ) ) {
    425                         for ( std::list< Declaration * >::const_iterator i = ctx->get_members().begin(); i != ctx->get_members().end(); ++i ) {
    426                             DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *i );
    427                             assert( dwt );
    428                             nextRound.push_back( dwt->clone() );
    429                         }
    430                         delete ctx;
    431                     } else {
    432                         FixFunction fixer;
    433                         *assertion = (*assertion )->acceptMutator( fixer );
    434                         if ( fixer.get_isVoid() ) {
    435                             throw SemanticError( "invalid type void in assertion of function ", func );
    436                         }
    437                         (*type )->get_assertions().push_back( *assertion );
    438                     }
    439                 }
    440                 toBeDone.clear();
    441                 toBeDone.splice( toBeDone.end(), nextRound );
    442             }
    443         }
    444456    }
    445457
    446458    void Pass3::visit( ObjectDecl *object ) {
    447         forallFixer( object->get_type() );
    448         if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
    449             forallFixer( pointer->get_base() );
    450         } // if
    451         Parent::visit( object );
    452         object->fixUniqueId();
     459                forallFixer( object->get_type() );
     460                if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
     461                        forallFixer( pointer->get_base() );
     462                } // if
     463                Parent::visit( object );
     464                object->fixUniqueId();
    453465    }
    454466
    455467    void Pass3::visit( FunctionDecl *func ) {
    456         forallFixer( func->get_type() );
    457         Parent::visit( func );
    458         func->fixUniqueId();
     468                forallFixer( func->get_type() );
     469                Parent::visit( func );
     470                func->fixUniqueId();
    459471    }
    460472
     
    462474
    463475    void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) {
    464         AddStructAssignment visitor;
    465         acceptAndAdd( translationUnit, visitor, false );
     476                AddStructAssignment visitor;
     477                acceptAndAdd( translationUnit, visitor, false );
    466478    }
    467479
    468480    template< typename OutputIterator >
    469481    void makeScalarAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, OutputIterator out ) {
    470         ObjectDecl *obj = dynamic_cast<ObjectDecl *>( member );
    471         // unnamed bit fields are not copied as they cannot be accessed
    472         if ( obj != NULL && obj->get_name() == "" && obj->get_bitfieldWidth() != NULL ) return;
    473 
    474         UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) );
    475  
    476         UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
    477         derefExpr->get_args().push_back( new VariableExpr( dstParam ) );
    478  
    479         // do something special for unnamed members
    480         Expression *dstselect = new AddressExpr( new MemberExpr( member, derefExpr ) );
    481         assignExpr->get_args().push_back( dstselect );
    482  
    483         Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) );
    484         assignExpr->get_args().push_back( srcselect );
    485  
    486         *out++ = new ExprStmt( noLabels, assignExpr );
     482                ObjectDecl *obj = dynamic_cast<ObjectDecl *>( member );
     483                // unnamed bit fields are not copied as they cannot be accessed
     484                if ( obj != NULL && obj->get_name() == "" && obj->get_bitfieldWidth() != NULL ) return;
     485
     486                UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) );
     487 
     488                UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
     489                derefExpr->get_args().push_back( new VariableExpr( dstParam ) );
     490 
     491                // do something special for unnamed members
     492                Expression *dstselect = new AddressExpr( new MemberExpr( member, derefExpr ) );
     493                assignExpr->get_args().push_back( dstselect );
     494 
     495                Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) );
     496                assignExpr->get_args().push_back( srcselect );
     497 
     498                *out++ = new ExprStmt( noLabels, assignExpr );
    487499    }
    488500
    489501    template< typename OutputIterator >
    490502    void makeArrayAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, ArrayType *array, OutputIterator out ) {
    491         static UniqueName indexName( "_index" );
    492  
    493         // for a flexible array member nothing is done -- user must define own assignment
    494         if ( ! array->get_dimension() ) return;
    495  
    496         ObjectDecl *index = new ObjectDecl( indexName.newName(), Declaration::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 );
    497         *out++ = new DeclStmt( noLabels, index );
    498  
    499         UntypedExpr *init = new UntypedExpr( new NameExpr( "?=?" ) );
    500         init->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
    501         init->get_args().push_back( new NameExpr( "0" ) );
    502         Statement *initStmt = new ExprStmt( noLabels, init );
    503  
    504         UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) );
    505         cond->get_args().push_back( new VariableExpr( index ) );
    506         cond->get_args().push_back( array->get_dimension()->clone() );
    507  
    508         UntypedExpr *inc = new UntypedExpr( new NameExpr( "++?" ) );
    509         inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
    510  
    511         UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) );
    512  
    513         UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
    514         derefExpr->get_args().push_back( new VariableExpr( dstParam ) );
    515  
    516         Expression *dstselect = new MemberExpr( member, derefExpr );
    517         UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?+?" ) );
    518         dstIndex->get_args().push_back( dstselect );
    519         dstIndex->get_args().push_back( new VariableExpr( index ) );
    520         assignExpr->get_args().push_back( dstIndex );
    521  
    522         Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) );
    523         UntypedExpr *srcIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
    524         srcIndex->get_args().push_back( srcselect );
    525         srcIndex->get_args().push_back( new VariableExpr( index ) );
    526         assignExpr->get_args().push_back( srcIndex );
    527  
    528         *out++ = new ForStmt( noLabels, initStmt, cond, inc, new ExprStmt( noLabels, assignExpr ) );
     503                static UniqueName indexName( "_index" );
     504 
     505                // for a flexible array member nothing is done -- user must define own assignment
     506                if ( ! array->get_dimension() ) return;
     507 
     508                ObjectDecl *index = new ObjectDecl( indexName.newName(), Declaration::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 );
     509                *out++ = new DeclStmt( noLabels, index );
     510 
     511                UntypedExpr *init = new UntypedExpr( new NameExpr( "?=?" ) );
     512                init->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
     513                init->get_args().push_back( new NameExpr( "0" ) );
     514                Statement *initStmt = new ExprStmt( noLabels, init );
     515 
     516                UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) );
     517                cond->get_args().push_back( new VariableExpr( index ) );
     518                cond->get_args().push_back( array->get_dimension()->clone() );
     519 
     520                UntypedExpr *inc = new UntypedExpr( new NameExpr( "++?" ) );
     521                inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
     522 
     523                UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) );
     524 
     525                UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
     526                derefExpr->get_args().push_back( new VariableExpr( dstParam ) );
     527 
     528                Expression *dstselect = new MemberExpr( member, derefExpr );
     529                UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?+?" ) );
     530                dstIndex->get_args().push_back( dstselect );
     531                dstIndex->get_args().push_back( new VariableExpr( index ) );
     532                assignExpr->get_args().push_back( dstIndex );
     533 
     534                Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) );
     535                UntypedExpr *srcIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
     536                srcIndex->get_args().push_back( srcselect );
     537                srcIndex->get_args().push_back( new VariableExpr( index ) );
     538                assignExpr->get_args().push_back( srcIndex );
     539 
     540                *out++ = new ForStmt( noLabels, initStmt, cond, inc, new ExprStmt( noLabels, assignExpr ) );
    529541    }
    530542
    531543    Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) {
    532         FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
    533  
    534         ObjectDecl *returnVal = new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
    535         assignType->get_returnVals().push_back( returnVal );
    536  
    537         ObjectDecl *dstParam = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
    538         assignType->get_parameters().push_back( dstParam );
    539  
    540         ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
    541         assignType->get_parameters().push_back( srcParam );
    542 
    543         // Routines at global scope marked "static" to prevent multiple definitions is separate translation units
    544         // because each unit generates copies of the default routines for each aggregate.
    545         FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );
    546         assignDecl->fixUniqueId();
    547  
    548         for ( std::list< Declaration * >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) {
    549             if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member ) ) {
    550                 if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) {
    551                     makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
    552                 } else {
    553                     makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) );
    554                 } // if
    555             } // if
    556         } // for
    557         assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
    558  
    559         return assignDecl;
     544                FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
     545 
     546                ObjectDecl *returnVal = new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
     547                assignType->get_returnVals().push_back( returnVal );
     548 
     549                ObjectDecl *dstParam = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
     550                assignType->get_parameters().push_back( dstParam );
     551 
     552                ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
     553                assignType->get_parameters().push_back( srcParam );
     554
     555                // Routines at global scope marked "static" to prevent multiple definitions is separate translation units
     556                // because each unit generates copies of the default routines for each aggregate.
     557                FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );
     558                assignDecl->fixUniqueId();
     559 
     560                for ( std::list< Declaration * >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) {
     561                        if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member ) ) {
     562                                if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) {
     563                                        makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
     564                                } else {
     565                                        makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) );
     566                                } // if
     567                        } // if
     568                } // for
     569                assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
     570 
     571                return assignDecl;
    560572    }
    561573
    562574    Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) {
    563         FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
    564  
    565         ObjectDecl *returnVal = new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
    566         assignType->get_returnVals().push_back( returnVal );
    567  
    568         ObjectDecl *dstParam = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
    569         assignType->get_parameters().push_back( dstParam );
    570  
    571         ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
    572         assignType->get_parameters().push_back( srcParam );
    573  
    574         // Routines at global scope marked "static" to prevent multiple definitions is separate translation units
    575         // because each unit generates copies of the default routines for each aggregate.
    576         FunctionDecl *assignDecl = new FunctionDecl( "?=?",  functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );
    577         assignDecl->fixUniqueId();
    578  
    579         UntypedExpr *copy = new UntypedExpr( new NameExpr( "__builtin_memcpy" ) );
    580         copy->get_args().push_back( new VariableExpr( dstParam ) );
    581         copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );
    582         copy->get_args().push_back( new SizeofExpr( refType->clone() ) );
    583 
    584         assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) );
    585         assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
    586  
    587         return assignDecl;
     575                FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
     576 
     577                ObjectDecl *returnVal = new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
     578                assignType->get_returnVals().push_back( returnVal );
     579 
     580                ObjectDecl *dstParam = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
     581                assignType->get_parameters().push_back( dstParam );
     582 
     583                ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
     584                assignType->get_parameters().push_back( srcParam );
     585 
     586                // Routines at global scope marked "static" to prevent multiple definitions is separate translation units
     587                // because each unit generates copies of the default routines for each aggregate.
     588                FunctionDecl *assignDecl = new FunctionDecl( "?=?",  functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );
     589                assignDecl->fixUniqueId();
     590 
     591                UntypedExpr *copy = new UntypedExpr( new NameExpr( "__builtin_memcpy" ) );
     592                copy->get_args().push_back( new VariableExpr( dstParam ) );
     593                copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );
     594                copy->get_args().push_back( new SizeofExpr( refType->clone() ) );
     595
     596                assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) );
     597                assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
     598 
     599                return assignDecl;
    588600    }
    589601
    590602    void AddStructAssignment::visit( StructDecl *structDecl ) {
    591         if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) {
    592             StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );
    593             structInst->set_baseStruct( structDecl );
    594             declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) );
    595             structsDone.insert( structDecl->get_name() );
    596         } // if
     603                if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) {
     604                        StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );
     605                        structInst->set_baseStruct( structDecl );
     606                        declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) );
     607                        structsDone.insert( structDecl->get_name() );
     608                } // if
    597609    }
    598610
    599611    void AddStructAssignment::visit( UnionDecl *unionDecl ) {
    600         if ( ! unionDecl->get_members().empty() ) {
    601             UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );
    602             unionInst->set_baseUnion( unionDecl );
    603             declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) );
    604         } // if
     612                if ( ! unionDecl->get_members().empty() ) {
     613                        UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );
     614                        unionInst->set_baseUnion( unionDecl );
     615                        declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) );
     616                } // if
    605617    }
    606618
    607619    void AddStructAssignment::visit( TypeDecl *typeDecl ) {
    608         CompoundStmt *stmts = 0;
    609         TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false );
    610         typeInst->set_baseType( typeDecl );
    611         ObjectDecl *src = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst->clone(), 0 );
    612         ObjectDecl *dst = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), typeInst->clone() ), 0 );
    613         if ( typeDecl->get_base() ) {
    614             stmts = new CompoundStmt( std::list< Label >() );
    615             UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
    616             assign->get_args().push_back( new CastExpr( new VariableExpr( dst ), new PointerType( Type::Qualifiers(), typeDecl->get_base()->clone() ) ) );
    617             assign->get_args().push_back( new CastExpr( new VariableExpr( src ), typeDecl->get_base()->clone() ) );
    618             stmts->get_kids().push_back( new ReturnStmt( std::list< Label >(), assign ) );
    619         } // if
    620         FunctionType *type = new FunctionType( Type::Qualifiers(), false );
    621         type->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst, 0 ) );
    622         type->get_parameters().push_back( dst );
    623         type->get_parameters().push_back( src );
    624         FunctionDecl *func = new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::AutoGen, type, stmts, false );
    625         declsToAdd.push_back( func );
     620                CompoundStmt *stmts = 0;
     621                TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false );
     622                typeInst->set_baseType( typeDecl );
     623                ObjectDecl *src = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst->clone(), 0 );
     624                ObjectDecl *dst = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), typeInst->clone() ), 0 );
     625                if ( typeDecl->get_base() ) {
     626                        stmts = new CompoundStmt( std::list< Label >() );
     627                        UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
     628                        assign->get_args().push_back( new CastExpr( new VariableExpr( dst ), new PointerType( Type::Qualifiers(), typeDecl->get_base()->clone() ) ) );
     629                        assign->get_args().push_back( new CastExpr( new VariableExpr( src ), typeDecl->get_base()->clone() ) );
     630                        stmts->get_kids().push_back( new ReturnStmt( std::list< Label >(), assign ) );
     631                } // if
     632                FunctionType *type = new FunctionType( Type::Qualifiers(), false );
     633                type->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst, 0 ) );
     634                type->get_parameters().push_back( dst );
     635                type->get_parameters().push_back( src );
     636                FunctionDecl *func = new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::AutoGen, type, stmts, false );
     637                declsToAdd.push_back( func );
    626638    }
    627639
    628640    void addDecls( std::list< Declaration * > &declsToAdd, std::list< Statement * > &statements, std::list< Statement * >::iterator i ) {
    629         if ( ! declsToAdd.empty() ) {
    630             for ( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) {
    631                 statements.insert( i, new DeclStmt( noLabels, *decl ) );
    632             } // for
    633             declsToAdd.clear();
    634         } // if
     641                if ( ! declsToAdd.empty() ) {
     642                        for ( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) {
     643                                statements.insert( i, new DeclStmt( noLabels, *decl ) );
     644                        } // for
     645                        declsToAdd.clear();
     646                } // if
    635647    }
    636648
    637649    void AddStructAssignment::visit( FunctionType *) {
    638         // ensure that we don't add assignment ops for types defined as part of the function
     650                // ensure that we don't add assignment ops for types defined as part of the function
    639651    }
    640652
    641653    void AddStructAssignment::visit( PointerType *) {
    642         // ensure that we don't add assignment ops for types defined as part of the pointer
     654                // ensure that we don't add assignment ops for types defined as part of the pointer
    643655    }
    644656
    645657    void AddStructAssignment::visit( ContextDecl *) {
    646         // ensure that we don't add assignment ops for types defined as part of the context
     658                // ensure that we don't add assignment ops for types defined as part of the context
    647659    }
    648660
    649661    template< typename StmtClass >
    650662    inline void AddStructAssignment::visitStatement( StmtClass *stmt ) {
    651         std::set< std::string > oldStructs = structsDone;
    652         addVisit( stmt, *this );
    653         structsDone = oldStructs;
     663                std::set< std::string > oldStructs = structsDone;
     664                addVisit( stmt, *this );
     665                structsDone = oldStructs;
    654666    }
    655667
    656668    void AddStructAssignment::visit( FunctionDecl *functionDecl ) {
    657         maybeAccept( functionDecl->get_functionType(), *this );
    658         acceptAll( functionDecl->get_oldDecls(), *this );
    659         functionNesting += 1;
    660         maybeAccept( functionDecl->get_statements(), *this );
    661         functionNesting -= 1;
     669                maybeAccept( functionDecl->get_functionType(), *this );
     670                acceptAll( functionDecl->get_oldDecls(), *this );
     671                functionNesting += 1;
     672                maybeAccept( functionDecl->get_statements(), *this );
     673                functionNesting -= 1;
    662674    }
    663675
    664676    void AddStructAssignment::visit( CompoundStmt *compoundStmt ) {
    665         visitStatement( compoundStmt );
     677                visitStatement( compoundStmt );
    666678    }
    667679
    668680    void AddStructAssignment::visit( IfStmt *ifStmt ) {
    669         visitStatement( ifStmt );
     681                visitStatement( ifStmt );
    670682    }
    671683
    672684    void AddStructAssignment::visit( WhileStmt *whileStmt ) {
    673         visitStatement( whileStmt );
     685                visitStatement( whileStmt );
    674686    }
    675687
    676688    void AddStructAssignment::visit( ForStmt *forStmt ) {
    677         visitStatement( forStmt );
     689                visitStatement( forStmt );
    678690    }
    679691
    680692    void AddStructAssignment::visit( SwitchStmt *switchStmt ) {
    681         visitStatement( switchStmt );
     693                visitStatement( switchStmt );
    682694    }
    683695
    684696    void AddStructAssignment::visit( ChooseStmt *switchStmt ) {
    685         visitStatement( switchStmt );
     697                visitStatement( switchStmt );
    686698    }
    687699
    688700    void AddStructAssignment::visit( CaseStmt *caseStmt ) {
    689         visitStatement( caseStmt );
     701                visitStatement( caseStmt );
    690702    }
    691703
    692704    void AddStructAssignment::visit( CatchStmt *cathStmt ) {
    693         visitStatement( cathStmt );
     705                visitStatement( cathStmt );
    694706    }
    695707
    696708    bool isTypedef( Declaration *decl ) {
    697         return dynamic_cast< TypedefDecl * >( decl );
     709                return dynamic_cast< TypedefDecl * >( decl );
    698710    }
    699711
    700712    void EliminateTypedef::eliminateTypedef( std::list< Declaration * > &translationUnit ) {
    701         EliminateTypedef eliminator;
    702         mutateAll( translationUnit, eliminator );
    703         filter( translationUnit, isTypedef, true );
     713                EliminateTypedef eliminator;
     714                mutateAll( translationUnit, eliminator );
     715                filter( translationUnit, isTypedef, true );
    704716    }
    705717
    706718    Type *EliminateTypedef::mutate( TypeInstType *typeInst ) {
    707         std::map< std::string, TypedefDecl * >::const_iterator def = typedefNames.find( typeInst->get_name() );
    708         if ( def != typedefNames.end() ) {
    709             Type *ret = def->second->get_base()->clone();
    710             ret->get_qualifiers() += typeInst->get_qualifiers();
    711             delete typeInst;
    712             return ret;
    713         } // if
    714         return typeInst;
     719                std::map< std::string, TypedefDecl * >::const_iterator def = typedefNames.find( typeInst->get_name() );
     720                if ( def != typedefNames.end() ) {
     721                        Type *ret = def->second->get_base()->clone();
     722                        ret->get_qualifiers() += typeInst->get_qualifiers();
     723                        delete typeInst;
     724                        return ret;
     725                } // if
     726                return typeInst;
    715727    }
    716728
    717729    Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) {
    718         Declaration *ret = Mutator::mutate( tyDecl );
    719         typedefNames[ tyDecl->get_name() ] = tyDecl;
    720         // When a typedef is a forward declaration:
    721         //    typedef struct screen SCREEN;
    722         // the declaration portion must be retained:
    723         //    struct screen;
    724         // because the expansion of the typedef is:
    725         //    void rtn( SCREEN *p ) => void rtn( struct screen *p )
    726         // hence the type-name "screen" must be defined.
    727         // Note, qualifiers on the typedef are superfluous for the forward declaration.
    728         if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( tyDecl->get_base() ) ) {
    729             return new StructDecl( aggDecl->get_name() );
    730         } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( tyDecl->get_base() ) ) {
    731             return new UnionDecl( aggDecl->get_name() );
    732         } else {
    733             return ret;
    734         } // if
     730                Declaration *ret = Mutator::mutate( tyDecl );
     731                typedefNames[ tyDecl->get_name() ] = tyDecl;
     732                // When a typedef is a forward declaration:
     733                //    typedef struct screen SCREEN;
     734                // the declaration portion must be retained:
     735                //    struct screen;
     736                // because the expansion of the typedef is:
     737                //    void rtn( SCREEN *p ) => void rtn( struct screen *p )
     738                // hence the type-name "screen" must be defined.
     739                // Note, qualifiers on the typedef are superfluous for the forward declaration.
     740                if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( tyDecl->get_base() ) ) {
     741                        return new StructDecl( aggDecl->get_name() );
     742                } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( tyDecl->get_base() ) ) {
     743                        return new UnionDecl( aggDecl->get_name() );
     744                } else {
     745                        return ret;
     746                } // if
    735747    }
    736748
    737749    TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) {
    738         std::map< std::string, TypedefDecl * >::iterator i = typedefNames.find( typeDecl->get_name() );
    739         if ( i != typedefNames.end() ) {
    740             typedefNames.erase( i ) ;
    741         } // if
    742         return typeDecl;
     750                std::map< std::string, TypedefDecl * >::iterator i = typedefNames.find( typeDecl->get_name() );
     751                if ( i != typedefNames.end() ) {
     752                        typedefNames.erase( i ) ;
     753                } // if
     754                return typeDecl;
    743755    }
    744756
    745757    DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) {
    746         std::map< std::string, TypedefDecl * > oldNames = typedefNames;
    747         DeclarationWithType *ret = Mutator::mutate( funcDecl );
    748         typedefNames = oldNames;
    749         return ret;
     758                std::map< std::string, TypedefDecl * > oldNames = typedefNames;
     759                DeclarationWithType *ret = Mutator::mutate( funcDecl );
     760                typedefNames = oldNames;
     761                return ret;
    750762    }
    751763
    752764    ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) {
    753         std::map< std::string, TypedefDecl * > oldNames = typedefNames;
    754         ObjectDecl *ret = Mutator::mutate( objDecl );
    755         typedefNames = oldNames;
    756         return ret;
     765                std::map< std::string, TypedefDecl * > oldNames = typedefNames;
     766                ObjectDecl *ret = Mutator::mutate( objDecl );
     767                typedefNames = oldNames;
     768                return ret;
    757769    }
    758770
    759771    Expression *EliminateTypedef::mutate( CastExpr *castExpr ) {
    760         std::map< std::string, TypedefDecl * > oldNames = typedefNames;
    761         Expression *ret = Mutator::mutate( castExpr );
    762         typedefNames = oldNames;
    763         return ret;
     772                std::map< std::string, TypedefDecl * > oldNames = typedefNames;
     773                Expression *ret = Mutator::mutate( castExpr );
     774                typedefNames = oldNames;
     775                return ret;
    764776    }
    765777
    766778    CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) {
    767         std::map< std::string, TypedefDecl * > oldNames = typedefNames;
    768         CompoundStmt *ret = Mutator::mutate( compoundStmt );
    769         std::list< Statement * >::iterator i = compoundStmt->get_kids().begin();
    770         while ( i != compoundStmt->get_kids().end() ) {
    771             std::list< Statement * >::iterator next = i;
    772             ++next;
    773             if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) {
    774                 if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) {
    775                     delete *i;
    776                     compoundStmt->get_kids().erase( i );
    777                 } // if
    778             } // if
    779             i = next;
    780         } // while
    781         typedefNames = oldNames;
    782         return ret;
     779                std::map< std::string, TypedefDecl * > oldNames = typedefNames;
     780                CompoundStmt *ret = Mutator::mutate( compoundStmt );
     781                std::list< Statement * >::iterator i = compoundStmt->get_kids().begin();
     782                while ( i != compoundStmt->get_kids().end() ) {
     783                        std::list< Statement * >::iterator next = i;
     784                        ++next;
     785                        if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) {
     786                                if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) {
     787                                        delete *i;
     788                                        compoundStmt->get_kids().erase( i );
     789                                } // if
     790                        } // if
     791                        i = next;
     792                } // while
     793                typedefNames = oldNames;
     794                return ret;
    783795    }
    784796} // namespace SymTab
     797
     798// Local Variables: //
     799// tab-width: 4 //
     800// mode: c++ //
     801// compile-command: "make install" //
     802// End: //
  • translator/SymTab/Validate.h

    ra32b204 r0dd3a2f  
    1 // This class is intended to perform pre-processing of declarations, validating their
    2 // correctness and computing some auxilliary data that is necessary for the indexer.
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Validate.h -- This class is intended to perform pre-processing of declarations, validating their correctness and
     8//               computing some auxilliary data that is necessary for the indexer.
     9//
     10// Author           : Richard C. Bilson
     11// Created On       : Sun May 17 21:53:34 2015
     12// Last Modified By : Peter A. Buhr
     13// Last Modified On : Sun May 17 21:55:09 2015
     14// Update Count     : 2
     15//
    316
    4 #ifndef SYMTAB_VALIDATE_H
    5 #define SYMTAB_VALIDATE_H
     17#ifndef VALIDATE_H
     18#define VALIDATE_H
    619
    720#include "SynTree/SynTree.h"
     
    1225    void validate( std::list< Declaration * > &translationUnit, bool doDebug = false );
    1326    void validateType( Type *type, const Indexer *indexer );
    14 } // SymTab
     27} // namespace SymTab
    1528
    16 #endif // SYMTAB_VALIDATE_H
     29#endif // VALIDATE_H
     30
     31// Local Variables: //
     32// tab-width: 4 //
     33// mode: c++ //
     34// compile-command: "make install" //
     35// End: //
  • translator/SynTree/AddressExpr.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: AddressExpr.cc,v 1.6 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// AddressExpr.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 23:54:44 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 07:48:14 2015
     13// Update Count     : 5
     14//
    715
    816#include "Expression.h"
     
    1018#include "utility.h"
    1119
    12 
    13 AddressExpr::AddressExpr( Expression *arg, Expression *_aname )
    14     : Expression( _aname ), arg( arg )
    15 {
     20AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) {
    1621    for ( std::list< Type* >::const_iterator i = arg->get_results().begin(); i != arg->get_results().end(); ++i ) {
    17         get_results().push_back( new PointerType( Type::Qualifiers(), (*i)->clone() ) );
    18     }
     22                get_results().push_back( new PointerType( Type::Qualifiers(), (*i)->clone() ) );
     23    } // for
    1924}
    2025
    21 AddressExpr::AddressExpr( const AddressExpr &other )
    22     : Expression( other ), arg( maybeClone( other.arg ) )
    23 {
     26AddressExpr::AddressExpr( const AddressExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
    2427}
    2528
    26 AddressExpr::~AddressExpr()
    27 {
     29AddressExpr::~AddressExpr() {
    2830    delete arg;
    2931}
    3032
    31 void
    32 AddressExpr::print( std::ostream &os, int indent ) const
    33 {
     33void AddressExpr::print( std::ostream &os, int indent ) const {
    3434    os << std::string( indent, ' ' ) << "Address of:" << std::endl;
    3535    if ( arg ) {
    36         arg->print( os, indent+2 );
    37     }
     36                arg->print( os, indent+2 );
     37    } // if
    3838}
    3939
    40 
     40// Local Variables: //
     41// tab-width: 4 //
     42// mode: c++ //
     43// compile-command: "make install" //
     44// End: //
  • translator/SynTree/AggregateDecl.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: AggregateDecl.cc,v 1.7 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// AggregateDecl.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 23:56:39 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 07:48:23 2015
     13// Update Count     : 4
     14//
    715
    816#include "Declaration.h"
     
    1119
    1220
    13 AggregateDecl::AggregateDecl( const std::string &name )
    14     : Parent( name, Declaration::NoStorageClass, LinkageSpec::Cforall )
    15 {
     21AggregateDecl::AggregateDecl( const std::string &name ) : Parent( name, Declaration::NoStorageClass, LinkageSpec::Cforall ) {
    1622}
    1723
    18 AggregateDecl::AggregateDecl( const AggregateDecl &other )
    19     : Parent( other )
    20 {
     24AggregateDecl::AggregateDecl( const AggregateDecl &other ) : Parent( other ) {
    2125    cloneAll( other.members, members );
    2226    cloneAll( other.parameters, parameters );
    2327}
    2428
    25 AggregateDecl::~AggregateDecl()
    26 {
     29AggregateDecl::~AggregateDecl() {
    2730    deleteAll( members );
    2831    deleteAll( parameters );
    2932}
    3033
    31 void
    32 AggregateDecl::print( std::ostream &os, int indent ) const
    33 {
     34void AggregateDecl::print( std::ostream &os, int indent ) const {
    3435    using std::string;
    3536    using std::endl;
     
    3738    os << typeString() << " " << get_name();
    3839    if ( ! parameters.empty() ) {
    39         os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
    40         printAll( parameters, os, indent+4 );
    41     }
     40                os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
     41                printAll( parameters, os, indent+4 );
     42    } // if
    4243    if ( ! members.empty() ) {
    43         os << endl << string( indent+2, ' ' ) << "with members" << endl;
    44         printAll( members, os, indent+4 );
    45     }
     44                os << endl << string( indent+2, ' ' ) << "with members" << endl;
     45                printAll( members, os, indent+4 );
     46    } // if
    4647}
    4748
    48 void
    49 AggregateDecl::printShort( std::ostream &os, int indent ) const
    50 {
     49void AggregateDecl::printShort( std::ostream &os, int indent ) const {
    5150    using std::string;
    5251    using std::endl;
     
    5453    os << typeString() << " " << get_name();
    5554    if ( ! parameters.empty() ) {
    56         os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
    57         printAll( parameters, os, indent+4 );
    58     }
     55                os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
     56                printAll( parameters, os, indent+4 );
     57    } // if
    5958}
    6059
     
    6766std::string ContextDecl::typeString() const { return "context"; }
    6867
     68// Local Variables: //
     69// tab-width: 4 //
     70// mode: c++ //
     71// compile-command: "make install" //
     72// End: //
  • translator/SynTree/ApplicationExpr.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// ApplicationExpr.cc.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 07:54:17 2015
     13// Update Count     : 4
     14//
     15
    116#include <cassert>
    217
     
    823
    924
    10 ParamEntry::ParamEntry( const ParamEntry &other )
    11     : decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) )
    12 {
     25ParamEntry::ParamEntry( const ParamEntry &other ) :
     26                decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) {
    1327}
    1428
    15 ParamEntry &
    16 ParamEntry::operator=( const ParamEntry &other )
    17 {
    18     if ( &other == this ) return *this;
    19     decl = other.decl;
    20     actualType = maybeClone( other.actualType );
    21     formalType = maybeClone( other.formalType );
    22     expr = maybeClone( other.expr );
    23     return *this;
     29ParamEntry &ParamEntry::operator=( const ParamEntry &other ) {
     30        if ( &other == this ) return *this;
     31        decl = other.decl;
     32        actualType = maybeClone( other.actualType );
     33        formalType = maybeClone( other.formalType );
     34        expr = maybeClone( other.expr );
     35        return *this;
    2436}
    2537
    26 ParamEntry::~ParamEntry()
    27 {
    28     delete actualType;
    29     delete formalType;
    30     delete expr;
     38ParamEntry::~ParamEntry() {
     39        delete actualType;
     40        delete formalType;
     41        delete expr;
    3142}
    3243
    33 ApplicationExpr::ApplicationExpr( Expression *funcExpr )
    34     : function( funcExpr )
    35 {
    36     PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() );
    37     assert( pointer );
    38     FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() );
    39     assert( function );
    40    
    41     for ( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) {
    42         get_results().push_back( (*i)->get_type()->clone() );
    43     }
     44ApplicationExpr::ApplicationExpr( Expression *funcExpr ) : function( funcExpr ) {
     45        PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() );
     46        assert( pointer );
     47        FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() );
     48        assert( function );
     49       
     50        for ( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) {
     51                get_results().push_back( (*i)->get_type()->clone() );
     52        } // for
    4453}
    4554
    46 ApplicationExpr::ApplicationExpr( const ApplicationExpr &other )
    47     : Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams )
    48 {
    49     cloneAll( other.args, args );
     55ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) :
     56                Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams ) {
     57        cloneAll( other.args, args );
    5058}
    5159
    52 ApplicationExpr::~ApplicationExpr()
    53 {
    54     delete function;
    55     deleteAll( args );
     60ApplicationExpr::~ApplicationExpr() {
     61        delete function;
     62        deleteAll( args );
    5663}
    5764
    58 void
    59 ApplicationExpr::print( std::ostream &os, int indent ) const
    60 {
    61     os << std::string( indent, ' ' ) << "Application of" << std::endl;
    62     function->print( os, indent+2 );
    63     if ( ! args.empty() ) {
    64         os << std::string( indent, ' ' ) << "to arguments" << std::endl;
    65         printAll( args, os, indent+2 );
    66     }
    67     if ( ! inferParams.empty() ) {
    68         os << std::string(indent, ' ') << "with inferred parameters:" << std::endl;
    69         for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) {
    70             os << std::string(indent+2, ' ');
    71             Declaration::declFromId( i->second.decl )->printShort( os, indent+2 );
    72             os << std::endl;
    73         }
    74     }
    75     Expression::print( os, indent );
     65void ApplicationExpr::print( std::ostream &os, int indent ) const {
     66        os << std::string( indent, ' ' ) << "Application of" << std::endl;
     67        function->print( os, indent+2 );
     68        if ( ! args.empty() ) {
     69                os << std::string( indent, ' ' ) << "to arguments" << std::endl;
     70                printAll( args, os, indent+2 );
     71        } // if
     72        if ( ! inferParams.empty() ) {
     73                os << std::string(indent, ' ') << "with inferred parameters:" << std::endl;
     74                for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) {
     75                        os << std::string(indent+2, ' ');
     76                        Declaration::declFromId( i->second.decl )->printShort( os, indent+2 );
     77                        os << std::endl;
     78                } // for
     79        } // if
     80        Expression::print( os, indent );
    7681}
    7782
     83// Local Variables: //
     84// tab-width: 4 //
     85// mode: c++ //
     86// compile-command: "make install" //
     87// End: //
  • translator/SynTree/ArrayType.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: ArrayType.cc,v 1.6 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// ArrayType.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 07:52:08 2015
     13// Update Count     : 2
     14//
    715
    816#include "Type.h"
     
    1220
    1321ArrayType::ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic )
    14     : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic )
    15 {
    16     base->set_isLvalue( false );
     22                : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) {
     23        base->set_isLvalue( false );
    1724}
    1825
    1926ArrayType::ArrayType( const ArrayType &other )
    20     : Type( other ), base( maybeClone( other.base ) ), dimension( maybeClone( other.dimension ) ),
    21         isVarLen( other.isVarLen ), isStatic( other.isStatic )
    22 {
     27        : Type( other ), base( maybeClone( other.base ) ), dimension( maybeClone( other.dimension ) ),
     28          isVarLen( other.isVarLen ), isStatic( other.isStatic ) {
    2329}
    2430
    25 ArrayType::~ArrayType()
    26 {
    27     delete base;
    28     delete dimension;
     31ArrayType::~ArrayType() {
     32        delete base;
     33        delete dimension;
    2934}
    3035
    31 void
    32 ArrayType::print( std::ostream &os, int indent ) const
    33 {
    34     Type::print( os, indent );
    35     if ( isStatic ) {
    36         os << "static ";
    37     }
    38     if ( isVarLen ) {
    39         os << "variable length array of ";
    40     } else if ( dimension ) {
    41         os << "array of ";
    42         dimension->print( os, indent );
    43     } else {
    44         os << "open array of ";
    45     }
    46     if ( base ) {
    47         base->print( os, indent );
    48     }
     36void ArrayType::print( std::ostream &os, int indent ) const {
     37        Type::print( os, indent );
     38        if ( isStatic ) {
     39                os << "static ";
     40        } // if
     41        if ( isVarLen ) {
     42                os << "variable length array of ";
     43        } else if ( dimension ) {
     44                os << "array of ";
     45                dimension->print( os, indent );
     46        } else {
     47                os << "open array of ";
     48        } // if
     49        if ( base ) {
     50                base->print( os, indent );
     51        } // if
    4952}
    5053
     54// Local Variables: //
     55// tab-width: 4 //
     56// mode: c++ //
     57// compile-command: "make install" //
     58// End: //
  • translator/SynTree/AttrType.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: AttrType.cc,v 1.3 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 07:53:48 2015
     13// Update Count     : 1
     14//
    715
    816#include "Type.h"
     
    1220
    1321AttrType::AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr )
    14     : Type( tq ), name( name ), expr( expr ), type( 0 ), isType( false )
    15 {
     22        : Type( tq ), name( name ), expr( expr ), type( 0 ), isType( false ) {
    1623}
    1724
    1825AttrType::AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type )
    19     : Type( tq ), name( name ), expr( 0 ), type( type ), isType( true )
    20 {
     26        : Type( tq ), name( name ), expr( 0 ), type( type ), isType( true ) {
    2127}
    2228
    2329AttrType::AttrType( const AttrType &other )
    24     : Type( other ), name( other.name ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType )
    25 {
     30        : Type( other ), name( other.name ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
    2631}
    2732
    28 AttrType::~AttrType()
    29 {
    30     delete expr;
    31     delete type;
     33AttrType::~AttrType() {
     34        delete expr;
     35        delete type;
    3236}
    3337
    34 void
    35 AttrType::print( std::ostream &os, int indent ) const
    36 {
    37     Type::print( os, indent );
    38     os << "attribute " << name << " applied to ";
    39     if ( expr ) {
    40         os << "expression ";
    41         expr->print( os, indent );
    42     }
    43     if ( type ) {
    44         os << "type ";
    45         type->print( os, indent );
    46     }
     38void AttrType::print( std::ostream &os, int indent ) const {
     39        Type::print( os, indent );
     40        os << "attribute " << name << " applied to ";
     41        if ( expr ) {
     42                os << "expression ";
     43                expr->print( os, indent );
     44        } // if
     45        if ( type ) {
     46                os << "type ";
     47                type->print( os, indent );
     48        } // if
    4749}
    4850
     51// Local Variables: //
     52// tab-width: 4 //
     53// mode: c++ //
     54// compile-command: "make install" //
     55// End: //
  • translator/SynTree/BasicType.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// BasicType.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 07:55:16 2015
     13// Update Count     : 1
     14//
     15
    116#include <cassert>
    2 
    317#include "Type.h"
    4 
    518
    619BasicType::BasicType( const Type::Qualifiers &tq, Kind bt ) : Type( tq ), kind( bt ) {}
    720
    821void BasicType::print( std::ostream &os, int indent ) const {
    9     static const char *kindNames[] = { 
    10         "_Bool", "char", "signed char", "unsigned char", "short signed int", "short unsigned int",
    11         "signed int", "unsigned int", "long signed int", "long unsigned int", "long long signed int",
    12         "long long unsigned int", "float", "double", "long double", "float _Complex", "double _Complex",
    13         "long double _Complex", "float _Imaginary", "double _Imaginary", "long double _Imaginary"
    14     };
     22        static const char *kindNames[] = {     
     23                "_Bool", "char", "signed char", "unsigned char", "short signed int", "short unsigned int",
     24                "signed int", "unsigned int", "long signed int", "long unsigned int", "long long signed int",
     25                "long long unsigned int", "float", "double", "long double", "float _Complex", "double _Complex",
     26                "long double _Complex", "float _Imaginary", "double _Imaginary", "long double _Imaginary"
     27        };
    1528
    16     Type::print( os, indent );
    17     os << kindNames[ kind ] << ' ';
     29        Type::print( os, indent );
     30        os << kindNames[ kind ] << ' ';
    1831}
    1932
    2033bool BasicType::isInteger() const {
    21     switch ( kind ) {
    22       case Bool:
    23       case Char:
    24       case SignedChar:
    25       case UnsignedChar:
    26       case ShortSignedInt:
    27       case ShortUnsignedInt:
    28       case SignedInt:
    29       case UnsignedInt:
    30       case LongSignedInt:
    31       case LongUnsignedInt:
    32       case LongLongSignedInt:
    33       case LongLongUnsignedInt:
    34         return true;
    35 
    36       case Float:
    37       case Double:
    38       case LongDouble:
    39       case FloatComplex:
    40       case DoubleComplex:
    41       case LongDoubleComplex:
    42       case FloatImaginary:
    43       case DoubleImaginary:
    44       case LongDoubleImaginary:
     34        switch ( kind ) {
     35          case Bool:
     36          case Char:
     37          case SignedChar:
     38          case UnsignedChar:
     39          case ShortSignedInt:
     40          case ShortUnsignedInt:
     41          case SignedInt:
     42          case UnsignedInt:
     43          case LongSignedInt:
     44          case LongUnsignedInt:
     45          case LongLongSignedInt:
     46          case LongLongUnsignedInt:
     47                return true;
     48          case Float:
     49          case Double:
     50          case LongDouble:
     51          case FloatComplex:
     52          case DoubleComplex:
     53          case LongDoubleComplex:
     54          case FloatImaginary:
     55          case DoubleImaginary:
     56          case LongDoubleImaginary:
     57                return false;
     58          case NUMBER_OF_BASIC_TYPES:
     59                assert( false );
     60        } // switch
     61        assert( false );
    4562        return false;
    46 
    47       case NUMBER_OF_BASIC_TYPES:
    48         assert( false );
    49     }
    50     assert( false );
    51     return false;
    5263}
    5364
    5465
     66// Local Variables: //
     67// tab-width: 4 //
     68// mode: c++ //
     69// compile-command: "make install" //
     70// End: //
  • translator/SynTree/CodeGenVisitor.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// CodeGenVisitor.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 07:57:51 2015
     13// Update Count     : 3
     14//
     15
    116#include <iostream>
    217#include <list>
     
    722using namespace std;
    823
    9 //*** Types
    10 void CodeGenVisitor::visit(Type *type){ }
    11 void CodeGenVisitor::visit(BasicType *basicType) { }
     24void CodeGenVisitor::visit( Type *type ){ }
     25void CodeGenVisitor::visit( BasicType *basicType ) { }
    1226
    13 //*** Constant
    14 void CodeGenVisitor::visit(Constant *constant) {
    15     cout << constant->get_value() << endl;
     27void CodeGenVisitor::visit( Constant *constant ) {
     28        cout << constant->get_value() << endl;
    1629}
    1730
    18 //*** Expressions
    19 void CodeGenVisitor::visit(Expression *expr){ }
     31void CodeGenVisitor::visit( Expression *expr ){ }
    2032
    21 void CodeGenVisitor::visit(ConstantExpr *cnst){
    22     if (cnst != 0)
    23         visit(cnst->get_constant());
     33void CodeGenVisitor::visit( ConstantExpr *cnst ) {
     34        if ( cnst != 0 )
     35                visit(cnst->get_constant());
    2436}
    2537
    26 //*** Statements
    27 void CodeGenVisitor::visit(Statement *stmt){ }
     38void CodeGenVisitor::visit( Statement *stmt ) { }
    2839
    29 void CodeGenVisitor::visit(ExprStmt *exprStmt){
    30     if (exprStmt != 0)
    31         exprStmt->get_expr()->accept(*this);    // visit(exprStmt->get_expr()) doesn't work
     40void CodeGenVisitor::visit( ExprStmt *exprStmt ) {
     41        if ( exprStmt != 0 )
     42                exprStmt->get_expr()->accept( *this );                  // visit(exprStmt->get_expr()) doesn't work
    3243}
    3344
    34 void CodeGenVisitor::visit(SwitchStmt *switchStmt){
    35     cout << "switch (" << endl;     
    36     // visit(switchStmt->get_condition());   // why doesn't this work?
    37     switchStmt->get_condition()->accept(*this);
     45void CodeGenVisitor::visit( SwitchStmt *switchStmt ) {
     46        cout << "switch (" << endl;         
     47        // visit(switchStmt->get_condition());   // why doesn't this work?
     48        switchStmt->get_condition()->accept(*this);
    3849
    39     cout << ") {" << endl;     
    40     // visit(switchStmt->get_body());  // why doesn't this work?
    41     cout << "}" << endl;       
     50        cout << ") {" << endl; 
     51        // visit(switchStmt->get_body());  // why doesn't this work?
     52        cout << "}" << endl;   
    4253}
    4354
    44 
     55// Local Variables: //
     56// tab-width: 4 //
     57// mode: c++ //
     58// compile-command: "make install" //
     59// End: //
  • translator/SynTree/CodeGenVisitor.h

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// CodeGenVisitor.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 08:46:47 2015
     13// Update Count     : 4
     14//
     15
    116#ifndef CODEGENV_H
    217#define CODEGENV_H
     
    722#include "Visitor.h"
    823
     24class CodeGenVisitor : public Visitor {
     25  public:
     26        virtual void visit( Type * );
     27        virtual void visit( BasicType * );
    928
    10 class CodeGenVisitor : public Visitor {
    11 public:
    12     //*** Types
    13     virtual void visit(Type *);
    14     virtual void visit(BasicType *);
     29        virtual void visit( Constant * );
    1530
    16     //*** Constant
    17     virtual void visit(Constant *);
     31        virtual void visit( Expression * );
     32        virtual void visit( ConstantExpr * );
    1833
    19     //*** Expressions
    20     virtual void visit(Expression *);
    21     virtual void visit(ConstantExpr *);
    22 
    23     //*** Statements
    24     virtual void visit(Statement *);
    25     virtual void visit(ExprStmt *);
    26     virtual void visit(SwitchStmt *);
     34        virtual void visit( Statement * );
     35        virtual void visit( ExprStmt * );
     36        virtual void visit( SwitchStmt * );
    2737};
    2838
     39#endif // CODEGENV_H
    2940
    30 #endif /* #ifndef CODEGENV_H */
     41// Local Variables: //
     42// tab-width: 4 //
     43// mode: c++ //
     44// compile-command: "make install" //
     45// End: //
  • translator/SynTree/CommaExpr.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: CommaExpr.cc,v 1.7 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// CommaExpr.cc --
     8//
     9// Author           : Richard C. Bilson
     10// 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
     13// Update Count     : 1
     14//
    715
    816#include "Expression.h"
     
    1018#include "utility.h"
    1119
    12 
    1320CommaExpr::CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname )
    14     : Expression( _aname ), arg1( arg1 ), arg2( arg2 )
    15 {
    16     cloneAll( arg2->get_results(), get_results() );
     21                : Expression( _aname ), arg1( arg1 ), arg2( arg2 ) {
     22        cloneAll( arg2->get_results(), get_results() );
    1723}
    1824
    1925CommaExpr::CommaExpr( const CommaExpr &other )
    20     : Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) )
    21 {
     26                : Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ) {
    2227}
    2328
    24 CommaExpr::~CommaExpr()
    25 {
    26     delete arg1;
    27     delete arg2;
     29CommaExpr::~CommaExpr() {
     30        delete arg1;
     31        delete arg2;
    2832}
    2933
    30 void
    31 CommaExpr::print( std::ostream &os, int indent ) const
    32 {
    33     os << std::string( indent, ' ' ) << "Comma Expression:" << std::endl;
    34     arg1->print( os, indent+2 );
    35     os << std::endl;
    36     arg2->print( os, indent+2 );
    37     Expression::print( os, indent );
     34void CommaExpr::print( std::ostream &os, int indent ) const {
     35        os << std::string( indent, ' ' ) << "Comma Expression:" << std::endl;
     36        arg1->print( os, indent+2 );
     37        os << std::endl;
     38        arg2->print( os, indent+2 );
     39        Expression::print( os, indent );
    3840}
    3941
    40 
     42// Local Variables: //
     43// tab-width: 4 //
     44// mode: c++ //
     45// compile-command: "make install" //
     46// End: //
  • translator/SynTree/CompoundStmt.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: CompoundStmt.cc,v 1.4 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 08:11:02 2015
     13// Update Count     : 1
     14//
    715
    816#include "Statement.h"
     
    1826
    1927CompoundStmt::CompoundStmt( const CompoundStmt &other ) : Statement( other ) {
    20     cloneAll( other.kids, kids );
     28        cloneAll( other.kids, kids );
    2129}
    2230
    2331CompoundStmt::~CompoundStmt() {
    24     deleteAll( kids );
     32        deleteAll( kids );
    2533}
    2634
    2735void CompoundStmt::print( std::ostream &os, int indent ) {
    28     os << "\r" << string(indent, ' ') << "CompoundStmt" << endl ;
    29     printAll( kids, os, indent+2 );
     36        os << "\r" << string(indent, ' ') << "CompoundStmt" << endl ;
     37        printAll( kids, os, indent+2 );
    3038}
    3139
    32 
    33 
    34 
    35 
     40// Local Variables: //
     41// tab-width: 4 //
     42// mode: c++ //
     43// compile-command: "make install" //
     44// End: //
  • translator/SynTree/Constant.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Constant.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 08:13:25 2015
     13// Update Count     : 1
     14//
     15
    116#include <iostream>
    217#include <list>
     
    520#include "Type.h"
    621
    7 
    8 Constant::Constant(Type *_type, std::string _value):
    9     type(_type), value(_value) {}
     22Constant::Constant( Type *_type, std::string _value ) : type(_type), value(_value) {}
    1023
    1124Constant::~Constant() {}
     
    1427
    1528void Constant::print( std::ostream &os ) const {
    16     os << value;
    17     if ( type ) {
    18         os << " (type: ";
    19         type->print( os );
    20         os << ")";
    21     }
     29        os << value;
     30        if ( type ) {
     31                os << " (type: ";
     32                type->print( os );
     33                os << ")";
     34        } // if
    2235}
    2336
    24 
    25 
    26 
     37// Local Variables: //
     38// tab-width: 4 //
     39// mode: c++ //
     40// compile-command: "make install" //
     41// End: //
  • translator/SynTree/Constant.h

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: Constant.h,v 1.6 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Constant.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 08:46:37 2015
     13// Update Count     : 2
     14//
    715
    816#ifndef CONSTANT_H
     
    1321#include "Mutator.h"
    1422
     23class Constant {
     24  public:
     25        Constant( Type *type, std::string value );
     26        virtual ~Constant();
    1527
    16 class Constant
    17 {
    18 public:
    19     Constant( Type *type, std::string value );
    20     virtual ~Constant();
     28        Type *get_type() { return type; }
     29        void set_type( Type *newValue ) { type = newValue; }
     30        std::string get_value() { return value; }
     31        void set_value( std::string newValue ) { value = newValue; }
    2132
    22     Type *get_type() { return type; }
    23     void set_type( Type *newValue ) { type = newValue; }
    24     std::string get_value() { return value; }
    25     void set_value( std::string newValue ) { value = newValue; }
    26 
    27     virtual Constant *clone() const;
    28     virtual void accept( Visitor &v ) { v.visit( this ); }
    29     virtual Constant *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    30     virtual void print( std::ostream &os ) const;
    31    
    32 private:
    33     Type *type;
    34     std::string value;
     33        virtual Constant *clone() const;
     34        virtual void accept( Visitor &v ) { v.visit( this ); }
     35        virtual Constant *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     36        virtual void print( std::ostream &os ) const;
     37  private:
     38        Type *type;
     39        std::string value;
    3540};
    3641
     42#endif // CONSTANT_H
    3743
    38 
    39 
    40 #endif /* #ifndef CONSTANT_H */
     44// Local Variables: //
     45// tab-width: 4 //
     46// mode: c++ //
     47// compile-command: "make install" //
     48// End: //
  • translator/SynTree/DeclStmt.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: DeclStmt.cc,v 1.4 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// DeclStmt.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 08:16:03 2015
     13// Update Count     : 2
     14//
    715
    816#include "Statement.h"
     
    1018#include "utility.h"
    1119
    12 
    13 DeclStmt::DeclStmt( std::list<Label> labels, Declaration *decl )
    14     : Statement( labels ), decl( decl )
    15 {
     20DeclStmt::DeclStmt( std::list<Label> labels, Declaration *decl ) : Statement( labels ), decl( decl ) {
    1621}
    1722
    18 DeclStmt::DeclStmt( const DeclStmt &other )
    19     : Statement( other ), decl( maybeClone( other.decl ) )
    20 {
     23DeclStmt::DeclStmt( const DeclStmt &other ) : Statement( other ), decl( maybeClone( other.decl ) ) {
    2124}
    2225
    23 DeclStmt::~DeclStmt()
    24 {
    25     delete decl;
     26DeclStmt::~DeclStmt() {
     27        delete decl;
    2628}
    2729
    28 void
    29 DeclStmt::print( std::ostream &os, int indent )
    30 {
    31     os << "Declaration of ";
    32     if ( decl ) {
    33         decl->print( os, indent );
    34     }
     30void DeclStmt::print( std::ostream &os, int indent ) {
     31        os << "Declaration of ";
     32        if ( decl ) {
     33                decl->print( os, indent );
     34        } // if
    3535}
    3636
    37 
     37// Local Variables: //
     38// tab-width: 4 //
     39// mode: c++ //
     40// compile-command: "make install" //
     41// End: //
  • translator/SynTree/Declaration.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: Declaration.cc,v 1.8 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Declaration.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 08:18:35 2015
     13// Update Count     : 2
     14//
    715
    816#include <string>
     
    1422#include "utility.h"
    1523
    16 
    1724const char* Declaration::storageClassName[] = { "", "auto", "static", "extern", "register" }; 
    1825
     
    2229
    2330Declaration::Declaration( const std::string &name, StorageClass sc, LinkageSpec::Type linkage )
    24     : name( name ), storageClass( sc ), linkage( linkage ), uniqueId( 0 )
    25 {
     31        : name( name ), storageClass( sc ), linkage( linkage ), uniqueId( 0 ) {
    2632}
    2733
    2834Declaration::Declaration( const Declaration &other )
    29     : name( other.name ), storageClass( other.storageClass ), linkage( other.linkage ), uniqueId( other.uniqueId )
    30 {
     35        : name( other.name ), storageClass( other.storageClass ), linkage( other.linkage ), uniqueId( other.uniqueId ) {
    3136}
    3237
    33 Declaration::~Declaration()
    34 {
     38Declaration::~Declaration() {
    3539}
    3640
    37 void
    38 Declaration::fixUniqueId()
    39 {
    40     uniqueId = ++lastUniqueId;
    41     idMap[ uniqueId ] = this;
     41void Declaration::fixUniqueId() {
     42        uniqueId = ++lastUniqueId;
     43        idMap[ uniqueId ] = this;
    4244}
    4345
    4446/* static class method */
    45 Declaration *
    46 Declaration::declFromId( UniqueId id )
    47 {
    48     IdMapType::const_iterator i = idMap.find( id );
    49     if ( i != idMap.end() ) {
    50         return i->second;
    51     } else {
    52         return 0;
    53     }
     47Declaration *Declaration::declFromId( UniqueId id ) {
     48        IdMapType::const_iterator i = idMap.find( id );
     49        if ( i != idMap.end() ) {
     50                return i->second;
     51        } else {
     52                return 0;
     53        } // if
    5454}
    5555
    5656/* static class method */
    57 void
    58 Declaration::dumpIds( std::ostream &os )
    59 {
    60     for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) {
    61         os << i->first << " -> ";
    62         i->second->printShort( os );
    63         os << std::endl;
    64     }
     57void Declaration::dumpIds( std::ostream &os ) {
     58        for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) {
     59                os << i->first << " -> ";
     60                i->second->printShort( os );
     61                os << std::endl;
     62        } // for
    6563}
    6664
     65// Local Variables: //
     66// tab-width: 4 //
     67// mode: c++ //
     68// compile-command: "make install" //
     69// End: //
  • translator/SynTree/Declaration.h

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Declaration.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 08:46:25 2015
     13// Update Count     : 2
     14//
     15
    116#ifndef DECLARATION_H
    217#define DECLARATION_H
     
    722#include "Parser/LinkageSpec.h"
    823
    9 
    1024class Declaration {
    1125  public:
    12     enum StorageClass { 
    13         NoStorageClass,
    14         Extern,
    15         Static,
    16         Auto,
    17         Register,
    18         Inline,
    19         Fortran,
    20     }; 
    21 
    22     Declaration( const std::string &name, StorageClass sc, LinkageSpec::Type linkage );
    23     Declaration( const Declaration &other );
    24     virtual ~Declaration();
    25 
    26     std::string get_name() const { return name; }
    27     void set_name( std::string newValue ) { name = newValue; }
    28     StorageClass get_storageClass() const { return storageClass; }
    29     void set_storageClass( StorageClass newValue ) { storageClass = newValue; }
    30     LinkageSpec::Type get_linkage() const { return linkage; }
    31     void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; }
    32     UniqueId get_uniqueId() const { return uniqueId; }
    33 
    34     void fixUniqueId( void );
    35     virtual Declaration *clone() const = 0;
    36     virtual void accept( Visitor &v ) = 0;
    37     virtual Declaration *acceptMutator( Mutator &m ) = 0;
    38     virtual void print( std::ostream &os, int indent = 0 ) const = 0;
    39     virtual void printShort( std::ostream &os, int indent = 0 ) const = 0;
    40 
    41     static const char* storageClassName[]; 
    42 
    43     static void dumpIds( std::ostream &os );
    44     static Declaration *declFromId( UniqueId id );
    45   private:
    46     std::string name;
    47     StorageClass storageClass;
    48     LinkageSpec::Type linkage;
    49     UniqueId uniqueId;
     26        enum StorageClass { 
     27                NoStorageClass,
     28                Extern,
     29                Static,
     30                Auto,
     31                Register,
     32                Inline,
     33                Fortran,
     34        };     
     35
     36        Declaration( const std::string &name, StorageClass sc, LinkageSpec::Type linkage );
     37        Declaration( const Declaration &other );
     38        virtual ~Declaration();
     39
     40        std::string get_name() const { return name; }
     41        void set_name( std::string newValue ) { name = newValue; }
     42        StorageClass get_storageClass() const { return storageClass; }
     43        void set_storageClass( StorageClass newValue ) { storageClass = newValue; }
     44        LinkageSpec::Type get_linkage() const { return linkage; }
     45        void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; }
     46        UniqueId get_uniqueId() const { return uniqueId; }
     47
     48        void fixUniqueId( void );
     49        virtual Declaration *clone() const = 0;
     50        virtual void accept( Visitor &v ) = 0;
     51        virtual Declaration *acceptMutator( Mutator &m ) = 0;
     52        virtual void print( std::ostream &os, int indent = 0 ) const = 0;
     53        virtual void printShort( std::ostream &os, int indent = 0 ) const = 0;
     54
     55        static const char* storageClassName[]; 
     56
     57        static void dumpIds( std::ostream &os );
     58        static Declaration *declFromId( UniqueId id );
     59  private:
     60        std::string name;
     61        StorageClass storageClass;
     62        LinkageSpec::Type linkage;
     63        UniqueId uniqueId;
    5064};
    5165
    5266class DeclarationWithType : public Declaration {
    5367  public:
    54     DeclarationWithType( const std::string &name, StorageClass sc, LinkageSpec::Type linkage );
    55     DeclarationWithType( const DeclarationWithType &other );
    56     virtual ~DeclarationWithType();
    57 
    58     std::string get_mangleName() const { return mangleName; }
    59     void set_mangleName( std::string newValue ) { mangleName = newValue; }
    60 
    61     virtual DeclarationWithType *clone() const = 0;
    62     virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
    63 
    64     virtual Type *get_type() const = 0;
    65     virtual void set_type(Type *) = 0;
    66   private:
    67     // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
    68     std::string mangleName;
     68        DeclarationWithType( const std::string &name, StorageClass sc, LinkageSpec::Type linkage );
     69        DeclarationWithType( const DeclarationWithType &other );
     70        virtual ~DeclarationWithType();
     71
     72        std::string get_mangleName() const { return mangleName; }
     73        void set_mangleName( std::string newValue ) { mangleName = newValue; }
     74
     75        virtual DeclarationWithType *clone() const = 0;
     76        virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
     77
     78        virtual Type *get_type() const = 0;
     79        virtual void set_type(Type *) = 0;
     80  private:
     81        // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
     82        std::string mangleName;
    6983};
    7084
    7185class ObjectDecl : public DeclarationWithType {
    72     typedef DeclarationWithType Parent;
    73   public:
    74     ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init );
    75     ObjectDecl( const ObjectDecl &other );
    76     virtual ~ObjectDecl();
    77 
    78     virtual Type *get_type() const { return type; }
    79     virtual void set_type(Type *newType) { type = newType; }
    80 
    81     Initializer *get_init() const { return init; }
    82     void set_init( Initializer *newValue ) { init = newValue; }
    83     Expression *get_bitfieldWidth() const { return bitfieldWidth; }
    84     void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
    85 
    86     virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
    87     virtual void accept( Visitor &v ) { v.visit( this ); }
    88     virtual ObjectDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    89     virtual void print( std::ostream &os, int indent = 0 ) const;
    90     virtual void printShort( std::ostream &os, int indent = 0 ) const;
    91   private:
    92     Type *type;
    93     Initializer *init;
    94     Expression *bitfieldWidth;
     86        typedef DeclarationWithType Parent;
     87  public:
     88        ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init );
     89        ObjectDecl( const ObjectDecl &other );
     90        virtual ~ObjectDecl();
     91
     92        virtual Type *get_type() const { return type; }
     93        virtual void set_type(Type *newType) { type = newType; }
     94
     95        Initializer *get_init() const { return init; }
     96        void set_init( Initializer *newValue ) { init = newValue; }
     97        Expression *get_bitfieldWidth() const { return bitfieldWidth; }
     98        void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
     99
     100        virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
     101        virtual void accept( Visitor &v ) { v.visit( this ); }
     102        virtual ObjectDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     103        virtual void print( std::ostream &os, int indent = 0 ) const;
     104        virtual void printShort( std::ostream &os, int indent = 0 ) const;
     105  private:
     106        Type *type;
     107        Initializer *init;
     108        Expression *bitfieldWidth;
    95109};
    96110
    97111class FunctionDecl : public DeclarationWithType {
    98     typedef DeclarationWithType Parent;
    99   public:
    100     FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline );
    101     FunctionDecl( const FunctionDecl &other );
    102     virtual ~FunctionDecl();
    103 
    104     Type *get_type() const;
    105     virtual void set_type(Type *);
    106 
    107     FunctionType *get_functionType() const { return type; }
    108     void set_functionType( FunctionType *newValue ) { type = newValue; }
    109     CompoundStmt *get_statements() const { return statements; }
    110     void set_statements( CompoundStmt *newValue ) { statements = newValue; }
     112        typedef DeclarationWithType Parent;
     113  public:
     114        FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline );
     115        FunctionDecl( const FunctionDecl &other );
     116        virtual ~FunctionDecl();
     117
     118        Type *get_type() const;
     119        virtual void set_type(Type *);
     120
     121        FunctionType *get_functionType() const { return type; }
     122        void set_functionType( FunctionType *newValue ) { type = newValue; }
     123        CompoundStmt *get_statements() const { return statements; }
     124        void set_statements( CompoundStmt *newValue ) { statements = newValue; }
    111125//    bool get_isInline() const { return isInline; }
    112126//    void set_isInline( bool newValue ) { isInline = newValue; }
    113     std::list< std::string >& get_oldIdents() { return oldIdents; }
    114     std::list< Declaration* >& get_oldDecls() { return oldDecls; }
    115 
    116     virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
    117     virtual void accept( Visitor &v ) { v.visit( this ); }
    118     virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    119     virtual void print( std::ostream &os, int indent = 0 ) const;
    120     virtual void printShort( std::ostream &os, int indent = 0 ) const;
    121   private:
    122     FunctionType *type;
    123     CompoundStmt *statements;
    124     bool isInline;
    125     std::list< std::string > oldIdents;
    126     std::list< Declaration* > oldDecls;
     127        std::list< std::string >& get_oldIdents() { return oldIdents; }
     128        std::list< Declaration* >& get_oldDecls() { return oldDecls; }
     129
     130        virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
     131        virtual void accept( Visitor &v ) { v.visit( this ); }
     132        virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     133        virtual void print( std::ostream &os, int indent = 0 ) const;
     134        virtual void printShort( std::ostream &os, int indent = 0 ) const;
     135  private:
     136        FunctionType *type;
     137        CompoundStmt *statements;
     138        bool isInline;
     139        std::list< std::string > oldIdents;
     140        std::list< Declaration* > oldDecls;
    127141};
    128142
    129143class NamedTypeDecl : public Declaration {
    130     typedef Declaration Parent;
    131   public:
    132     NamedTypeDecl( const std::string &name, StorageClass sc, Type *type );
    133     NamedTypeDecl( const TypeDecl &other );
    134     virtual ~NamedTypeDecl();
    135 
    136     Type *get_base() const { return base; }
    137     void set_base( Type *newValue ) { base = newValue; }
    138     std::list< TypeDecl* >& get_parameters() { return parameters; }
    139     std::list< DeclarationWithType* >& get_assertions() { return assertions; }
    140 
    141     virtual NamedTypeDecl *clone() const = 0;
    142     virtual void print( std::ostream &os, int indent = 0 ) const;
    143     virtual void printShort( std::ostream &os, int indent = 0 ) const;
     144        typedef Declaration Parent;
     145  public:
     146        NamedTypeDecl( const std::string &name, StorageClass sc, Type *type );
     147        NamedTypeDecl( const TypeDecl &other );
     148        virtual ~NamedTypeDecl();
     149
     150        Type *get_base() const { return base; }
     151        void set_base( Type *newValue ) { base = newValue; }
     152        std::list< TypeDecl* >& get_parameters() { return parameters; }
     153        std::list< DeclarationWithType* >& get_assertions() { return assertions; }
     154
     155        virtual NamedTypeDecl *clone() const = 0;
     156        virtual void print( std::ostream &os, int indent = 0 ) const;
     157        virtual void printShort( std::ostream &os, int indent = 0 ) const;
    144158  protected:
    145     virtual std::string typeString() const = 0;
    146   private:
    147     Type *base;
    148     std::list< TypeDecl* > parameters;
    149     std::list< DeclarationWithType* > assertions;
     159        virtual std::string typeString() const = 0;
     160  private:
     161        Type *base;
     162        std::list< TypeDecl* > parameters;
     163        std::list< DeclarationWithType* > assertions;
    150164};
    151165
    152166class TypeDecl : public NamedTypeDecl {
    153     typedef NamedTypeDecl Parent;
    154   public:
    155     enum Kind { Any, Dtype, Ftype };
    156 
    157     TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind );
    158     TypeDecl( const TypeDecl &other );
    159 
    160     Kind get_kind() const { return kind; }
    161 
    162     virtual TypeDecl *clone() const { return new TypeDecl( *this ); }
    163     virtual void accept( Visitor &v ) { v.visit( this ); }
    164     virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    165   private:
    166     virtual std::string typeString() const;
    167     Kind kind;
     167        typedef NamedTypeDecl Parent;
     168  public:
     169        enum Kind { Any, Dtype, Ftype };
     170
     171        TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind );
     172        TypeDecl( const TypeDecl &other );
     173
     174        Kind get_kind() const { return kind; }
     175
     176        virtual TypeDecl *clone() const { return new TypeDecl( *this ); }
     177        virtual void accept( Visitor &v ) { v.visit( this ); }
     178        virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     179  private:
     180        virtual std::string typeString() const;
     181        Kind kind;
    168182};
    169183
    170184class TypedefDecl : public NamedTypeDecl {
    171     typedef NamedTypeDecl Parent;
    172   public:
    173     TypedefDecl( const std::string &name, StorageClass sc, Type *type ) : Parent( name, sc, type ) {}
    174     TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
    175 
    176     virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); }
    177     virtual void accept( Visitor &v ) { v.visit( this ); }
    178     virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    179   private:
    180     virtual std::string typeString() const;
     185        typedef NamedTypeDecl Parent;
     186  public:
     187        TypedefDecl( const std::string &name, StorageClass sc, Type *type ) : Parent( name, sc, type ) {}
     188        TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
     189
     190        virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); }
     191        virtual void accept( Visitor &v ) { v.visit( this ); }
     192        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     193  private:
     194        virtual std::string typeString() const;
    181195};
    182196
    183197class AggregateDecl : public Declaration {
    184     typedef Declaration Parent;
    185   public:
    186     AggregateDecl( const std::string &name );
    187     AggregateDecl( const AggregateDecl &other );
    188     virtual ~AggregateDecl();
    189 
    190     std::list<Declaration*>& get_members() { return members; }
    191     std::list<TypeDecl*>& get_parameters() { return parameters; }
    192 
    193     virtual void print( std::ostream &os, int indent = 0 ) const;
    194     virtual void printShort( std::ostream &os, int indent = 0 ) const;
     198        typedef Declaration Parent;
     199  public:
     200        AggregateDecl( const std::string &name );
     201        AggregateDecl( const AggregateDecl &other );
     202        virtual ~AggregateDecl();
     203
     204        std::list<Declaration*>& get_members() { return members; }
     205        std::list<TypeDecl*>& get_parameters() { return parameters; }
     206
     207        virtual void print( std::ostream &os, int indent = 0 ) const;
     208        virtual void printShort( std::ostream &os, int indent = 0 ) const;
    195209  protected:
    196     virtual std::string typeString() const = 0;
    197 
    198   private:
    199     std::list<Declaration*> members;
    200     std::list<TypeDecl*> parameters;
     210        virtual std::string typeString() const = 0;
     211
     212  private:
     213        std::list<Declaration*> members;
     214        std::list<TypeDecl*> parameters;
    201215};
    202216
    203217class StructDecl : public AggregateDecl {
    204     typedef AggregateDecl Parent;
    205   public:
    206     StructDecl( const std::string &name ) : Parent( name ) {}
    207     StructDecl( const StructDecl &other ) : Parent( other ) {}
    208 
    209     virtual StructDecl *clone() const { return new StructDecl( *this ); }
    210     virtual void accept( Visitor &v ) { v.visit( this ); }
    211     virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    212 
    213   private:
    214     virtual std::string typeString() const;
     218        typedef AggregateDecl Parent;
     219  public:
     220        StructDecl( const std::string &name ) : Parent( name ) {}
     221        StructDecl( const StructDecl &other ) : Parent( other ) {}
     222
     223        virtual StructDecl *clone() const { return new StructDecl( *this ); }
     224        virtual void accept( Visitor &v ) { v.visit( this ); }
     225        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     226
     227  private:
     228        virtual std::string typeString() const;
    215229};
    216230
    217231class UnionDecl : public AggregateDecl {
    218     typedef AggregateDecl Parent;
    219   public:
    220     UnionDecl( const std::string &name ) : Parent( name ) {}
    221     UnionDecl( const UnionDecl &other ) : Parent( other ) {}
    222 
    223     virtual UnionDecl *clone() const { return new UnionDecl( *this ); }
    224     virtual void accept( Visitor &v ) { v.visit( this ); }
    225     virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    226   private:
    227     virtual std::string typeString() const;
     232        typedef AggregateDecl Parent;
     233  public:
     234        UnionDecl( const std::string &name ) : Parent( name ) {}
     235        UnionDecl( const UnionDecl &other ) : Parent( other ) {}
     236
     237        virtual UnionDecl *clone() const { return new UnionDecl( *this ); }
     238        virtual void accept( Visitor &v ) { v.visit( this ); }
     239        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     240  private:
     241        virtual std::string typeString() const;
    228242};
    229243
    230244class EnumDecl : public AggregateDecl {
    231     typedef AggregateDecl Parent;
    232   public:
    233     EnumDecl( const std::string &name ) : Parent( name ) {}
    234     EnumDecl( const EnumDecl &other ) : Parent( other ) {}
    235 
    236     virtual EnumDecl *clone() const { return new EnumDecl( *this ); }
    237     virtual void accept( Visitor &v ) { v.visit( this ); }
    238     virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    239   private:
    240     virtual std::string typeString() const;
     245        typedef AggregateDecl Parent;
     246  public:
     247        EnumDecl( const std::string &name ) : Parent( name ) {}
     248        EnumDecl( const EnumDecl &other ) : Parent( other ) {}
     249
     250        virtual EnumDecl *clone() const { return new EnumDecl( *this ); }
     251        virtual void accept( Visitor &v ) { v.visit( this ); }
     252        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     253  private:
     254        virtual std::string typeString() const;
    241255};
    242256
    243257class ContextDecl : public AggregateDecl {
    244     typedef AggregateDecl Parent;
    245   public:
    246     ContextDecl( const std::string &name ) : Parent( name ) {}
    247     ContextDecl( const ContextDecl &other ) : Parent( other ) {}
    248 
    249     virtual ContextDecl *clone() const { return new ContextDecl( *this ); }
    250     virtual void accept( Visitor &v ) { v.visit( this ); }
    251     virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    252   private:
    253     virtual std::string typeString() const;
     258        typedef AggregateDecl Parent;
     259  public:
     260        ContextDecl( const std::string &name ) : Parent( name ) {}
     261        ContextDecl( const ContextDecl &other ) : Parent( other ) {}
     262
     263        virtual ContextDecl *clone() const { return new ContextDecl( *this ); }
     264        virtual void accept( Visitor &v ) { v.visit( this ); }
     265        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     266  private:
     267        virtual std::string typeString() const;
    254268};
    255269
    256270#endif // DECLARATION_H
     271
     272// Local Variables: //
     273// tab-width: 4 //
     274// mode: c++ //
     275// compile-command: "make install" //
     276// End: //
  • translator/SynTree/DeclarationWithType.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: DeclarationWithType.cc,v 1.9 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// DeclarationWithType.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 08:20:23 2015
     13// Update Count     : 2
     14//
    715
    816#include "Declaration.h"
     
    1018#include "utility.h"
    1119
    12 
    1320DeclarationWithType::DeclarationWithType( const std::string &name, StorageClass sc, LinkageSpec::Type linkage )
    14     : Declaration( name, sc, linkage )
    15 {
     21                : Declaration( name, sc, linkage ) {
    1622}
    1723
    1824DeclarationWithType::DeclarationWithType( const DeclarationWithType &other )
    19     : Declaration( other ), mangleName( other.mangleName )
    20 {
     25                : Declaration( other ), mangleName( other.mangleName ) {
    2126}
    2227
    23 DeclarationWithType::~DeclarationWithType()
    24 {
     28DeclarationWithType::~DeclarationWithType() {
    2529}
    2630
     31// Local Variables: //
     32// tab-width: 4 //
     33// mode: c++ //
     34// compile-command: "make install" //
     35// End: //
  • translator/SynTree/Expression.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Expression.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 08:27:07 2015
     13// Update Count     : 2
     14//
     15
    116#include <iostream>
    217#include <cassert>
     
    1429
    1530
    16 //*** Expression
    1731Expression::Expression( Expression *_aname ) : env( 0 ), argName( _aname ) {}
    18 Expression::Expression( const Expression &other )
    19     : env( maybeClone( other.env ) )
    20  {
    21      cloneAll( other.results, results );
    22      argName = other.get_argName();
    23  }
    24 Expression::~Expression()
    25 {
    26     delete env;
    27     // delete argName;  // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
    28     deleteAll( results );
    29 }
    30 
    31 void
    32 Expression::add_result( Type *t )
    33 {
    34     if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) {
    35         std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) );
    36     } else {
    37         results.push_back(t);
    38     }
     32
     33Expression::Expression( const Expression &other ) : env( maybeClone( other.env ) ) {
     34        cloneAll( other.results, results );
     35        argName = other.get_argName();
     36}
     37
     38Expression::~Expression() {
     39        delete env;
     40        // delete argName;      // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
     41        deleteAll( results );
     42}
     43
     44void Expression::add_result( Type *t ) {
     45        if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) {
     46                std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) );
     47        } else {
     48                results.push_back(t);
     49        } // if
    3950}
    4051
    4152void Expression::print(std::ostream &os, int indent) const {
    42     if ( env ) {
    43         os << std::string(indent, ' ') << "with environment:" << std::endl;
    44         env->print( os, indent+2 );
    45     }
    46 
    47     if ( argName ) {
    48         os << std::string(indent, ' ') << "with designator:";
    49         argName->print( os, indent+2 );
    50     }
    51 }
    52 
    53 //*** ConstantExpr
    54 ConstantExpr::ConstantExpr(Constant _c, Expression *_aname ):
    55     Expression( _aname ), constant(_c)
    56 {
    57     add_result( constant.get_type()->clone() );
    58 }
    59 
    60 ConstantExpr::ConstantExpr( const ConstantExpr &other)
    61     : Expression( other ), constant( other.constant )
    62 {}
     53        if ( env ) {
     54                os << std::string(indent, ' ') << "with environment:" << std::endl;
     55                env->print( os, indent+2 );
     56        } // if
     57
     58        if ( argName ) {
     59                os << std::string(indent, ' ') << "with designator:";
     60                argName->print( os, indent+2 );
     61        } // if
     62}
     63
     64ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) {
     65        add_result( constant.get_type()->clone() );
     66}
     67
     68ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
     69}
    6370
    6471ConstantExpr::~ConstantExpr() {}
    6572
    66 void ConstantExpr::print(std::ostream &os, int indent) const {
    67     os << std::string(indent, ' ') << "Constant Expression: " ;
    68     constant.print(os);
    69     os << std::endl;
    70     Expression::print( os, indent );
    71 }
    72 
    73 //*** VariableExpr
    74 VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var )
    75 {
    76     add_result( var->get_type()->clone() );
    77     for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
    78         (*i)->set_isLvalue( true );
    79     }
    80 }
    81 
    82 VariableExpr::VariableExpr( const VariableExpr &other )
    83     : Expression( other ), var( other.var )
    84 {
    85 }
    86 
    87 VariableExpr::~VariableExpr()
    88 {
    89     // don't delete the declaration, since it points somewhere else in the tree
    90 }
    91 
    92 void VariableExpr::print(std::ostream &os, int indent) const {
    93     os << std::string(indent, ' ') << "Variable Expression: ";
    94 
    95     Declaration *decl = get_var();
    96     // if ( decl != 0) decl->print(os, indent + 2);
    97     if ( decl != 0) decl->printShort(os, indent + 2);
    98     os << std::endl;
    99     Expression::print( os, indent );
    100 }
    101 
    102 //*** SizeofExpr
     73void ConstantExpr::print( std::ostream &os, int indent ) const {
     74        os << std::string(indent, ' ') << "Constant Expression: " ;
     75        constant.print(os);
     76        os << std::endl;
     77        Expression::print( os, indent );
     78}
     79
     80VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) {
     81        add_result( var->get_type()->clone() );
     82        for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
     83                (*i)->set_isLvalue( true );
     84        } // for
     85}
     86
     87VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) {
     88}
     89
     90VariableExpr::~VariableExpr() {
     91        // don't delete the declaration, since it points somewhere else in the tree
     92}
     93
     94void VariableExpr::print( std::ostream &os, int indent ) const {
     95        os << std::string(indent, ' ') << "Variable Expression: ";
     96
     97        Declaration *decl = get_var();
     98        // if ( decl != 0) decl->print(os, indent + 2);
     99        if ( decl != 0) decl->printShort(os, indent + 2);
     100        os << std::endl;
     101        Expression::print( os, indent );
     102}
     103
    103104SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) :
    104     Expression( _aname ), expr(expr_), type(0), isType(false)
    105 {
    106     add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) );
     105                Expression( _aname ), expr(expr_), type(0), isType(false) {
     106        add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) );
    107107}
    108108
    109109SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) :
    110     Expression( _aname ), expr(0), type(type_), isType(true)
    111 {
    112     add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) );
    113 }
    114 
    115 SizeofExpr::SizeofExpr( const SizeofExpr &other )
    116     : Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType )
    117 {
    118 }
    119 
    120 SizeofExpr::~SizeofExpr(){
    121     delete expr;
    122     delete type;
     110                Expression( _aname ), expr(0), type(type_), isType(true) {
     111        add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) );
     112}
     113
     114SizeofExpr::SizeofExpr( const SizeofExpr &other ) :
     115        Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
     116}
     117
     118SizeofExpr::~SizeofExpr() {
     119        delete expr;
     120        delete type;
    123121}
    124122
    125123void SizeofExpr::print( std::ostream &os, int indent) const {
    126     os << std::string(indent, ' ') << "Sizeof Expression on: ";
    127 
    128     if (isType)
    129         type->print(os, indent + 2);
    130     else
    131         expr->print(os, indent + 2);
    132 
    133     os << std::endl;
    134     Expression::print( os, indent );
    135 }
    136 
    137 //*** AttrExpr
     124        os << std::string(indent, ' ') << "Sizeof Expression on: ";
     125
     126        if (isType)
     127                type->print(os, indent + 2);
     128        else
     129                expr->print(os, indent + 2);
     130
     131        os << std::endl;
     132        Expression::print( os, indent );
     133}
     134
    138135AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) :
    139     Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false)
    140 {
     136                Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) {
    141137}
    142138
    143139AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) :
    144     Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true)
    145 {
    146 }
    147 
    148 AttrExpr::AttrExpr( const AttrExpr &other )
    149     : Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType )
    150 {
    151 }
    152 
    153 AttrExpr::~AttrExpr(){
    154     delete attr;
    155     delete expr;
    156     delete type;
     140                Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) {
     141}
     142
     143AttrExpr::AttrExpr( const AttrExpr &other ) :
     144                Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
     145}
     146
     147AttrExpr::~AttrExpr() {
     148        delete attr;
     149        delete expr;
     150        delete type;
    157151}
    158152
    159153void AttrExpr::print( std::ostream &os, int indent) const {
    160     os << std::string(indent, ' ') << "Attr ";
    161     attr->print( os, indent + 2 );
    162     if ( isType || expr ) {
    163         os << "applied to: ";
    164 
    165         if (isType)
    166             type->print(os, indent + 2);
    167         else
    168             expr->print(os, indent + 2);
    169     }
    170 
    171     os << std::endl;
    172     Expression::print( os, indent );
    173 }
    174 
    175 //*** CastExpr
    176 CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_)
    177 {
    178     add_result(toType);
     154        os << std::string(indent, ' ') << "Attr ";
     155        attr->print( os, indent + 2 );
     156        if ( isType || expr ) {
     157                os << "applied to: ";
     158
     159                if (isType)
     160                        type->print(os, indent + 2);
     161                else
     162                        expr->print(os, indent + 2);
     163        } // if
     164
     165        os << std::endl;
     166        Expression::print( os, indent );
     167}
     168
     169CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) {
     170        add_result(toType);
    179171}
    180172
     
    182174}
    183175
    184 CastExpr::CastExpr( const CastExpr &other )
    185     : Expression( other ), arg( maybeClone( other.arg ) )
    186 {
     176CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
    187177}
    188178
    189179CastExpr::~CastExpr() {
    190     delete arg;
     180        delete arg;
    191181}
    192182
     
    194184
    195185void CastExpr::print( std::ostream &os, int indent ) const {
    196     os << std::string(indent, ' ') << "Cast of:" << std::endl;
    197     arg->print(os, indent+2);
    198     os << std::endl << std::string(indent, ' ') << "to:" << std::endl;
    199     if ( results.empty() ) {
    200         os << std::string(indent+2, ' ') << "nothing" << std::endl;
    201     } else {
    202         printAll(results, os, indent+2);
    203     }
    204     Expression::print( os, indent );
    205 }
    206 
    207 //*** UntypedMemberExpr
     186        os << std::string(indent, ' ') << "Cast of:" << std::endl;
     187        arg->print(os, indent+2);
     188        os << std::endl << std::string(indent, ' ') << "to:" << std::endl;
     189        if ( results.empty() ) {
     190                os << std::string(indent+2, ' ') << "nothing" << std::endl;
     191        } else {
     192                printAll(results, os, indent+2);
     193        } // if
     194        Expression::print( os, indent );
     195}
     196
    208197UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) :
    209     Expression( _aname ), member(_member), aggregate(_aggregate) {}
    210 
    211 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other )
    212     : Expression( other ),   member( other.member ), aggregate( maybeClone( other.aggregate ) )
    213 {
     198                Expression( _aname ), member(_member), aggregate(_aggregate) {}
     199
     200UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
     201                Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
    214202}
    215203
    216204UntypedMemberExpr::~UntypedMemberExpr() {
    217     delete aggregate;
     205        delete aggregate;
    218206}
    219207
    220208void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
    221     os << std::string(indent, ' ') << "Member Expression, with field: " << get_member();
    222 
    223     Expression *agg = get_aggregate();
    224     os << std::string(indent, ' ') << "from aggregate: ";
    225     if (agg != 0) agg->print(os, indent + 2);
    226     Expression::print( os, indent );
    227 }
    228 
    229 
    230 //*** MemberExpr
     209        os << std::string(indent, ' ') << "Member Expression, with field: " << get_member();
     210
     211        Expression *agg = get_aggregate();
     212        os << std::string(indent, ' ') << "from aggregate: ";
     213        if (agg != 0) agg->print(os, indent + 2);
     214        Expression::print( os, indent );
     215}
     216
     217
    231218MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
    232     Expression( _aname ), member(_member), aggregate(_aggregate)
    233 {
    234     add_result( member->get_type()->clone() );
    235     for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
    236         (*i)->set_isLvalue( true );
    237     }
    238 }
    239 
    240 MemberExpr::MemberExpr( const MemberExpr &other )
    241     : Expression( other ),   member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) )
    242 {
     219                Expression( _aname ), member(_member), aggregate(_aggregate) {
     220        add_result( member->get_type()->clone() );
     221        for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
     222                (*i)->set_isLvalue( true );
     223        } // for
     224}
     225
     226MemberExpr::MemberExpr( const MemberExpr &other ) :
     227                Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
    243228}
    244229
    245230MemberExpr::~MemberExpr() {
    246     delete member;
    247     delete aggregate;
     231        delete member;
     232        delete aggregate;
    248233}
    249234
    250235void MemberExpr::print( std::ostream &os, int indent ) const {
    251     os << std::string(indent, ' ') << "Member Expression, with field: " << std::endl;
    252 
    253     assert( member );
    254     os << std::string(indent + 2, ' ');
    255     member->print( os, indent + 2 );
    256     os << std::endl;
    257 
    258     Expression *agg = get_aggregate();
    259     os << std::string(indent, ' ') << "from aggregate: " << std::endl;
    260     if (agg != 0) agg->print(os, indent + 2);
    261     Expression::print( os, indent );
    262 }
    263 
    264 
    265 //*** UntypedExpr
     236        os << std::string(indent, ' ') << "Member Expression, with field: " << std::endl;
     237
     238        assert( member );
     239        os << std::string(indent + 2, ' ');
     240        member->print( os, indent + 2 );
     241        os << std::endl;
     242
     243        Expression *agg = get_aggregate();
     244        os << std::string(indent, ' ') << "from aggregate: " << std::endl;
     245        if (agg != 0) agg->print(os, indent + 2);
     246        Expression::print( os, indent );
     247}
     248
     249
    266250UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function ) {}
    267251
    268 UntypedExpr::UntypedExpr( const UntypedExpr &other )
    269     : Expression( other ), function( maybeClone( other.function ) )
    270 {
    271     cloneAll( other.args, args );
     252UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
     253                Expression( other ), function( maybeClone( other.function ) ) {
     254        cloneAll( other.args, args );
    272255}
    273256
    274257UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) :
    275     Expression( _aname ), function(_function), args(_args) {}
     258                Expression( _aname ), function(_function), args(_args) {}
    276259
    277260UntypedExpr::~UntypedExpr() {}
    278261
    279262void UntypedExpr::print( std::ostream &os, int indent ) const {
    280     os << std::string(indent, ' ') << "Applying untyped: " << std::endl;
    281     function->print(os, indent + 4);
    282     os << "\r" << std::string(indent, ' ') << "...to: " << std::endl;
    283     printArgs(os, indent + 4);
    284     Expression::print( os, indent );
    285 }
    286 
    287 void UntypedExpr::printArgs(std::ostream &os, int indent ) const {
    288     std::list<Expression *>::const_iterator i;
    289     for (i = args.begin(); i != args.end(); i++)
    290         (*i)->print(os, indent);
    291 }
    292 
    293 //*** NameExpr
     263        os << std::string(indent, ' ') << "Applying untyped: " << std::endl;
     264        function->print(os, indent + 4);
     265        os << "\r" << std::string(indent, ' ') << "...to: " << std::endl;
     266        printArgs(os, indent + 4);
     267        Expression::print( os, indent );
     268}
     269
     270void UntypedExpr::printArgs( std::ostream &os, int indent ) const {
     271        std::list<Expression *>::const_iterator i;
     272        for (i = args.begin(); i != args.end(); i++)
     273                (*i)->print(os, indent);
     274}
     275
    294276NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {}
    295277
    296 NameExpr::NameExpr( const NameExpr &other )
    297     : Expression( other ), name( other.name )
    298 {
     278NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
    299279}
    300280
     
    302282
    303283void NameExpr::print( std::ostream &os, int indent ) const {
    304     os << std::string(indent, ' ') << "Name: " << get_name() << std::endl;
    305     Expression::print( os, indent );
    306 }
    307 
    308 //*** LogicalExpr
     284        os << std::string(indent, ' ') << "Name: " << get_name() << std::endl;
     285        Expression::print( os, indent );
     286}
     287
    309288LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) :
    310     Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp)
    311 {
    312     add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
    313 }
    314 
    315 LogicalExpr::LogicalExpr( const LogicalExpr &other )
    316     : Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd )
    317 {
     289                Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) {
     290        add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
     291}
     292
     293LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
     294                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
    318295}
    319296
    320297LogicalExpr::~LogicalExpr(){
    321     delete arg1;
    322     delete arg2;
     298        delete arg1;
     299        delete arg2;
    323300}
    324301
    325302void LogicalExpr::print( std::ostream &os, int indent )const {
    326     os << std::string(indent, ' ') << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: ";
    327     arg1->print(os);
    328     os << " and ";
    329     arg2->print(os);
    330     os << std::endl;
    331     Expression::print( os, indent );
    332 }
    333 
    334 //*** ConditionalExpr
     303        os << std::string(indent, ' ') << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: ";
     304        arg1->print(os);
     305        os << " and ";
     306        arg2->print(os);
     307        os << std::endl;
     308        Expression::print( os, indent );
     309}
     310
    335311ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) :
    336     Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {}
    337 
    338 ConditionalExpr::ConditionalExpr( const ConditionalExpr &other )
    339      : Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) )
    340  {
    341  }
     312                Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {}
     313
     314ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
     315                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
     316}
    342317
    343318ConditionalExpr::~ConditionalExpr() {
    344     delete arg1;
    345     delete arg2;
    346     delete arg3;
     319        delete arg1;
     320        delete arg2;
     321        delete arg3;
    347322}
    348323
    349324void ConditionalExpr::print( std::ostream &os, int indent ) const {
    350     os << std::string(indent, ' ') << "Conditional expression on: " << std::endl;
    351     arg1->print( os, indent+2 );
    352     os << std::string(indent, ' ') << "First alternative:" << std::endl;
    353     arg2->print( os, indent+2 );
    354     os << std::string(indent, ' ') << "Second alternative:" << std::endl;
    355     arg3->print( os, indent+2 );
    356     os << std::endl;
    357     Expression::print( os, indent );
    358 }
    359 
    360 //*** UntypedValofExpr
    361 void UntypedValofExpr::print( std::ostream &os, int indent ) const
    362 {
    363     os << std::string(indent, ' ') << "Valof Expression: " << std::endl;
    364     if ( get_body() != 0 )
    365         get_body()->print( os, indent + 2 );
    366 }
    367 
    368 
     325        os << std::string(indent, ' ') << "Conditional expression on: " << std::endl;
     326        arg1->print( os, indent+2 );
     327        os << std::string(indent, ' ') << "First alternative:" << std::endl;
     328        arg2->print( os, indent+2 );
     329        os << std::string(indent, ' ') << "Second alternative:" << std::endl;
     330        arg3->print( os, indent+2 );
     331        os << std::endl;
     332        Expression::print( os, indent );
     333}
     334
     335void UntypedValofExpr::print( std::ostream &os, int indent ) const {
     336        os << std::string(indent, ' ') << "Valof Expression: " << std::endl;
     337        if ( get_body() != 0 )
     338                get_body()->print( os, indent + 2 );
     339}
     340
     341// Local Variables: //
     342// tab-width: 4 //
     343// mode: c++ //
     344// compile-command: "make install" //
     345// End: //
  • translator/SynTree/Expression.h

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: Expression.h,v 1.31 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Expression.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 08:46:15 2015
     13// Update Count     : 3
     14//
    715
    816#ifndef EXPRESSION_H
     
    1523#include "Constant.h"
    1624
    17 
    18 class Expression
    19 {
    20 public:
    21     Expression(Expression *_aname = 0 );
    22     Expression( const Expression &other );
    23     virtual ~Expression();
    24 
    25     std::list<Type *>& get_results() { return results; }
    26     void add_result(Type *t);
    27 
    28     TypeSubstitution *get_env() const { return env; }
    29     void set_env( TypeSubstitution *newValue ) { env = newValue; }
    30     Expression *get_argName() const { return argName; }
    31     void set_argName( Expression *name ) { argName = name; }
    32 
    33     virtual Expression *clone() const = 0;
    34     virtual void accept( Visitor &v ) = 0;
    35     virtual Expression *acceptMutator( Mutator &m ) = 0;
    36     virtual void print( std::ostream &os, int indent = 0 ) const;
    37    
    38 protected:
    39     std::list<Type *> results;
    40     TypeSubstitution *env;
    41     Expression* argName; // if expression is used as an argument, it can be "designated" by this name
     25class Expression {
     26  public:
     27        Expression(Expression *_aname = 0 );
     28        Expression( const Expression &other );
     29        virtual ~Expression();
     30
     31        std::list<Type *>& get_results() { return results; }
     32        void add_result(Type *t);
     33
     34        TypeSubstitution *get_env() const { return env; }
     35        void set_env( TypeSubstitution *newValue ) { env = newValue; }
     36        Expression *get_argName() const { return argName; }
     37        void set_argName( Expression *name ) { argName = name; }
     38
     39        virtual Expression *clone() const = 0;
     40        virtual void accept( Visitor &v ) = 0;
     41        virtual Expression *acceptMutator( Mutator &m ) = 0;
     42        virtual void print( std::ostream &os, int indent = 0 ) const;
     43  protected:
     44        std::list<Type *> results;
     45        TypeSubstitution *env;
     46        Expression* argName; // if expression is used as an argument, it can be "designated" by this name
    4247};
    4348
    4449// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
    4550// but subject to decay-to-pointer and type parameter renaming
    46 struct ParamEntry
    47 {
    48     ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {}
    49     ParamEntry( UniqueId decl, Type *actualType, Type *formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ) {}
    50     ParamEntry( const ParamEntry &other );
    51     ~ParamEntry();
    52     ParamEntry &operator=( const ParamEntry &other );
    53 
    54     UniqueId decl;
    55     Type *actualType;
    56     Type *formalType;
    57     Expression* expr;
     51
     52struct ParamEntry {
     53        ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {}
     54        ParamEntry( UniqueId decl, Type *actualType, Type *formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ) {}
     55        ParamEntry( const ParamEntry &other );
     56        ~ParamEntry();
     57        ParamEntry &operator=( const ParamEntry &other );
     58
     59        UniqueId decl;
     60        Type *actualType;
     61        Type *formalType;
     62        Expression* expr;
    5863};
    5964
     
    6267// ApplicationExpr represents the application of a function to a set of parameters.  This is the
    6368// result of running an UntypedExpr through the expression analyzer.
    64 class ApplicationExpr : public Expression
    65 {
    66 public:
    67     ApplicationExpr( Expression *function );
    68     ApplicationExpr( const ApplicationExpr &other );
    69     virtual ~ApplicationExpr();
    70 
    71     Expression *get_function() const { return function; }
    72     void set_function( Expression *newValue ) { function = newValue; }
    73     std::list<Expression *>& get_args() { return args; }
    74     InferredParams &get_inferParams() { return inferParams; }
    75 
    76     virtual ApplicationExpr *clone() const { return new ApplicationExpr( *this ); }
    77     virtual void accept( Visitor &v ) { v.visit( this ); }
    78     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    79     virtual void print( std::ostream &os, int indent = 0 ) const;
    80    
    81 private:
    82     Expression *function;
    83     std::list<Expression *> args;
    84     InferredParams inferParams;
     69
     70class ApplicationExpr : public Expression {
     71  public:
     72        ApplicationExpr( Expression *function );
     73        ApplicationExpr( const ApplicationExpr &other );
     74        virtual ~ApplicationExpr();
     75
     76        Expression *get_function() const { return function; }
     77        void set_function( Expression *newValue ) { function = newValue; }
     78        std::list<Expression *>& get_args() { return args; }
     79        InferredParams &get_inferParams() { return inferParams; }
     80
     81        virtual ApplicationExpr *clone() const { return new ApplicationExpr( *this ); }
     82        virtual void accept( Visitor &v ) { v.visit( this ); }
     83        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     84        virtual void print( std::ostream &os, int indent = 0 ) const;
     85  private:
     86        Expression *function;
     87        std::list<Expression *> args;
     88        InferredParams inferParams;
    8589};
    8690
     
    8892// particular overload for the function name has not yet been determined.  Most operators are
    8993// converted into functional form automatically, to permit operator overloading.
    90 class UntypedExpr : public Expression
    91 {
    92 public:
    93     UntypedExpr( Expression *function, Expression *_aname = 0 );
    94     UntypedExpr( const UntypedExpr &other );
    95     UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = 0 );
    96     virtual ~UntypedExpr();
    97 
    98     Expression *get_function() const { return function; }
    99     void set_function( Expression *newValue ) { function = newValue; }
    100 
    101     void set_args( std::list<Expression *> &listArgs ) { args = listArgs; }
    102     std::list<Expression*>::iterator begin_args() { return args.begin(); }
    103     std::list<Expression*>::iterator end_args() { return args.end(); }
    104     std::list<Expression*>& get_args() { return args; }
    105 
    106     virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); }
    107     virtual void accept( Visitor &v ) { v.visit( this ); }
    108     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    109     virtual void print( std::ostream &os, int indent = 0 ) const;
    110     virtual void printArgs(std::ostream &os, int indent = 0) const;
    111    
    112 private:
    113    
    114     Expression *function;
    115     std::list<Expression*> args;
     94
     95class UntypedExpr : public Expression {
     96  public:
     97        UntypedExpr( Expression *function, Expression *_aname = 0 );
     98        UntypedExpr( const UntypedExpr &other );
     99        UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = 0 );
     100        virtual ~UntypedExpr();
     101
     102        Expression *get_function() const { return function; }
     103        void set_function( Expression *newValue ) { function = newValue; }
     104
     105        void set_args( std::list<Expression *> &listArgs ) { args = listArgs; }
     106        std::list<Expression*>::iterator begin_args() { return args.begin(); }
     107        std::list<Expression*>::iterator end_args() { return args.end(); }
     108        std::list<Expression*>& get_args() { return args; }
     109
     110        virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); }
     111        virtual void accept( Visitor &v ) { v.visit( this ); }
     112        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     113        virtual void print( std::ostream &os, int indent = 0 ) const;
     114        virtual void printArgs(std::ostream &os, int indent = 0) const;
     115  private:
     116        Expression *function;
     117        std::list<Expression*> args;
    116118};
    117119
    118120// this class contains a name whose meaning is still not determined
    119 class NameExpr : public Expression
    120 {
    121 public:
    122     NameExpr( std::string name, Expression *_aname = 0 );
    123     NameExpr( const NameExpr &other );
    124     virtual ~NameExpr();
    125 
    126     std::string get_name() const { return name; }
    127     void set_name( std::string newValue ) { name = newValue; }
    128 
    129     virtual NameExpr *clone() const { return new NameExpr( *this ); }
    130     virtual void accept( Visitor &v ) { v.visit( this ); }
    131     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    132     virtual void print( std::ostream &os, int indent = 0 ) const;
    133    
    134 private:
    135    
    136     std::string name;
     121class NameExpr : public Expression {
     122  public:
     123        NameExpr( std::string name, Expression *_aname = 0 );
     124        NameExpr( const NameExpr &other );
     125        virtual ~NameExpr();
     126
     127        std::string get_name() const { return name; }
     128        void set_name( std::string newValue ) { name = newValue; }
     129
     130        virtual NameExpr *clone() const { return new NameExpr( *this ); }
     131        virtual void accept( Visitor &v ) { v.visit( this ); }
     132        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     133        virtual void print( std::ostream &os, int indent = 0 ) const;
     134  private:
     135        std::string name;
    137136};
    138137
     
    141140
    142141// AddressExpr represents a address-of expression, e.g. &e
    143 class AddressExpr : public Expression
    144 {
    145 public:
    146     AddressExpr( Expression *arg, Expression *_aname = 0 );
    147     AddressExpr( const AddressExpr &other );
    148     virtual ~AddressExpr();
    149 
    150     Expression *get_arg() const { return arg; }
    151     void set_arg(Expression *newValue ) { arg = newValue; }
    152 
    153     virtual AddressExpr *clone() const { return new AddressExpr( *this ); }
    154     virtual void accept( Visitor &v ) { v.visit( this ); }
    155     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    156     virtual void print( std::ostream &os, int indent = 0 ) const;
    157    
    158 private:
    159     Expression *arg;
    160 };
    161 
    162 class LabelAddressExpr : public Expression
    163 {
    164 public:
    165     LabelAddressExpr( Expression *arg );
    166     LabelAddressExpr( const AddressExpr &other );
    167     virtual ~LabelAddressExpr();
    168 
    169     Expression *get_arg() const { return arg; }
    170     void set_arg(Expression *newValue ) { arg = newValue; }
    171 
    172     virtual LabelAddressExpr *clone() const { return new LabelAddressExpr( *this ); }
    173     virtual void accept( Visitor &v ) { v.visit( this ); }
    174     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    175     virtual void print( std::ostream &os, int indent = 0 ) const;
    176    
    177 private:
    178     Expression *arg;
     142class AddressExpr : public Expression {
     143  public:
     144        AddressExpr( Expression *arg, Expression *_aname = 0 );
     145        AddressExpr( const AddressExpr &other );
     146        virtual ~AddressExpr();
     147
     148        Expression *get_arg() const { return arg; }
     149        void set_arg(Expression *newValue ) { arg = newValue; }
     150
     151        virtual AddressExpr *clone() const { return new AddressExpr( *this ); }
     152        virtual void accept( Visitor &v ) { v.visit( this ); }
     153        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     154        virtual void print( std::ostream &os, int indent = 0 ) const;
     155  private:
     156        Expression *arg;
     157};
     158
     159class LabelAddressExpr : public Expression {
     160  public:
     161        LabelAddressExpr( Expression *arg );
     162        LabelAddressExpr( const AddressExpr &other );
     163        virtual ~LabelAddressExpr();
     164
     165        Expression *get_arg() const { return arg; }
     166        void set_arg(Expression *newValue ) { arg = newValue; }
     167
     168        virtual LabelAddressExpr *clone() const { return new LabelAddressExpr( *this ); }
     169        virtual void accept( Visitor &v ) { v.visit( this ); }
     170        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     171        virtual void print( std::ostream &os, int indent = 0 ) const;
     172  private:
     173        Expression *arg;
    179174};
    180175
    181176// CastExpr represents a type cast expression, e.g. (int)e
    182 class CastExpr : public Expression
    183 {
    184 public:
    185     CastExpr( Expression *arg, Expression *_aname = 0 );
    186     CastExpr( Expression *arg, Type *toType, Expression *_aname = 0 );
    187     CastExpr( const CastExpr &other );
    188     virtual ~CastExpr();
    189 
    190     Expression *get_arg() const { return arg; }
    191     void set_arg(Expression *newValue ) { arg = newValue; }
    192 
    193     virtual CastExpr *clone() const { return new CastExpr( *this ); }
    194     virtual void accept( Visitor &v ) { v.visit( this ); }
    195     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    196     virtual void print( std::ostream &os, int indent = 0 ) const;
    197    
    198 private:
    199     Expression *arg;
    200 };
    201 
    202 // UntypedMemberExpr represents a member selection operation, e.g. q.p
    203 // before processing by the expression analyzer
    204 class UntypedMemberExpr : public Expression
    205 {
    206 public:
    207     UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = 0 );
    208     UntypedMemberExpr( const UntypedMemberExpr &other );
    209     virtual ~UntypedMemberExpr();
    210 
    211     std::string get_member() const { return member; }
    212     void set_member( const std::string &newValue ) { member = newValue; }
    213     Expression *get_aggregate() const { return aggregate; }
    214     void set_aggregate( Expression *newValue ) { aggregate = newValue; }
    215 
    216     virtual UntypedMemberExpr *clone() const { return new UntypedMemberExpr( *this ); }
    217     virtual void accept( Visitor &v ) { v.visit( this ); }
    218     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    219     virtual void print( std::ostream &os, int indent = 0 ) const;
    220    
    221 private:
    222     std::string member;
    223     Expression *aggregate;
    224 };
    225 
    226 // MemberExpr represents a member selection operation, e.g. q.p
    227 // after processing by the expression analyzer
    228 class MemberExpr : public Expression
    229 {
    230 public:
    231     MemberExpr( DeclarationWithType *member, Expression *aggregate, Expression *_aname = 0 );
    232     MemberExpr( const MemberExpr &other );
    233     virtual ~MemberExpr();
    234 
    235     DeclarationWithType *get_member() const { return member; }
    236     void set_member( DeclarationWithType *newValue ) { member = newValue; }
    237     Expression *get_aggregate() const { return aggregate; }
    238     void set_aggregate( Expression *newValue ) { aggregate = newValue; }
    239 
    240     virtual MemberExpr *clone() const { return new MemberExpr( *this ); }
    241     virtual void accept( Visitor &v ) { v.visit( this ); }
    242     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    243     virtual void print( std::ostream &os, int indent = 0 ) const;
    244    
    245 private:
    246     DeclarationWithType *member;
    247     Expression *aggregate;
     177class CastExpr : public Expression {
     178  public:
     179        CastExpr( Expression *arg, Expression *_aname = 0 );
     180        CastExpr( Expression *arg, Type *toType, Expression *_aname = 0 );
     181        CastExpr( const CastExpr &other );
     182        virtual ~CastExpr();
     183
     184        Expression *get_arg() const { return arg; }
     185        void set_arg(Expression *newValue ) { arg = newValue; }
     186
     187        virtual CastExpr *clone() const { return new CastExpr( *this ); }
     188        virtual void accept( Visitor &v ) { v.visit( this ); }
     189        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     190        virtual void print( std::ostream &os, int indent = 0 ) const;
     191  private:
     192        Expression *arg;
     193};
     194
     195// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
     196class UntypedMemberExpr : public Expression {
     197  public:
     198        UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = 0 );
     199        UntypedMemberExpr( const UntypedMemberExpr &other );
     200        virtual ~UntypedMemberExpr();
     201
     202        std::string get_member() const { return member; }
     203        void set_member( const std::string &newValue ) { member = newValue; }
     204        Expression *get_aggregate() const { return aggregate; }
     205        void set_aggregate( Expression *newValue ) { aggregate = newValue; }
     206
     207        virtual UntypedMemberExpr *clone() const { return new UntypedMemberExpr( *this ); }
     208        virtual void accept( Visitor &v ) { v.visit( this ); }
     209        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     210        virtual void print( std::ostream &os, int indent = 0 ) const;
     211  private:
     212        std::string member;
     213        Expression *aggregate;
     214};
     215
     216// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
     217class MemberExpr : public Expression {
     218  public:
     219        MemberExpr( DeclarationWithType *member, Expression *aggregate, Expression *_aname = 0 );
     220        MemberExpr( const MemberExpr &other );
     221        virtual ~MemberExpr();
     222
     223        DeclarationWithType *get_member() const { return member; }
     224        void set_member( DeclarationWithType *newValue ) { member = newValue; }
     225        Expression *get_aggregate() const { return aggregate; }
     226        void set_aggregate( Expression *newValue ) { aggregate = newValue; }
     227
     228        virtual MemberExpr *clone() const { return new MemberExpr( *this ); }
     229        virtual void accept( Visitor &v ) { v.visit( this ); }
     230        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     231        virtual void print( std::ostream &os, int indent = 0 ) const;
     232  private:
     233        DeclarationWithType *member;
     234        Expression *aggregate;
    248235};
    249236
    250237// VariableExpr represents an expression that simply refers to the value of a named variable
    251 class VariableExpr : public Expression
    252 {
    253 public:
    254     VariableExpr( DeclarationWithType *var, Expression *_aname = 0 );
    255     VariableExpr( const VariableExpr &other );
    256     virtual ~VariableExpr();
    257 
    258     DeclarationWithType *get_var() const { return var; }
    259     void set_var( DeclarationWithType *newValue ) { var = newValue; }
    260 
    261     virtual VariableExpr *clone() const { return new VariableExpr( *this ); }
    262     virtual void accept( Visitor &v ) { v.visit( this ); }
    263     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    264     virtual void print( std::ostream &os, int indent = 0 ) const;
    265    
    266 private:
    267     DeclarationWithType *var;
     238class VariableExpr : public Expression {
     239  public:
     240        VariableExpr( DeclarationWithType *var, Expression *_aname = 0 );
     241        VariableExpr( const VariableExpr &other );
     242        virtual ~VariableExpr();
     243
     244        DeclarationWithType *get_var() const { return var; }
     245        void set_var( DeclarationWithType *newValue ) { var = newValue; }
     246
     247        virtual VariableExpr *clone() const { return new VariableExpr( *this ); }
     248        virtual void accept( Visitor &v ) { v.visit( this ); }
     249        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     250        virtual void print( std::ostream &os, int indent = 0 ) const;
     251  private:
     252        DeclarationWithType *var;
    268253};
    269254
    270255// ConstantExpr represents an expression that simply refers to the value of a constant
    271 class ConstantExpr : public Expression
    272 {
    273 public:
    274     ConstantExpr( Constant constant, Expression *_aname = 0 );
    275     ConstantExpr( const ConstantExpr &other );
    276     virtual ~ConstantExpr();
    277 
    278     Constant *get_constant() { return &constant; }
    279     void set_constant( const Constant &newValue ) { constant = newValue; }
    280 
    281     virtual ConstantExpr *clone() const { return new ConstantExpr( *this ); }
    282     virtual void accept( Visitor &v ) { v.visit( this ); }
    283     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    284     virtual void print( std::ostream &os, int indent = 0 ) const;
    285    
    286 private:
    287     Constant constant;
     256class ConstantExpr : public Expression {
     257  public:
     258        ConstantExpr( Constant constant, Expression *_aname = 0 );
     259        ConstantExpr( const ConstantExpr &other );
     260        virtual ~ConstantExpr();
     261
     262        Constant *get_constant() { return &constant; }
     263        void set_constant( const Constant &newValue ) { constant = newValue; }
     264
     265        virtual ConstantExpr *clone() const { return new ConstantExpr( *this ); }
     266        virtual void accept( Visitor &v ) { v.visit( this ); }
     267        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     268        virtual void print( std::ostream &os, int indent = 0 ) const;
     269  private:
     270        Constant constant;
    288271};
    289272
    290273// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
    291 class SizeofExpr : public Expression
    292 {
    293 public:
    294     SizeofExpr( Expression *expr, Expression *_aname = 0 );
    295     SizeofExpr( const SizeofExpr &other );
    296     SizeofExpr( Type *type, Expression *_aname = 0 );
    297     virtual ~SizeofExpr();
    298 
    299     Expression *get_expr() const { return expr; }
    300     void set_expr( Expression *newValue ) { expr = newValue; }
    301     Type *get_type() const { return type; }
    302     void set_type( Type *newValue ) { type = newValue; }
    303     bool get_isType() const { return isType; }
    304     void set_isType( bool newValue ) { isType = newValue; }
    305 
    306     virtual SizeofExpr *clone() const { return new SizeofExpr( *this ); }
    307     virtual void accept( Visitor &v ) { v.visit( this ); }
    308     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    309     virtual void print( std::ostream &os, int indent = 0 ) const;
    310    
    311 private:
    312     Expression *expr;
    313     Type *type;
    314     bool isType;
     274class SizeofExpr : public Expression {
     275  public:
     276        SizeofExpr( Expression *expr, Expression *_aname = 0 );
     277        SizeofExpr( const SizeofExpr &other );
     278        SizeofExpr( Type *type, Expression *_aname = 0 );
     279        virtual ~SizeofExpr();
     280
     281        Expression *get_expr() const { return expr; }
     282        void set_expr( Expression *newValue ) { expr = newValue; }
     283        Type *get_type() const { return type; }
     284        void set_type( Type *newValue ) { type = newValue; }
     285        bool get_isType() const { return isType; }
     286        void set_isType( bool newValue ) { isType = newValue; }
     287
     288        virtual SizeofExpr *clone() const { return new SizeofExpr( *this ); }
     289        virtual void accept( Visitor &v ) { v.visit( this ); }
     290        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     291        virtual void print( std::ostream &os, int indent = 0 ) const;
     292  private:
     293        Expression *expr;
     294        Type *type;
     295        bool isType;
    315296};
    316297
    317298// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
    318 class AttrExpr : public Expression
    319 {
    320 public:
    321     AttrExpr(Expression *attr, Expression *expr, Expression *_aname = 0 );
    322     AttrExpr( const AttrExpr &other );
    323     AttrExpr( Expression *attr, Type *type, Expression *_aname = 0 );
    324     virtual ~AttrExpr();
    325 
    326     Expression *get_attr() const { return attr; }
    327     void set_attr( Expression *newValue ) { attr = newValue; }
    328     Expression *get_expr() const { return expr; }
    329     void set_expr( Expression *newValue ) { expr = newValue; }
    330     Type *get_type() const { return type; }
    331     void set_type( Type *newValue ) { type = newValue; }
    332     bool get_isType() const { return isType; }
    333     void set_isType( bool newValue ) { isType = newValue; }
    334 
    335     virtual AttrExpr *clone() const { return new AttrExpr( *this ); }
    336     virtual void accept( Visitor &v ) { v.visit( this ); }
    337     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    338     virtual void print( std::ostream &os, int indent = 0 ) const;
    339    
    340 private:
    341     Expression *attr;
    342     Expression *expr;
    343     Type *type;
    344     bool isType;
     299class AttrExpr : public Expression {
     300  public:
     301        AttrExpr(Expression *attr, Expression *expr, Expression *_aname = 0 );
     302        AttrExpr( const AttrExpr &other );
     303        AttrExpr( Expression *attr, Type *type, Expression *_aname = 0 );
     304        virtual ~AttrExpr();
     305
     306        Expression *get_attr() const { return attr; }
     307        void set_attr( Expression *newValue ) { attr = newValue; }
     308        Expression *get_expr() const { return expr; }
     309        void set_expr( Expression *newValue ) { expr = newValue; }
     310        Type *get_type() const { return type; }
     311        void set_type( Type *newValue ) { type = newValue; }
     312        bool get_isType() const { return isType; }
     313        void set_isType( bool newValue ) { isType = newValue; }
     314
     315        virtual AttrExpr *clone() const { return new AttrExpr( *this ); }
     316        virtual void accept( Visitor &v ) { v.visit( this ); }
     317        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     318        virtual void print( std::ostream &os, int indent = 0 ) const;
     319  private:
     320        Expression *attr;
     321        Expression *expr;
     322        Type *type;
     323        bool isType;
    345324};
    346325
    347326// LogicalExpr represents a short-circuit boolean expression (&& or ||)
    348 class LogicalExpr : public Expression
    349 {
    350 public:
    351     LogicalExpr( Expression *arg1, Expression *arg2, bool andp = true, Expression *_aname = 0 );
    352     LogicalExpr( const LogicalExpr &other );
    353     virtual ~LogicalExpr();
    354 
    355     bool get_isAnd() const { return isAnd; }
    356     Expression *get_arg1() { return arg1; }
    357     void set_arg1( Expression *newValue ) { arg1 = newValue; }
    358     Expression *get_arg2() const { return arg2; }
    359     void set_arg2( Expression *newValue ) { arg2 = newValue; }
    360 
    361     virtual LogicalExpr *clone() const { return new LogicalExpr( *this ); }
    362     virtual void accept( Visitor &v ) { v.visit( this ); }
    363     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    364     virtual void print( std::ostream &os, int indent = 0 ) const;
    365    
    366 private:
    367     Expression *arg1;
    368     Expression *arg2;
    369     bool isAnd;
     327class LogicalExpr : public Expression {
     328  public:
     329        LogicalExpr( Expression *arg1, Expression *arg2, bool andp = true, Expression *_aname = 0 );
     330        LogicalExpr( const LogicalExpr &other );
     331        virtual ~LogicalExpr();
     332
     333        bool get_isAnd() const { return isAnd; }
     334        Expression *get_arg1() { return arg1; }
     335        void set_arg1( Expression *newValue ) { arg1 = newValue; }
     336        Expression *get_arg2() const { return arg2; }
     337        void set_arg2( Expression *newValue ) { arg2 = newValue; }
     338
     339        virtual LogicalExpr *clone() const { return new LogicalExpr( *this ); }
     340        virtual void accept( Visitor &v ) { v.visit( this ); }
     341        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     342        virtual void print( std::ostream &os, int indent = 0 ) const;
     343  private:
     344        Expression *arg1;
     345        Expression *arg2;
     346        bool isAnd;
    370347};
    371348
    372349// ConditionalExpr represents the three-argument conditional ( p ? a : b )
    373 class ConditionalExpr : public Expression
    374 {
    375 public:
    376     ConditionalExpr( Expression *arg1, Expression *arg2, Expression *arg3, Expression *_aname = 0 );
    377     ConditionalExpr( const ConditionalExpr &other );
    378     virtual ~ConditionalExpr();
    379 
    380     Expression *get_arg1() const { return arg1; }
    381     void set_arg1( Expression *newValue ) { arg1 = newValue; }
    382     Expression *get_arg2() const { return arg2; }
    383     void set_arg2( Expression *newValue ) { arg2 = newValue; }
    384     Expression *get_arg3() const { return arg3; }
    385     void set_arg3( Expression *newValue ) { arg3 = newValue; }
    386 
    387     virtual ConditionalExpr *clone() const { return new ConditionalExpr( *this ); }
    388     virtual void accept( Visitor &v ) { v.visit( this ); }
    389     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    390     virtual void print( std::ostream &os, int indent = 0 ) const;
    391    
    392 private:
    393     Expression *arg1;
    394     Expression *arg2;
    395     Expression *arg3;
     350class ConditionalExpr : public Expression {
     351  public:
     352        ConditionalExpr( Expression *arg1, Expression *arg2, Expression *arg3, Expression *_aname = 0 );
     353        ConditionalExpr( const ConditionalExpr &other );
     354        virtual ~ConditionalExpr();
     355
     356        Expression *get_arg1() const { return arg1; }
     357        void set_arg1( Expression *newValue ) { arg1 = newValue; }
     358        Expression *get_arg2() const { return arg2; }
     359        void set_arg2( Expression *newValue ) { arg2 = newValue; }
     360        Expression *get_arg3() const { return arg3; }
     361        void set_arg3( Expression *newValue ) { arg3 = newValue; }
     362
     363        virtual ConditionalExpr *clone() const { return new ConditionalExpr( *this ); }
     364        virtual void accept( Visitor &v ) { v.visit( this ); }
     365        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     366        virtual void print( std::ostream &os, int indent = 0 ) const;
     367  private:
     368        Expression *arg1;
     369        Expression *arg2;
     370        Expression *arg3;
    396371};
    397372
    398373// CommaExpr represents the sequence operator ( a, b )
    399 class CommaExpr : public Expression
    400 {
    401 public:
    402     CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname = 0 );
    403     CommaExpr( const CommaExpr &other );
    404     virtual ~CommaExpr();
    405 
    406     Expression *get_arg1() const { return arg1; }
    407     void set_arg1( Expression *newValue ) { arg1 = newValue; }
    408     Expression *get_arg2() const { return arg2; }
    409     void set_arg2( Expression *newValue ) { arg2 = newValue; }
    410 
    411     virtual CommaExpr *clone() const { return new CommaExpr( *this ); }
    412     virtual void accept( Visitor &v ) { v.visit( this ); }
    413     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    414     virtual void print( std::ostream &os, int indent = 0 ) const;
    415    
    416 private:
    417     Expression *arg1;
    418     Expression *arg2;
     374class CommaExpr : public Expression {
     375  public:
     376        CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname = 0 );
     377        CommaExpr( const CommaExpr &other );
     378        virtual ~CommaExpr();
     379
     380        Expression *get_arg1() const { return arg1; }
     381        void set_arg1( Expression *newValue ) { arg1 = newValue; }
     382        Expression *get_arg2() const { return arg2; }
     383        void set_arg2( Expression *newValue ) { arg2 = newValue; }
     384
     385        virtual CommaExpr *clone() const { return new CommaExpr( *this ); }
     386        virtual void accept( Visitor &v ) { v.visit( this ); }
     387        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     388        virtual void print( std::ostream &os, int indent = 0 ) const;
     389  private:
     390        Expression *arg1;
     391        Expression *arg2;
    419392};
    420393
    421394// TupleExpr represents a tuple expression ( [a, b, c] )
    422 class TupleExpr : public Expression
    423 {
    424 public:
    425     TupleExpr( Expression *_aname = 0 );
    426     TupleExpr( const TupleExpr &other );
    427     virtual ~TupleExpr();
    428 
    429     void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
    430     std::list<Expression*>& get_exprs() { return exprs; }
    431 
    432     virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
    433     virtual void accept( Visitor &v ) { v.visit( this ); }
    434     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    435     virtual void print( std::ostream &os, int indent = 0 ) const;
    436    
    437 private:
    438     std::list<Expression*> exprs;
     395class TupleExpr : public Expression {
     396  public:
     397        TupleExpr( Expression *_aname = 0 );
     398        TupleExpr( const TupleExpr &other );
     399        virtual ~TupleExpr();
     400
     401        void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
     402        std::list<Expression*>& get_exprs() { return exprs; }
     403
     404        virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
     405        virtual void accept( Visitor &v ) { v.visit( this ); }
     406        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     407        virtual void print( std::ostream &os, int indent = 0 ) const;
     408  private:
     409        std::list<Expression*> exprs;
    439410};
    440411
    441412// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
    442 class SolvedTupleExpr : public Expression
    443 {
    444 public:
    445 
    446     SolvedTupleExpr( Expression *_aname = 0 ) : Expression( _aname ) {}
    447     SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = 0 );
    448     SolvedTupleExpr( const SolvedTupleExpr &other );
    449     virtual ~SolvedTupleExpr() {}
    450 
    451     std::list<Expression*> &get_exprs() { return exprs; }
    452 
    453     virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); }
    454     virtual void accept( Visitor &v ) { v.visit( this ); }
    455     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    456     virtual void print( std::ostream &os, int indent = 0 ) const;
    457 private:
    458     std::list<Expression*> exprs;
     413class SolvedTupleExpr : public Expression {
     414  public:
     415        SolvedTupleExpr( Expression *_aname = 0 ) : Expression( _aname ) {}
     416        SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = 0 );
     417        SolvedTupleExpr( const SolvedTupleExpr &other );
     418        virtual ~SolvedTupleExpr() {}
     419
     420        std::list<Expression*> &get_exprs() { return exprs; }
     421
     422        virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); }
     423        virtual void accept( Visitor &v ) { v.visit( this ); }
     424        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     425        virtual void print( std::ostream &os, int indent = 0 ) const;
     426  private:
     427        std::list<Expression*> exprs;
    459428};
    460429
    461430// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
    462 class TypeExpr : public Expression
    463 {
    464 public:
    465     TypeExpr( Type *type );
    466     TypeExpr( const TypeExpr &other );
    467     virtual ~TypeExpr();
    468 
    469     Type *get_type() const { return type; }
    470     void set_type( Type *newValue ) { type = newValue; }
    471 
    472     virtual TypeExpr *clone() const { return new TypeExpr( *this ); }
    473     virtual void accept( Visitor &v ) { v.visit( this ); }
    474     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    475     virtual void print( std::ostream &os, int indent = 0 ) const;
    476    
    477 private:
    478     Type *type;
     431class TypeExpr : public Expression {
     432  public:
     433        TypeExpr( Type *type );
     434        TypeExpr( const TypeExpr &other );
     435        virtual ~TypeExpr();
     436
     437        Type *get_type() const { return type; }
     438        void set_type( Type *newValue ) { type = newValue; }
     439
     440        virtual TypeExpr *clone() const { return new TypeExpr( *this ); }
     441        virtual void accept( Visitor &v ) { v.visit( this ); }
     442        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     443        virtual void print( std::ostream &os, int indent = 0 ) const;
     444  private:
     445        Type *type;
    479446};
    480447
    481448// ValofExpr represents a GCC 'lambda expression'
    482 class UntypedValofExpr : public Expression
    483 {
    484 public:
    485     UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {}
    486     virtual ~UntypedValofExpr() {}
    487 
    488     Expression *get_value();
    489     Statement *get_body() const { return body; }
    490 
    491     virtual UntypedValofExpr *clone() const { return new UntypedValofExpr( *this ); }
    492     virtual void accept( Visitor &v ) { v.visit( this ); }
    493     virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    494     virtual void print( std::ostream &os, int indent = 0 ) const;
    495    
    496 private:
    497     Statement *body;
    498 };
    499 
    500 
    501 #endif /* #ifndef EXPRESSION_H */
    502 
    503 /*
    504     Local Variables:
    505     mode: c++
    506     End:
    507 */
     449class UntypedValofExpr : public Expression {
     450  public:
     451        UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {}
     452        virtual ~UntypedValofExpr() {}
     453
     454        Expression *get_value();
     455        Statement *get_body() const { return body; }
     456
     457        virtual UntypedValofExpr *clone() const { return new UntypedValofExpr( *this ); }
     458        virtual void accept( Visitor &v ) { v.visit( this ); }
     459        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     460        virtual void print( std::ostream &os, int indent = 0 ) const;
     461  private:
     462        Statement *body;
     463};
     464
     465#endif // EXPRESSION_H
     466
     467// Local Variables: //
     468// tab-width: 4 //
     469// mode: c++ //
     470// compile-command: "make install" //
     471// End: //
  • translator/SynTree/FunctionDecl.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// FunctionDecl.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 08:48:46 2015
     13// Update Count     : 1
     14//
     15
    116#include <cassert>
    217
     
    621#include "utility.h"
    722
    8 
    923FunctionDecl::FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline )
    1024        : Parent( name, sc, linkage ), type( type ), statements( statements ), isInline( isInline ) {
    11     // this is a brazen hack to force the function "main" to have C linkage
    12     if ( name == "main" ) {
    13         set_linkage( LinkageSpec::C );
    14     }
     25        // this is a brazen hack to force the function "main" to have C linkage
     26        if ( name == "main" ) {
     27                set_linkage( LinkageSpec::C );
     28        } // if
    1529}
    1630
    1731FunctionDecl::FunctionDecl( const FunctionDecl &other )
    18     : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), isInline( other.isInline ) {
     32        : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), isInline( other.isInline ) {
    1933}
    2034
    2135FunctionDecl::~FunctionDecl() {
    22     delete type;
    23     delete statements;
     36        delete type;
     37        delete statements;
    2438}
    2539
    2640Type * FunctionDecl::get_type() const {
    27     return type;
     41        return type;
    2842}
    2943
    3044void FunctionDecl::set_type( Type *t ) {
    31     type = dynamic_cast< FunctionType* >( t );
    32     assert( type );
     45        type = dynamic_cast< FunctionType* >( t );
     46        assert( type );
    3347}
    3448
    3549void FunctionDecl::print( std::ostream &os, int indent ) const {
    36     using std::endl;
    37     using std::string;
    38    
    39     if ( get_name() != "" ) {
    40         os << get_name() << ": a ";
    41     }
    42     if ( get_linkage() != LinkageSpec::Cforall ) {
    43         os << LinkageSpec::toString( get_linkage() ) << " ";
    44     }
    45     if ( isInline ) {
    46         os << "inline ";
    47     }
    48     if ( get_storageClass() != NoStorageClass ) {
    49         os << storageClassName[ get_storageClass() ] << ' ';
    50     }
    51     if ( get_type() ) {
    52         get_type()->print( os, indent );
    53     } else {
    54         os << "untyped entity ";
    55     }
    56     if ( ! oldIdents.empty() ) {
    57         os << string( indent+2, ' ' ) << "with parameter names" << endl;
    58         for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {
    59             os << string( indent+4, ' ' ) << *i << endl;
    60         }
    61     }
    62     if ( ! oldDecls.empty() ) {
    63         os << string( indent+2, ' ' ) << "with parameter declarations" << endl;
    64         printAll( oldDecls, os, indent+4 );
    65     }
    66     if ( statements ) {
    67         os << string( indent+2, ' ' ) << "with body " << endl;
    68         statements->print( os, indent+4 );
    69     }
     50        using std::endl;
     51        using std::string;
     52       
     53        if ( get_name() != "" ) {
     54                os << get_name() << ": a ";
     55        } // if
     56        if ( get_linkage() != LinkageSpec::Cforall ) {
     57                os << LinkageSpec::toString( get_linkage() ) << " ";
     58        } // if
     59        if ( isInline ) {
     60                os << "inline ";
     61        } // if
     62        if ( get_storageClass() != NoStorageClass ) {
     63                os << storageClassName[ get_storageClass() ] << ' ';
     64        } // if
     65        if ( get_type() ) {
     66                get_type()->print( os, indent );
     67        } else {
     68                os << "untyped entity ";
     69        } // if
     70        if ( ! oldIdents.empty() ) {
     71                os << string( indent+2, ' ' ) << "with parameter names" << endl;
     72                for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {
     73                        os << string( indent+4, ' ' ) << *i << endl;
     74                } // for
     75        } // if
     76        if ( ! oldDecls.empty() ) {
     77                os << string( indent+2, ' ' ) << "with parameter declarations" << endl;
     78                printAll( oldDecls, os, indent+4 );
     79        } // if
     80        if ( statements ) {
     81                os << string( indent+2, ' ' ) << "with body " << endl;
     82                statements->print( os, indent+4 );
     83        } // if
    7084}
    7185
    7286void FunctionDecl::printShort( std::ostream &os, int indent ) const {
    73     using std::endl;
    74     using std::string;
    75    
    76     if ( get_name() != "" ) {
    77         os << get_name() << ": a ";
    78     }
    79     if ( isInline ) {
    80         os << "inline ";
    81     }
    82     if ( get_storageClass() != NoStorageClass ) {
    83         os << storageClassName[ get_storageClass() ] << ' ';
    84     }
    85     if ( get_type() ) {
    86         get_type()->print( os, indent );
    87     } else {
    88         os << "untyped entity ";
    89     }
     87        using std::endl;
     88        using std::string;
     89       
     90        if ( get_name() != "" ) {
     91                os << get_name() << ": a ";
     92        } // if
     93        if ( isInline ) {
     94                os << "inline ";
     95        } // if
     96        if ( get_storageClass() != NoStorageClass ) {
     97                os << storageClassName[ get_storageClass() ] << ' ';
     98        } // if
     99        if ( get_type() ) {
     100                get_type()->print( os, indent );
     101        } else {
     102                os << "untyped entity ";
     103        } // if
    90104}
     105
     106// Local Variables: //
     107// tab-width: 4 //
     108// mode: c++ //
     109// compile-command: "make install" //
     110// End: //
  • translator/SynTree/FunctionType.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// FunctionType.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 09:01:28 2015
     13// Update Count     : 1
     14//
     15
    116#include <algorithm>
    217
     
    520#include "utility.h"
    621
    7 
    822FunctionType::FunctionType( const Type::Qualifiers &tq, bool isVarArgs ) : Type( tq ), isVarArgs( isVarArgs ) {
    923}
    1024
    1125FunctionType::FunctionType( const FunctionType &other ) : Type( other ), isVarArgs( other.isVarArgs ) {
    12     cloneAll( other.returnVals, returnVals );
    13     cloneAll( other.parameters, parameters );
     26        cloneAll( other.returnVals, returnVals );
     27        cloneAll( other.parameters, parameters );
    1428}
    1529
    1630FunctionType::~FunctionType() {
    17     deleteAll( returnVals );
    18     deleteAll( parameters );
     31        deleteAll( returnVals );
     32        deleteAll( parameters );
    1933}
    2034
    2135void FunctionType::print( std::ostream &os, int indent ) const {
    22     using std::string;
    23     using std::endl;
     36        using std::string;
     37        using std::endl;
    2438
    25     Type::print( os, indent );
    26     os << "function" << endl;
    27     if ( ! parameters.empty() ) {
    28         os << string( indent + 2, ' ' ) << "with parameters" << endl;
    29         printAll( parameters, os, indent + 4 );
    30         if ( isVarArgs ) {
    31             os << string( indent + 4, ' ' ) << "and a variable number of other arguments" << endl;
    32         }
    33     } else if ( isVarArgs ) {
    34         os << string( indent + 4, ' ' ) << "accepting unspecified arguments" << endl;
    35     }
    36     os << string( indent + 2, ' ' ) << "returning ";
    37     if ( returnVals.empty() ) {
    38         os << endl << string( indent + 4, ' ' ) << "nothing " << endl;
    39     } else {
    40         os << endl;
    41         printAll( returnVals, os, indent + 4 );
    42     }
     39        Type::print( os, indent );
     40        os << "function" << endl;
     41        if ( ! parameters.empty() ) {
     42                os << string( indent + 2, ' ' ) << "with parameters" << endl;
     43                printAll( parameters, os, indent + 4 );
     44                if ( isVarArgs ) {
     45                        os << string( indent + 4, ' ' ) << "and a variable number of other arguments" << endl;
     46                } // if
     47        } else if ( isVarArgs ) {
     48                os << string( indent + 4, ' ' ) << "accepting unspecified arguments" << endl;
     49        } // if
     50        os << string( indent + 2, ' ' ) << "returning ";
     51        if ( returnVals.empty() ) {
     52                os << endl << string( indent + 4, ' ' ) << "nothing " << endl;
     53        } else {
     54                os << endl;
     55                printAll( returnVals, os, indent + 4 );
     56        } // if
    4357}
    4458
     59// Local Variables: //
     60// tab-width: 4 //
     61// mode: c++ //
     62// compile-command: "make install" //
     63// End: //
  • translator/SynTree/Initializer.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Initializer.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 09:02:45 2015
     13// Update Count     : 2
     14//
     15
    116#include "Initializer.h"
    217#include "Expression.h"
    318#include "utility.h"
    4 
    519
    620Initializer::Initializer() {}
     
    923
    1024std::string Initializer::designator_name( Expression *des ) {
    11     if ( NameExpr *n = dynamic_cast<NameExpr *>(des) )
    12         return n->get_name();
    13     else
    14         throw 0;
     25        if ( NameExpr *n = dynamic_cast<NameExpr *>(des) )
     26                return n->get_name();
     27        else
     28                throw 0;
    1529}
    1630
     
    2135
    2236SingleInit::SingleInit( const SingleInit &other ) : value ( other.value ) {
    23     cloneAll(other.designators, designators );
     37        cloneAll(other.designators, designators );
    2438}
    2539
     
    2943
    3044void SingleInit::print( std::ostream &os, int indent ) {
    31     os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: ";
    32     value->print( os, indent+2 );
     45        os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: ";
     46        value->print( os, indent+2 );
    3347
    34     if ( ! designators.empty() ) {
    35         os << std::endl << std::string(indent + 2, ' ' ) << "designated by: "  ;
    36         for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ )
    37             ( *i )->print(os, indent + 4 );
    38     }
     48        if ( ! designators.empty() ) {
     49                os << std::endl << std::string(indent + 2, ' ' ) << "designated by: "  ;
     50                for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ )
     51                        ( *i )->print(os, indent + 4 );
     52        } // if
    3953}
    4054
    4155ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators )
    42     : initializers( _initializers ), designators( _designators ) {
     56        : initializers( _initializers ), designators( _designators ) {
    4357}
    4458
     
    4660
    4761ListInit *ListInit::clone() const {
    48     return new ListInit( *this );
     62        return new ListInit( *this );
    4963}
    5064
    5165void ListInit::print( std::ostream &os, int indent ) {
    52     os << std::endl << std::string(indent, ' ') << "Compound initializer:  ";
    53     if ( ! designators.empty() ) {
    54         os << std::string(indent + 2, ' ' ) << "designated by: [";
    55         for ( std::list < Expression * >::iterator i = designators.begin();
    56                     i != designators.end(); i++ ) {
    57             ( *i )->print(os, indent + 4 );
    58         }
     66        os << std::endl << std::string(indent, ' ') << "Compound initializer:  ";
     67        if ( ! designators.empty() ) {
     68                os << std::string(indent + 2, ' ' ) << "designated by: [";
     69                for ( std::list < Expression * >::iterator i = designators.begin();
     70                          i != designators.end(); i++ ) {
     71                        ( *i )->print(os, indent + 4 );
     72                } // for
    5973       
    60         os << std::string(indent + 2, ' ' ) << "]";
    61     }
     74                os << std::string(indent + 2, ' ' ) << "]";
     75        } // if
    6276
    63     for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ )
    64         (*i)->print( os, indent + 2 );
     77        for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ )
     78                (*i)->print( os, indent + 2 );
    6579}
     80// Local Variables: //
     81// tab-width: 4 //
     82// mode: c++ //
     83// compile-command: "make install" //
     84// End: //
  • translator/SynTree/Initializer.h

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Initializer.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 09:03:48 2015
     13// Update Count     : 1
     14//
     15
    116#ifndef INITIALIZER_H
    217#define INITIALIZER_H
     
    823#include <cassert>
    924
    10 
    1125// Initializer: base class for object initializers (provide default values)
    1226class Initializer {
    1327  public:
    14     //  Initializer( std::string _name = std::string(""), int _pos = 0 );
    15     Initializer( );
    16     virtual ~Initializer();
     28        //      Initializer( std::string _name = std::string(""), int _pos = 0 );
     29        Initializer( );
     30        virtual ~Initializer();
    1731
    18     static std::string designator_name( Expression *designator );
     32        static std::string designator_name( Expression *designator );
    1933
    20     //  void set_name( std::string newValue ) { name = newValue; }
    21     //  std::string get_name() const { return name; }
     34        //      void set_name( std::string newValue ) { name = newValue; }
     35        //      std::string get_name() const { return name; }
    2236
    23     //  void set_pos( int newValue ) { pos = newValue; }
    24     //  int get_pos() const { return pos; }
    25     virtual void set_designators( std::list<Expression *> & ) { assert(false); }
    26     virtual std::list<Expression *> &get_designators() {
    27         assert(false);
    28         std::list<Expression *> *ret = 0; return *ret;  // never reached
    29     }
     37        //      void set_pos( int newValue ) { pos = newValue; }
     38        //      int get_pos() const { return pos; }
     39        virtual void set_designators( std::list<Expression *> & ) { assert(false); }
     40        virtual std::list<Expression *> &get_designators() {
     41                assert(false);
     42                std::list<Expression *> *ret = 0; return *ret;  // never reached
     43        }
    3044
    31     virtual Initializer *clone() const = 0;
    32     virtual void accept( Visitor &v ) = 0;
    33     virtual Initializer *acceptMutator( Mutator &m ) = 0;
    34     virtual void print( std::ostream &os, int indent = 0 );
     45        virtual Initializer *clone() const = 0;
     46        virtual void accept( Visitor &v ) = 0;
     47        virtual Initializer *acceptMutator( Mutator &m ) = 0;
     48        virtual void print( std::ostream &os, int indent = 0 );
    3549  private:
    36     //  std::string name;
    37     //  int pos;
     50        //      std::string name;
     51        //      int pos;
    3852};
    3953
     
    4155class SingleInit : public Initializer {
    4256  public:
    43     SingleInit( Expression *value, std::list< Expression *> &designators );
    44     SingleInit( const SingleInit &other );
    45     virtual ~SingleInit();
    46    
    47     Expression *get_value() { return value; }
    48     void set_value( Expression *newValue ) { value = newValue; }
     57        SingleInit( Expression *value, std::list< Expression *> &designators );
     58        SingleInit( const SingleInit &other );
     59        virtual ~SingleInit();
     60       
     61        Expression *get_value() { return value; }
     62        void set_value( Expression *newValue ) { value = newValue; }
    4963
    50     void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
    51     std::list<Expression *> &get_designators() { return designators; }
     64        void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
     65        std::list<Expression *> &get_designators() { return designators; }
    5266
    53     virtual SingleInit *clone() const;
    54     virtual void accept( Visitor &v ) { v.visit( this ); }
    55     virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    56     virtual void print( std::ostream &os, int indent = 0 );
     67        virtual SingleInit *clone() const;
     68        virtual void accept( Visitor &v ) { v.visit( this ); }
     69        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     70        virtual void print( std::ostream &os, int indent = 0 );
    5771  private:
    58     //Constant *value;
    59     Expression *value;  // has to be a compile-time constant
    60     std::list< Expression * > designators;
     72        //Constant *value;
     73        Expression *value;      // has to be a compile-time constant
     74        std::list< Expression * > designators;
    6175};
    6276
     
    6579class ListInit : public Initializer {
    6680  public:
    67     ListInit( std::list<Initializer*> &,
    68               std::list<Expression *> &designators = *(new std::list<Expression *>()) );
    69     virtual ~ListInit();
     81        ListInit( std::list<Initializer*> &,
     82                          std::list<Expression *> &designators = *(new std::list<Expression *>()) );
     83        virtual ~ListInit();
    7084
    71     void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
    72     std::list<Expression *> &get_designators() { return designators; }
    73     void set_initializers( std::list<Initializer*> &newValue ) { initializers = newValue; }
    74     std::list<Initializer*> &get_initializers() { return initializers; }
     85        void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
     86        std::list<Expression *> &get_designators() { return designators; }
     87        void set_initializers( std::list<Initializer*> &newValue ) { initializers = newValue; }
     88        std::list<Initializer*> &get_initializers() { return initializers; }
    7589
    76     std::list<Initializer*>::iterator begin_initializers() { return initializers.begin(); }
    77     std::list<Initializer*>::iterator end_initializers() { return initializers.end(); }
     90        std::list<Initializer*>::iterator begin_initializers() { return initializers.begin(); }
     91        std::list<Initializer*>::iterator end_initializers() { return initializers.end(); }
    7892
    79     virtual ListInit *clone() const;
    80     virtual void accept( Visitor &v ) { v.visit( this ); }
    81     virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    82     virtual void print( std::ostream &os, int indent = 0 );
     93        virtual ListInit *clone() const;
     94        virtual void accept( Visitor &v ) { v.visit( this ); }
     95        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     96        virtual void print( std::ostream &os, int indent = 0 );
    8397  private:
    84     std::list<Initializer*> initializers;  // order *is* important
    85     std::list<Expression *> designators;
     98        std::list<Initializer*> initializers;  // order *is* important
     99        std::list<Expression *> designators;
    86100};
    87101
    88102#endif // INITIALIZER_H
     103
     104// Local Variables: //
     105// tab-width: 4 //
     106// mode: c++ //
     107// compile-command: "make install" //
     108// End: //
  • translator/SynTree/Mutator.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Mutator.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 10:10:46 2015
     13// Update Count     : 1
     14//
     15
    116#include <cassert>
    217#include "Mutator.h"
     
    1429
    1530ObjectDecl *Mutator::mutate( ObjectDecl *objectDecl ) {
    16     objectDecl->set_type( maybeMutate( objectDecl->get_type(), *this ) );
    17     objectDecl->set_init( maybeMutate( objectDecl->get_init(), *this ) );
    18     objectDecl->set_bitfieldWidth( maybeMutate( objectDecl->get_bitfieldWidth(), *this ) );
    19     return objectDecl;
     31        objectDecl->set_type( maybeMutate( objectDecl->get_type(), *this ) );
     32        objectDecl->set_init( maybeMutate( objectDecl->get_init(), *this ) );
     33        objectDecl->set_bitfieldWidth( maybeMutate( objectDecl->get_bitfieldWidth(), *this ) );
     34        return objectDecl;
    2035}
    2136
    2237DeclarationWithType *Mutator::mutate( FunctionDecl *functionDecl ) {
    23     functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) );
    24     mutateAll( functionDecl->get_oldDecls(), *this );
    25     functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
    26     return functionDecl;
     38        functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) );
     39        mutateAll( functionDecl->get_oldDecls(), *this );
     40        functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
     41        return functionDecl;
    2742}
    2843
    2944Declaration *Mutator::handleAggregateDecl( AggregateDecl *aggregateDecl ) {
    30     mutateAll( aggregateDecl->get_parameters(), *this );
    31     mutateAll( aggregateDecl->get_members(), *this );
    32     return aggregateDecl;
     45        mutateAll( aggregateDecl->get_parameters(), *this );
     46        mutateAll( aggregateDecl->get_members(), *this );
     47        return aggregateDecl;
    3348}
    3449
    3550Declaration *Mutator::mutate( StructDecl *aggregateDecl ) {
    36     handleAggregateDecl( aggregateDecl );
    37     return aggregateDecl;
     51        handleAggregateDecl( aggregateDecl );
     52        return aggregateDecl;
    3853}
    3954
    4055Declaration *Mutator::mutate( UnionDecl *aggregateDecl ) {
    41     handleAggregateDecl( aggregateDecl );
    42     return aggregateDecl;
     56        handleAggregateDecl( aggregateDecl );
     57        return aggregateDecl;
    4358}
    4459
    4560Declaration *Mutator::mutate( EnumDecl *aggregateDecl ) {
    46     handleAggregateDecl( aggregateDecl );
    47     return aggregateDecl;
     61        handleAggregateDecl( aggregateDecl );
     62        return aggregateDecl;
    4863}
    4964
    5065Declaration *Mutator::mutate( ContextDecl *aggregateDecl ) {
    51     handleAggregateDecl( aggregateDecl );
    52     return aggregateDecl;
     66        handleAggregateDecl( aggregateDecl );
     67        return aggregateDecl;
    5368}
    5469
    5570Declaration *Mutator::handleNamedTypeDecl( NamedTypeDecl *typeDecl ) {
    56     mutateAll( typeDecl->get_parameters(), *this );
    57     mutateAll( typeDecl->get_assertions(), *this );
    58     typeDecl->set_base( maybeMutate( typeDecl->get_base(), *this ) );
    59     return typeDecl;
     71        mutateAll( typeDecl->get_parameters(), *this );
     72        mutateAll( typeDecl->get_assertions(), *this );
     73        typeDecl->set_base( maybeMutate( typeDecl->get_base(), *this ) );
     74        return typeDecl;
    6075}
    6176
    6277TypeDecl *Mutator::mutate( TypeDecl *typeDecl ) {
    63     handleNamedTypeDecl( typeDecl );
    64     return typeDecl;
     78        handleNamedTypeDecl( typeDecl );
     79        return typeDecl;
    6580}
    6681
    6782Declaration *Mutator::mutate( TypedefDecl *typeDecl ) {
    68     handleNamedTypeDecl( typeDecl );
    69     return typeDecl;
     83        handleNamedTypeDecl( typeDecl );
     84        return typeDecl;
    7085}
    7186
    7287CompoundStmt *Mutator::mutate( CompoundStmt *compoundStmt ) {
    73     mutateAll( compoundStmt->get_kids(), *this );
    74     return compoundStmt;
     88        mutateAll( compoundStmt->get_kids(), *this );
     89        return compoundStmt;
    7590}
    7691
    7792Statement *Mutator::mutate( ExprStmt *exprStmt ) {
    78     exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );
    79     return exprStmt;
     93        exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );
     94        return exprStmt;
    8095}
    8196
    8297Statement *Mutator::mutate( IfStmt *ifStmt ) {
    83     ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) );
    84     ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) );
    85     ifStmt->set_elsePart( maybeMutate( ifStmt->get_elsePart(), *this ) );
    86     return ifStmt;
     98        ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) );
     99        ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) );
     100        ifStmt->set_elsePart( maybeMutate( ifStmt->get_elsePart(), *this ) );
     101        return ifStmt;
    87102}
    88103
    89104Statement *Mutator::mutate( WhileStmt *whileStmt ) {
    90     whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) );
    91     whileStmt->set_body( maybeMutate( whileStmt->get_body(), *this ) );
    92     return whileStmt;
     105        whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) );
     106        whileStmt->set_body( maybeMutate( whileStmt->get_body(), *this ) );
     107        return whileStmt;
    93108}
    94109
    95110Statement *Mutator::mutate( ForStmt *forStmt ) {
    96     forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ) );
    97     forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) );
    98     forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) );
    99     forStmt->set_body( maybeMutate( forStmt->get_body(), *this ) );
    100     return forStmt;
     111        forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ) );
     112        forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) );
     113        forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) );
     114        forStmt->set_body( maybeMutate( forStmt->get_body(), *this ) );
     115        return forStmt;
    101116}
    102117
    103118Statement *Mutator::mutate( SwitchStmt *switchStmt ) {
    104     switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
    105     mutateAll( switchStmt->get_branches(), *this );
    106     return switchStmt;
     119        switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
     120        mutateAll( switchStmt->get_branches(), *this );
     121        return switchStmt;
    107122}
    108123
    109124Statement *Mutator::mutate( ChooseStmt *switchStmt ) {
    110     switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
    111     mutateAll( switchStmt->get_branches(), *this );
    112     return switchStmt;
     125        switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
     126        mutateAll( switchStmt->get_branches(), *this );
     127        return switchStmt;
    113128}
    114129
    115130Statement *Mutator::mutate( FallthruStmt *fallthruStmt ) {
    116     return fallthruStmt;
     131        return fallthruStmt;
    117132}
    118133
    119134Statement *Mutator::mutate( CaseStmt *caseStmt ) {
    120     caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) );
    121     mutateAll (caseStmt->get_statements(), *this );
    122 
    123     return caseStmt;
     135        caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) );
     136        mutateAll (caseStmt->get_statements(), *this );
     137
     138        return caseStmt;
    124139}
    125140
    126141Statement *Mutator::mutate( BranchStmt *branchStmt ) {
    127     return branchStmt;
     142        return branchStmt;
    128143}
    129144
    130145Statement *Mutator::mutate( ReturnStmt *returnStmt ) {
    131     returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) );
    132     return returnStmt;
     146        returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) );
     147        return returnStmt;
    133148}
    134149
    135150Statement *Mutator::mutate( TryStmt *tryStmt ) {
    136     tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );
    137     mutateAll( tryStmt->get_catchers(), *this );
    138     return tryStmt;
     151        tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );
     152        mutateAll( tryStmt->get_catchers(), *this );
     153        return tryStmt;
    139154}
    140155
    141156Statement *Mutator::mutate( CatchStmt *catchStmt ) {
    142     catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) );
    143     catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) );
    144     return catchStmt;
     157        catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) );
     158        catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) );
     159        return catchStmt;
    145160}
    146161
    147162Statement *Mutator::mutate( FinallyStmt *finalStmt ) {
    148     finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) );
    149     return finalStmt;
     163        finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) );
     164        return finalStmt;
    150165}
    151166
    152167NullStmt *Mutator::mutate( NullStmt *nullStmt ) {
    153     return nullStmt;
     168        return nullStmt;
    154169}
    155170
    156171Statement *Mutator::mutate( DeclStmt *declStmt ) {
    157     declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) );
    158     return declStmt;
     172        declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) );
     173        return declStmt;
    159174}
    160175
    161176Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) {
    162     mutateAll( applicationExpr->get_results(), *this );
    163     applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) );
    164     mutateAll( applicationExpr->get_args(), *this );
    165     return applicationExpr;
     177        mutateAll( applicationExpr->get_results(), *this );
     178        applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) );
     179        mutateAll( applicationExpr->get_args(), *this );
     180        return applicationExpr;
    166181}
    167182
    168183Expression *Mutator::mutate( UntypedExpr *untypedExpr ) {
    169     mutateAll( untypedExpr->get_results(), *this );
    170     mutateAll( untypedExpr->get_args(), *this );
    171     return untypedExpr;
     184        mutateAll( untypedExpr->get_results(), *this );
     185        mutateAll( untypedExpr->get_args(), *this );
     186        return untypedExpr;
    172187}
    173188
    174189Expression *Mutator::mutate( NameExpr *nameExpr ) {
    175     mutateAll( nameExpr->get_results(), *this );
    176     return nameExpr;
     190        mutateAll( nameExpr->get_results(), *this );
     191        return nameExpr;
    177192}
    178193
    179194Expression *Mutator::mutate( AddressExpr *addressExpr ) {
    180     mutateAll( addressExpr->get_results(), *this );
    181     addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) );
    182     return addressExpr;
     195        mutateAll( addressExpr->get_results(), *this );
     196        addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) );
     197        return addressExpr;
    183198}
    184199
    185200Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) {
    186     mutateAll( labelAddressExpr->get_results(), *this );
    187     labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) );
    188     return labelAddressExpr;
     201        mutateAll( labelAddressExpr->get_results(), *this );
     202        labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) );
     203        return labelAddressExpr;
    189204}
    190205
    191206Expression *Mutator::mutate( CastExpr *castExpr ) {
    192     mutateAll( castExpr->get_results(), *this );
    193     castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) );
    194     return castExpr;
     207        mutateAll( castExpr->get_results(), *this );
     208        castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) );
     209        return castExpr;
    195210}
    196211
    197212Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) {
    198     mutateAll( memberExpr->get_results(), *this );
    199     memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
    200     return memberExpr;
     213        mutateAll( memberExpr->get_results(), *this );
     214        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
     215        return memberExpr;
    201216}
    202217
    203218Expression *Mutator::mutate( MemberExpr *memberExpr ) {
    204     mutateAll( memberExpr->get_results(), *this );
    205     memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
    206     return memberExpr;
     219        mutateAll( memberExpr->get_results(), *this );
     220        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
     221        return memberExpr;
    207222}
    208223
    209224Expression *Mutator::mutate( VariableExpr *variableExpr ) {
    210     mutateAll( variableExpr->get_results(), *this );
    211     return variableExpr;
     225        mutateAll( variableExpr->get_results(), *this );
     226        return variableExpr;
    212227}
    213228
    214229Expression *Mutator::mutate( ConstantExpr *constantExpr ) {
    215     mutateAll( constantExpr->get_results(), *this );
     230        mutateAll( constantExpr->get_results(), *this );
    216231//  maybeMutate( constantExpr->get_constant(), *this )
    217     return constantExpr;
     232        return constantExpr;
    218233}
    219234
    220235Expression *Mutator::mutate( SizeofExpr *sizeofExpr ) {
    221     mutateAll( sizeofExpr->get_results(), *this );
    222     if ( sizeofExpr->get_isType() ) {
    223         sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) );
    224     } else {
    225         sizeofExpr->set_expr( maybeMutate( sizeofExpr->get_expr(), *this ) );
    226     }
    227     return sizeofExpr;
     236        mutateAll( sizeofExpr->get_results(), *this );
     237        if ( sizeofExpr->get_isType() ) {
     238                sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) );
     239        } else {
     240                sizeofExpr->set_expr( maybeMutate( sizeofExpr->get_expr(), *this ) );
     241        }
     242        return sizeofExpr;
    228243}
    229244
    230245Expression *Mutator::mutate( AttrExpr *attrExpr ) {
    231     mutateAll( attrExpr->get_results(), *this );
    232     if ( attrExpr->get_isType() ) {
    233         attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) );
    234     } else {
    235         attrExpr->set_expr( maybeMutate( attrExpr->get_expr(), *this ) );
    236     }
    237     return attrExpr;
     246        mutateAll( attrExpr->get_results(), *this );
     247        if ( attrExpr->get_isType() ) {
     248                attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) );
     249        } else {
     250                attrExpr->set_expr( maybeMutate( attrExpr->get_expr(), *this ) );
     251        }
     252        return attrExpr;
    238253}
    239254
    240255Expression *Mutator::mutate( LogicalExpr *logicalExpr ) {
    241     mutateAll( logicalExpr->get_results(), *this );
    242     logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) );
    243     logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) );
    244     return logicalExpr;
     256        mutateAll( logicalExpr->get_results(), *this );
     257        logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) );
     258        logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) );
     259        return logicalExpr;
    245260}
    246261
    247262Expression *Mutator::mutate( ConditionalExpr *conditionalExpr ) {
    248     mutateAll( conditionalExpr->get_results(), *this );
    249     conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) );
    250     conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) );
    251     conditionalExpr->set_arg3( maybeMutate( conditionalExpr->get_arg3(), *this ) );
    252     return conditionalExpr;
     263        mutateAll( conditionalExpr->get_results(), *this );
     264        conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) );
     265        conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) );
     266        conditionalExpr->set_arg3( maybeMutate( conditionalExpr->get_arg3(), *this ) );
     267        return conditionalExpr;
    253268}
    254269
    255270Expression *Mutator::mutate( CommaExpr *commaExpr ) {
    256     mutateAll( commaExpr->get_results(), *this );
    257     commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) );
    258     commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) );
    259     return commaExpr;
     271        mutateAll( commaExpr->get_results(), *this );
     272        commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) );
     273        commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) );
     274        return commaExpr;
    260275}
    261276
    262277Expression *Mutator::mutate( TupleExpr *tupleExpr ) {
    263     mutateAll( tupleExpr->get_results(), *this );
    264     mutateAll( tupleExpr->get_exprs(), *this );
    265     return tupleExpr;
     278        mutateAll( tupleExpr->get_results(), *this );
     279        mutateAll( tupleExpr->get_exprs(), *this );
     280        return tupleExpr;
    266281}
    267282
    268283Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) {
    269     mutateAll( tupleExpr->get_results(), *this );
    270     mutateAll( tupleExpr->get_exprs(), *this );
    271     return tupleExpr;
     284        mutateAll( tupleExpr->get_results(), *this );
     285        mutateAll( tupleExpr->get_exprs(), *this );
     286        return tupleExpr;
    272287}
    273288
    274289Expression *Mutator::mutate( TypeExpr *typeExpr ) {
    275     mutateAll( typeExpr->get_results(), *this );
    276     typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) );
    277     return typeExpr;
     290        mutateAll( typeExpr->get_results(), *this );
     291        typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) );
     292        return typeExpr;
    278293}
    279294
    280295Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
    281     mutateAll( valofExpr->get_results(), *this );
    282     return valofExpr;
     296        mutateAll( valofExpr->get_results(), *this );
     297        return valofExpr;
    283298}
    284299
    285300Type *Mutator::mutate( VoidType *voidType ) {
    286     mutateAll( voidType->get_forall(), *this );
    287     return voidType;
     301        mutateAll( voidType->get_forall(), *this );
     302        return voidType;
    288303}
    289304
    290305Type *Mutator::mutate( BasicType *basicType ) {
    291     mutateAll( basicType->get_forall(), *this );
    292     return basicType;
     306        mutateAll( basicType->get_forall(), *this );
     307        return basicType;
    293308}
    294309
    295310Type *Mutator::mutate( PointerType *pointerType ) {
    296     mutateAll( pointerType->get_forall(), *this );
    297     pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) );
    298     return pointerType;
     311        mutateAll( pointerType->get_forall(), *this );
     312        pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) );
     313        return pointerType;
    299314}
    300315
    301316Type *Mutator::mutate( ArrayType *arrayType ) {
    302     mutateAll( arrayType->get_forall(), *this );
    303     arrayType->set_dimension( maybeMutate( arrayType->get_dimension(), *this ) );
    304     arrayType->set_base( maybeMutate( arrayType->get_base(), *this ) );
    305     return arrayType;
     317        mutateAll( arrayType->get_forall(), *this );
     318        arrayType->set_dimension( maybeMutate( arrayType->get_dimension(), *this ) );
     319        arrayType->set_base( maybeMutate( arrayType->get_base(), *this ) );
     320        return arrayType;
    306321}
    307322
    308323Type *Mutator::mutate( FunctionType *functionType ) {
    309     mutateAll( functionType->get_forall(), *this );
    310     mutateAll( functionType->get_returnVals(), *this );
    311     mutateAll( functionType->get_parameters(), *this );
    312     return functionType;
     324        mutateAll( functionType->get_forall(), *this );
     325        mutateAll( functionType->get_returnVals(), *this );
     326        mutateAll( functionType->get_parameters(), *this );
     327        return functionType;
    313328}
    314329
    315330Type *Mutator::handleReferenceToType( ReferenceToType *aggregateUseType ) {
    316     mutateAll( aggregateUseType->get_forall(), *this );
    317     mutateAll( aggregateUseType->get_parameters(), *this );
    318     return aggregateUseType;
     331        mutateAll( aggregateUseType->get_forall(), *this );
     332        mutateAll( aggregateUseType->get_parameters(), *this );
     333        return aggregateUseType;
    319334}
    320335
    321336Type *Mutator::mutate( StructInstType *aggregateUseType ) {
    322     handleReferenceToType( aggregateUseType );
    323     return aggregateUseType;
     337        handleReferenceToType( aggregateUseType );
     338        return aggregateUseType;
    324339}
    325340
    326341Type *Mutator::mutate( UnionInstType *aggregateUseType ) {
    327     handleReferenceToType( aggregateUseType );
    328     return aggregateUseType;
     342        handleReferenceToType( aggregateUseType );
     343        return aggregateUseType;
    329344}
    330345
    331346Type *Mutator::mutate( EnumInstType *aggregateUseType ) {
    332     handleReferenceToType( aggregateUseType );
    333     return aggregateUseType;
     347        handleReferenceToType( aggregateUseType );
     348        return aggregateUseType;
    334349}
    335350
    336351Type *Mutator::mutate( ContextInstType *aggregateUseType ) {
    337     handleReferenceToType( aggregateUseType );
    338     mutateAll( aggregateUseType->get_members(), *this );
    339     return aggregateUseType;
     352        handleReferenceToType( aggregateUseType );
     353        mutateAll( aggregateUseType->get_members(), *this );
     354        return aggregateUseType;
    340355}
    341356
    342357Type *Mutator::mutate( TypeInstType *aggregateUseType ) {
    343     handleReferenceToType( aggregateUseType );
    344     return aggregateUseType;
     358        handleReferenceToType( aggregateUseType );
     359        return aggregateUseType;
    345360}
    346361
    347362Type *Mutator::mutate( TupleType *tupleType ) {
    348     mutateAll( tupleType->get_forall(), *this );
    349     mutateAll( tupleType->get_types(), *this );
    350     return tupleType;
     363        mutateAll( tupleType->get_forall(), *this );
     364        mutateAll( tupleType->get_types(), *this );
     365        return tupleType;
    351366}
    352367
    353368Type *Mutator::mutate( TypeofType *typeofType ) {
    354     assert( typeofType->get_expr() );
    355     typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) );
    356     return typeofType;
     369        assert( typeofType->get_expr() );
     370        typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) );
     371        return typeofType;
    357372}
    358373
    359374Type *Mutator::mutate( AttrType *attrType ) {
    360     if ( attrType->get_isType() ) {
    361         assert( attrType->get_type() );
    362         attrType->set_type( attrType->get_type()->acceptMutator( *this ) );
    363     } else {
    364         assert( attrType->get_expr() );
    365         attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) );
    366     }
    367     return attrType;
     375        if ( attrType->get_isType() ) {
     376                assert( attrType->get_type() );
     377                attrType->set_type( attrType->get_type()->acceptMutator( *this ) );
     378        } else {
     379                assert( attrType->get_expr() );
     380                attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) );
     381        }
     382        return attrType;
    368383}
    369384
    370385Initializer *Mutator::mutate( SingleInit *singleInit ) {
    371     singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) );
    372     return singleInit;
     386        singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) );
     387        return singleInit;
    373388}
    374389
    375390Initializer *Mutator::mutate( ListInit *listInit ) {
    376     mutateAll( listInit->get_designators(), *this );
    377     mutateAll( listInit->get_initializers(), *this );
    378     return listInit;
     391        mutateAll( listInit->get_designators(), *this );
     392        mutateAll( listInit->get_initializers(), *this );
     393        return listInit;
    379394}
    380395
    381396Subrange *Mutator::mutate( Subrange *subrange ) {
    382     return subrange;
     397        return subrange;
    383398}
    384399
    385400Constant *Mutator::mutate( Constant *constant ) {
    386     return constant;
    387 }
     401        return constant;
     402}
     403
     404// Local Variables: //
     405// tab-width: 4 //
     406// mode: c++ //
     407// compile-command: "make install" //
     408// End: //
  • translator/SynTree/Mutator.h

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Mutator.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 10:12:28 2015
     13// Update Count     : 3
     14//
    115#include <cassert>
    216
     
    418#include "SemanticError.h"
    519
    6 #ifndef SYNTREE_MUTATOR_H
    7 #define SYNTREE_MUTATOR_H
     20#ifndef MUTATOR_H
     21#define MUTATOR_H
    822
    923class Mutator {
    1024  protected:
    11     Mutator();
    12     virtual ~Mutator();
     25        Mutator();
     26        virtual ~Mutator();
    1327  public:
    14     virtual ObjectDecl* mutate( ObjectDecl *objectDecl );
    15     virtual DeclarationWithType* mutate( FunctionDecl *functionDecl );
    16     virtual Declaration* mutate( StructDecl *aggregateDecl );
    17     virtual Declaration* mutate( UnionDecl *aggregateDecl );
    18     virtual Declaration* mutate( EnumDecl *aggregateDecl );
    19     virtual Declaration* mutate( ContextDecl *aggregateDecl );
    20     virtual TypeDecl* mutate( TypeDecl *typeDecl );
    21     virtual Declaration* mutate( TypedefDecl *typeDecl );
     28        virtual ObjectDecl* mutate( ObjectDecl *objectDecl );
     29        virtual DeclarationWithType* mutate( FunctionDecl *functionDecl );
     30        virtual Declaration* mutate( StructDecl *aggregateDecl );
     31        virtual Declaration* mutate( UnionDecl *aggregateDecl );
     32        virtual Declaration* mutate( EnumDecl *aggregateDecl );
     33        virtual Declaration* mutate( ContextDecl *aggregateDecl );
     34        virtual TypeDecl* mutate( TypeDecl *typeDecl );
     35        virtual Declaration* mutate( TypedefDecl *typeDecl );
    2236
    23     virtual CompoundStmt* mutate( CompoundStmt *compoundStmt );
    24     virtual Statement* mutate( ExprStmt *exprStmt );
    25     virtual Statement* mutate( IfStmt *ifStmt );
    26     virtual Statement* mutate( WhileStmt *whileStmt );
    27     virtual Statement* mutate( ForStmt *forStmt );
    28     virtual Statement* mutate( SwitchStmt *switchStmt );
    29     virtual Statement* mutate( ChooseStmt *chooseStmt );
    30     virtual Statement* mutate( FallthruStmt *fallthruStmt );
    31     virtual Statement* mutate( CaseStmt *caseStmt );
    32     virtual Statement* mutate( BranchStmt *branchStmt );
    33     virtual Statement* mutate( ReturnStmt *returnStmt );
    34     virtual Statement* mutate( TryStmt *returnStmt );
    35     virtual Statement* mutate( CatchStmt *catchStmt );
    36     virtual Statement* mutate( FinallyStmt *catchStmt );
    37     virtual NullStmt* mutate( NullStmt *nullStmt );
    38     virtual Statement* mutate( DeclStmt *declStmt );
     37        virtual CompoundStmt* mutate( CompoundStmt *compoundStmt );
     38        virtual Statement* mutate( ExprStmt *exprStmt );
     39        virtual Statement* mutate( IfStmt *ifStmt );
     40        virtual Statement* mutate( WhileStmt *whileStmt );
     41        virtual Statement* mutate( ForStmt *forStmt );
     42        virtual Statement* mutate( SwitchStmt *switchStmt );
     43        virtual Statement* mutate( ChooseStmt *chooseStmt );
     44        virtual Statement* mutate( FallthruStmt *fallthruStmt );
     45        virtual Statement* mutate( CaseStmt *caseStmt );
     46        virtual Statement* mutate( BranchStmt *branchStmt );
     47        virtual Statement* mutate( ReturnStmt *returnStmt );
     48        virtual Statement* mutate( TryStmt *returnStmt );
     49        virtual Statement* mutate( CatchStmt *catchStmt );
     50        virtual Statement* mutate( FinallyStmt *catchStmt );
     51        virtual NullStmt* mutate( NullStmt *nullStmt );
     52        virtual Statement* mutate( DeclStmt *declStmt );
    3953
    40     virtual Expression* mutate( ApplicationExpr *applicationExpr );
    41     virtual Expression* mutate( UntypedExpr *untypedExpr );
    42     virtual Expression* mutate( NameExpr *nameExpr );
    43     virtual Expression* mutate( AddressExpr *castExpr );
    44     virtual Expression* mutate( LabelAddressExpr *labAddressExpr );
    45     virtual Expression* mutate( CastExpr *castExpr );
    46     virtual Expression* mutate( UntypedMemberExpr *memberExpr );
    47     virtual Expression* mutate( MemberExpr *memberExpr );
    48     virtual Expression* mutate( VariableExpr *variableExpr );
    49     virtual Expression* mutate( ConstantExpr *constantExpr );
    50     virtual Expression* mutate( SizeofExpr *sizeofExpr );
    51     virtual Expression* mutate( AttrExpr *attrExpr );
    52     virtual Expression* mutate( LogicalExpr *logicalExpr );
    53     virtual Expression* mutate( ConditionalExpr *conditionalExpr );
    54     virtual Expression* mutate( CommaExpr *commaExpr );
    55     virtual Expression* mutate( TupleExpr *tupleExpr );
    56     virtual Expression* mutate( SolvedTupleExpr *tupleExpr );
    57     virtual Expression* mutate( TypeExpr *typeExpr );
    58     virtual Expression* mutate( UntypedValofExpr *valofExpr );
     54        virtual Expression* mutate( ApplicationExpr *applicationExpr );
     55        virtual Expression* mutate( UntypedExpr *untypedExpr );
     56        virtual Expression* mutate( NameExpr *nameExpr );
     57        virtual Expression* mutate( AddressExpr *castExpr );
     58        virtual Expression* mutate( LabelAddressExpr *labAddressExpr );
     59        virtual Expression* mutate( CastExpr *castExpr );
     60        virtual Expression* mutate( UntypedMemberExpr *memberExpr );
     61        virtual Expression* mutate( MemberExpr *memberExpr );
     62        virtual Expression* mutate( VariableExpr *variableExpr );
     63        virtual Expression* mutate( ConstantExpr *constantExpr );
     64        virtual Expression* mutate( SizeofExpr *sizeofExpr );
     65        virtual Expression* mutate( AttrExpr *attrExpr );
     66        virtual Expression* mutate( LogicalExpr *logicalExpr );
     67        virtual Expression* mutate( ConditionalExpr *conditionalExpr );
     68        virtual Expression* mutate( CommaExpr *commaExpr );
     69        virtual Expression* mutate( TupleExpr *tupleExpr );
     70        virtual Expression* mutate( SolvedTupleExpr *tupleExpr );
     71        virtual Expression* mutate( TypeExpr *typeExpr );
     72        virtual Expression* mutate( UntypedValofExpr *valofExpr );
    5973
    60     virtual Type* mutate( VoidType *basicType );
    61     virtual Type* mutate( BasicType *basicType );
    62     virtual Type* mutate( PointerType *pointerType );
    63     virtual Type* mutate( ArrayType *arrayType );
    64     virtual Type* mutate( FunctionType *functionType );
    65     virtual Type* mutate( StructInstType *aggregateUseType );
    66     virtual Type* mutate( UnionInstType *aggregateUseType );
    67     virtual Type* mutate( EnumInstType *aggregateUseType );
    68     virtual Type* mutate( ContextInstType *aggregateUseType );
    69     virtual Type* mutate( TypeInstType *aggregateUseType );
    70     virtual Type* mutate( TupleType *tupleType );
    71     virtual Type* mutate( TypeofType *typeofType );
    72     virtual Type* mutate( AttrType *attrType );
     74        virtual Type* mutate( VoidType *basicType );
     75        virtual Type* mutate( BasicType *basicType );
     76        virtual Type* mutate( PointerType *pointerType );
     77        virtual Type* mutate( ArrayType *arrayType );
     78        virtual Type* mutate( FunctionType *functionType );
     79        virtual Type* mutate( StructInstType *aggregateUseType );
     80        virtual Type* mutate( UnionInstType *aggregateUseType );
     81        virtual Type* mutate( EnumInstType *aggregateUseType );
     82        virtual Type* mutate( ContextInstType *aggregateUseType );
     83        virtual Type* mutate( TypeInstType *aggregateUseType );
     84        virtual Type* mutate( TupleType *tupleType );
     85        virtual Type* mutate( TypeofType *typeofType );
     86        virtual Type* mutate( AttrType *attrType );
    7387
    74     virtual Initializer* mutate( SingleInit *singleInit );
    75     virtual Initializer* mutate( ListInit *listInit );
     88        virtual Initializer* mutate( SingleInit *singleInit );
     89        virtual Initializer* mutate( ListInit *listInit );
    7690
    77     virtual Subrange *mutate( Subrange *subrange );
     91        virtual Subrange *mutate( Subrange *subrange );
    7892
    79     virtual Constant *mutate( Constant *constant );
     93        virtual Constant *mutate( Constant *constant );
    8094  private:
    81     virtual Declaration* handleAggregateDecl(AggregateDecl *aggregateDecl );
    82     virtual Declaration* handleNamedTypeDecl(NamedTypeDecl *typeDecl );
    83     virtual Type* handleReferenceToType(ReferenceToType *aggregateUseType );
     95        virtual Declaration* handleAggregateDecl(AggregateDecl *aggregateDecl );
     96        virtual Declaration* handleNamedTypeDecl(NamedTypeDecl *typeDecl );
     97        virtual Type* handleReferenceToType(ReferenceToType *aggregateUseType );
    8498};
    8599
    86100template< typename TreeType, typename MutatorType >
    87101inline TreeType *maybeMutate( TreeType *tree, MutatorType &mutator ) {
    88     if ( tree ) {
    89         TreeType *newnode = dynamic_cast< TreeType* >( tree->acceptMutator( mutator ) );
    90         assert( newnode );
    91         return newnode;
     102        if ( tree ) {
     103                TreeType *newnode = dynamic_cast< TreeType* >( tree->acceptMutator( mutator ) );
     104                assert( newnode );
     105                return newnode;
    92106///         return tree->acceptMutator( mutator );
    93     } else {
    94         return 0;
    95     }
     107        } else {
     108                return 0;
     109        } // if
    96110}
    97111
    98112template< typename Container, typename MutatorType >
    99113inline void mutateAll( Container &container, MutatorType &mutator ) {
    100     SemanticError errors;
    101     for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    102         try {
    103             if ( *i ) {
     114        SemanticError errors;
     115        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
     116                try {
     117                        if ( *i ) {
    104118///                 *i = (*i)->acceptMutator( mutator );
    105                 *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) );
    106                 assert( *i );
    107             }
    108         } catch( SemanticError &e ) {
    109             errors.append( e );
    110         }
    111     }
    112     if ( ! errors.isEmpty() ) {
    113         throw errors;
    114     }
     119                                *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) );
     120                                assert( *i );
     121                        } // if
     122                } catch( SemanticError &e ) {
     123                        errors.append( e );
     124                } // try
     125        } // for
     126        if ( ! errors.isEmpty() ) {
     127                throw errors;
     128        } // if
    115129}
    116130
    117 #endif // SYNTREE_MUTATOR_H
     131#endif // MUTATOR_H
    118132
    119133// Local Variables: //
     134// tab-width: 4 //
    120135// mode: c++ //
    121 // End:  //
     136// compile-command: "make install" //
     137// End: //
  • translator/SynTree/NamedTypeDecl.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// NamedTypeDecl.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 10:13:19 2015
     13// Update Count     : 1
     14//
     15
    116#include "Declaration.h"
    217#include "Type.h"
    318#include "utility.h"
    419
    5 
    620NamedTypeDecl::NamedTypeDecl( const std::string &name, StorageClass sc, Type *base )
    7     : Parent( name, sc, LinkageSpec::Cforall ), base( base )
    8 {}
     21        : Parent( name, sc, LinkageSpec::Cforall ), base( base ) {}
    922
    1023NamedTypeDecl::NamedTypeDecl( const TypeDecl &other )
    11     : Parent( other ), base( maybeClone( other.base ) )
    12 {
    13     cloneAll( other.parameters, parameters );
    14     cloneAll( other.assertions, assertions );
     24        : Parent( other ), base( maybeClone( other.base ) ) {
     25        cloneAll( other.parameters, parameters );
     26        cloneAll( other.assertions, assertions );
    1527}
    1628
    1729NamedTypeDecl::~NamedTypeDecl() {
    18     delete base;
    19     deleteAll( parameters );
    20     deleteAll( assertions );
     30        delete base;
     31        deleteAll( parameters );
     32        deleteAll( assertions );
    2133}
    2234
    2335void NamedTypeDecl::print( std::ostream &os, int indent ) const {
    24     using namespace std;
    25    
    26     if ( get_name() != "" ) {
    27         os << get_name() << ": a ";
    28     } // if
    29     if ( get_storageClass() != NoStorageClass ) {
    30         os << storageClassName[ get_storageClass() ] << ' ';
    31     } // if
    32     os << typeString();
    33     if ( base ) {
    34         os << " for ";
    35         base->print( os, indent );
    36     } // if
    37     if ( ! parameters.empty() ) {
    38         os << endl << string( indent, ' ' ) << "with parameters" << endl;
    39         printAll( parameters, os, indent+2 );
    40     } // if
    41     if ( ! assertions.empty() ) {
    42         os << endl << string( indent, ' ' ) << "with assertions" << endl;
    43         printAll( assertions, os, indent+2 );
    44     } // if
     36        using namespace std;
     37       
     38        if ( get_name() != "" ) {
     39                os << get_name() << ": a ";
     40        } // if
     41        if ( get_storageClass() != NoStorageClass ) {
     42                os << storageClassName[ get_storageClass() ] << ' ';
     43        } // if
     44        os << typeString();
     45        if ( base ) {
     46                os << " for ";
     47                base->print( os, indent );
     48        } // if
     49        if ( ! parameters.empty() ) {
     50                os << endl << string( indent, ' ' ) << "with parameters" << endl;
     51                printAll( parameters, os, indent+2 );
     52        } // if
     53        if ( ! assertions.empty() ) {
     54                os << endl << string( indent, ' ' ) << "with assertions" << endl;
     55                printAll( assertions, os, indent+2 );
     56        } // if
    4557}
    4658
    4759void NamedTypeDecl::printShort( std::ostream &os, int indent ) const {
    48     using namespace std;
    49    
    50     if ( get_name() != "" ) {
    51         os << get_name() << ": a ";
    52     } // if
    53     if ( get_storageClass() != NoStorageClass ) {
    54         os << storageClassName[ get_storageClass() ] << ' ';
    55     } // if
    56     os << typeString();
    57     if ( base ) {
    58         os << " for ";
    59         base->print( os, indent );
    60     } // if
    61     if ( ! parameters.empty() ) {
    62         os << endl << string( indent, ' ' ) << "with parameters" << endl;
    63         printAll( parameters, os, indent+2 );
    64     } // if
     60        using namespace std;
     61       
     62        if ( get_name() != "" ) {
     63                os << get_name() << ": a ";
     64        } // if
     65        if ( get_storageClass() != NoStorageClass ) {
     66                os << storageClassName[ get_storageClass() ] << ' ';
     67        } // if
     68        os << typeString();
     69        if ( base ) {
     70                os << " for ";
     71                base->print( os, indent );
     72        } // if
     73        if ( ! parameters.empty() ) {
     74                os << endl << string( indent, ' ' ) << "with parameters" << endl;
     75                printAll( parameters, os, indent+2 );
     76        } // if
    6577}
    6678
    6779std::string TypedefDecl::typeString() const { return "typedef"; }
     80
     81// Local Variables: //
     82// tab-width: 4 //
     83// mode: c++ //
     84// compile-command: "make install" //
     85// End: //
  • translator/SynTree/ObjectDecl.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// ObjectDecl.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 10:14:18 2015
     13// Update Count     : 2
     14//
     15
    116#include "Declaration.h"
    217#include "Type.h"
     
    520#include "utility.h"
    621
    7 
    822ObjectDecl::ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init )
    9     : Parent( name, sc, linkage ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) {
     23        : Parent( name, sc, linkage ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) {
    1024}
    1125
    1226ObjectDecl::ObjectDecl( const ObjectDecl &other )
    13     : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {
     27        : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {
    1428}
    1529
    1630ObjectDecl::~ObjectDecl() {
    17     delete type;
    18     delete init;
    19     delete bitfieldWidth;
     31        delete type;
     32        delete init;
     33        delete bitfieldWidth;
    2034}
    2135
    2236void ObjectDecl::print( std::ostream &os, int indent ) const {
    23     if ( get_name() != "" ) {
    24         os << get_name() << ": a ";
    25     }
     37        if ( get_name() != "" ) {
     38                os << get_name() << ": a ";
     39        } // if
    2640
    27     if ( get_linkage() != LinkageSpec::Cforall ) {
    28         os << LinkageSpec::toString( get_linkage() ) << " ";
    29     }
     41        if ( get_linkage() != LinkageSpec::Cforall ) {
     42                os << LinkageSpec::toString( get_linkage() ) << " ";
     43        } // if
    3044
    31     if ( get_storageClass() != NoStorageClass ) {
    32         os << storageClassName[ get_storageClass() ] << ' ';
    33     }
     45        if ( get_storageClass() != NoStorageClass ) {
     46                os << storageClassName[ get_storageClass() ] << ' ';
     47        } // if
    3448
    35     if ( get_type() ) {
    36         get_type()->print( os, indent );
    37     } else {
    38         os << "untyped entity ";
    39     }
     49        if ( get_type() ) {
     50                get_type()->print( os, indent );
     51        } else {
     52                os << "untyped entity ";
     53        } // if
    4054
    41     if ( init ) {
    42         os << "with initializer ";
    43         init->print( os, indent );
    44     }
     55        if ( init ) {
     56                os << "with initializer ";
     57                init->print( os, indent );
     58        } // if
    4559
    46     if ( bitfieldWidth ) {
    47         os << "with bitfield width ";
    48         bitfieldWidth->print( os );
    49     }
     60        if ( bitfieldWidth ) {
     61                os << "with bitfield width ";
     62                bitfieldWidth->print( os );
     63        } // if
    5064}
    5165
    5266void ObjectDecl::printShort( std::ostream &os, int indent ) const {
    53     if ( get_name() != "" ) {
    54         os << get_name() << ": a ";
    55     }
     67        if ( get_name() != "" ) {
     68                os << get_name() << ": a ";
     69        } // if
    5670
    57     if ( get_storageClass() != NoStorageClass ) {
    58         os << storageClassName[ get_storageClass() ] << ' ';
    59     }
     71        if ( get_storageClass() != NoStorageClass ) {
     72                os << storageClassName[ get_storageClass() ] << ' ';
     73        } // if
    6074
    61     if ( get_type() ) {
    62         get_type()->print( os, indent );
    63     } else {
    64         os << "untyped entity ";
    65     }
     75        if ( get_type() ) {
     76                get_type()->print( os, indent );
     77        } else {
     78                os << "untyped entity ";
     79        } // if
    6680
    67     if ( bitfieldWidth ) {
    68         os << "with bitfield width ";
    69         bitfieldWidth->print( os );
    70     }
     81        if ( bitfieldWidth ) {
     82                os << "with bitfield width ";
     83                bitfieldWidth->print( os );
     84        } // if
    7185}
     86
     87// Local Variables: //
     88// tab-width: 4 //
     89// mode: c++ //
     90// compile-command: "make install" //
     91// End: //
  • translator/SynTree/PointerType.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: PointerType.cc,v 1.8 2005/08/29 20:59:26 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// PointerType.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 10:15:16 2015
     13// Update Count     : 2
     14//
    715
    816#include "Type.h"
     
    1018#include "utility.h"
    1119
    12 
    1320PointerType::PointerType( const Type::Qualifiers &tq, Type *base )
    14     : Type( tq ), base( base ), dimension( 0 ), isVarLen( false ), isStatic( false )
    15 {
    16     base->set_isLvalue( false );
     21        : Type( tq ), base( base ), dimension( 0 ), isVarLen( false ), isStatic( false ) {
     22        base->set_isLvalue( false );
    1723}
    1824
    1925PointerType::PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic )
    20     : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic )
    21 {
    22     base->set_isLvalue( false );
     26        : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) {
     27        base->set_isLvalue( false );
    2328}
    2429
    2530PointerType::PointerType( const PointerType &other )
    26     : Type( other ), base( maybeClone( other.base ) ), dimension( maybeClone( other.dimension ) ),
    27         isVarLen( other.isVarLen ), isStatic( other.isStatic )
    28 {
     31        : Type( other ), base( maybeClone( other.base ) ), dimension( maybeClone( other.dimension ) ),
     32          isVarLen( other.isVarLen ), isStatic( other.isStatic ) {
    2933}
    3034
    31 PointerType::~PointerType()
    32 {
    33     delete base;
    34     delete dimension;
     35PointerType::~PointerType() {
     36        delete base;
     37        delete dimension;
    3538}
    3639
    37 void
    38 PointerType::print( std::ostream &os, int indent ) const
    39 {
    40     Type::print( os, indent );
    41     os << "pointer to ";
    42     if ( isStatic ) {
    43         os << "static ";
    44     }
    45     if ( isVarLen ) {
    46         os << "variable length array of ";
    47     } else if ( dimension ) {
    48         os << "array of ";
    49         dimension->print( os, indent );
    50     }
    51     if ( base ) {
    52         base->print( os, indent );
    53     }
     40void PointerType::print( std::ostream &os, int indent ) const {
     41        Type::print( os, indent );
     42        os << "pointer to ";
     43        if ( isStatic ) {
     44                os << "static ";
     45        } // if
     46        if ( isVarLen ) {
     47                os << "variable length array of ";
     48        } else if ( dimension ) {
     49                os << "array of ";
     50                dimension->print( os, indent );
     51        } // if
     52        if ( base ) {
     53                base->print( os, indent );
     54        } // if
    5455}
    5556
     57// Local Variables: //
     58// tab-width: 4 //
     59// mode: c++ //
     60// compile-command: "make install" //
     61// End: //
  • translator/SynTree/ReferenceToType.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: ReferenceToType.cc,v 1.16 2005/08/29 20:59:26 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// ReferenceToType.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 10:49:00 2015
     13// Update Count     : 2
     14//
    715
    816#include <string>
     
    1523#include "utility.h"
    1624
    17 
    18 ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name )
    19     : Type( tq ), name( name )
    20 {
     25ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name ) : Type( tq ), name( name ) {
    2126}
    2227
    23 ReferenceToType::ReferenceToType( const ReferenceToType &other )
    24     : Type( other ), name( other.name )
    25 {
     28ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ) {
    2629    cloneAll( other.parameters, parameters );
    2730}
    2831
    29 ReferenceToType::~ReferenceToType()
    30 {
     32ReferenceToType::~ReferenceToType() {
    3133    deleteAll( parameters );
    3234}
    3335
    34 void
    35 ReferenceToType::print( std::ostream &os, int indent ) const
    36 {
     36void ReferenceToType::print( std::ostream &os, int indent ) const {
    3737    using std::endl;
    3838   
     
    4040    os << "instance of " << typeString() << " " << name << " ";
    4141    if ( ! parameters.empty() ) {
    42         os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
    43         printAll( parameters, os, indent+2 );
    44     }
     42                os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
     43                printAll( parameters, os, indent+2 );
     44    } // if
    4545}
    4646
    4747namespace {
    48 
    49 void
    50 doLookup( const std::list< Declaration* > &members, const std::list< TypeDecl* > &parms, const std::list< Expression* > &args, const std::string &name, std::list< Declaration* > &foundDecls )
    51 {
    52     std::list< Declaration* > found;
    53     for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
    54         if ( (*i)->get_name() == name ) {
    55             found.push_back( *i );
     48        void doLookup( const std::list< Declaration* > &members, const std::list< TypeDecl* > &parms, const std::list< Expression* > &args, const std::string &name, std::list< Declaration* > &foundDecls ) {
     49                std::list< Declaration* > found;
     50                for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
     51                        if ( (*i)->get_name() == name ) {
     52                                found.push_back( *i );
     53                        } // if
     54                } // for
     55                applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) );
    5656        }
    57     }
    58     applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) );
    59 }
    60 
    6157} // namespace
    6258
    6359std::string StructInstType::typeString() const { return "struct"; }
    6460
    65 void
    66 StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const
    67 {
     61void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
    6862    assert( baseStruct );
    6963    doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls );
     
    7266std::string UnionInstType::typeString() const { return "union"; }
    7367
    74 void
    75 UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const
    76 {
     68void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
    7769    assert( baseUnion );
    7870    doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls );
     
    8375std::string ContextInstType::typeString() const { return "context"; }
    8476
    85 ContextInstType::ContextInstType( const ContextInstType &other )
    86     : Parent( other )
    87 {
     77ContextInstType::ContextInstType( const ContextInstType &other ) : Parent( other ) {
    8878    cloneAll( other.members, members );
    8979}
    9080
    91 ContextInstType::~ContextInstType()
    92 {
     81ContextInstType::~ContextInstType() {
    9382    deleteAll( members );
    9483}
    9584
    96 TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name )
    97 {
     85TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) {
    9886    set_baseType( baseType );
    9987}
    10088
    101 TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype )
    102 {
     89TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype ) {
    10390}
    10491
    105 void TypeInstType::set_baseType( TypeDecl *newValue )
    106 {
     92void TypeInstType::set_baseType( TypeDecl *newValue ) {
    10793    baseType = newValue;
    10894    isFtype = newValue->get_kind() == TypeDecl::Ftype;
     
    11197std::string TypeInstType::typeString() const { return "type"; }
    11298
    113 void
    114 TypeInstType::print( std::ostream &os, int indent ) const
    115 {
     99void TypeInstType::print( std::ostream &os, int indent ) const {
    116100    using std::endl;
    117101   
     
    119103    os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " a function type) ";
    120104    if ( ! parameters.empty() ) {
    121         os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
    122         printAll( parameters, os, indent+2 );
    123     }
     105                os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
     106                printAll( parameters, os, indent+2 );
     107    } // if
    124108}
    125109
     110// Local Variables: //
     111// tab-width: 4 //
     112// mode: c++ //
     113// compile-command: "make install" //
     114// End: //
  • translator/SynTree/Statement.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Statement.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 10:55:19 2015
     13// Update Count     : 2
     14//
     15
    116#include <functional>
    217#include <algorithm>
     
    1328using std::endl;
    1429
    15 
    16 Statement::Statement(std::list<Label> _labels):
    17     labels(_labels) {}
    18 
    19 void Statement::print(std::ostream &, int indent) {}
     30Statement::Statement( std::list<Label> _labels ) : labels(_labels ) {}
     31
     32void Statement::print( std::ostream &, int indent ) {}
    2033
    2134Statement::~Statement() {}
    2235
    23 ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ):
    24     Statement(_labels), expr(_expr) {}
     36ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement(_labels ), expr(_expr ) {}
    2537
    2638ExprStmt::~ExprStmt() {}
    2739
    2840void ExprStmt::print( std::ostream &os, int indent ) {
    29     os << "\r" << string(indent, ' ') << "Expression Statement:" << endl;
    30     expr->print(os, indent + 2);
     41        os << "\r" << string(indent, ' ') << "Expression Statement:" << endl;
     42        expr->print( os, indent + 2 );
    3143}
    3244
    3345const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
    3446
    35 BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type )
    36     throw (SemanticError) :
    37     Statement(labels), target(_target), type(_type)
    38 {
    39     //actually this is a syntactic error signaled by the parser
    40     if (type == BranchStmt::Goto && target.size() == 0)
    41         throw SemanticError("goto without target");
    42 }
    43 
    44 BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type)
    45     throw (SemanticError) :
    46     Statement(labels), computedTarget(_computedTarget), type(_type)
    47 {
    48     if (type != BranchStmt::Goto || computedTarget == 0)
    49         throw SemanticError("Computed target not valid in branch statement");
     47BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) throw ( SemanticError ) :
     48        Statement( labels ), target(_target ), type(_type ) {
     49        //actually this is a syntactic error signaled by the parser
     50        if ( type == BranchStmt::Goto && target.size() == 0 )
     51                throw SemanticError("goto without target");
     52}
     53
     54BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type ) throw ( SemanticError ) :
     55        Statement( labels ), computedTarget(_computedTarget ), type(_type ) {
     56        if ( type != BranchStmt::Goto || computedTarget == 0 )
     57                throw SemanticError("Computed target not valid in branch statement");
    5058}
    5159
    5260void BranchStmt::print( std::ostream &os, int indent ){
    53     os << "\r" << string(indent, ' ') << "Branch (" << brType[type] << ")" << endl ;
    54 }
    55 
    56 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr, bool throwP ) :
    57     Statement( labels ), expr( _expr ), isThrow( throwP ) {}
     61        os << "\r" << string( indent, ' ') << "Branch (" << brType[type] << ")" << endl ;
     62}
     63
     64ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr, bool throwP ) : Statement( labels ), expr( _expr ), isThrow( throwP ) {}
    5865
    5966ReturnStmt::~ReturnStmt() {
    60     delete expr;
    61 }
    62 
    63 void ReturnStmt::print( std::ostream &os, int indent ){
    64     os << "\r" << std::string(indent, ' ') << string ( isThrow? "Throw":"Return" ) << " Statement, returning: ";
    65     if (expr != 0) expr->print(os);
    66     os << endl;
    67 }
    68 
     67        delete expr;
     68}
     69
     70void ReturnStmt::print( std::ostream &os, int indent ) {
     71        os << "\r" << std::string( indent, ' ') << string ( isThrow? "Throw":"Return" ) << " Statement, returning: ";
     72        if ( expr != 0 ) expr->print( os );
     73        os << endl;
     74}
    6975
    7076IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ):
    71     Statement(_labels), condition(_condition), thenPart(_thenPart), elsePart(_elsePart) {}
     77        Statement(_labels ), condition(_condition ), thenPart(_thenPart ), elsePart(_elsePart ) {}
    7278
    7379IfStmt::~IfStmt() {}
    7480
    7581void IfStmt::print( std::ostream &os, int indent ){
    76     os << "\r" << string(indent, ' ') << "If on condition: " << endl ;
    77     condition->print(os, indent + 4);
    78 
    79     os << string(indent, ' ') << ".... and branches: " << endl;
    80 
    81     thenPart->print(os, indent + 4);
    82 
    83     if (elsePart != 0){
    84         elsePart->print(os, indent + 4);
    85     }
    86 }
    87 
    88 SwitchStmt::SwitchStmt(std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches):
    89     Statement(_labels), condition(_condition), branches(_branches)
    90 { }
     82        os << "\r" << string( indent, ' ') << "If on condition: " << endl ;
     83        condition->print( os, indent + 4 );
     84
     85        os << string( indent, ' ') << ".... and branches: " << endl;
     86
     87        thenPart->print( os, indent + 4 );
     88
     89        if ( elsePart != 0 ) {
     90                elsePart->print( os, indent + 4 );
     91        } // if
     92}
     93
     94SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ):
     95        Statement(_labels ), condition(_condition ), branches(_branches ) {
     96}
    9197
    9298SwitchStmt::~SwitchStmt() {
    93     delete condition;
    94     // destroy branches
    95 }
    96 
    97 void SwitchStmt::add_case(CaseStmt *c) {}
    98 
    99 void SwitchStmt::print(std::ostream &os, int indent) {
    100     os << "\r" << string(indent, ' ') << "Switch on condition: ";
    101     condition->print(os);
    102     os << endl;
    103 
    104     // branches
    105     std::list<Statement *>::iterator i;
    106     for (i = branches.begin(); i != branches.end(); i++)
    107         (*i)->print(os, indent + 4);
    108 
    109     //for_each(branches.begin(), branches.end(), mem_fun(bind1st(&Statement::print), os));
    110 }
    111 
    112 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition,
    113                                         std::list<Statement *> &_statements, bool deflt )
    114     throw (SemanticError) :
    115     Statement(_labels), condition(_condition), stmts(_statements), _isDefault(deflt)
    116 {
    117     if (isDefault() && condition != 0)
    118         throw SemanticError("default with conditions");
     99        delete condition;
     100        // destroy branches
     101}
     102
     103void SwitchStmt::add_case( CaseStmt *c ) {}
     104
     105void SwitchStmt::print( std::ostream &os, int indent ) {
     106        os << "\r" << string( indent, ' ') << "Switch on condition: ";
     107        condition->print( os );
     108        os << endl;
     109
     110        // branches
     111        std::list<Statement *>::iterator i;
     112        for ( i = branches.begin(); i != branches.end(); i++)
     113                (*i )->print( os, indent + 4 );
     114
     115        //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os ));
     116}
     117
     118CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) :
     119        Statement(_labels ), condition(_condition ), stmts(_statements ), _isDefault( deflt ) {
     120        if ( isDefault() && condition != 0 )
     121                throw SemanticError("default with conditions");
    119122}
    120123
    121124CaseStmt::~CaseStmt() {
    122     delete condition;
    123 }
    124 
    125 void CaseStmt::print(std::ostream &os, int indent) {
    126     os << "\r" << string(indent, ' ');
    127 
    128     if (isDefault())
    129         os << "Default ";
    130     else {
    131         os << "Case ";
    132         condition->print(os);
    133     }
    134 
    135     os << endl;
    136 
    137     std::list<Statement *>::iterator i;
    138     for (i = stmts.begin(); i != stmts.end(); i++)
    139         (*i)->print(os, indent + 4);
     125        delete condition;
     126}
     127
     128void CaseStmt::print( std::ostream &os, int indent ) {
     129        os << "\r" << string( indent, ' ');
     130
     131        if ( isDefault())
     132                os << "Default ";
     133        else {
     134                os << "Case ";
     135                condition->print( os );
     136        } // if
     137
     138        os << endl;
     139
     140        std::list<Statement *>::iterator i;
     141        for ( i = stmts.begin(); i != stmts.end(); i++)
     142                (*i )->print( os, indent + 4 );
    140143}
    141144
    142145//ChooseStmt::ChooseStmt( std::list<Label> labels, Expression *condition, Statement *body ) {}
    143 ChooseStmt::ChooseStmt(std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches):
    144     Statement(_labels), condition(_condition), branches(_branches)
    145 { }
     146ChooseStmt::ChooseStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ):
     147        Statement(_labels ), condition(_condition ), branches(_branches ) {
     148}
    146149
    147150ChooseStmt::~ChooseStmt() {
    148     delete condition;
    149 }
    150 
    151 void ChooseStmt::add_case(CaseStmt *c) {}
    152 
    153 void ChooseStmt::print(std::ostream &os, int indent) {
    154     os << "\r" << string(indent, ' ') << "Choose on condition: ";
    155     condition->print(os);
    156     os << endl;
    157 
    158     // branches
    159     std::list<Statement *>::iterator i;
    160     for (i = branches.begin(); i != branches.end(); i++)
    161         (*i)->print(os, indent + 4);
    162 
    163     //for_each(branches.begin(), branches.end(), mem_fun(bind1st(&Statement::print), os));
    164 }
    165 
    166 void FallthruStmt::print(std::ostream &os, int indent) {
    167     os << "\r" << string(indent, ' ') << "Fall-through statement" << endl;
    168 }
    169 
    170 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_,
    171                                             Statement *body_, bool isDoWhile_ ):
    172     Statement( labels ), condition(condition_), body(body_), isDoWhile(isDoWhile_)
    173 {}
     151        delete condition;
     152}
     153
     154void ChooseStmt::add_case( CaseStmt *c ) {}
     155
     156void ChooseStmt::print( std::ostream &os, int indent ) {
     157        os << "\r" << string( indent, ' ') << "Choose on condition: ";
     158        condition->print( os );
     159        os << endl;
     160
     161        // branches
     162        std::list<Statement *>::iterator i;
     163        for ( i = branches.begin(); i != branches.end(); i++)
     164                (*i )->print( os, indent + 4 );
     165
     166        //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os ));
     167}
     168
     169void FallthruStmt::print( std::ostream &os, int indent ) {
     170        os << "\r" << string( indent, ' ') << "Fall-through statement" << endl;
     171}
     172
     173WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ):
     174        Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) {
     175}
    174176
    175177WhileStmt::~WhileStmt(){
    176     delete body;
     178        delete body;
    177179}
    178180
    179181void WhileStmt::print( std::ostream &os, int indent ){
    180     os << "\r" << string(indent, ' ') << "While on condition: " << endl ;
    181     condition->print(os, indent + 4);
    182 
    183     os << string(indent, ' ') << ".... with body: " << endl;
    184 
    185     if (body != 0) body->print(os, indent + 4);
    186 }
    187 
    188 ForStmt::ForStmt( std::list<Label> labels, Statement *initialization_,
    189                                     Expression *condition_, Expression *increment_, Statement *body_ ):
    190     Statement( labels ), initialization( initialization_ ),
    191     condition( condition_ ), increment( increment_ ), body( body_ )
    192 { }
    193 
     182        os << "\r" << string( indent, ' ') << "While on condition: " << endl ;
     183        condition->print( os, indent + 4 );
     184
     185        os << string( indent, ' ') << ".... with body: " << endl;
     186
     187        if ( body != 0 ) body->print( os, indent + 4 );
     188}
     189
     190ForStmt::ForStmt( std::list<Label> labels, Statement *initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):
     191        Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) {
     192}
    194193
    195194ForStmt::~ForStmt() {
    196     delete initialization;
    197     delete condition;
    198     delete increment;
    199     delete body;
     195        delete initialization;
     196        delete condition;
     197        delete increment;
     198        delete body;
    200199}
    201200
    202201void ForStmt::print( std::ostream &os, int indent ){
    203     os << "\r" << string(indent, ' ') << "For Statement" << endl ;
    204 
    205     os << "\r" << string(indent + 2, ' ') << "initialization: \n";
    206     if (initialization != 0)
    207         initialization->print(os, indent + 4);
    208 
    209     os << "\n\r" << string(indent + 2, ' ') << "condition: \n";
    210     if (condition != 0)
    211         condition->print(os, indent + 4);
    212 
    213     os << "\n\r" << string(indent + 2, ' ') << "increment: \n";
    214     if (increment != 0)
    215         increment->print(os, indent + 4);
    216 
    217     os << "\n\r" << string(indent + 2, ' ') << "statement block: \n";
    218     if (body != 0)
    219         body->print(os, indent + 4);
    220 
    221     os << endl;
     202        os << "\r" << string( indent, ' ') << "For Statement" << endl ;
     203
     204        os << "\r" << string( indent + 2, ' ') << "initialization: \n";
     205        if ( initialization != 0 )
     206                initialization->print( os, indent + 4 );
     207
     208        os << "\n\r" << string( indent + 2, ' ') << "condition: \n";
     209        if ( condition != 0 )
     210                condition->print( os, indent + 4 );
     211
     212        os << "\n\r" << string( indent + 2, ' ') << "increment: \n";
     213        if ( increment != 0 )
     214                increment->print( os, indent + 4 );
     215
     216        os << "\n\r" << string( indent + 2, ' ') << "statement block: \n";
     217        if ( body != 0 )
     218                body->print( os, indent + 4 );
     219
     220        os << endl;
    222221}
    223222
    224223TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &_handlers, FinallyStmt *_finallyBlock ) :
    225     Statement( labels ), block( tryBlock ),  handlers( _handlers ), finallyBlock( _finallyBlock )
    226 { }
    227 
    228 TryStmt::TryStmt( const TryStmt &other) : Statement( other.labels ) {
    229     block = other.block;
    230     std::copy( other.handlers.begin(), other.handlers.end(), back_inserter(handlers) );
    231     finallyBlock = other.finallyBlock;
     224        Statement( labels ), block( tryBlock ),  handlers( _handlers ), finallyBlock( _finallyBlock ) {
     225}
     226
     227TryStmt::TryStmt( const TryStmt &other ) : Statement( other.labels ) {
     228        block = other.block;
     229        std::copy( other.handlers.begin(), other.handlers.end(), back_inserter( handlers ) );
     230        finallyBlock = other.finallyBlock;
    232231}
    233232
    234233TryStmt::~TryStmt(){
    235     delete block;
     234        delete block;
    236235}
    237236
    238237void TryStmt::print( std::ostream &os, int indent ) {
    239     os << "\r" << string(indent, ' ') << "Try Statement" << endl;
    240     os << string(indent + 2, ' ') << "with block: " << endl;
    241     block->print(os, indent + 4);
    242 
    243     // handlers
    244     os << string(indent + 2, ' ') << "and handlers: " << endl;
    245     std::list<Statement *>::iterator i;
    246     for (i = handlers.begin(); i != handlers.end(); i++)
    247         (*i)->print(os, indent + 4);
    248 
    249     // finally block
    250     if ( finallyBlock != 0 ) {
    251         os << string(indent + 2, ' ') << "Finally block: " << endl;
    252         finallyBlock->print(os, indent + 4 );
    253     }
     238        os << "\r" << string( indent, ' ') << "Try Statement" << endl;
     239        os << string( indent + 2, ' ') << "with block: " << endl;
     240        block->print( os, indent + 4 );
     241
     242        // handlers
     243        os << string( indent + 2, ' ') << "and handlers: " << endl;
     244        std::list<Statement *>::iterator i;
     245        for ( i = handlers.begin(); i != handlers.end(); i++)
     246                (*i )->print( os, indent + 4 );
     247
     248        // finally block
     249        if ( finallyBlock != 0 ) {
     250                os << string( indent + 2, ' ') << "Finally block: " << endl;
     251                finallyBlock->print( os, indent + 4 );
     252        } // if
    254253}
    255254
    256255CatchStmt::CatchStmt( std::list<Label> labels, Declaration *_decl, Statement *_body, bool isCatchRest ) :
    257     Statement( labels ), decl ( _decl ), body( _body ), catchRest ( isCatchRest )
    258 { }
     256        Statement( labels ), decl ( _decl ), body( _body ), catchRest ( isCatchRest ) {
     257}
    259258
    260259CatchStmt::~CatchStmt(){
    261     delete decl;
    262     delete body;
     260        delete decl;
     261        delete body;
    263262}
    264263
    265264void CatchStmt::print( std::ostream &os, int indent ) {
    266     os << "\r" << string(indent, ' ') << "Catch Statement" << endl;
    267 
    268     os << "\r" << string(indent, ' ') << "... catching" << endl;
    269     if ( decl ) {
    270         decl->printShort( os, indent + 4 );
    271         os << endl;
    272     } else if ( catchRest )
    273         os << "\r" << string(indent + 4 , ' ') << "the rest" << endl;
    274     else
    275         os << "\r" << string(indent + 4 , ' ') << ">>> Error:  this catch clause must have a declaration <<<" << endl;
    276 }
    277 
    278 
    279 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) :
    280     Statement( labels ), block( _block )
    281 {
    282     assert( labels.empty() ); // finally statement cannot be labeled
    283 }
    284 
    285 FinallyStmt::~FinallyStmt(){
    286     delete block;
     265        os << "\r" << string( indent, ' ') << "Catch Statement" << endl;
     266
     267        os << "\r" << string( indent, ' ') << "... catching" << endl;
     268        if ( decl ) {
     269                decl->printShort( os, indent + 4 );
     270                os << endl;
     271        } else if ( catchRest )
     272                os << "\r" << string( indent + 4 , ' ') << "the rest" << endl;
     273        else
     274                os << "\r" << string( indent + 4 , ' ') << ">>> Error:  this catch clause must have a declaration <<<" << endl;
     275}
     276
     277
     278FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) {
     279        assert( labels.empty() ); // finally statement cannot be labeled
     280}
     281
     282FinallyStmt::~FinallyStmt() {
     283        delete block;
    287284}
    288285
    289286void FinallyStmt::print( std::ostream &os, int indent ) {
    290     os << "\r" << string(indent, ' ') << "Finally Statement" << endl;
    291     os << string(indent + 2, ' ') << "with block: " << endl;
    292     block->print(os, indent + 4);
     287        os << "\r" << string( indent, ' ') << "Finally Statement" << endl;
     288        os << string( indent + 2, ' ') << "with block: " << endl;
     289        block->print( os, indent + 4 );
    293290}
    294291
     
    298295
    299296void NullStmt::print( std::ostream &os, int indent ) {
    300     os << "\r" << string(indent, ' ') << "Null Statement" << endl ;
    301 }
    302 
    303 
    304 
    305 /*
    306 Local Variables:
    307 compile-command: "cd ..; gmake"
    308 End:
    309 */
     297        os << "\r" << string( indent, ' ') << "Null Statement" << endl ;
     298}
     299
     300// Local Variables: //
     301// tab-width: 4 //
     302// mode: c++ //
     303// compile-command: "make install" //
     304// End: //
  • translator/SynTree/Statement.h

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Statement.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 10:57:40 2015
     13// Update Count     : 2
     14//
     15
    116#ifndef STATEMENT_H
    217#define STATEMENT_H
     
    722#include "Common/SemanticError.h"
    823
    9 
    10 class Statement
    11 {
    12 public:
    13     Statement( std::list<Label> labels );
    14     virtual ~Statement();
    15 
    16     std::list<Label> & get_labels() { return labels; }
    17 
    18     virtual Statement *clone() const = 0;
    19     virtual void accept( Visitor &v ) = 0;
    20     virtual Statement *acceptMutator( Mutator &m ) = 0;
    21     virtual void print( std::ostream &os, int indent = 0 );
    22    
    23 protected:
    24     std::list<Label> labels;
    25 };
    26 
    27 class CompoundStmt : public Statement
    28 {
    29 public:
    30     CompoundStmt( std::list<Label> labels );
    31     CompoundStmt( const CompoundStmt &other );
    32     virtual ~CompoundStmt();
    33 
    34     std::list<Statement*>& get_kids() { return kids; }
    35 
    36     virtual CompoundStmt *clone() const { return new CompoundStmt( *this ); }
    37     virtual void accept( Visitor &v ) { v.visit( this ); }
    38     virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    39     virtual void print( std::ostream &os, int indent = 0 );
    40    
    41 private:
    42     std::list<Statement*> kids;
    43 };
    44 
    45 class ExprStmt : public Statement
    46 {
    47 public:
    48     ExprStmt( std::list<Label> labels, Expression *expr );
    49     virtual ~ExprStmt();
    50 
    51     Expression *get_expr() { return expr; }
    52     void set_expr( Expression *newValue ) { expr = newValue; }
    53 
    54     virtual ExprStmt *clone() const { return new ExprStmt( *this ); }
    55     virtual void accept( Visitor &v ) { v.visit( this ); }
    56     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    57     virtual void print( std::ostream &os, int indent = 0 );
    58    
    59 private:
    60     Expression *expr;
    61 };
    62 
    63 class IfStmt : public Statement
    64 {
    65 public:
    66     IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
    67     virtual ~IfStmt();
    68 
    69     Expression *get_condition() { return condition; }
    70     void set_condition( Expression *newValue ) { condition = newValue; }
    71     Statement *get_thenPart() { return thenPart; }
    72     void set_thenPart( Statement *newValue ) { thenPart = newValue; }
    73     Statement *get_elsePart() { return elsePart; }
    74     void set_elsePart( Statement *newValue ) { elsePart = newValue; }
    75    
    76     virtual IfStmt *clone() const { return new IfStmt( *this ); }
    77     virtual void accept( Visitor &v ) { v.visit( this ); }
    78     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    79     virtual void print( std::ostream &os, int indent = 0 );
    80    
    81 private:
    82     Expression *condition;
    83     Statement *thenPart;
    84     Statement *elsePart;
    85 };
    86 
    87 class SwitchStmt : public Statement
    88 {
    89 public:
    90     SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches );
    91     virtual ~SwitchStmt();
    92 
    93     Expression *get_condition() { return condition; }
    94     void set_condition( Expression *newValue ) { condition = newValue; }
    95 
    96     std::list<Statement *>& get_branches() { return branches; }
    97     void add_case( CaseStmt * );
    98 
    99     virtual void accept( Visitor &v ) { v.visit( this ); }
    100     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    101 
    102     virtual SwitchStmt *clone() const { return new SwitchStmt( *this ); }
    103     virtual void print( std::ostream &os, int indent = 0 );
    104    
    105 private:
    106     Expression * condition;
    107     std::list<Statement *> branches; // should be list of CaseStmt
    108 };
    109 
    110 class ChooseStmt : public Statement
    111 {
    112 public:
    113     ChooseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches );
    114     virtual ~ChooseStmt();
    115 
    116     Expression *get_condition() { return condition; }
    117     void set_condition( Expression *newValue ) { condition = newValue; }
    118 
    119     std::list<Statement *>& get_branches() { return branches; }
    120     void add_case( CaseStmt * );
    121    
    122 
    123     virtual void accept( Visitor &v ) { v.visit( this ); }
    124     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    125 
    126     virtual ChooseStmt *clone() const { return new ChooseStmt( *this ); }
    127     virtual void print( std::ostream &os, int indent = 0 );
    128    
    129 private:
    130     Expression *condition;
    131     std::list<Statement *> branches; // should be list of CaseStmt
     24class Statement {
     25  public:
     26        Statement( std::list<Label> labels );
     27        virtual ~Statement();
     28
     29        std::list<Label> & get_labels() { return labels; }
     30
     31        virtual Statement *clone() const = 0;
     32        virtual void accept( Visitor &v ) = 0;
     33        virtual Statement *acceptMutator( Mutator &m ) = 0;
     34        virtual void print( std::ostream &os, int indent = 0 );
     35  protected:
     36        std::list<Label> labels;
     37};
     38
     39class CompoundStmt : public Statement {
     40  public:
     41        CompoundStmt( std::list<Label> labels );
     42        CompoundStmt( const CompoundStmt &other );
     43        virtual ~CompoundStmt();
     44
     45        std::list<Statement*>& get_kids() { return kids; }
     46
     47        virtual CompoundStmt *clone() const { return new CompoundStmt( *this ); }
     48        virtual void accept( Visitor &v ) { v.visit( this ); }
     49        virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     50        virtual void print( std::ostream &os, int indent = 0 );
     51  private:
     52        std::list<Statement*> kids;
     53};
     54
     55class ExprStmt : public Statement {
     56  public:
     57        ExprStmt( std::list<Label> labels, Expression *expr );
     58        virtual ~ExprStmt();
     59
     60        Expression *get_expr() { return expr; }
     61        void set_expr( Expression *newValue ) { expr = newValue; }
     62
     63        virtual ExprStmt *clone() const { return new ExprStmt( *this ); }
     64        virtual void accept( Visitor &v ) { v.visit( this ); }
     65        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     66        virtual void print( std::ostream &os, int indent = 0 );
     67  private:
     68        Expression *expr;
     69};
     70
     71class IfStmt : public Statement {
     72  public:
     73        IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
     74        virtual ~IfStmt();
     75
     76        Expression *get_condition() { return condition; }
     77        void set_condition( Expression *newValue ) { condition = newValue; }
     78        Statement *get_thenPart() { return thenPart; }
     79        void set_thenPart( Statement *newValue ) { thenPart = newValue; }
     80        Statement *get_elsePart() { return elsePart; }
     81        void set_elsePart( Statement *newValue ) { elsePart = newValue; }
     82       
     83        virtual IfStmt *clone() const { return new IfStmt( *this ); }
     84        virtual void accept( Visitor &v ) { v.visit( this ); }
     85        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     86        virtual void print( std::ostream &os, int indent = 0 );
     87  private:
     88        Expression *condition;
     89        Statement *thenPart;
     90        Statement *elsePart;
     91};
     92
     93class SwitchStmt : public Statement {
     94  public:
     95        SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches );
     96        virtual ~SwitchStmt();
     97
     98        Expression *get_condition() { return condition; }
     99        void set_condition( Expression *newValue ) { condition = newValue; }
     100
     101        std::list<Statement *>& get_branches() { return branches; }
     102        void add_case( CaseStmt * );
     103
     104        virtual void accept( Visitor &v ) { v.visit( this ); }
     105        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     106
     107        virtual SwitchStmt *clone() const { return new SwitchStmt( *this ); }
     108        virtual void print( std::ostream &os, int indent = 0 );
     109  private:
     110        Expression * condition;
     111        std::list<Statement *> branches; // should be list of CaseStmt
     112};
     113
     114class ChooseStmt : public Statement {
     115  public:
     116        ChooseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches );
     117        virtual ~ChooseStmt();
     118
     119        Expression *get_condition() { return condition; }
     120        void set_condition( Expression *newValue ) { condition = newValue; }
     121
     122        std::list<Statement *>& get_branches() { return branches; }
     123        void add_case( CaseStmt * );
     124
     125        virtual void accept( Visitor &v ) { v.visit( this ); }
     126        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     127
     128        virtual ChooseStmt *clone() const { return new ChooseStmt( *this ); }
     129        virtual void print( std::ostream &os, int indent = 0 );
     130  private:
     131        Expression *condition;
     132        std::list<Statement *> branches; // should be list of CaseStmt
    132133};
    133134
    134135class FallthruStmt : public Statement {
    135 public:
    136     FallthruStmt( std::list<Label> labels ) : Statement( labels ) { }
    137 
    138     virtual void accept( Visitor &v ) { v.visit( this ); }
    139     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    140 
    141     virtual FallthruStmt *clone() const { return new FallthruStmt( *this ); }
    142     virtual void print( std::ostream &os, int indent = 0 );
    143 };
    144 
    145 class CaseStmt : public Statement
    146 {
    147 public:
    148     CaseStmt( std::list<Label> labels, Expression *conditions,
    149             std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
    150     virtual ~CaseStmt();
    151 
    152     bool isDefault() { return _isDefault; }
    153     void set_default(bool b) { _isDefault = b; }
    154 
    155     Expression * &get_condition() { return condition; }
    156     void set_condition( Expression *newValue ) { condition = newValue; }
    157 
    158     std::list<Statement *> &get_statements() { return stmts; }
    159     void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; }
    160    
    161     virtual void accept( Visitor &v ) { v.visit( this ); }
    162     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    163 
    164     virtual CaseStmt *clone() const { return new CaseStmt( *this ); }
    165     virtual void print( std::ostream &os, int indent = 0 );
    166 
    167 private:
    168     Expression * condition;
    169     std::list<Statement *> stmts;
    170     bool _isDefault;
    171 };
    172 
    173 class WhileStmt : public Statement
    174 {
    175 public:
    176     WhileStmt( std::list<Label> labels, Expression *condition,
    177                                     Statement *body, bool isDoWhile = false );
    178     virtual ~WhileStmt();
    179 
    180     Expression *get_condition() { return condition; }
    181     void set_condition( Expression *newValue ) { condition = newValue; }
    182     Statement *get_body() { return body; }
    183     void set_body( Statement *newValue ) { body = newValue; }
    184     bool get_isDoWhile() { return isDoWhile; }
    185     void set_isDoWhile( bool newValue ) { isDoWhile = newValue; }
    186    
    187     virtual WhileStmt *clone() const { return new WhileStmt( *this ); }
    188     virtual void accept( Visitor &v ) { v.visit( this ); }
    189     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    190     virtual void print( std::ostream &os, int indent = 0 );
    191    
    192 private:
    193     Expression *condition;
    194     Statement *body;
    195     bool isDoWhile;
    196 };
    197 
    198 class ForStmt : public Statement
    199 {
    200 public:
    201     ForStmt( std::list<Label> labels, Statement *initialization = 0,
    202          Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
    203     virtual ~ForStmt();
    204 
    205     Statement *get_initialization() { return initialization; }
    206     void set_initialization( Statement *newValue ) { initialization = newValue; }
    207     Expression *get_condition() { return condition; }
    208     void set_condition( Expression *newValue ) { condition = newValue; }
    209     Expression *get_increment() { return increment; }
    210     void set_increment( Expression *newValue ) { increment = newValue; }
    211     Statement *get_body() { return body; }
    212     void set_body( Statement *newValue ) { body = newValue; }
    213    
    214     virtual ForStmt *clone() const { return new ForStmt( *this ); }
    215     virtual void accept( Visitor &v ) { v.visit( this ); }
    216     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    217     virtual void print( std::ostream &os, int indent = 0 );
    218    
    219 private:
    220     Statement *initialization;
    221     Expression *condition;
    222     Expression *increment;
    223     Statement *body;
    224 };
    225 
    226 class BranchStmt : public Statement
    227 {
    228 public:
    229 
    230     enum Type { Goto = 0 , Break, Continue };
    231 
    232     BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
    233     BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError);
    234     virtual ~BranchStmt() {}
    235 
    236     Label get_target() { return target; }
    237     void set_target( Label newValue ) { target = newValue; }
    238    
    239     Expression *get_computedTarget() { return computedTarget; }
    240     void set_target( Expression * newValue ) { computedTarget = newValue; }
    241 
    242     Type get_type() { return type; }
    243     const char *get_typename() { return brType[ type ]; }
    244 
    245     virtual BranchStmt *clone() const { return new BranchStmt( *this ); }
    246     virtual void accept( Visitor &v ) { v.visit( this ); }
    247     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    248     virtual void print( std::ostream &os, int indent = 0 );
    249    
    250 private:
    251     static const char *brType[];
    252     Label target;
    253     Expression *computedTarget;
    254     Type type;
    255 };
    256 
    257 class ReturnStmt : public Statement
    258 {
    259 public:
    260     ReturnStmt( std::list<Label> labels, Expression *expr, bool throwP = false );
    261     virtual ~ReturnStmt();
    262 
    263     Expression *get_expr() { return expr; }
    264     void set_expr( Expression *newValue ) { expr = newValue; }
    265    
    266     virtual ReturnStmt *clone() const { return new ReturnStmt( *this ); }
    267     virtual void accept( Visitor &v ) { v.visit( this ); }
    268     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    269     virtual void print( std::ostream &os, int indent = 0 );
    270    
    271 private:
    272     Expression *expr;
    273     bool isThrow;
    274 };
    275 
    276 
    277 class NullStmt : public CompoundStmt
    278 {
    279 public:
    280     NullStmt();
    281     NullStmt( std::list<Label> labels );
    282     virtual ~NullStmt();
    283 
    284     virtual NullStmt *clone() const { return new NullStmt( *this ); }
    285     virtual void accept( Visitor &v ) { v.visit( this ); }
    286     virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    287     virtual void print( std::ostream &os, int indent = 0 );
    288    
    289 private:
    290 };
    291 
    292 class TryStmt : public Statement
    293 {
    294 public:
    295     TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &handlers, FinallyStmt *finallyBlock = 0 );
    296     TryStmt( const TryStmt &other );
    297     virtual ~TryStmt();
    298 
    299     CompoundStmt *get_block() const { return block; }
    300     void set_block( CompoundStmt *newValue ) { block = newValue; }
    301     std::list<Statement *>& get_catchers() { return handlers; }
    302 
    303     FinallyStmt *get_finally() const { return finallyBlock; }
    304     void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; }
    305 
    306     virtual TryStmt *clone() const { return new TryStmt( *this ); }
    307     virtual void accept( Visitor &v ) { v.visit( this ); }
    308     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    309     virtual void print( std::ostream &os, int indent = 0 );
    310    
    311 private:
    312     CompoundStmt *block;
    313     std::list<Statement *> handlers;
    314     FinallyStmt *finallyBlock;
     136  public:
     137        FallthruStmt( std::list<Label> labels ) : Statement( labels ) { }
     138
     139        virtual void accept( Visitor &v ) { v.visit( this ); }
     140        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     141
     142        virtual FallthruStmt *clone() const { return new FallthruStmt( *this ); }
     143        virtual void print( std::ostream &os, int indent = 0 );
     144};
     145
     146class CaseStmt : public Statement {
     147  public:
     148        CaseStmt( std::list<Label> labels, Expression *conditions,
     149              std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
     150        virtual ~CaseStmt();
     151
     152        bool isDefault() { return _isDefault; }
     153        void set_default(bool b) { _isDefault = b; }
     154
     155        Expression * &get_condition() { return condition; }
     156        void set_condition( Expression *newValue ) { condition = newValue; }
     157
     158        std::list<Statement *> &get_statements() { return stmts; }
     159        void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; }
     160       
     161        virtual void accept( Visitor &v ) { v.visit( this ); }
     162        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     163
     164        virtual CaseStmt *clone() const { return new CaseStmt( *this ); }
     165        virtual void print( std::ostream &os, int indent = 0 );
     166  private:
     167        Expression * condition;
     168        std::list<Statement *> stmts;
     169        bool _isDefault;
     170};
     171
     172class WhileStmt : public Statement {
     173  public:
     174        WhileStmt( std::list<Label> labels, Expression *condition,
     175               Statement *body, bool isDoWhile = false );
     176        virtual ~WhileStmt();
     177
     178        Expression *get_condition() { return condition; }
     179        void set_condition( Expression *newValue ) { condition = newValue; }
     180        Statement *get_body() { return body; }
     181        void set_body( Statement *newValue ) { body = newValue; }
     182        bool get_isDoWhile() { return isDoWhile; }
     183        void set_isDoWhile( bool newValue ) { isDoWhile = newValue; }
     184       
     185        virtual WhileStmt *clone() const { return new WhileStmt( *this ); }
     186        virtual void accept( Visitor &v ) { v.visit( this ); }
     187        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     188        virtual void print( std::ostream &os, int indent = 0 );
     189  private:
     190        Expression *condition;
     191        Statement *body;
     192        bool isDoWhile;
     193};
     194
     195class ForStmt : public Statement {
     196  public:
     197        ForStmt( std::list<Label> labels, Statement *initialization = 0,
     198             Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
     199        virtual ~ForStmt();
     200
     201        Statement *get_initialization() { return initialization; }
     202        void set_initialization( Statement *newValue ) { initialization = newValue; }
     203        Expression *get_condition() { return condition; }
     204        void set_condition( Expression *newValue ) { condition = newValue; }
     205        Expression *get_increment() { return increment; }
     206        void set_increment( Expression *newValue ) { increment = newValue; }
     207        Statement *get_body() { return body; }
     208        void set_body( Statement *newValue ) { body = newValue; }
     209       
     210        virtual ForStmt *clone() const { return new ForStmt( *this ); }
     211        virtual void accept( Visitor &v ) { v.visit( this ); }
     212        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     213        virtual void print( std::ostream &os, int indent = 0 );
     214  private:
     215        Statement *initialization;
     216        Expression *condition;
     217        Expression *increment;
     218        Statement *body;
     219};
     220
     221class BranchStmt : public Statement {
     222  public:
     223        enum Type { Goto = 0 , Break, Continue };
     224
     225        BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
     226        BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError);
     227        virtual ~BranchStmt() {}
     228
     229        Label get_target() { return target; }
     230        void set_target( Label newValue ) { target = newValue; }
     231       
     232        Expression *get_computedTarget() { return computedTarget; }
     233        void set_target( Expression * newValue ) { computedTarget = newValue; }
     234
     235        Type get_type() { return type; }
     236        const char *get_typename() { return brType[ type ]; }
     237
     238        virtual BranchStmt *clone() const { return new BranchStmt( *this ); }
     239        virtual void accept( Visitor &v ) { v.visit( this ); }
     240        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     241        virtual void print( std::ostream &os, int indent = 0 );
     242  private:
     243        static const char *brType[];
     244        Label target;
     245        Expression *computedTarget;
     246        Type type;
     247};
     248
     249class ReturnStmt : public Statement {
     250  public:
     251        ReturnStmt( std::list<Label> labels, Expression *expr, bool throwP = false );
     252        virtual ~ReturnStmt();
     253
     254        Expression *get_expr() { return expr; }
     255        void set_expr( Expression *newValue ) { expr = newValue; }
     256       
     257        virtual ReturnStmt *clone() const { return new ReturnStmt( *this ); }
     258        virtual void accept( Visitor &v ) { v.visit( this ); }
     259        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     260        virtual void print( std::ostream &os, int indent = 0 );
     261  private:
     262        Expression *expr;
     263        bool isThrow;
     264};
     265
     266
     267class NullStmt : public CompoundStmt {
     268  public:
     269        NullStmt();
     270        NullStmt( std::list<Label> labels );
     271        virtual ~NullStmt();
     272
     273        virtual NullStmt *clone() const { return new NullStmt( *this ); }
     274        virtual void accept( Visitor &v ) { v.visit( this ); }
     275        virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     276        virtual void print( std::ostream &os, int indent = 0 );
     277       
     278  private:
     279};
     280
     281class TryStmt : public Statement {
     282  public:
     283        TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &handlers, FinallyStmt *finallyBlock = 0 );
     284        TryStmt( const TryStmt &other );
     285        virtual ~TryStmt();
     286
     287        CompoundStmt *get_block() const { return block; }
     288        void set_block( CompoundStmt *newValue ) { block = newValue; }
     289        std::list<Statement *>& get_catchers() { return handlers; }
     290
     291        FinallyStmt *get_finally() const { return finallyBlock; }
     292        void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; }
     293
     294        virtual TryStmt *clone() const { return new TryStmt( *this ); }
     295        virtual void accept( Visitor &v ) { v.visit( this ); }
     296        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     297        virtual void print( std::ostream &os, int indent = 0 );
     298       
     299  private:
     300        CompoundStmt *block;
     301        std::list<Statement *> handlers;
     302        FinallyStmt *finallyBlock;
    315303};
    316304
    317 class CatchStmt : public Statement
    318 {
    319 public:
    320     CatchStmt( std::list<Label> labels, Declaration *decl, Statement *body, bool isCatchRest = false );
    321     virtual ~CatchStmt();
    322 
    323     Declaration *get_decl() { return decl; }
    324     void set_decl( Declaration *newValue ) { decl = newValue; }
    325 
    326     Statement *get_body() { return body; }
    327     void set_body( Statement *newValue ) { body = newValue; }
    328    
    329     virtual CatchStmt *clone() const { return new CatchStmt( *this ); }
    330     virtual void accept( Visitor &v ) { v.visit( this ); }
    331     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    332     virtual void print( std::ostream &os, int indent = 0 );
    333    
    334 private:
    335     Declaration *decl;
    336     Statement *body;
    337     bool catchRest;
    338 };
    339 
    340 class FinallyStmt : public Statement
    341 {
    342 public:
    343     FinallyStmt( std::list<Label> labels, CompoundStmt *block );
    344     virtual ~FinallyStmt();
    345 
    346     CompoundStmt *get_block() const { return block; }
    347     void set_block( CompoundStmt *newValue ) { block = newValue; }
    348    
    349     virtual FinallyStmt *clone() const { return new FinallyStmt( *this ); }
    350     virtual void accept( Visitor &v ) { v.visit( this ); }
    351     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    352     virtual void print( std::ostream &os, int indent = 0 );
    353    
    354 private:
    355     CompoundStmt *block;
     305class CatchStmt : public Statement {
     306  public:
     307        CatchStmt( std::list<Label> labels, Declaration *decl, Statement *body, bool isCatchRest = false );
     308        virtual ~CatchStmt();
     309
     310        Declaration *get_decl() { return decl; }
     311        void set_decl( Declaration *newValue ) { decl = newValue; }
     312
     313        Statement *get_body() { return body; }
     314        void set_body( Statement *newValue ) { body = newValue; }
     315       
     316        virtual CatchStmt *clone() const { return new CatchStmt( *this ); }
     317        virtual void accept( Visitor &v ) { v.visit( this ); }
     318        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     319        virtual void print( std::ostream &os, int indent = 0 );
     320       
     321  private:
     322        Declaration *decl;
     323        Statement *body;
     324        bool catchRest;
     325};
     326
     327class FinallyStmt : public Statement {
     328  public:
     329        FinallyStmt( std::list<Label> labels, CompoundStmt *block );
     330        virtual ~FinallyStmt();
     331
     332        CompoundStmt *get_block() const { return block; }
     333        void set_block( CompoundStmt *newValue ) { block = newValue; }
     334       
     335        virtual FinallyStmt *clone() const { return new FinallyStmt( *this ); }
     336        virtual void accept( Visitor &v ) { v.visit( this ); }
     337        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     338        virtual void print( std::ostream &os, int indent = 0 );
     339  private:
     340        CompoundStmt *block;
    356341};
    357342
    358343
    359344// represents a declaration that occurs as part of a compound statement
    360 class DeclStmt : public Statement
    361 {
    362 public:
    363     DeclStmt( std::list<Label> labels, Declaration *decl );
    364     DeclStmt( const DeclStmt &other );
    365     virtual ~DeclStmt();
    366 
    367     Declaration *get_decl() { return decl; }
    368     void set_decl( Declaration *newValue ) { decl = newValue; }
    369 
    370     virtual DeclStmt *clone() const { return new DeclStmt( *this ); }
    371     virtual void accept( Visitor &v ) { v.visit( this ); }
    372     virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    373     virtual void print( std::ostream &os, int indent = 0 );
    374    
    375 private:
    376     Declaration *decl;
    377 };
    378 
    379 
    380 
    381 #endif /* #ifndef STATEMENT_H */
    382 
    383 /*
    384     Local Variables:
    385     mode: c++
    386     End:
    387 */
     345class DeclStmt : public Statement {
     346  public:
     347        DeclStmt( std::list<Label> labels, Declaration *decl );
     348        DeclStmt( const DeclStmt &other );
     349        virtual ~DeclStmt();
     350
     351        Declaration *get_decl() { return decl; }
     352        void set_decl( Declaration *newValue ) { decl = newValue; }
     353
     354        virtual DeclStmt *clone() const { return new DeclStmt( *this ); }
     355        virtual void accept( Visitor &v ) { v.visit( this ); }
     356        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     357        virtual void print( std::ostream &os, int indent = 0 );
     358  private:
     359        Declaration *decl;
     360};
     361
     362#endif // STATEMENT_H
     363
     364// Local Variables: //
     365// tab-width: 4 //
     366// mode: c++ //
     367// compile-command: "make install" //
     368// End: //
  • translator/SynTree/SynTree.h

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: SynTree.h,v 1.22 2005/08/29 20:59:26 rcbilson Exp $
    5  *
    6  * Forward declarations for syntax tree classes, so that they can be mutually
    7  * interdependent
    8  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// SynTree.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 10:58:22 2015
     13// Update Count     : 1
     14//
    915
    1016#ifndef SYNTREE_H
     
    1521#include <map>
    1622#include <iostream>
    17 
    1823
    1924class Declaration;
     
    102107class TypeSubstitution;
    103108
     109#endif // SYNTREE_H
    104110
    105 #endif /* #ifndef SYNTREE_H */
     111// Local Variables: //
     112// tab-width: 4 //
     113// mode: c++ //
     114// compile-command: "make install" //
     115// End: //
  • translator/SynTree/TupleExpr.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: TupleExpr.cc,v 1.11 2005/08/29 20:59:26 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// TupleExpr.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 10:59:19 2015
     13// Update Count     : 1
     14//
    715
    816#include "Expression.h"
    917#include "utility.h"
    1018
    11 
    12 TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname )
    13 {
     19TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) {
    1420}
    1521
    16 TupleExpr::TupleExpr( const TupleExpr &other )
    17     : Expression( other )
    18 {
    19     cloneAll( other.exprs, exprs );
     22TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) {
     23        cloneAll( other.exprs, exprs );
    2024}
    2125
    22 TupleExpr::~TupleExpr()
    23 {
    24     deleteAll( exprs );
     26TupleExpr::~TupleExpr() {
     27        deleteAll( exprs );
    2528}
    2629
    27 void
    28 TupleExpr::print( std::ostream &os, int indent ) const
    29 {
    30     os << std::string( indent, ' ' ) << "Tuple:" << std::endl;
    31     printAll( exprs, os, indent+2 );
    32     Expression::print( os, indent );
     30void TupleExpr::print( std::ostream &os, int indent ) const {
     31        os << std::string( indent, ' ' ) << "Tuple:" << std::endl;
     32        printAll( exprs, os, indent+2 );
     33        Expression::print( os, indent );
    3334}
    3435
    35 SolvedTupleExpr::SolvedTupleExpr( std::list<Expression *> &_exprs, Expression *_aname )
    36     :  Expression( _aname )
    37 {
    38     std::copy(_exprs.begin(), _exprs.end(), back_inserter(exprs));
     36SolvedTupleExpr::SolvedTupleExpr( std::list<Expression *> &_exprs, Expression *_aname ) : Expression( _aname ) {
     37        std::copy(_exprs.begin(), _exprs.end(), back_inserter(exprs));
    3938}
    4039
    41 SolvedTupleExpr::SolvedTupleExpr( const SolvedTupleExpr &other )
    42     : Expression( other )
    43 {
    44     cloneAll( other.exprs, exprs );
     40SolvedTupleExpr::SolvedTupleExpr( const SolvedTupleExpr &other ) : Expression( other ) {
     41        cloneAll( other.exprs, exprs );
    4542}
    4643
    47 void
    48 SolvedTupleExpr::print( std::ostream &os, int indent ) const
    49 {
    50     os << std::string( indent, ' ' ) << "Solved Tuple:" << std::endl;
    51     printAll( exprs, os, indent+2 );
    52     Expression::print( os, indent );
     44void SolvedTupleExpr::print( std::ostream &os, int indent ) const {
     45        os << std::string( indent, ' ' ) << "Solved Tuple:" << std::endl;
     46        printAll( exprs, os, indent+2 );
     47        Expression::print( os, indent );
    5348}
    5449
     50// Local Variables: //
     51// tab-width: 4 //
     52// mode: c++ //
     53// compile-command: "make install" //
     54// End: //
  • translator/SynTree/TupleType.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: TupleType.cc,v 1.6 2005/08/29 20:59:26 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// TupleType.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:00:01 2015
     13// Update Count     : 2
     14//
    715
    816#include "Type.h"
    917#include "utility.h"
    1018
    11 
    12 TupleType::TupleType( const Type::Qualifiers &tq )
    13     : Type( tq )
    14 {
     19TupleType::TupleType( const Type::Qualifiers &tq ) : Type( tq ) {
    1520}
    1621
    17 TupleType::TupleType( const TupleType& other )
    18     : Type( other )
    19 {
    20     cloneAll( other.types, types );
     22TupleType::TupleType( const TupleType& other ) : Type( other ) {
     23        cloneAll( other.types, types );
    2124}
    2225
    23 TupleType::~TupleType()
    24 {
    25     deleteAll( types );
     26TupleType::~TupleType() {
     27        deleteAll( types );
    2628}
    2729
    28 void
    29 TupleType::print( std::ostream &os, int indent ) const
    30 {
    31     Type::print( os, indent );
    32     os << "tuple of types" << std::endl;
    33     printAll( types, os, indent+2 );
     30void TupleType::print( std::ostream &os, int indent ) const {
     31        Type::print( os, indent );
     32        os << "tuple of types" << std::endl;
     33        printAll( types, os, indent+2 );
    3434}
    3535
     36// Local Variables: //
     37// tab-width: 4 //
     38// mode: c++ //
     39// compile-command: "make install" //
     40// End: //
  • translator/SynTree/Type.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Type.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:00:29 2015
     13// Update Count     : 1
     14//
     15
    116#include "SynTree.h"
    217#include "Visitor.h"
     
    4156void Type::print( std::ostream &os, int indent ) const {
    4257    if ( ! forall.empty() ) {
    43         os << "forall" << std::endl;
    44         printAll( forall, os, indent + 4 );
    45         os << std::string( indent+2, ' ' );
     58                os << "forall" << std::endl;
     59                printAll( forall, os, indent + 4 );
     60                os << std::string( indent+2, ' ' );
    4661    } // if
    4762    if ( tq.isConst ) {
    48         os << "const ";
     63                os << "const ";
    4964    } // if
    5065    if ( tq.isVolatile ) {
    51         os << "volatile ";
     66                os << "volatile ";
    5267    } // if
    5368    if ( tq.isRestrict ) {
    54         os << "restrict ";
     69                os << "restrict ";
    5570    } // if
    5671    if ( tq.isLvalue ) {
    57         os << "lvalue ";
     72                os << "lvalue ";
    5873    } // if
    5974    if ( tq.isAtomic ) {
    60         os << "_Atomic ";
     75                os << "_Atomic ";
    6176    } // if
    6277}
     78
     79// Local Variables: //
     80// tab-width: 4 //
     81// mode: c++ //
     82// compile-command: "make install" //
     83// End: //
  • translator/SynTree/Type.h

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Type.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:01:40 2015
     13// Update Count     : 1
     14//
     15
    116#ifndef TYPE_H
    217#define TYPE_H
     
    621#include "Mutator.h"
    722
    8 
    923class Type {
    1024  public:
    11     struct Qualifiers { 
    12       Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isAttribute( false ) {}
    13       Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isAttribute): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isAttribute( isAttribute ) {}
    14        
    15         Qualifiers &operator+=( const Qualifiers &other );
    16         Qualifiers &operator-=( const Qualifiers &other );
    17         Qualifiers operator+( const Type::Qualifiers &other );
    18         bool operator==( const Qualifiers &other );
    19         bool operator!=( const Qualifiers &other );
    20         bool operator<=( const Qualifiers &other );
    21         bool operator>=( const Qualifiers &other );
    22         bool operator<( const Qualifiers &other );
    23         bool operator>( const Qualifiers &other );
    24        
    25         bool isConst;
    26         bool isVolatile;
    27         bool isRestrict;
    28         bool isLvalue;
    29         bool isAtomic;
    30         bool isAttribute;
    31     }; 
    32 
    33     Type( const Qualifiers &tq );
    34     Type( const Type &other );
    35     virtual ~Type();
    36 
    37     Qualifiers &get_qualifiers() { return tq; }
    38     bool get_isConst() { return tq.isConst; }
    39     bool get_isVolatile() { return tq.isVolatile; }
    40     bool get_isRestrict() { return tq.isRestrict; }
    41     bool get_isLvalue() { return tq.isLvalue; }
    42     bool get_isAtomic() { return tq.isAtomic; }
    43     bool get_isAttribute() { return tq.isAttribute; }
    44     void set_isConst( bool newValue ) { tq.isConst = newValue; }
    45     void set_iisVolatile( bool newValue ) { tq.isVolatile = newValue; }
    46     void set_isRestrict( bool newValue ) { tq.isRestrict = newValue; }
    47     void set_isLvalue( bool newValue ) { tq.isLvalue = newValue; }
    48     void set_isAtomic( bool newValue ) { tq.isAtomic = newValue; }
    49     void set_isAttribute( bool newValue ) { tq.isAttribute = newValue; }
    50     std::list<TypeDecl*>& get_forall() { return forall; }
    51 
    52     virtual Type *clone() const = 0;
    53     virtual void accept( Visitor &v ) = 0;
    54     virtual Type *acceptMutator( Mutator &m ) = 0;
    55     virtual void print( std::ostream &os, int indent = 0 ) const;
    56   private:
    57     Qualifiers tq;
    58     std::list<TypeDecl*> forall;
     25        struct Qualifiers { 
     26                Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isAttribute( false ) {}
     27                Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isAttribute): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isAttribute( isAttribute ) {}
     28       
     29                Qualifiers &operator+=( const Qualifiers &other );
     30                Qualifiers &operator-=( const Qualifiers &other );
     31                Qualifiers operator+( const Type::Qualifiers &other );
     32                bool operator==( const Qualifiers &other );
     33                bool operator!=( const Qualifiers &other );
     34                bool operator<=( const Qualifiers &other );
     35                bool operator>=( const Qualifiers &other );
     36                bool operator<( const Qualifiers &other );
     37                bool operator>( const Qualifiers &other );
     38       
     39                bool isConst;
     40                bool isVolatile;
     41                bool isRestrict;
     42                bool isLvalue;
     43                bool isAtomic;
     44                bool isAttribute;
     45        };     
     46
     47        Type( const Qualifiers &tq );
     48        Type( const Type &other );
     49        virtual ~Type();
     50
     51        Qualifiers &get_qualifiers() { return tq; }
     52        bool get_isConst() { return tq.isConst; }
     53        bool get_isVolatile() { return tq.isVolatile; }
     54        bool get_isRestrict() { return tq.isRestrict; }
     55        bool get_isLvalue() { return tq.isLvalue; }
     56        bool get_isAtomic() { return tq.isAtomic; }
     57        bool get_isAttribute() { return tq.isAttribute; }
     58        void set_isConst( bool newValue ) { tq.isConst = newValue; }
     59        void set_iisVolatile( bool newValue ) { tq.isVolatile = newValue; }
     60        void set_isRestrict( bool newValue ) { tq.isRestrict = newValue; }
     61        void set_isLvalue( bool newValue ) { tq.isLvalue = newValue; }
     62        void set_isAtomic( bool newValue ) { tq.isAtomic = newValue; }
     63        void set_isAttribute( bool newValue ) { tq.isAttribute = newValue; }
     64        std::list<TypeDecl*>& get_forall() { return forall; }
     65
     66        virtual Type *clone() const = 0;
     67        virtual void accept( Visitor &v ) = 0;
     68        virtual Type *acceptMutator( Mutator &m ) = 0;
     69        virtual void print( std::ostream &os, int indent = 0 ) const;
     70  private:
     71        Qualifiers tq;
     72        std::list<TypeDecl*> forall;
    5973};
    6074
    6175class VoidType : public Type {
    6276  public:
    63     VoidType( const Type::Qualifiers &tq );
    64 
    65     virtual VoidType *clone() const { return new VoidType( *this ); }
    66     virtual void accept( Visitor &v ) { v.visit( this ); }
    67     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    68     virtual void print( std::ostream &os, int indent = 0 ) const;
     77        VoidType( const Type::Qualifiers &tq );
     78
     79        virtual VoidType *clone() const { return new VoidType( *this ); }
     80        virtual void accept( Visitor &v ) { v.visit( this ); }
     81        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     82        virtual void print( std::ostream &os, int indent = 0 ) const;
    6983};
    7084
    7185class BasicType : public Type {
    7286  public:
    73     enum Kind { 
    74         Bool,
    75         Char,
    76         SignedChar,
    77         UnsignedChar,
    78         ShortSignedInt,
    79         ShortUnsignedInt,
    80         SignedInt,
    81         UnsignedInt,
    82         LongSignedInt,
    83         LongUnsignedInt,
    84         LongLongSignedInt,
    85         LongLongUnsignedInt,
    86         Float,
    87         Double,
    88         LongDouble,
    89         FloatComplex,
    90         DoubleComplex,
    91         LongDoubleComplex,
    92         FloatImaginary,
    93         DoubleImaginary,
    94         LongDoubleImaginary,
    95         NUMBER_OF_BASIC_TYPES
    96     }; 
    97 
    98     static const char *typeNames[];                     // string names for basic types, MUST MATCH with Kind
    99 
    100     BasicType( const Type::Qualifiers &tq, Kind bt );
    101 
    102     Kind get_kind() { return kind; }
    103     void set_kind( Kind newValue ) { kind = newValue; }
    104 
    105     virtual BasicType *clone() const { return new BasicType( *this ); }
    106     virtual void accept( Visitor &v ) { v.visit( this ); }
    107     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    108     virtual void print( std::ostream &os, int indent = 0 ) const;
    109 
    110     bool isInteger() const;
    111   private:
    112     Kind kind;
     87        enum Kind { 
     88                Bool,
     89                Char,
     90                SignedChar,
     91                UnsignedChar,
     92                ShortSignedInt,
     93                ShortUnsignedInt,
     94                SignedInt,
     95                UnsignedInt,
     96                LongSignedInt,
     97                LongUnsignedInt,
     98                LongLongSignedInt,
     99                LongLongUnsignedInt,
     100                Float,
     101                Double,
     102                LongDouble,
     103                FloatComplex,
     104                DoubleComplex,
     105                LongDoubleComplex,
     106                FloatImaginary,
     107                DoubleImaginary,
     108                LongDoubleImaginary,
     109                NUMBER_OF_BASIC_TYPES
     110        }; 
     111
     112        static const char *typeNames[];                 // string names for basic types, MUST MATCH with Kind
     113
     114        BasicType( const Type::Qualifiers &tq, Kind bt );
     115
     116        Kind get_kind() { return kind; }
     117        void set_kind( Kind newValue ) { kind = newValue; }
     118
     119        virtual BasicType *clone() const { return new BasicType( *this ); }
     120        virtual void accept( Visitor &v ) { v.visit( this ); }
     121        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     122        virtual void print( std::ostream &os, int indent = 0 ) const;
     123
     124        bool isInteger() const;
     125  private:
     126        Kind kind;
    113127};
    114128
    115129class PointerType : public Type {
    116130  public:
    117     PointerType( const Type::Qualifiers &tq, Type *base );
    118     PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
    119     PointerType( const PointerType& );
    120     virtual ~PointerType();
    121 
    122     Type *get_base() { return base; }
    123     void set_base( Type *newValue ) { base = newValue; }
    124     Expression *get_dimension() { return dimension; }
    125     void set_dimension( Expression *newValue ) { dimension = newValue; }
    126     bool get_isVarLen() { return isVarLen; }
    127     void set_isVarLen( bool newValue ) { isVarLen = newValue; }
    128     bool get_isStatic() { return isStatic; }
    129     void set_isStatic( bool newValue ) { isStatic = newValue; }
    130 
    131     virtual PointerType *clone() const { return new PointerType( *this ); }
    132     virtual void accept( Visitor &v ) { v.visit( this ); }
    133     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    134     virtual void print( std::ostream &os, int indent = 0 ) const;
    135   private:
    136     Type *base;
    137    
    138     // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
    139     Expression *dimension;
    140     bool isVarLen;
    141     bool isStatic;
     131        PointerType( const Type::Qualifiers &tq, Type *base );
     132        PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
     133        PointerType( const PointerType& );
     134        virtual ~PointerType();
     135
     136        Type *get_base() { return base; }
     137        void set_base( Type *newValue ) { base = newValue; }
     138        Expression *get_dimension() { return dimension; }
     139        void set_dimension( Expression *newValue ) { dimension = newValue; }
     140        bool get_isVarLen() { return isVarLen; }
     141        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
     142        bool get_isStatic() { return isStatic; }
     143        void set_isStatic( bool newValue ) { isStatic = newValue; }
     144
     145        virtual PointerType *clone() const { return new PointerType( *this ); }
     146        virtual void accept( Visitor &v ) { v.visit( this ); }
     147        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     148        virtual void print( std::ostream &os, int indent = 0 ) const;
     149  private:
     150        Type *base;
     151       
     152        // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
     153        Expression *dimension;
     154        bool isVarLen;
     155        bool isStatic;
    142156};
    143157
    144158class ArrayType : public Type {
    145159  public:
    146     ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
    147     ArrayType( const ArrayType& );
    148     virtual ~ArrayType();
    149 
    150     Type *get_base() { return base; }
    151     void set_base( Type *newValue ) { base = newValue; }
    152     Expression *get_dimension() { return dimension; }
    153     void set_dimension( Expression *newValue ) { dimension = newValue; }
    154     bool get_isVarLen() { return isVarLen; }
    155     void set_isVarLen( bool newValue ) { isVarLen = newValue; }
    156     bool get_isStatic() { return isStatic; }
    157     void set_isStatic( bool newValue ) { isStatic = newValue; }
    158 
    159     virtual ArrayType *clone() const { return new ArrayType( *this ); }
    160     virtual void accept( Visitor &v ) { v.visit( this ); }
    161     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    162     virtual void print( std::ostream &os, int indent = 0 ) const;
    163   private:
    164     Type *base;
    165     Expression *dimension;
    166     bool isVarLen;
    167     bool isStatic;
     160        ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
     161        ArrayType( const ArrayType& );
     162        virtual ~ArrayType();
     163
     164        Type *get_base() { return base; }
     165        void set_base( Type *newValue ) { base = newValue; }
     166        Expression *get_dimension() { return dimension; }
     167        void set_dimension( Expression *newValue ) { dimension = newValue; }
     168        bool get_isVarLen() { return isVarLen; }
     169        void set_isVarLen( bool newValue ) { isVarLen = newValue; }
     170        bool get_isStatic() { return isStatic; }
     171        void set_isStatic( bool newValue ) { isStatic = newValue; }
     172
     173        virtual ArrayType *clone() const { return new ArrayType( *this ); }
     174        virtual void accept( Visitor &v ) { v.visit( this ); }
     175        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     176        virtual void print( std::ostream &os, int indent = 0 ) const;
     177  private:
     178        Type *base;
     179        Expression *dimension;
     180        bool isVarLen;
     181        bool isStatic;
    168182};
    169183
    170184class FunctionType : public Type {
    171185  public:
    172     FunctionType( const Type::Qualifiers &tq, bool isVarArgs );
    173     FunctionType( const FunctionType& );
    174     virtual ~FunctionType();
    175 
    176     std::list<DeclarationWithType*>& get_returnVals() { return returnVals; }
    177     std::list<DeclarationWithType*>& get_parameters() { return parameters; }
    178     bool get_isVarArgs() { return isVarArgs; }
    179     void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
    180 
    181     virtual FunctionType *clone() const { return new FunctionType( *this ); }
    182     virtual void accept( Visitor &v ) { v.visit( this ); }
    183     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    184     virtual void print( std::ostream &os, int indent = 0 ) const;
    185   private:
    186     std::list<DeclarationWithType*> returnVals;
    187     std::list<DeclarationWithType*> parameters;
    188 
    189     // does the function accept a variable number of arguments following the arguments
    190     // specified in the parameters list.    This could be because of
    191     // - an ellipsis in a prototype declaration
    192     // - an unprototyped declaration
    193     bool isVarArgs;
     186        FunctionType( const Type::Qualifiers &tq, bool isVarArgs );
     187        FunctionType( const FunctionType& );
     188        virtual ~FunctionType();
     189
     190        std::list<DeclarationWithType*>& get_returnVals() { return returnVals; }
     191        std::list<DeclarationWithType*>& get_parameters() { return parameters; }
     192        bool get_isVarArgs() { return isVarArgs; }
     193        void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
     194
     195        virtual FunctionType *clone() const { return new FunctionType( *this ); }
     196        virtual void accept( Visitor &v ) { v.visit( this ); }
     197        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     198        virtual void print( std::ostream &os, int indent = 0 ) const;
     199  private:
     200        std::list<DeclarationWithType*> returnVals;
     201        std::list<DeclarationWithType*> parameters;
     202
     203        // does the function accept a variable number of arguments following the arguments
     204        // specified in the parameters list.    This could be because of
     205        // - an ellipsis in a prototype declaration
     206        // - an unprototyped declaration
     207        bool isVarArgs;
    194208};
    195209
    196210class ReferenceToType : public Type {
    197211  public:
    198     ReferenceToType( const Type::Qualifiers &tq, const std::string &name );
    199     ReferenceToType( const ReferenceToType &other );
    200     virtual ~ReferenceToType();
    201 
    202     std::string get_name() const { return name; }
    203     void set_name( std::string newValue ) { name = newValue; }
    204     std::list< Expression* >& get_parameters() { return parameters; }
    205    
    206     virtual ReferenceToType *clone() const = 0;
    207     virtual void accept( Visitor &v ) = 0;
    208     virtual Type *acceptMutator( Mutator &m ) = 0;
    209     virtual void print( std::ostream &os, int indent = 0 ) const;
     212        ReferenceToType( const Type::Qualifiers &tq, const std::string &name );
     213        ReferenceToType( const ReferenceToType &other );
     214        virtual ~ReferenceToType();
     215
     216        std::string get_name() const { return name; }
     217        void set_name( std::string newValue ) { name = newValue; }
     218        std::list< Expression* >& get_parameters() { return parameters; }
     219       
     220        virtual ReferenceToType *clone() const = 0;
     221        virtual void accept( Visitor &v ) = 0;
     222        virtual Type *acceptMutator( Mutator &m ) = 0;
     223        virtual void print( std::ostream &os, int indent = 0 ) const;
    210224  protected:
    211     virtual std::string typeString() const = 0;
    212     std::list< Expression* > parameters;
    213   private:
    214     std::string name;
     225        virtual std::string typeString() const = 0;
     226        std::list< Expression* > parameters;
     227  private:
     228        std::string name;
    215229};
    216230
    217231class StructInstType : public ReferenceToType {
    218     typedef ReferenceToType Parent;
    219   public:
    220     StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {}
    221     StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {}
    222 
    223     StructDecl *get_baseStruct() const { return baseStruct; }
    224     void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
    225    
    226     // a utility function
    227     void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
    228 
    229     virtual StructInstType *clone() const { return new StructInstType( *this ); }
    230     virtual void accept( Visitor &v ) { v.visit( this ); }
    231     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    232 
    233   private:
    234     virtual std::string typeString() const;
    235    
    236     // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
    237     // where the structure used in this type is actually defined
    238     StructDecl *baseStruct;
     232        typedef ReferenceToType Parent;
     233  public:
     234        StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {}
     235        StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {}
     236
     237        StructDecl *get_baseStruct() const { return baseStruct; }
     238        void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
     239       
     240        // a utility function
     241        void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
     242
     243        virtual StructInstType *clone() const { return new StructInstType( *this ); }
     244        virtual void accept( Visitor &v ) { v.visit( this ); }
     245        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     246  private:
     247        virtual std::string typeString() const;
     248       
     249        // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
     250        // where the structure used in this type is actually defined
     251        StructDecl *baseStruct;
    239252};
    240253
    241254class UnionInstType : public ReferenceToType {
    242     typedef ReferenceToType Parent;
    243   public:
    244     UnionInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseUnion( 0 ) {}
    245     UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {}
    246 
    247     UnionDecl *get_baseUnion() const { return baseUnion; }
    248     void set_baseUnion( UnionDecl *newValue ) { baseUnion = newValue; }
    249    
    250     // a utility function
    251     void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
    252 
    253     virtual UnionInstType *clone() const { return new UnionInstType( *this ); }
    254     virtual void accept( Visitor &v ) { v.visit( this ); }
    255     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    256   private:
    257     virtual std::string typeString() const;
    258    
    259     // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
    260     // where the union used in this type is actually defined
    261     UnionDecl *baseUnion;
     255        typedef ReferenceToType Parent;
     256  public:
     257        UnionInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseUnion( 0 ) {}
     258        UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {}
     259
     260        UnionDecl *get_baseUnion() const { return baseUnion; }
     261        void set_baseUnion( UnionDecl *newValue ) { baseUnion = newValue; }
     262       
     263        // a utility function
     264        void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
     265
     266        virtual UnionInstType *clone() const { return new UnionInstType( *this ); }
     267        virtual void accept( Visitor &v ) { v.visit( this ); }
     268        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     269  private:
     270        virtual std::string typeString() const;
     271       
     272        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
     273        // where the union used in this type is actually defined
     274        UnionDecl *baseUnion;
    262275};
    263276
    264277class EnumInstType : public ReferenceToType {
    265     typedef ReferenceToType Parent;
    266   public:
    267     EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
    268     EnumInstType( const EnumInstType &other ) : Parent( other ) {}
    269 
    270     virtual EnumInstType *clone() const { return new EnumInstType( *this ); }
    271     virtual void accept( Visitor &v ) { v.visit( this ); }
    272     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    273 
    274   private:
    275     virtual std::string typeString() const;
     278        typedef ReferenceToType Parent;
     279  public:
     280        EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
     281        EnumInstType( const EnumInstType &other ) : Parent( other ) {}
     282
     283        virtual EnumInstType *clone() const { return new EnumInstType( *this ); }
     284        virtual void accept( Visitor &v ) { v.visit( this ); }
     285        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     286  private:
     287        virtual std::string typeString() const;
    276288};
    277289
    278290class ContextInstType : public ReferenceToType {
    279     typedef ReferenceToType Parent;
    280   public:
    281     ContextInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
    282     ContextInstType( const ContextInstType &other );
    283     ~ContextInstType();
    284 
    285     std::list< Declaration* >& get_members() { return members; }
    286 
    287     virtual ContextInstType *clone() const { return new ContextInstType( *this ); }
    288     virtual void accept( Visitor &v ) { v.visit( this ); }
    289     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    290   private:
    291     virtual std::string typeString() const;
    292    
    293     // this member is filled in by the validate pass, which instantiates the members of the correponding
    294     // aggregate with the actual type parameters specified for this use of the context
    295     std::list< Declaration* > members;
     291        typedef ReferenceToType Parent;
     292  public:
     293        ContextInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
     294        ContextInstType( const ContextInstType &other );
     295        ~ContextInstType();
     296
     297        std::list< Declaration* >& get_members() { return members; }
     298
     299        virtual ContextInstType *clone() const { return new ContextInstType( *this ); }
     300        virtual void accept( Visitor &v ) { v.visit( this ); }
     301        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     302  private:
     303        virtual std::string typeString() const;
     304       
     305        // this member is filled in by the validate pass, which instantiates the members of the correponding
     306        // aggregate with the actual type parameters specified for this use of the context
     307        std::list< Declaration* > members;
    296308};
    297309
    298310class TypeInstType : public ReferenceToType {
    299     typedef ReferenceToType Parent;
    300   public:
    301     TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType );
    302     TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype );
    303     TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {}
    304 
    305     TypeDecl *get_baseType() const { return baseType; }
    306     void set_baseType( TypeDecl *newValue );
    307     bool get_isFtype() const { return isFtype; }
    308     void set_isFtype( bool newValue ) { isFtype = newValue; }
    309    
    310     virtual TypeInstType *clone() const { return new TypeInstType( *this ); }
    311     virtual void accept( Visitor &v ) { v.visit( this ); }
    312     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    313     virtual void print( std::ostream &os, int indent = 0 ) const;
    314   private:
    315     virtual std::string typeString() const;
    316     // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
    317     // where the type used here is actually defined
    318     TypeDecl *baseType;
    319     bool isFtype;
     311        typedef ReferenceToType Parent;
     312  public:
     313        TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType );
     314        TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype );
     315        TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {}
     316
     317        TypeDecl *get_baseType() const { return baseType; }
     318        void set_baseType( TypeDecl *newValue );
     319        bool get_isFtype() const { return isFtype; }
     320        void set_isFtype( bool newValue ) { isFtype = newValue; }
     321       
     322        virtual TypeInstType *clone() const { return new TypeInstType( *this ); }
     323        virtual void accept( Visitor &v ) { v.visit( this ); }
     324        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     325        virtual void print( std::ostream &os, int indent = 0 ) const;
     326  private:
     327        virtual std::string typeString() const;
     328        // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
     329        // where the type used here is actually defined
     330        TypeDecl *baseType;
     331        bool isFtype;
    320332};
    321333
    322334class TupleType : public Type {
    323335  public:
    324     TupleType( const Type::Qualifiers &tq );
    325     TupleType( const TupleType& );
    326     virtual ~TupleType();
    327 
    328     std::list<Type*>& get_types() { return types; }
    329 
    330     virtual TupleType *clone() const { return new TupleType( *this ); }
    331     virtual void accept( Visitor &v ) { v.visit( this ); }
    332     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    333     virtual void print( std::ostream &os, int indent = 0 ) const;
    334   private:
    335     std::list<Type*> types;
     336        TupleType( const Type::Qualifiers &tq );
     337        TupleType( const TupleType& );
     338        virtual ~TupleType();
     339
     340        std::list<Type*>& get_types() { return types; }
     341
     342        virtual TupleType *clone() const { return new TupleType( *this ); }
     343        virtual void accept( Visitor &v ) { v.visit( this ); }
     344        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     345        virtual void print( std::ostream &os, int indent = 0 ) const;
     346  private:
     347        std::list<Type*> types;
    336348};
    337349
    338350class TypeofType : public Type {
    339351  public:
    340     TypeofType( const Type::Qualifiers &tq, Expression *expr );
    341     TypeofType( const TypeofType& );
    342     virtual ~TypeofType();
    343 
    344     Expression *get_expr() const { return expr; }
    345     void set_expr( Expression *newValue ) { expr = newValue; }
    346 
    347     virtual TypeofType *clone() const { return new TypeofType( *this ); }
    348     virtual void accept( Visitor &v ) { v.visit( this ); }
    349     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    350     virtual void print( std::ostream &os, int indent = 0 ) const;
    351   private:
    352     Expression *expr;
     352        TypeofType( const Type::Qualifiers &tq, Expression *expr );
     353        TypeofType( const TypeofType& );
     354        virtual ~TypeofType();
     355
     356        Expression *get_expr() const { return expr; }
     357        void set_expr( Expression *newValue ) { expr = newValue; }
     358
     359        virtual TypeofType *clone() const { return new TypeofType( *this ); }
     360        virtual void accept( Visitor &v ) { v.visit( this ); }
     361        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     362        virtual void print( std::ostream &os, int indent = 0 ) const;
     363  private:
     364        Expression *expr;
    353365};
    354366
    355367class AttrType : public Type {
    356368  public:
    357     AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr );
    358     AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type );
    359     AttrType( const AttrType& );
    360     virtual ~AttrType();
    361 
    362     std::string get_name() const { return name; }
    363     void set_name( const std::string &newValue ) { name = newValue; }
    364     Expression *get_expr() const { return expr; }
    365     void set_expr( Expression *newValue ) { expr = newValue; }
    366     Type *get_type() const { return type; }
    367     void set_type( Type *newValue ) { type = newValue; }
    368     bool get_isType() const { return isType; }
    369     void set_isType( bool newValue ) { isType = newValue; }
    370 
    371     virtual AttrType *clone() const { return new AttrType( *this ); }
    372     virtual void accept( Visitor &v ) { v.visit( this ); }
    373     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    374     virtual void print( std::ostream &os, int indent = 0 ) const;
    375 
    376   private:
    377     std::string name;
    378     Expression *expr;
    379     Type *type;
    380     bool isType;
     369        AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr );
     370        AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type );
     371        AttrType( const AttrType& );
     372        virtual ~AttrType();
     373
     374        std::string get_name() const { return name; }
     375        void set_name( const std::string &newValue ) { name = newValue; }
     376        Expression *get_expr() const { return expr; }
     377        void set_expr( Expression *newValue ) { expr = newValue; }
     378        Type *get_type() const { return type; }
     379        void set_type( Type *newValue ) { type = newValue; }
     380        bool get_isType() const { return isType; }
     381        void set_isType( bool newValue ) { isType = newValue; }
     382
     383        virtual AttrType *clone() const { return new AttrType( *this ); }
     384        virtual void accept( Visitor &v ) { v.visit( this ); }
     385        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     386        virtual void print( std::ostream &os, int indent = 0 ) const;
     387  private:
     388        std::string name;
     389        Expression *expr;
     390        Type *type;
     391        bool isType;
    381392};
    382393
    383394inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) {
    384     isConst |= other.isConst;
    385     isVolatile |= other.isVolatile;
    386     isRestrict |= other.isRestrict;
    387     isLvalue |= other.isLvalue;
    388     isAtomic |= other.isAtomic;
    389     return *this;
     395        isConst |= other.isConst;
     396        isVolatile |= other.isVolatile;
     397        isRestrict |= other.isRestrict;
     398        isLvalue |= other.isLvalue;
     399        isAtomic |= other.isAtomic;
     400        return *this;
    390401}
    391402
    392403inline Type::Qualifiers &Type::Qualifiers::operator-=( const Type::Qualifiers &other ) {
    393     if ( other.isConst ) isConst = 0;
    394     if ( other.isVolatile ) isVolatile = 0;
    395     if ( other.isRestrict ) isRestrict = 0;
    396     if ( other.isAtomic ) isAtomic = 0;
    397     return *this;
     404        if ( other.isConst ) isConst = 0;
     405        if ( other.isVolatile ) isVolatile = 0;
     406        if ( other.isRestrict ) isRestrict = 0;
     407        if ( other.isAtomic ) isAtomic = 0;
     408        return *this;
    398409}
    399410
    400411inline Type::Qualifiers Type::Qualifiers::operator+( const Type::Qualifiers &other ) {
    401     Qualifiers q = other;
    402     q += *this;
    403     return q;
     412        Qualifiers q = other;
     413        q += *this;
     414        return q;
    404415}
    405416
    406417inline bool Type::Qualifiers::operator==( const Qualifiers &other ) {
    407     return isConst == other.isConst
    408         && isVolatile == other.isVolatile
    409         && isRestrict == other.isRestrict
     418        return isConst == other.isConst
     419                && isVolatile == other.isVolatile
     420                && isRestrict == other.isRestrict
    410421//      && isLvalue == other.isLvalue
    411         && isAtomic == other.isAtomic;
     422                && isAtomic == other.isAtomic;
    412423}
    413424
    414425inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) {
    415     return isConst != other.isConst
    416         || isVolatile != other.isVolatile
    417         || isRestrict != other.isRestrict
     426        return isConst != other.isConst
     427                || isVolatile != other.isVolatile
     428                || isRestrict != other.isRestrict
    418429//      || isLvalue != other.isLvalue
    419         || isAtomic != other.isAtomic;
     430                || isAtomic != other.isAtomic;
    420431}
    421432
    422433inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) {
    423     return isConst <= other.isConst
    424         && isVolatile <= other.isVolatile
    425         && isRestrict <= other.isRestrict
     434        return isConst <= other.isConst
     435                && isVolatile <= other.isVolatile
     436                && isRestrict <= other.isRestrict
    426437//      && isLvalue >= other.isLvalue
    427         && isAtomic == other.isAtomic;
     438                && isAtomic == other.isAtomic;
    428439}
    429440
    430441inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) {
    431     return isConst >= other.isConst
    432         && isVolatile >= other.isVolatile
    433         && isRestrict >= other.isRestrict
     442        return isConst >= other.isConst
     443                && isVolatile >= other.isVolatile
     444                && isRestrict >= other.isRestrict
    434445//      && isLvalue <= other.isLvalue
    435         && isAtomic == other.isAtomic;
     446                && isAtomic == other.isAtomic;
    436447}
    437448
    438449inline bool Type::Qualifiers::operator<( const Type::Qualifiers &other ) {
    439     return operator!=( other ) && operator<=( other );
     450        return operator!=( other ) && operator<=( other );
    440451}
    441452
    442453inline bool Type::Qualifiers::operator>( const Type::Qualifiers &other ) {
    443     return operator!=( other ) && operator>=( other );
     454        return operator!=( other ) && operator>=( other );
    444455}
    445456
    446457#endif // TYPE_H
     458
     459// Local Variables: //
     460// tab-width: 4 //
     461// mode: c++ //
     462// compile-command: "make install" //
     463// End: //
  • translator/SynTree/TypeDecl.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// TypeDecl.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:02:11 2015
     13// Update Count     : 1
     14//
     15
    116#include "Declaration.h"
    217#include "Type.h"
    318#include "utility.h"
    419
    5 
    6 TypeDecl::TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind )
    7     : Parent( name, sc, type ), kind( kind )
    8 {
     20TypeDecl::TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind ) : Parent( name, sc, type ), kind( kind ) {
    921}
    1022
    11 TypeDecl::TypeDecl( const TypeDecl &other )
    12     : Parent( other ), kind( other.kind )
    13 {
     23TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), kind( other.kind ) {
    1424}
    1525
    16 std::string
    17 TypeDecl::typeString() const
    18 {
    19     static const char *kindNames[] = { "type", "incomplete type", "function type" };
    20     return kindNames[ kind ];
     26std::string TypeDecl::typeString() const {
     27        static const char *kindNames[] = { "type", "incomplete type", "function type" };
     28        return kindNames[ kind ];
    2129}
    2230
     31// Local Variables: //
     32// tab-width: 4 //
     33// mode: c++ //
     34// compile-command: "make install" //
     35// End: //
  • translator/SynTree/TypeExpr.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: TypeExpr.cc,v 1.4 2005/08/29 20:59:26 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// TypeExpr.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:03:15 2015
     13// Update Count     : 1
     14//
    715
    816#include "Expression.h"
     
    1018#include "utility.h"
    1119
    12 
    13 TypeExpr::TypeExpr( Type *type )
    14     : type( type )
    15 {
     20TypeExpr::TypeExpr( Type *type ) : type( type ) {
    1621}
    1722
    18 TypeExpr::TypeExpr( const TypeExpr &other )
    19     : type( maybeClone( other.type ) )
    20 {
     23TypeExpr::TypeExpr( const TypeExpr &other ) : type( maybeClone( other.type ) ) {
    2124}
    2225
    23 TypeExpr::~TypeExpr()
    24 {
    25     delete type;
     26TypeExpr::~TypeExpr() {
     27        delete type;
    2628}
    2729
    28 void
    29 TypeExpr::print( std::ostream &os, int indent ) const
    30 {
    31     if ( type ) type->print( os, indent );
    32     Expression::print( os, indent );
     30void TypeExpr::print( std::ostream &os, int indent ) const {
     31        if ( type ) type->print( os, indent );
     32        Expression::print( os, indent );
    3333}
    3434
     35// Local Variables: //
     36// tab-width: 4 //
     37// mode: c++ //
     38// compile-command: "make install" //
     39// End: //
  • translator/SynTree/TypeSubstitution.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: TypeSubstitution.cc,v 1.9 2005/08/29 20:59:26 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// TypeSubstitution.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:10:04 2015
     13// Update Count     : 2
     14//
    715
    816#include "Type.h"
    917#include "TypeSubstitution.h"
    1018
    11 
    12 TypeSubstitution::TypeSubstitution()
    13 {
     19TypeSubstitution::TypeSubstitution() {
    1420}
    1521
    16 TypeSubstitution::TypeSubstitution( const TypeSubstitution &other )
    17 {
    18     initialize( other, *this );
     22TypeSubstitution::TypeSubstitution( const TypeSubstitution &other ) {
     23        initialize( other, *this );
    1924}
    2025
    21 TypeSubstitution::~TypeSubstitution()
    22 {
    23     for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
    24         delete( i->second );
    25     }
    26     for ( VarEnvType::iterator i = varEnv.begin(); i != varEnv.end(); ++i ) {
    27         delete( i->second );
    28     }
     26TypeSubstitution::~TypeSubstitution() {
     27        for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
     28                delete( i->second );
     29        }
     30        for ( VarEnvType::iterator i = varEnv.begin(); i != varEnv.end(); ++i ) {
     31                delete( i->second );
     32        }
    2933}
    3034
    31 TypeSubstitution &
    32 TypeSubstitution::operator=( const TypeSubstitution &other )
    33 {
    34     if ( this == &other ) return *this;
    35     initialize( other, *this );
    36     return *this;
     35TypeSubstitution &TypeSubstitution::operator=( const TypeSubstitution &other ) {
     36        if ( this == &other ) return *this;
     37        initialize( other, *this );
     38        return *this;
    3739}
    3840
    39 void
    40 TypeSubstitution::initialize( const TypeSubstitution &src, TypeSubstitution &dest )
    41 {
    42     dest.typeEnv.clear();
    43     dest.varEnv.clear();
    44     dest.add( src );
     41void TypeSubstitution::initialize( const TypeSubstitution &src, TypeSubstitution &dest ) {
     42        dest.typeEnv.clear();
     43        dest.varEnv.clear();
     44        dest.add( src );
    4545}
    4646
    47 void
    48 TypeSubstitution::add( const TypeSubstitution &other )
    49 {
    50     for ( TypeEnvType::const_iterator i = other.typeEnv.begin(); i != other.typeEnv.end(); ++i ) {
    51         typeEnv[ i->first ] = i->second->clone();
    52     }
    53     for ( VarEnvType::const_iterator i = other.varEnv.begin(); i != other.varEnv.end(); ++i ) {
    54         varEnv[ i->first ] = i->second->clone();
    55     }
     47void TypeSubstitution::add( const TypeSubstitution &other ) {
     48        for ( TypeEnvType::const_iterator i = other.typeEnv.begin(); i != other.typeEnv.end(); ++i ) {
     49                typeEnv[ i->first ] = i->second->clone();
     50        } // for
     51        for ( VarEnvType::const_iterator i = other.varEnv.begin(); i != other.varEnv.end(); ++i ) {
     52                varEnv[ i->first ] = i->second->clone();
     53        } // for
    5654}
    5755
    58 void
    59 TypeSubstitution::add( std::string formalType, Type *actualType )
    60 {
    61     TypeEnvType::iterator i = typeEnv.find( formalType );
    62     if ( i != typeEnv.end() ) {
    63         delete i->second;
    64     }
    65     typeEnv[ formalType ] = actualType->clone();
     56void TypeSubstitution::add( std::string formalType, Type *actualType ) {
     57        TypeEnvType::iterator i = typeEnv.find( formalType );
     58        if ( i != typeEnv.end() ) {
     59                delete i->second;
     60        } // if
     61        typeEnv[ formalType ] = actualType->clone();
    6662}
    6763
    68 void
    69 TypeSubstitution::remove( std::string formalType )
    70 {
    71     TypeEnvType::iterator i = typeEnv.find( formalType );
    72     if ( i != typeEnv.end() ) {
    73         delete i->second;
    74         typeEnv.erase( formalType );
    75     }
     64void TypeSubstitution::remove( std::string formalType ) {
     65        TypeEnvType::iterator i = typeEnv.find( formalType );
     66        if ( i != typeEnv.end() ) {
     67                delete i->second;
     68                typeEnv.erase( formalType );
     69        } // if
    7670}
    7771
    78 Type *
    79 TypeSubstitution::lookup( std::string formalType ) const
    80 {
    81     TypeEnvType::const_iterator i = typeEnv.find( formalType );
    82     if ( i == typeEnv.end() ) {
    83         return 0;
    84     } else {
    85         return i->second;
    86     }
     72Type *TypeSubstitution::lookup( std::string formalType ) const {
     73        TypeEnvType::const_iterator i = typeEnv.find( formalType );
     74        if ( i == typeEnv.end() ) {
     75                return 0;
     76        } else {
     77                return i->second;
     78        } // if
    8779}
    8880
    89 bool
    90 TypeSubstitution::empty() const
    91 {
    92     return typeEnv.empty() && varEnv.empty();
     81bool TypeSubstitution::empty() const {
     82        return typeEnv.empty() && varEnv.empty();
    9383}
    9484
    95 void
    96 TypeSubstitution::normalize()
    97 {
    98     do {
    99         subCount = 0;
    100         freeOnly = true;
    101         for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
    102             i->second = i->second->acceptMutator( *this );
    103         }
    104     } while ( subCount );
     85void TypeSubstitution::normalize() {
     86        do {
     87                subCount = 0;
     88                freeOnly = true;
     89                for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
     90                        i->second = i->second->acceptMutator( *this );
     91                }
     92        } while ( subCount );
    10593}
    10694
    107 Type*
    108 TypeSubstitution::mutate(TypeInstType *inst)
    109 {
    110     BoundVarsType::const_iterator bound = boundVars.find( inst->get_name() );
    111     if ( bound != boundVars.end() ) return inst;
    112    
    113     TypeEnvType::const_iterator i = typeEnv.find( inst->get_name() );
    114     if ( i == typeEnv.end() ) {
    115         return inst;
    116     } else {
     95Type * TypeSubstitution::mutate( TypeInstType *inst ) {
     96        BoundVarsType::const_iterator bound = boundVars.find( inst->get_name() );
     97        if ( bound != boundVars.end() ) return inst;
     98       
     99        TypeEnvType::const_iterator i = typeEnv.find( inst->get_name() );
     100        if ( i == typeEnv.end() ) {
     101                return inst;
     102        } else {
    117103///         std::cout << "found " << inst->get_name() << ", replacing with ";
    118104///         i->second->print( std::cout );
    119105///         std::cout << std::endl;
    120         subCount++;
    121         Type *newtype = i->second->clone();
    122         newtype->get_qualifiers() += inst->get_qualifiers();
    123         delete inst;
    124         return newtype;
    125     }
     106                subCount++;
     107                Type *newtype = i->second->clone();
     108                newtype->get_qualifiers() += inst->get_qualifiers();
     109                delete inst;
     110                return newtype;
     111        } // if
    126112}
    127113
    128 Expression*
    129 TypeSubstitution::mutate(NameExpr *nameExpr)
    130 {
    131     VarEnvType::const_iterator i = varEnv.find( nameExpr->get_name() );
    132     if ( i == varEnv.end() ) {
    133         return nameExpr;
    134     } else {
    135         subCount++;
    136         delete nameExpr;
    137         return i->second->clone();
    138     }
     114Expression * TypeSubstitution::mutate( NameExpr *nameExpr ) {
     115        VarEnvType::const_iterator i = varEnv.find( nameExpr->get_name() );
     116        if ( i == varEnv.end() ) {
     117                return nameExpr;
     118        } else {
     119                subCount++;
     120                delete nameExpr;
     121                return i->second->clone();
     122        } // if
    139123}
    140124
    141125template< typename TypeClass >
    142 Type *
    143 TypeSubstitution::handleType( TypeClass *type )
    144 {
    145     BoundVarsType oldBoundVars( boundVars );
    146     if ( freeOnly ) {
    147         for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) {
    148             boundVars.insert( (*tyvar)->get_name() );
    149         }
    150     }
    151     Type *ret = Mutator::mutate( type );
    152     boundVars = oldBoundVars;
    153     return ret;
     126Type *TypeSubstitution::handleType( TypeClass *type ) {
     127        BoundVarsType oldBoundVars( boundVars );
     128        if ( freeOnly ) {
     129                for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) {
     130                        boundVars.insert( (*tyvar )->get_name() );
     131                } // for
     132        } // if
     133        Type *ret = Mutator::mutate( type );
     134        boundVars = oldBoundVars;
     135        return ret;
    154136}
    155137
    156 Type*
    157 TypeSubstitution::mutate(VoidType *basicType)
    158 {
    159     return handleType( basicType );
     138Type * TypeSubstitution::mutate( VoidType *basicType ) {
     139        return handleType( basicType );
    160140}
    161141
    162 Type*
    163 TypeSubstitution::mutate(BasicType *basicType)
    164 {
    165     return handleType( basicType );
     142Type * TypeSubstitution::mutate( BasicType *basicType ) {
     143        return handleType( basicType );
    166144}
    167145
    168 Type*
    169 TypeSubstitution::mutate(PointerType *pointerType)
    170 {
    171     return handleType( pointerType );
     146Type * TypeSubstitution::mutate( PointerType *pointerType ) {
     147        return handleType( pointerType );
    172148}
    173149
    174 Type*
    175 TypeSubstitution::mutate(ArrayType *arrayType)
    176 {
    177     return handleType( arrayType );
     150Type * TypeSubstitution::mutate( ArrayType *arrayType ) {
     151        return handleType( arrayType );
    178152}
    179153
    180 Type*
    181 TypeSubstitution::mutate(FunctionType *functionType)
    182 {
    183     return handleType( functionType );
     154Type * TypeSubstitution::mutate( FunctionType *functionType ) {
     155        return handleType( functionType );
    184156}
    185157
    186 Type*
    187 TypeSubstitution::mutate(StructInstType *aggregateUseType)
    188 {
    189     return handleType( aggregateUseType );
     158Type * TypeSubstitution::mutate( StructInstType *aggregateUseType ) {
     159        return handleType( aggregateUseType );
    190160}
    191161
    192 Type*
    193 TypeSubstitution::mutate(UnionInstType *aggregateUseType)
    194 {
    195     return handleType( aggregateUseType );
     162Type * TypeSubstitution::mutate( UnionInstType *aggregateUseType ) {
     163        return handleType( aggregateUseType );
    196164}
    197165
    198 Type*
    199 TypeSubstitution::mutate(EnumInstType *aggregateUseType)
    200 {
    201     return handleType( aggregateUseType );
     166Type * TypeSubstitution::mutate( EnumInstType *aggregateUseType ) {
     167        return handleType( aggregateUseType );
    202168}
    203169
    204 Type*
    205 TypeSubstitution::mutate(ContextInstType *aggregateUseType)
    206 {
    207     return handleType( aggregateUseType );
     170Type * TypeSubstitution::mutate( ContextInstType *aggregateUseType ) {
     171        return handleType( aggregateUseType );
    208172}
    209173
    210 Type*
    211 TypeSubstitution::mutate(TupleType *tupleType)
    212 {
    213     return handleType( tupleType );
     174Type * TypeSubstitution::mutate( TupleType *tupleType ) {
     175        return handleType( tupleType );
    214176}
    215177
    216 void
    217 TypeSubstitution::print( std::ostream &os, int indent ) const
    218 {
    219     os << std::string( indent, ' ' ) << "Types:" << std::endl;
    220     for ( TypeEnvType::const_iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
    221         os << std::string( indent+2, ' ' ) << i->first << " -> ";
    222         i->second->print( os, indent+4 );
    223         os << std::endl;
    224     }
    225     os << std::string( indent, ' ' ) << "Non-types:" << std::endl;
    226     for ( VarEnvType::const_iterator i = varEnv.begin(); i != varEnv.end(); ++i ) {
    227         os << std::string( indent+2, ' ' ) << i->first << " -> ";
    228         i->second->print( os, indent+4 );
    229         os << std::endl;
    230     }
     178void TypeSubstitution::print( std::ostream &os, int indent ) const {
     179        os << std::string( indent, ' ' ) << "Types:" << std::endl;
     180        for ( TypeEnvType::const_iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
     181                os << std::string( indent+2, ' ' ) << i->first << " -> ";
     182                i->second->print( os, indent+4 );
     183                os << std::endl;
     184        } // for
     185        os << std::string( indent, ' ' ) << "Non-types:" << std::endl;
     186        for ( VarEnvType::const_iterator i = varEnv.begin(); i != varEnv.end(); ++i ) {
     187                os << std::string( indent+2, ' ' ) << i->first << " -> ";
     188                i->second->print( os, indent+4 );
     189                os << std::endl;
     190        } // for
    231191}
    232192
     193// Local Variables: //
     194// tab-width: 4 //
     195// mode: c++ //
     196// compile-command: "make install" //
     197// End: //
  • translator/SynTree/TypeSubstitution.h

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: TypeSubstitution.h,v 1.9 2005/08/29 20:59:26 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// TypeSubstitution.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:12:30 2015
     13// Update Count     : 1
     14//
    715
    8 #ifndef SYNTREE_TYPESUBSTITUTION_H
    9 #define SYNTREE_TYPESUBSTITUTION_H
     16#ifndef TYPESUBSTITUTION_H
     17#define TYPESUBSTITUTION_H
    1018
    1119#include <map>
     
    1725#include "SynTree/Expression.h"
    1826
     27class TypeSubstitution : public Mutator {
     28        typedef Mutator Parent;
     29  public:
     30        TypeSubstitution();
     31        template< typename FormalIterator, typename ActualIterator >
     32        TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin );
     33        TypeSubstitution( const TypeSubstitution &other );
     34        virtual ~TypeSubstitution();
     35       
     36        TypeSubstitution &operator=( const TypeSubstitution &other );
     37       
     38        template< typename SynTreeClass > int apply( SynTreeClass *&input );
     39        template< typename SynTreeClass > int applyFree( SynTreeClass *&input );
     40       
     41        void add( std::string formalType, Type *actualType );
     42        void add( const TypeSubstitution &other );
     43        void remove( std::string formalType );
     44        Type *lookup( std::string formalType ) const;
     45        bool empty() const;
     46       
     47        template< typename FormalIterator, typename ActualIterator >
     48        void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin );
     49       
     50        template< typename TypeInstListIterator >
     51        void extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result );
     52       
     53        void normalize();
    1954
    20 class TypeSubstitution : public Mutator
    21 {
    22     typedef Mutator Parent;
    23    
    24 public:
    25     TypeSubstitution();
    26     template< typename FormalIterator, typename ActualIterator >
    27     TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin );
    28     TypeSubstitution( const TypeSubstitution &other );
    29     virtual ~TypeSubstitution();
    30    
    31     TypeSubstitution &operator=( const TypeSubstitution &other );
    32    
    33     template< typename SynTreeClass > int apply( SynTreeClass *&input );
    34     template< typename SynTreeClass > int applyFree( SynTreeClass *&input );
    35    
    36     void add( std::string formalType, Type *actualType );
    37     void add( const TypeSubstitution &other );
    38     void remove( std::string formalType );
    39     Type *lookup( std::string formalType ) const;
    40     bool empty() const;
    41    
    42     template< typename FormalIterator, typename ActualIterator >
    43     void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin );
    44    
    45     template< typename TypeInstListIterator >
    46     void extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result );
    47    
    48     void normalize();
     55        void print( std::ostream &os, int indent = 0 ) const;
     56        TypeSubstitution *clone() const { return new TypeSubstitution( *this ); }
     57  private:
     58        virtual Type* mutate(TypeInstType *aggregateUseType);
     59        virtual Expression* mutate(NameExpr *nameExpr);
     60       
     61        template< typename TypeClass > Type *handleType( TypeClass *type );
     62       
     63        virtual Type* mutate(VoidType *basicType);
     64        virtual Type* mutate(BasicType *basicType);
     65        virtual Type* mutate(PointerType *pointerType);
     66        virtual Type* mutate(ArrayType *arrayType);
     67        virtual Type* mutate(FunctionType *functionType);
     68        virtual Type* mutate(StructInstType *aggregateUseType);
     69        virtual Type* mutate(UnionInstType *aggregateUseType);
     70        virtual Type* mutate(EnumInstType *aggregateUseType);
     71        virtual Type* mutate(ContextInstType *aggregateUseType);
     72        virtual Type* mutate(TupleType *tupleType);
     73       
     74        // TODO: worry about traversing into a forall-qualified function type or type decl with assertions
     75       
     76        void initialize( const TypeSubstitution &src, TypeSubstitution &dest );
    4977
    50     void print( std::ostream &os, int indent = 0 ) const;
    51     TypeSubstitution *clone() const { return new TypeSubstitution( *this ); }
    52    
    53 private:
    54     virtual Type* mutate(TypeInstType *aggregateUseType);
    55     virtual Expression* mutate(NameExpr *nameExpr);
    56    
    57     template< typename TypeClass > Type *handleType( TypeClass *type );
    58    
    59     virtual Type* mutate(VoidType *basicType);
    60     virtual Type* mutate(BasicType *basicType);
    61     virtual Type* mutate(PointerType *pointerType);
    62     virtual Type* mutate(ArrayType *arrayType);
    63     virtual Type* mutate(FunctionType *functionType);
    64     virtual Type* mutate(StructInstType *aggregateUseType);
    65     virtual Type* mutate(UnionInstType *aggregateUseType);
    66     virtual Type* mutate(EnumInstType *aggregateUseType);
    67     virtual Type* mutate(ContextInstType *aggregateUseType);
    68     virtual Type* mutate(TupleType *tupleType);
    69    
    70     // TODO: worry about traversing into a forall-qualified function type or type decl with assertions
    71    
    72     void initialize( const TypeSubstitution &src, TypeSubstitution &dest );
    73 
    74     typedef std::map< std::string, Type* > TypeEnvType;
    75     typedef std::map< std::string, Expression* > VarEnvType;
    76     typedef std::set< std::string > BoundVarsType;
    77     TypeEnvType typeEnv;
    78     VarEnvType varEnv;
    79     BoundVarsType boundVars;
    80     int subCount;
    81     bool freeOnly;
     78        typedef std::map< std::string, Type* > TypeEnvType;
     79        typedef std::map< std::string, Expression* > VarEnvType;
     80        typedef std::set< std::string > BoundVarsType;
     81        TypeEnvType typeEnv;
     82        VarEnvType varEnv;
     83        BoundVarsType boundVars;
     84        int subCount;
     85        bool freeOnly;
    8286};
    8387
    8488template< typename FormalIterator, typename ActualIterator >
    85 void
    86 TypeSubstitution::add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin )
    87 {
    88     // FormalIterator points to a TypeDecl
    89     // ActualIterator points to a Type
    90     FormalIterator formalIt = formalBegin;
    91     ActualIterator actualIt = actualBegin;
    92     for ( ; formalIt != formalEnd; ++formalIt, ++actualIt ) {
    93         if ( TypeDecl *formal = dynamic_cast< TypeDecl* >( *formalIt ) ) {
    94             if ( TypeExpr *actual = dynamic_cast< TypeExpr* >( *actualIt ) ) {
    95                 if ( formal->get_name() != "" ) {
    96                     TypeEnvType::iterator i = typeEnv.find( formal->get_name() );
    97                     if ( i != typeEnv.end() ) {
    98                         delete i->second;
    99                     }
    100                     typeEnv[ formal->get_name() ] = actual->get_type()->clone();
    101                 }
    102             } else {
    103                 throw SemanticError( "Attempt to provide non-type parameter for type parameter", formal );
    104             }
    105         } else {
    106             // TODO: type check the formal and actual parameters
    107             if ( (*formalIt)->get_name() != "" ) {
    108                 varEnv[ (*formalIt)->get_name() ] = (*actualIt)->clone();
    109             }
    110         }
    111     }
     89void TypeSubstitution::add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) {
     90        // FormalIterator points to a TypeDecl
     91        // ActualIterator points to a Type
     92        FormalIterator formalIt = formalBegin;
     93        ActualIterator actualIt = actualBegin;
     94        for ( ; formalIt != formalEnd; ++formalIt, ++actualIt ) {
     95                if ( TypeDecl *formal = dynamic_cast< TypeDecl* >( *formalIt ) ) {
     96                        if ( TypeExpr *actual = dynamic_cast< TypeExpr* >( *actualIt ) ) {
     97                                if ( formal->get_name() != "" ) {
     98                                        TypeEnvType::iterator i = typeEnv.find( formal->get_name() );
     99                                        if ( i != typeEnv.end() ) {
     100                                                delete i->second;
     101                                        } // if
     102                                        typeEnv[ formal->get_name() ] = actual->get_type()->clone();
     103                                } // if
     104                        } else {
     105                                throw SemanticError( "Attempt to provide non-type parameter for type parameter", formal );
     106                        } // if
     107                } else {
     108                        // TODO: type check the formal and actual parameters
     109                        if ( (*formalIt)->get_name() != "" ) {
     110                                varEnv[ (*formalIt)->get_name() ] = (*actualIt)->clone();
     111                        } // if
     112                } // if
     113        } // for
    112114}
    113115
     
    115117TypeSubstitution::TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin )
    116118{
    117     add( formalBegin, formalEnd, actualBegin );
     119        add( formalBegin, formalEnd, actualBegin );
    118120}
    119121
    120122template< typename SynTreeClass >
    121 int
    122 TypeSubstitution::apply( SynTreeClass *&input )
    123 {
    124     assert( input );
    125     subCount = 0;
    126     freeOnly = false;
    127     input = dynamic_cast< SynTreeClass *>( input->acceptMutator( *this ) );
    128     assert( input );
     123int TypeSubstitution::apply( SynTreeClass *&input ) {
     124        assert( input );
     125        subCount = 0;
     126        freeOnly = false;
     127        input = dynamic_cast< SynTreeClass *>( input->acceptMutator( *this ) );
     128        assert( input );
    129129///     std::cout << "substitution result is: ";
    130130///     newType->print( std::cout );
    131131///     std::cout << std::endl;
    132     return subCount;
     132        return subCount;
    133133}
    134    
     134       
    135135template< typename SynTreeClass >
    136 int
    137 TypeSubstitution::applyFree( SynTreeClass *&input )
    138 {
    139     assert( input );
    140     subCount = 0;
    141     freeOnly = true;
    142     input = dynamic_cast< SynTreeClass *>( input->acceptMutator( *this ) );
    143     assert( input );
     136int TypeSubstitution::applyFree( SynTreeClass *&input ) {
     137        assert( input );
     138        subCount = 0;
     139        freeOnly = true;
     140        input = dynamic_cast< SynTreeClass *>( input->acceptMutator( *this ) );
     141        assert( input );
    144142///     std::cout << "substitution result is: ";
    145143///     newType->print( std::cout );
    146144///     std::cout << std::endl;
    147     return subCount;
     145        return subCount;
    148146}
    149    
     147       
    150148template< typename TypeInstListIterator >
    151 void
    152 TypeSubstitution::extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result )
    153 {
    154     while ( begin != end ) {
    155         TypeEnvType::iterator cur = typeEnv.find( (*begin++)->get_name() );
    156         if ( cur != typeEnv.end() ) {
    157             result.typeEnv[ cur->first ] = cur->second;
    158             typeEnv.erase( cur );
    159         }
    160     }
     149void TypeSubstitution::extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result ) {
     150        while ( begin != end ) {
     151                TypeEnvType::iterator cur = typeEnv.find( (*begin++)->get_name() );
     152                if ( cur != typeEnv.end() ) {
     153                        result.typeEnv[ cur->first ] = cur->second;
     154                        typeEnv.erase( cur );
     155                } // if
     156        } // while
    161157}
    162158
    163159// helper function
    164160template< typename FormalIterator, typename ActualIterator, typename MemberIterator, typename OutputIterator >
    165 void
    166 applySubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actual, MemberIterator memberBegin, MemberIterator memberEnd, OutputIterator out )
    167 {
    168     // Instantiate each member of the context given the actual parameters specified, and store the
    169     // instantiations for use by the indexer
     161void applySubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actual, MemberIterator memberBegin, MemberIterator memberEnd, OutputIterator out ) {
     162        // Instantiate each member of the context given the actual parameters specified, and store the
     163        // instantiations for use by the indexer
    170164
    171     TypeSubstitution sub = TypeSubstitution( formalBegin, formalEnd, actual );
    172     for ( std::list< Declaration* >::iterator i = memberBegin; i != memberEnd; ++i ) {
    173         Declaration *newdecl = (*i)->clone();
    174         sub.apply( newdecl );
    175         *out++ = newdecl;
    176     }
     165        TypeSubstitution sub = TypeSubstitution( formalBegin, formalEnd, actual );
     166        for ( std::list< Declaration* >::iterator i = memberBegin; i != memberEnd; ++i ) {
     167                Declaration *newdecl = (*i)->clone();
     168                sub.apply( newdecl );
     169                *out++ = newdecl;
     170        } // for
    177171}
    178172
     173#endif // TYPESUBSTITUTION_H
    179174
    180 #endif /* #ifndef SYNTREE_TYPESUBSTITUTION_H */
     175// Local Variables: //
     176// tab-width: 4 //
     177// mode: c++ //
     178// compile-command: "make install" //
     179// End: //
  • translator/SynTree/TypeofType.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: TypeofType.cc,v 1.3 2005/08/29 20:59:27 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// TypeofType.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:13:29 2015
     13// Update Count     : 2
     14//
    715
    816#include "Type.h"
     
    1018#include "utility.h"
    1119
    12 
    13 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr )
    14     : Type( tq ), expr( expr )
    15 {
     20TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr ) : Type( tq ), expr( expr ) {
    1621}
    1722
    18 TypeofType::TypeofType( const TypeofType &other )
    19     : Type( other ), expr( maybeClone( other.expr ) )
    20 {
     23TypeofType::TypeofType( const TypeofType &other ) : Type( other ), expr( maybeClone( other.expr ) ) {
    2124}
    2225
    23 TypeofType::~TypeofType()
    24 {
    25     delete expr;
     26TypeofType::~TypeofType() {
     27        delete expr;
    2628}
    2729
    28 void
    29 TypeofType::print( std::ostream &os, int indent ) const
    30 {
    31     Type::print( os, indent );
    32     os << "type-of expression ";
    33     if ( expr ) {
    34         expr->print( os, indent );
    35     }
     30void TypeofType::print( std::ostream &os, int indent ) const {
     31        Type::print( os, indent );
     32        os << "type-of expression ";
     33        if ( expr ) {
     34                expr->print( os, indent );
     35        }
    3636}
    3737
     38// Local Variables: //
     39// tab-width: 4 //
     40// mode: c++ //
     41// compile-command: "make install" //
     42// End: //
  • translator/SynTree/Visitor.cc

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Visitor.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:14:51 2015
     13// Update Count     : 2
     14//
     15
    116#include <cassert>
    217#include "Visitor.h"
     
    823#include "Constant.h"
    924
    10 
    1125Visitor::Visitor() {}
    1226
    1327Visitor::~Visitor() {}
    1428
    15 void Visitor::visit(ObjectDecl *objectDecl) {
    16     maybeAccept( objectDecl->get_type(), *this );
    17     maybeAccept( objectDecl->get_init(), *this );
    18     maybeAccept( objectDecl->get_bitfieldWidth(), *this );
    19 }
    20 
    21 void Visitor::visit(FunctionDecl *functionDecl) {
    22     maybeAccept( functionDecl->get_functionType(), *this );
    23     acceptAll( functionDecl->get_oldDecls(), *this );
    24     maybeAccept( functionDecl->get_statements(), *this );
    25 }
    26 
    27 void Visitor::visit(AggregateDecl *aggregateDecl) {
    28     acceptAll( aggregateDecl->get_parameters(), *this );
    29     acceptAll( aggregateDecl->get_members(), *this );
    30 }
    31 
    32 void Visitor::visit(StructDecl *aggregateDecl) {
    33     visit( static_cast< AggregateDecl* >( aggregateDecl ) );
    34 }
    35 
    36 void Visitor::visit(UnionDecl *aggregateDecl) {
    37     visit( static_cast< AggregateDecl* >( aggregateDecl ) );
    38 }
    39 
    40 void Visitor::visit(EnumDecl *aggregateDecl) {
    41     visit( static_cast< AggregateDecl* >( aggregateDecl ) );
    42 }
    43 
    44 void Visitor::visit(ContextDecl *aggregateDecl) {
    45     visit( static_cast< AggregateDecl* >( aggregateDecl ) );
    46 }
    47 
    48 void Visitor::visit(NamedTypeDecl *typeDecl) {
    49     acceptAll( typeDecl->get_parameters(), *this );
    50     acceptAll( typeDecl->get_assertions(), *this );
    51     maybeAccept( typeDecl->get_base(), *this );
    52 }
    53 
    54 void Visitor::visit(TypeDecl *typeDecl) {
    55     visit( static_cast< NamedTypeDecl* >( typeDecl ) );
    56 }
    57 
    58 void Visitor::visit(TypedefDecl *typeDecl) {
    59     visit( static_cast< NamedTypeDecl* >( typeDecl ) );
    60 }
    61 
    62 void Visitor::visit(CompoundStmt *compoundStmt) {
    63     acceptAll( compoundStmt->get_kids(), *this );
    64 }
    65 
    66 void Visitor::visit(ExprStmt *exprStmt) {
    67     maybeAccept( exprStmt->get_expr(), *this );
    68 }
    69 
    70 void Visitor::visit(IfStmt *ifStmt) {
    71     maybeAccept( ifStmt->get_condition(), *this );
    72     maybeAccept( ifStmt->get_thenPart(), *this );
    73     maybeAccept( ifStmt->get_elsePart(), *this );
    74 }
    75 
    76 void Visitor::visit(WhileStmt *whileStmt) {
    77     maybeAccept( whileStmt->get_condition(), *this );
    78     maybeAccept( whileStmt->get_body(), *this );
    79 }
    80 
    81 void Visitor::visit(ForStmt *forStmt) {
    82     // ForStmt still needs to be fixed
    83     maybeAccept( forStmt->get_initialization(), *this );
    84     maybeAccept( forStmt->get_condition(), *this );
    85     maybeAccept( forStmt->get_increment(), *this );
    86     maybeAccept( forStmt->get_body(), *this );
    87 }
    88 
    89 void Visitor::visit(SwitchStmt *switchStmt) {
    90     maybeAccept( switchStmt->get_condition(), *this );
    91     acceptAll( switchStmt->get_branches(), *this );
    92 }
    93 
    94 void Visitor::visit(ChooseStmt *switchStmt) {
    95     maybeAccept( switchStmt->get_condition(), *this );
    96     acceptAll( switchStmt->get_branches(), *this );
    97 }
    98 
    99 void Visitor::visit(FallthruStmt *fallthruStmt){}
    100 
    101 void Visitor::visit(CaseStmt *caseStmt) {
    102     maybeAccept( caseStmt->get_condition(), *this );
    103     acceptAll( caseStmt->get_statements(), *this );
    104 }
    105 
    106 void Visitor::visit(BranchStmt *branchStmt) {
    107 }
    108 
    109 void Visitor::visit(ReturnStmt *returnStmt) {
    110     maybeAccept( returnStmt->get_expr(), *this );
    111 }
    112 
    113 void Visitor::visit(TryStmt *tryStmt) {
    114     maybeAccept( tryStmt->get_block(), *this );
    115     acceptAll( tryStmt->get_catchers(), *this );
    116 }
    117 
    118 void Visitor::visit(CatchStmt *catchStmt) {
    119     maybeAccept( catchStmt->get_decl(), *this );
    120     maybeAccept( catchStmt->get_body(), *this );
    121 }
    122 
    123 void Visitor::visit(FinallyStmt *finalStmt) {
    124     maybeAccept( finalStmt->get_block(), *this );
    125 }
    126 
    127 void Visitor::visit(NullStmt *nullStmt) {
    128 }
    129 
    130 void Visitor::visit(DeclStmt *declStmt) {
    131     maybeAccept( declStmt->get_decl(), *this );
    132 }
    133 
    134 void Visitor::visit(ApplicationExpr *applicationExpr) {
    135     acceptAll( applicationExpr->get_results(), *this );
    136     maybeAccept( applicationExpr->get_function(), *this );
    137     acceptAll( applicationExpr->get_args(), *this );
    138 }
    139 
    140 void Visitor::visit(UntypedExpr *untypedExpr) {
    141     acceptAll( untypedExpr->get_results(), *this );
    142     acceptAll( untypedExpr->get_args(), *this );
    143 }
    144 
    145 void Visitor::visit(NameExpr *nameExpr) {
    146     acceptAll( nameExpr->get_results(), *this );
    147 }
    148 
    149 void Visitor::visit(AddressExpr *addressExpr) {
    150     acceptAll( addressExpr->get_results(), *this );
    151     maybeAccept( addressExpr->get_arg(), *this );
    152 }
    153 
    154 void Visitor::visit(LabelAddressExpr *labAddressExpr) {
    155     acceptAll( labAddressExpr->get_results(), *this );
    156     maybeAccept( labAddressExpr->get_arg(), *this );
    157 }
    158 
    159 void Visitor::visit(CastExpr *castExpr) {
    160     acceptAll( castExpr->get_results(), *this );
    161     maybeAccept( castExpr->get_arg(), *this );
    162 }
    163 
    164 void Visitor::visit(UntypedMemberExpr *memberExpr) {
    165     acceptAll( memberExpr->get_results(), *this );
    166     maybeAccept( memberExpr->get_aggregate(), *this );
    167 }
    168 
    169 void Visitor::visit(MemberExpr *memberExpr) {
    170     acceptAll( memberExpr->get_results(), *this );
    171     maybeAccept( memberExpr->get_aggregate(), *this );
    172 }
    173 
    174 void Visitor::visit(VariableExpr *variableExpr) {
    175     acceptAll( variableExpr->get_results(), *this );
    176 }
    177 
    178 void Visitor::visit(ConstantExpr *constantExpr) {
    179     acceptAll( constantExpr->get_results(), *this );
    180     maybeAccept( constantExpr->get_constant(), *this );
    181 }
    182 
    183 void Visitor::visit(SizeofExpr *sizeofExpr) {
    184     acceptAll( sizeofExpr->get_results(), *this );
    185     if ( sizeofExpr->get_isType() ) {
    186         maybeAccept( sizeofExpr->get_type(), *this );
    187     } else {
    188         maybeAccept( sizeofExpr->get_expr(), *this );
    189     }
    190 }
    191 
    192 void Visitor::visit(AttrExpr *attrExpr) {
    193     acceptAll( attrExpr->get_results(), *this );
    194     if ( attrExpr->get_isType() ) {
    195         maybeAccept( attrExpr->get_type(), *this );
    196     } else {
    197         maybeAccept( attrExpr->get_expr(), *this );
    198     }
    199 }
    200 
    201 void Visitor::visit(LogicalExpr *logicalExpr) {
    202     acceptAll( logicalExpr->get_results(), *this );
    203     maybeAccept( logicalExpr->get_arg1(), *this );
    204     maybeAccept( logicalExpr->get_arg2(), *this );
    205 }
    206 
    207 void Visitor::visit(ConditionalExpr *conditionalExpr) {
    208     acceptAll( conditionalExpr->get_results(), *this );
    209     maybeAccept( conditionalExpr->get_arg1(), *this );
    210     maybeAccept( conditionalExpr->get_arg2(), *this );
    211     maybeAccept( conditionalExpr->get_arg3(), *this );
    212 }
    213 
    214 void Visitor::visit(CommaExpr *commaExpr) {
    215     acceptAll( commaExpr->get_results(), *this );
    216     maybeAccept( commaExpr->get_arg1(), *this );
    217     maybeAccept( commaExpr->get_arg2(), *this );
    218 }
    219 
    220 void Visitor::visit(TupleExpr *tupleExpr) {
    221     acceptAll( tupleExpr->get_results(), *this );
    222     acceptAll( tupleExpr->get_exprs(), *this );
    223 }
    224 
    225 void Visitor::visit(SolvedTupleExpr *tupleExpr) {
    226     acceptAll( tupleExpr->get_results(), *this );
    227     acceptAll( tupleExpr->get_exprs(), *this );
    228 }
    229 
    230 void Visitor::visit(TypeExpr *typeExpr) {
    231     acceptAll( typeExpr->get_results(), *this );
    232     maybeAccept( typeExpr->get_type(), *this );
    233 }
    234 
    235 void Visitor::visit(UntypedValofExpr *valofExpr) {
    236     acceptAll( valofExpr->get_results(), *this );
    237     maybeAccept( valofExpr->get_body(), *this );
    238 }
    239 
    240 void Visitor::visit(VoidType *voidType) {
    241     acceptAll( voidType->get_forall(), *this );
    242 }
    243 
    244 void Visitor::visit(BasicType *basicType) {
    245     acceptAll( basicType->get_forall(), *this );
    246 }
    247 
    248 void Visitor::visit(PointerType *pointerType) {
    249     acceptAll( pointerType->get_forall(), *this );
    250     maybeAccept( pointerType->get_base(), *this );
    251 }
    252 
    253 void Visitor::visit(ArrayType *arrayType) {
    254     acceptAll( arrayType->get_forall(), *this );
    255     maybeAccept( arrayType->get_dimension(), *this );
    256     maybeAccept( arrayType->get_base(), *this );
    257 }
    258 
    259 void Visitor::visit(FunctionType *functionType) {
    260     acceptAll( functionType->get_forall(), *this );
    261     acceptAll( functionType->get_returnVals(), *this );
    262     acceptAll( functionType->get_parameters(), *this );
    263 }
    264 
    265 void Visitor::visit(ReferenceToType *aggregateUseType) {
    266     acceptAll( aggregateUseType->get_forall(), *this );
    267     acceptAll( aggregateUseType->get_parameters(), *this );
    268 }
    269 
    270 void Visitor::visit(StructInstType *aggregateUseType) {
    271     visit( static_cast< ReferenceToType* >( aggregateUseType ) );
    272 }
    273 
    274 void Visitor::visit(UnionInstType *aggregateUseType) {
    275     visit( static_cast< ReferenceToType* >( aggregateUseType ) );
    276 }
    277 
    278 void Visitor::visit(EnumInstType *aggregateUseType) {
    279     visit( static_cast< ReferenceToType* >( aggregateUseType ) );
    280 }
    281 
    282 void Visitor::visit(ContextInstType *aggregateUseType) {
    283     visit( static_cast< ReferenceToType* >( aggregateUseType ) );
    284     acceptAll( aggregateUseType->get_members(), *this );
    285 }
    286 
    287 void Visitor::visit(TypeInstType *aggregateUseType) {
    288     visit( static_cast< ReferenceToType* >( aggregateUseType ) );
    289 }
    290 
    291 void Visitor::visit(TupleType *tupleType) {
    292     acceptAll( tupleType->get_forall(), *this );
    293     acceptAll( tupleType->get_types(), *this );
    294 }
    295 
    296 void Visitor::visit(TypeofType *typeofType) {
    297     assert( typeofType->get_expr() );
    298     typeofType->get_expr()->accept( *this );
    299 }
    300 
    301 void Visitor::visit(AttrType *attrType) {
    302     if ( attrType->get_isType() ) {
    303         assert( attrType->get_type() );
    304         attrType->get_type()->accept( *this );
    305     } else {
    306         assert( attrType->get_expr() );
    307         attrType->get_expr()->accept( *this );
    308     }
    309 }
    310 
    311 void Visitor::visit(SingleInit *singleInit) {
    312     singleInit->get_value()->accept( *this );
    313 }
    314 
    315 void Visitor::visit(ListInit *listInit) {
    316     acceptAll( listInit->get_designators(), *this );
    317     acceptAll( listInit->get_initializers(), *this );
    318 }
    319 
    320 void Visitor::visit(Subrange *subrange) {}
    321 
    322 void Visitor::visit(Constant *constant) {}
     29void Visitor::visit( ObjectDecl *objectDecl ) {
     30        maybeAccept( objectDecl->get_type(), *this );
     31        maybeAccept( objectDecl->get_init(), *this );
     32        maybeAccept( objectDecl->get_bitfieldWidth(), *this );
     33}
     34
     35void Visitor::visit( FunctionDecl *functionDecl ) {
     36        maybeAccept( functionDecl->get_functionType(), *this );
     37        acceptAll( functionDecl->get_oldDecls(), *this );
     38        maybeAccept( functionDecl->get_statements(), *this );
     39}
     40
     41void Visitor::visit( AggregateDecl *aggregateDecl ) {
     42        acceptAll( aggregateDecl->get_parameters(), *this );
     43        acceptAll( aggregateDecl->get_members(), *this );
     44}
     45
     46void Visitor::visit( StructDecl *aggregateDecl ) {
     47        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
     48}
     49
     50void Visitor::visit( UnionDecl *aggregateDecl ) {
     51        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
     52}
     53
     54void Visitor::visit( EnumDecl *aggregateDecl ) {
     55        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
     56}
     57
     58void Visitor::visit( ContextDecl *aggregateDecl ) {
     59        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
     60}
     61
     62void Visitor::visit( NamedTypeDecl *typeDecl ) {
     63        acceptAll( typeDecl->get_parameters(), *this );
     64        acceptAll( typeDecl->get_assertions(), *this );
     65        maybeAccept( typeDecl->get_base(), *this );
     66}
     67
     68void Visitor::visit( TypeDecl *typeDecl ) {
     69        visit( static_cast< NamedTypeDecl* >( typeDecl ) );
     70}
     71
     72void Visitor::visit( TypedefDecl *typeDecl ) {
     73        visit( static_cast< NamedTypeDecl* >( typeDecl ) );
     74}
     75
     76void Visitor::visit( CompoundStmt *compoundStmt ) {
     77        acceptAll( compoundStmt->get_kids(), *this );
     78}
     79
     80void Visitor::visit( ExprStmt *exprStmt ) {
     81        maybeAccept( exprStmt->get_expr(), *this );
     82}
     83
     84void Visitor::visit( IfStmt *ifStmt ) {
     85        maybeAccept( ifStmt->get_condition(), *this );
     86        maybeAccept( ifStmt->get_thenPart(), *this );
     87        maybeAccept( ifStmt->get_elsePart(), *this );
     88}
     89
     90void Visitor::visit( WhileStmt *whileStmt ) {
     91        maybeAccept( whileStmt->get_condition(), *this );
     92        maybeAccept( whileStmt->get_body(), *this );
     93}
     94
     95void Visitor::visit( ForStmt *forStmt ) {
     96        // ForStmt still needs to be fixed
     97        maybeAccept( forStmt->get_initialization(), *this );
     98        maybeAccept( forStmt->get_condition(), *this );
     99        maybeAccept( forStmt->get_increment(), *this );
     100        maybeAccept( forStmt->get_body(), *this );
     101}
     102
     103void Visitor::visit( SwitchStmt *switchStmt ) {
     104        maybeAccept( switchStmt->get_condition(), *this );
     105        acceptAll( switchStmt->get_branches(), *this );
     106}
     107
     108void Visitor::visit( ChooseStmt *switchStmt ) {
     109        maybeAccept( switchStmt->get_condition(), *this );
     110        acceptAll( switchStmt->get_branches(), *this );
     111}
     112
     113void Visitor::visit( FallthruStmt *fallthruStmt ){}
     114
     115void Visitor::visit( CaseStmt *caseStmt ) {
     116        maybeAccept( caseStmt->get_condition(), *this );
     117        acceptAll( caseStmt->get_statements(), *this );
     118}
     119
     120void Visitor::visit( BranchStmt *branchStmt ) {
     121}
     122
     123void Visitor::visit( ReturnStmt *returnStmt ) {
     124        maybeAccept( returnStmt->get_expr(), *this );
     125}
     126
     127void Visitor::visit( TryStmt *tryStmt ) {
     128        maybeAccept( tryStmt->get_block(), *this );
     129        acceptAll( tryStmt->get_catchers(), *this );
     130}
     131
     132void Visitor::visit( CatchStmt *catchStmt ) {
     133        maybeAccept( catchStmt->get_decl(), *this );
     134        maybeAccept( catchStmt->get_body(), *this );
     135}
     136
     137void Visitor::visit( FinallyStmt *finalStmt ) {
     138        maybeAccept( finalStmt->get_block(), *this );
     139}
     140
     141void Visitor::visit( NullStmt *nullStmt ) {
     142}
     143
     144void Visitor::visit( DeclStmt *declStmt ) {
     145        maybeAccept( declStmt->get_decl(), *this );
     146}
     147
     148void Visitor::visit( ApplicationExpr *applicationExpr ) {
     149        acceptAll( applicationExpr->get_results(), *this );
     150        maybeAccept( applicationExpr->get_function(), *this );
     151        acceptAll( applicationExpr->get_args(), *this );
     152}
     153
     154void Visitor::visit( UntypedExpr *untypedExpr ) {
     155        acceptAll( untypedExpr->get_results(), *this );
     156        acceptAll( untypedExpr->get_args(), *this );
     157}
     158
     159void Visitor::visit( NameExpr *nameExpr ) {
     160        acceptAll( nameExpr->get_results(), *this );
     161}
     162
     163void Visitor::visit( AddressExpr *addressExpr ) {
     164        acceptAll( addressExpr->get_results(), *this );
     165        maybeAccept( addressExpr->get_arg(), *this );
     166}
     167
     168void Visitor::visit( LabelAddressExpr *labAddressExpr ) {
     169        acceptAll( labAddressExpr->get_results(), *this );
     170        maybeAccept( labAddressExpr->get_arg(), *this );
     171}
     172
     173void Visitor::visit( CastExpr *castExpr ) {
     174        acceptAll( castExpr->get_results(), *this );
     175        maybeAccept( castExpr->get_arg(), *this );
     176}
     177
     178void Visitor::visit( UntypedMemberExpr *memberExpr ) {
     179        acceptAll( memberExpr->get_results(), *this );
     180        maybeAccept( memberExpr->get_aggregate(), *this );
     181}
     182
     183void Visitor::visit( MemberExpr *memberExpr ) {
     184        acceptAll( memberExpr->get_results(), *this );
     185        maybeAccept( memberExpr->get_aggregate(), *this );
     186}
     187
     188void Visitor::visit( VariableExpr *variableExpr ) {
     189        acceptAll( variableExpr->get_results(), *this );
     190}
     191
     192void Visitor::visit( ConstantExpr *constantExpr ) {
     193        acceptAll( constantExpr->get_results(), *this );
     194        maybeAccept( constantExpr->get_constant(), *this );
     195}
     196
     197void Visitor::visit( SizeofExpr *sizeofExpr ) {
     198        acceptAll( sizeofExpr->get_results(), *this );
     199        if ( sizeofExpr->get_isType() ) {
     200                maybeAccept( sizeofExpr->get_type(), *this );
     201        } else {
     202                maybeAccept( sizeofExpr->get_expr(), *this );
     203        }
     204}
     205
     206void Visitor::visit( AttrExpr *attrExpr ) {
     207        acceptAll( attrExpr->get_results(), *this );
     208        if ( attrExpr->get_isType() ) {
     209                maybeAccept( attrExpr->get_type(), *this );
     210        } else {
     211                maybeAccept( attrExpr->get_expr(), *this );
     212        }
     213}
     214
     215void Visitor::visit( LogicalExpr *logicalExpr ) {
     216        acceptAll( logicalExpr->get_results(), *this );
     217        maybeAccept( logicalExpr->get_arg1(), *this );
     218        maybeAccept( logicalExpr->get_arg2(), *this );
     219}
     220
     221void Visitor::visit( ConditionalExpr *conditionalExpr ) {
     222        acceptAll( conditionalExpr->get_results(), *this );
     223        maybeAccept( conditionalExpr->get_arg1(), *this );
     224        maybeAccept( conditionalExpr->get_arg2(), *this );
     225        maybeAccept( conditionalExpr->get_arg3(), *this );
     226}
     227
     228void Visitor::visit( CommaExpr *commaExpr ) {
     229        acceptAll( commaExpr->get_results(), *this );
     230        maybeAccept( commaExpr->get_arg1(), *this );
     231        maybeAccept( commaExpr->get_arg2(), *this );
     232}
     233
     234void Visitor::visit( TupleExpr *tupleExpr ) {
     235        acceptAll( tupleExpr->get_results(), *this );
     236        acceptAll( tupleExpr->get_exprs(), *this );
     237}
     238
     239void Visitor::visit( SolvedTupleExpr *tupleExpr ) {
     240        acceptAll( tupleExpr->get_results(), *this );
     241        acceptAll( tupleExpr->get_exprs(), *this );
     242}
     243
     244void Visitor::visit( TypeExpr *typeExpr ) {
     245        acceptAll( typeExpr->get_results(), *this );
     246        maybeAccept( typeExpr->get_type(), *this );
     247}
     248
     249void Visitor::visit( UntypedValofExpr *valofExpr ) {
     250        acceptAll( valofExpr->get_results(), *this );
     251        maybeAccept( valofExpr->get_body(), *this );
     252}
     253
     254void Visitor::visit( VoidType *voidType ) {
     255        acceptAll( voidType->get_forall(), *this );
     256}
     257
     258void Visitor::visit( BasicType *basicType ) {
     259        acceptAll( basicType->get_forall(), *this );
     260}
     261
     262void Visitor::visit( PointerType *pointerType ) {
     263        acceptAll( pointerType->get_forall(), *this );
     264        maybeAccept( pointerType->get_base(), *this );
     265}
     266
     267void Visitor::visit( ArrayType *arrayType ) {
     268        acceptAll( arrayType->get_forall(), *this );
     269        maybeAccept( arrayType->get_dimension(), *this );
     270        maybeAccept( arrayType->get_base(), *this );
     271}
     272
     273void Visitor::visit( FunctionType *functionType ) {
     274        acceptAll( functionType->get_forall(), *this );
     275        acceptAll( functionType->get_returnVals(), *this );
     276        acceptAll( functionType->get_parameters(), *this );
     277}
     278
     279void Visitor::visit( ReferenceToType *aggregateUseType ) {
     280        acceptAll( aggregateUseType->get_forall(), *this );
     281        acceptAll( aggregateUseType->get_parameters(), *this );
     282}
     283
     284void Visitor::visit( StructInstType *aggregateUseType ) {
     285        visit( static_cast< ReferenceToType* >( aggregateUseType ) );
     286}
     287
     288void Visitor::visit( UnionInstType *aggregateUseType ) {
     289        visit( static_cast< ReferenceToType* >( aggregateUseType ) );
     290}
     291
     292void Visitor::visit( EnumInstType *aggregateUseType ) {
     293        visit( static_cast< ReferenceToType* >( aggregateUseType ) );
     294}
     295
     296void Visitor::visit( ContextInstType *aggregateUseType ) {
     297        visit( static_cast< ReferenceToType* >( aggregateUseType ) );
     298        acceptAll( aggregateUseType->get_members(), *this );
     299}
     300
     301void Visitor::visit( TypeInstType *aggregateUseType ) {
     302        visit( static_cast< ReferenceToType* >( aggregateUseType ) );
     303}
     304
     305void Visitor::visit( TupleType *tupleType ) {
     306        acceptAll( tupleType->get_forall(), *this );
     307        acceptAll( tupleType->get_types(), *this );
     308}
     309
     310void Visitor::visit( TypeofType *typeofType ) {
     311        assert( typeofType->get_expr() );
     312        typeofType->get_expr()->accept( *this );
     313}
     314
     315void Visitor::visit( AttrType *attrType ) {
     316        if ( attrType->get_isType() ) {
     317                assert( attrType->get_type() );
     318                attrType->get_type()->accept( *this );
     319        } else {
     320                assert( attrType->get_expr() );
     321                attrType->get_expr()->accept( *this );
     322        } // if
     323}
     324
     325void Visitor::visit( SingleInit *singleInit ) {
     326        singleInit->get_value()->accept( *this );
     327}
     328
     329void Visitor::visit( ListInit *listInit ) {
     330        acceptAll( listInit->get_designators(), *this );
     331        acceptAll( listInit->get_initializers(), *this );
     332}
     333
     334void Visitor::visit( Subrange *subrange ) {}
     335
     336void Visitor::visit( Constant *constant ) {}
     337// Local Variables: //
     338// tab-width: 4 //
     339// mode: c++ //
     340// compile-command: "make install" //
     341// End: //
  • translator/SynTree/Visitor.h

    ra32b204 r0dd3a2f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Visitor.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:15:55 2015
     13// Update Count     : 2
     14//
     15
    116#ifndef VISITOR_H
    217#define VISITOR_H
     
    621#include "CompilerError.h"
    722
    8 
    923class Visitor {
    1024  protected:
    11     Visitor();
    12     virtual ~Visitor();
     25        Visitor();
     26        virtual ~Visitor();
    1327  public:
    14     virtual void visit( ObjectDecl *objectDecl );
    15     virtual void visit( FunctionDecl *functionDecl );
    16     virtual void visit( StructDecl *aggregateDecl );
    17     virtual void visit( UnionDecl *aggregateDecl );
    18     virtual void visit( EnumDecl *aggregateDecl );
    19     virtual void visit( ContextDecl *aggregateDecl );
    20     virtual void visit( TypeDecl *typeDecl );
    21     virtual void visit( TypedefDecl *typeDecl );
     28        virtual void visit( ObjectDecl *objectDecl );
     29        virtual void visit( FunctionDecl *functionDecl );
     30        virtual void visit( StructDecl *aggregateDecl );
     31        virtual void visit( UnionDecl *aggregateDecl );
     32        virtual void visit( EnumDecl *aggregateDecl );
     33        virtual void visit( ContextDecl *aggregateDecl );
     34        virtual void visit( TypeDecl *typeDecl );
     35        virtual void visit( TypedefDecl *typeDecl );
    2236
    23     virtual void visit( CompoundStmt *compoundStmt );
    24     virtual void visit( ExprStmt *exprStmt );
    25     virtual void visit( IfStmt *ifStmt );
    26     virtual void visit( WhileStmt *whileStmt );
    27     virtual void visit( ForStmt *forStmt );
    28     virtual void visit( SwitchStmt *switchStmt );
    29     virtual void visit( ChooseStmt *switchStmt );
    30     virtual void visit( FallthruStmt *switchStmt );
    31     virtual void visit( CaseStmt *caseStmt );
    32     virtual void visit( BranchStmt *branchStmt );
    33     virtual void visit( ReturnStmt *returnStmt );
    34     virtual void visit( TryStmt *tryStmt );
    35     virtual void visit( CatchStmt *catchStmt );
    36     virtual void visit( FinallyStmt *finallyStmt );
    37     virtual void visit( NullStmt *nullStmt );
    38     virtual void visit( DeclStmt *declStmt );
     37        virtual void visit( CompoundStmt *compoundStmt );
     38        virtual void visit( ExprStmt *exprStmt );
     39        virtual void visit( IfStmt *ifStmt );
     40        virtual void visit( WhileStmt *whileStmt );
     41        virtual void visit( ForStmt *forStmt );
     42        virtual void visit( SwitchStmt *switchStmt );
     43        virtual void visit( ChooseStmt *switchStmt );
     44        virtual void visit( FallthruStmt *switchStmt );
     45        virtual void visit( CaseStmt *caseStmt );
     46        virtual void visit( BranchStmt *branchStmt );
     47        virtual void visit( ReturnStmt *returnStmt );
     48        virtual void visit( TryStmt *tryStmt );
     49        virtual void visit( CatchStmt *catchStmt );
     50        virtual void visit( FinallyStmt *finallyStmt );
     51        virtual void visit( NullStmt *nullStmt );
     52        virtual void visit( DeclStmt *declStmt );
    3953
    40     virtual void visit( ApplicationExpr *applicationExpr );
    41     virtual void visit( UntypedExpr *untypedExpr );
    42     virtual void visit( NameExpr *nameExpr );
    43     virtual void visit( CastExpr *castExpr );
    44     virtual void visit( AddressExpr *addressExpr );
    45     virtual void visit( LabelAddressExpr *labAddressExpr );
    46     virtual void visit( UntypedMemberExpr *memberExpr );
    47     virtual void visit( MemberExpr *memberExpr );
    48     virtual void visit( VariableExpr *variableExpr );
    49     virtual void visit( ConstantExpr *constantExpr );
    50     virtual void visit( SizeofExpr *sizeofExpr );
    51     virtual void visit( AttrExpr *attrExpr );
    52     virtual void visit( LogicalExpr *logicalExpr );
    53     virtual void visit( ConditionalExpr *conditionalExpr );
    54     virtual void visit( CommaExpr *commaExpr );
    55     virtual void visit( TupleExpr *tupleExpr );
    56     virtual void visit( SolvedTupleExpr *tupleExpr );
    57     virtual void visit( TypeExpr *typeExpr );
    58     virtual void visit( UntypedValofExpr *valofExpr );
     54        virtual void visit( ApplicationExpr *applicationExpr );
     55        virtual void visit( UntypedExpr *untypedExpr );
     56        virtual void visit( NameExpr *nameExpr );
     57        virtual void visit( CastExpr *castExpr );
     58        virtual void visit( AddressExpr *addressExpr );
     59        virtual void visit( LabelAddressExpr *labAddressExpr );
     60        virtual void visit( UntypedMemberExpr *memberExpr );
     61        virtual void visit( MemberExpr *memberExpr );
     62        virtual void visit( VariableExpr *variableExpr );
     63        virtual void visit( ConstantExpr *constantExpr );
     64        virtual void visit( SizeofExpr *sizeofExpr );
     65        virtual void visit( AttrExpr *attrExpr );
     66        virtual void visit( LogicalExpr *logicalExpr );
     67        virtual void visit( ConditionalExpr *conditionalExpr );
     68        virtual void visit( CommaExpr *commaExpr );
     69        virtual void visit( TupleExpr *tupleExpr );
     70        virtual void visit( SolvedTupleExpr *tupleExpr );
     71        virtual void visit( TypeExpr *typeExpr );
     72        virtual void visit( UntypedValofExpr *valofExpr );
    5973
    60     virtual void visit( VoidType *basicType );
    61     virtual void visit( BasicType *basicType );
    62     virtual void visit( PointerType *pointerType );
    63     virtual void visit( ArrayType *arrayType );
    64     virtual void visit( FunctionType *functionType );
    65     virtual void visit( StructInstType *aggregateUseType );
    66     virtual void visit( UnionInstType *aggregateUseType );
    67     virtual void visit( EnumInstType *aggregateUseType );
    68     virtual void visit( ContextInstType *aggregateUseType );
    69     virtual void visit( TypeInstType *aggregateUseType );
    70     virtual void visit( TupleType *tupleType );
    71     virtual void visit( TypeofType *typeofType );
    72     virtual void visit( AttrType *attrType );
     74        virtual void visit( VoidType *basicType );
     75        virtual void visit( BasicType *basicType );
     76        virtual void visit( PointerType *pointerType );
     77        virtual void visit( ArrayType *arrayType );
     78        virtual void visit( FunctionType *functionType );
     79        virtual void visit( StructInstType *aggregateUseType );
     80        virtual void visit( UnionInstType *aggregateUseType );
     81        virtual void visit( EnumInstType *aggregateUseType );
     82        virtual void visit( ContextInstType *aggregateUseType );
     83        virtual void visit( TypeInstType *aggregateUseType );
     84        virtual void visit( TupleType *tupleType );
     85        virtual void visit( TypeofType *typeofType );
     86        virtual void visit( AttrType *attrType );
    7387
    74     virtual void visit( SingleInit *singleInit );
    75     virtual void visit( ListInit *listInit );
     88        virtual void visit( SingleInit *singleInit );
     89        virtual void visit( ListInit *listInit );
    7690
    77     virtual void visit( Subrange *subrange );
     91        virtual void visit( Subrange *subrange );
    7892
    79     virtual void visit( Constant *constant );
     93        virtual void visit( Constant *constant );
    8094  private:
    81     virtual void visit( AggregateDecl *aggregateDecl );
    82     virtual void visit( NamedTypeDecl *typeDecl );
    83     virtual void visit( ReferenceToType *aggregateUseType );
     95        virtual void visit( AggregateDecl *aggregateDecl );
     96        virtual void visit( NamedTypeDecl *typeDecl );
     97        virtual void visit( ReferenceToType *aggregateUseType );
    8498};
    8599
    86100template< typename TreeType, typename VisitorType >
    87101inline void maybeAccept( TreeType *tree, VisitorType &visitor ) {
    88     if ( tree ) {
    89         tree->accept( visitor );
    90     }
     102        if ( tree ) {
     103                tree->accept( visitor );
     104        }
    91105}
    92106
    93107template< typename Container, typename VisitorType >
    94108inline void acceptAll( Container &container, VisitorType &visitor ) {
    95     SemanticError errors;
    96     for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    97         try {
    98             if ( *i ) {
    99                 (*i)->accept( visitor );
    100             }
    101         } catch( SemanticError &e ) {
    102             errors.append( e );
     109        SemanticError errors;
     110        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
     111                try {
     112                        if ( *i ) {
     113                                (*i)->accept( visitor );
     114                        }
     115                } catch( SemanticError &e ) {
     116                        errors.append( e );
     117                }
    103118        }
    104     }
    105     if ( ! errors.isEmpty() ) {
    106         throw errors;
    107     }
     119        if ( ! errors.isEmpty() ) {
     120                throw errors;
     121        }
    108122}
    109123
    110124template< typename Container, typename VisitorType >
    111125void acceptAllFold( Container &container, VisitorType &visitor, VisitorType &around ) {
    112     SemanticError errors;
    113     for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    114         try {
    115             if ( *i ) {
    116                 VisitorType *v = new VisitorType;
    117                 (*i)->accept( *v );
     126        SemanticError errors;
     127        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
     128                try {
     129                        if ( *i ) {
     130                                VisitorType *v = new VisitorType;
     131                                (*i)->accept( *v );
    118132
    119                 typename Container::iterator nxt = i; nxt++; // forward_iterator
    120                 if ( nxt == container.end() )
    121                     visitor += *v;
    122                 else
    123                     visitor += *v + around;
     133                                typename Container::iterator nxt = i; nxt++; // forward_iterator
     134                                if ( nxt == container.end() )
     135                                        visitor += *v;
     136                                else
     137                                        visitor += *v + around;
    124138
    125                 delete v;
    126             }
    127         } catch( SemanticError &e ) {
    128             errors.append( e );
    129         }
    130     }
    131     if ( ! errors.isEmpty() ) {
    132         throw errors;
    133     }
     139                                delete v;
     140                        } // if
     141                } catch( SemanticError &e ) {
     142                        errors.append( e );
     143                } // try
     144        } // for
     145        if ( ! errors.isEmpty() ) {
     146                throw errors;
     147        } // if
    134148}
    135149
    136150#endif // VISITOR_H
     151
     152// Local Variables: //
     153// tab-width: 4 //
     154// mode: c++ //
     155// compile-command: "make install" //
     156// End: //
  • translator/SynTree/VoidType.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: VoidType.cc,v 1.3 2005/08/29 20:59:27 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// VoidType.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:16:42 2015
     13// Update Count     : 1
     14//
    715
    816#include "Type.h"
    917
    10 
    11 VoidType::VoidType( const Type::Qualifiers &tq )
    12     : Type( tq )
    13 {
     18VoidType::VoidType( const Type::Qualifiers &tq ) : Type( tq ) {
    1419}
    1520
    16 void
    17 VoidType::print( std::ostream &os, int indent ) const
    18 {
    19     Type::print( os, indent );
    20     os << "void ";
     21void VoidType::print( std::ostream &os, int indent ) const {
     22        Type::print( os, indent );
     23        os << "void ";
    2124}
    2225
     26// Local Variables: //
     27// tab-width: 4 //
     28// mode: c++ //
     29// compile-command: "make install" //
     30// End: //
Note: See TracChangeset for help on using the changeset viewer.