Changes in / [7821d6c:e1ff775]
- Location:
- src
- Files:
-
- 2 deleted
- 61 edited
-
CodeGen/CodeGenerator.cc (modified) (1 diff)
-
Common/Indenter.h (modified) (2 diffs)
-
Common/utility.h (modified) (4 diffs)
-
GenPoly/Box.cc (modified) (9 diffs)
-
GenPoly/FindFunction.cc (modified) (6 diffs)
-
GenPoly/Specialize.cc (modified) (1 diff)
-
InitTweak/FixInit.cc (modified) (3 diffs)
-
Parser/ExpressionNode.cc (modified) (3 diffs)
-
ResolvExpr/AdjustExprType.cc (modified) (5 diffs)
-
ResolvExpr/Alternative.cc (modified) (1 diff)
-
ResolvExpr/Alternative.h (modified) (1 diff)
-
ResolvExpr/AlternativeFinder.cc (modified) (5 diffs)
-
ResolvExpr/ResolveTypeof.cc (modified) (3 diffs)
-
ResolvExpr/TypeEnvironment.cc (modified) (2 diffs)
-
ResolvExpr/TypeEnvironment.h (modified) (2 diffs)
-
ResolvExpr/Unify.cc (modified) (4 diffs)
-
SymTab/FixFunction.cc (modified) (2 diffs)
-
SymTab/FixFunction.h (modified) (1 diff)
-
SymTab/Validate.cc (modified) (3 diffs)
-
SynTree/AddressExpr.cc (modified) (4 diffs)
-
SynTree/AggregateDecl.cc (modified) (1 diff)
-
SynTree/ApplicationExpr.cc (modified) (2 diffs)
-
SynTree/ArrayType.cc (modified) (1 diff)
-
SynTree/AttrType.cc (modified) (2 diffs)
-
SynTree/Attribute.cc (modified) (2 diffs)
-
SynTree/Attribute.h (modified) (1 diff)
-
SynTree/BaseSyntaxNode.h (modified) (2 diffs)
-
SynTree/BasicType.cc (modified) (2 diffs)
-
SynTree/CommaExpr.cc (modified) (2 diffs)
-
SynTree/CompoundStmt.cc (modified) (1 diff)
-
SynTree/DeclStmt.cc (modified) (1 diff)
-
SynTree/Declaration.cc (modified) (1 diff)
-
SynTree/Declaration.h (modified) (7 diffs)
-
SynTree/Expression.cc (modified) (30 diffs)
-
SynTree/Expression.h (modified) (58 diffs)
-
SynTree/FunctionDecl.cc (modified) (2 diffs)
-
SynTree/FunctionType.cc (modified) (2 diffs)
-
SynTree/Initializer.cc (modified) (4 diffs)
-
SynTree/Initializer.h (modified) (5 diffs)
-
SynTree/NamedTypeDecl.cc (modified) (2 diffs)
-
SynTree/ObjectDecl.cc (modified) (3 diffs)
-
SynTree/PointerType.cc (modified) (1 diff)
-
SynTree/ReferenceToType.cc (modified) (9 diffs)
-
SynTree/ReferenceType.cc (modified) (1 diff)
-
SynTree/Statement.cc (modified) (18 diffs)
-
SynTree/Statement.h (modified) (19 diffs)
-
SynTree/TupleExpr.cc (modified) (5 diffs)
-
SynTree/TupleType.cc (modified) (1 diff)
-
SynTree/Type.cc (modified) (2 diffs)
-
SynTree/Type.h (modified) (17 diffs)
-
SynTree/TypeDecl.cc (modified) (1 diff)
-
SynTree/TypeExpr.cc (modified) (1 diff)
-
SynTree/TypeSubstitution.cc (modified) (1 diff)
-
SynTree/TypeSubstitution.h (modified) (1 diff)
-
SynTree/TypeofType.cc (modified) (2 diffs)
-
SynTree/VarArgsType.cc (modified) (1 diff)
-
SynTree/VoidType.cc (modified) (2 diffs)
-
SynTree/ZeroOneType.cc (modified) (2 diffs)
-
Tuples/TupleAssignment.cc (modified) (2 diffs)
-
tests/.expect/castError.txt (modified) (1 diff)
-
tests/.expect/references.txt (deleted)
-
tests/.expect/scopeErrors.txt (modified) (1 diff)
-
tests/references.c (deleted)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r7821d6c re1ff775 1088 1088 } // namespace CodeGen 1089 1089 1090 1091 unsigned Indenter::tabsize = 2;1092 1093 1090 std::ostream & operator<<( std::ostream & out, const BaseSyntaxNode * node ) { 1094 1091 if ( node ) { -
src/Common/Indenter.h
r7821d6c re1ff775 18 18 19 19 struct Indenter { 20 static unsigned tabsize; 21 22 Indenter( unsigned int amt = tabsize, unsigned int indent = 0 ) : amt( amt ), indent( indent ) {} 23 unsigned int amt; // amount 1 level increases indent by (i.e. how much to increase by in operator++) 24 unsigned int indent; 20 Indenter( unsigned int amt = 2 ) : amt( amt ) {} 21 unsigned int amt = 2; // amount 1 level increases indent by (i.e. how much to increase by in operator++) 22 unsigned int indent = 0; 25 23 26 24 Indenter & operator+=(int nlevels) { indent += amt*nlevels; return *this; } … … 32 30 }; 33 31 34 inline std::ostream & operator<<( std::ostream & out, constIndenter & indent ) {32 inline std::ostream & operator<<( std::ostream & out, Indenter & indent ) { 35 33 return out << std::string(indent.indent, ' '); 36 34 } -
src/Common/utility.h
r7821d6c re1ff775 28 28 #include <cassert> 29 29 30 #include "Common/Indenter.h"31 32 30 template< typename T > 33 31 static inline T * maybeClone( const T *orig ) { … … 77 75 78 76 template< typename Container > 79 void printAll( const Container &container, std::ostream &os, Indenter indent = {}) {77 void printAll( const Container &container, std::ostream &os, int indent = 0 ) { 80 78 for ( typename Container::const_iterator i = container.begin(); i != container.end(); ++i ) { 81 79 if ( *i ) { 82 os << indent;83 (*i)->print( os, indent );80 os << std::string( indent, ' ' ); 81 (*i)->print( os, indent + 2 ); 84 82 // need an endl after each element because it's not easy to know when each individual item should end 85 83 os << std::endl; … … 353 351 template< typename T1, typename T2 > 354 352 struct group_iterate_t { 355 private:356 std::tuple<T1, T2> args;357 public:358 353 group_iterate_t( bool skipBoundsCheck, const T1 & v1, const T2 & v2 ) : args(v1, v2) { 359 354 assertf(skipBoundsCheck || v1.size() == v2.size(), "group iteration requires containers of the same size: <%zd, %zd>.", v1.size(), v2.size()); 360 355 }; 361 356 362 typedef std::tuple<decltype(*std::get<0>(args).begin()), decltype(*std::get<1>(args).begin())> value_type;363 typedef decltype(std::get<0>(args).begin()) T1Iter;364 typedef decltype(std::get<1>(args).begin()) T2Iter;365 366 357 struct iterator { 358 typedef typename std::remove_reference<T1>::type T1val; 359 typedef typename std::remove_reference<T2>::type T2val; 360 typedef std::tuple<typename T1val::value_type &, typename T2val::value_type &> value_type; 361 typedef typename T1val::iterator T1Iter; 362 typedef typename T2val::iterator T2Iter; 367 363 typedef std::tuple<T1Iter, T2Iter> IterTuple; 368 364 IterTuple it; … … 374 370 value_type operator*() const { return std::tie( *std::get<0>(it), *std::get<1>(it) ); } 375 371 }; 376 377 372 iterator begin() { return iterator( std::get<0>(args).begin(), std::get<1>(args).begin() ); } 378 373 iterator end() { return iterator( std::get<0>(args).end(), std::get<1>(args).end() ); } 374 375 private: 376 std::tuple<T1, T2> args; 379 377 }; 380 378 -
src/GenPoly/Box.cc
r7821d6c re1ff775 600 600 601 601 // add size/align for generic types to parameter list 602 if ( ! appExpr->get_function()-> result) return;602 if ( ! appExpr->get_function()->has_result() ) return; 603 603 FunctionType *funcType = getFunctionType( appExpr->get_function()->get_result() ); 604 604 assert( funcType ); … … 714 714 715 715 void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) { 716 assertf( arg-> result, "arg does not have result: %s", toString( arg ).c_str() );716 assertf( arg->has_result(), "arg does not have result: %s", toString( arg ).c_str() ); 717 717 if ( isPolyType( param, exprTyVars ) ) { 718 718 Type * newType = arg->get_result()->clone(); … … 965 965 if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic ) { 966 966 if ( varExpr->get_var()->get_name() == "?[?]" ) { 967 assert( appExpr-> result);967 assert( appExpr->has_result() ); 968 968 assert( appExpr->get_args().size() == 2 ); 969 969 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result(), scopeTyVars, env ); … … 999 999 } // if 1000 1000 } else if ( varExpr->get_var()->get_name() == "*?" ) { 1001 assert( appExpr-> result);1001 assert( appExpr->has_result() ); 1002 1002 assert( ! appExpr->get_args().empty() ); 1003 1003 if ( isPolyType( appExpr->get_result(), scopeTyVars, env ) ) { … … 1016 1016 } // if 1017 1017 } else if ( varExpr->get_var()->get_name() == "?++" || varExpr->get_var()->get_name() == "?--" ) { 1018 assert( appExpr-> result);1018 assert( appExpr->has_result() ); 1019 1019 assert( appExpr->get_args().size() == 1 ); 1020 1020 if ( Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env ) ) { … … 1036 1036 } // if 1037 1037 } else if ( varExpr->get_var()->get_name() == "++?" || varExpr->get_var()->get_name() == "--?" ) { 1038 assert( appExpr-> result);1038 assert( appExpr->has_result() ); 1039 1039 assert( appExpr->get_args().size() == 1 ); 1040 1040 if ( Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env ) ) { … … 1042 1042 } // if 1043 1043 } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) { 1044 assert( appExpr-> result);1044 assert( appExpr->has_result() ); 1045 1045 assert( appExpr->get_args().size() == 2 ); 1046 1046 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result(), scopeTyVars, env ); … … 1068 1068 } // if 1069 1069 } else if ( varExpr->get_var()->get_name() == "?+=?" || varExpr->get_var()->get_name() == "?-=?" ) { 1070 assert( appExpr-> result);1070 assert( appExpr->has_result() ); 1071 1071 assert( appExpr->get_args().size() == 2 ); 1072 1072 Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env ); … … 1162 1162 void Pass1::premutate( AddressExpr * ) { visit_children = false; } 1163 1163 Expression * Pass1::postmutate( AddressExpr * addrExpr ) { 1164 assert( addrExpr->get_arg()-> result&& ! addrExpr->get_arg()->get_result()->isVoid() );1164 assert( addrExpr->get_arg()->has_result() && ! addrExpr->get_arg()->get_result()->isVoid() ); 1165 1165 1166 1166 bool needs = false; 1167 1167 if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) { 1168 if ( expr-> result&& isPolyType( expr->get_result(), scopeTyVars, env ) ) {1168 if ( expr->has_result() && isPolyType( expr->get_result(), scopeTyVars, env ) ) { 1169 1169 if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) { 1170 1170 if ( name->get_name() == "*?" ) { 1171 1171 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) { 1172 assert( appExpr->get_function()-> result);1172 assert( appExpr->get_function()->has_result() ); 1173 1173 FunctionType *function = getFunctionType( appExpr->get_function()->get_result() ); 1174 1174 assert( function ); -
src/GenPoly/FindFunction.cc
r7821d6c re1ff775 18 18 #include <utility> // for pair 19 19 20 #include "Common/PassVisitor.h" // for PassVisitor21 20 #include "Common/SemanticError.h" // for SemanticError 22 21 #include "GenPoly/ErasableScopedMap.h" // for ErasableScopedMap<>::iterator … … 28 27 29 28 namespace GenPoly { 30 class FindFunction : public WithGuards, public WithVisitorRef<FindFunction>, public WithShortCircuiting{29 class FindFunction : public Mutator { 31 30 public: 32 31 FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate ); 33 32 34 void premutate( FunctionType * functionType ); 35 Type * postmutate( FunctionType * functionType ); 36 void premutate( PointerType * pointerType ); 33 virtual Type *mutate( FunctionType *functionType ); 34 virtual Type *mutate( PointerType *pointerType ); 37 35 private: 38 36 void handleForall( const Type::ForallList &forall ); … … 45 43 46 44 void findFunction( Type *type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) { 47 PassVisitor<FindFunction>finder( functions, tyVars, false, predicate );45 FindFunction finder( functions, tyVars, false, predicate ); 48 46 type->acceptMutator( finder ); 49 47 } 50 48 51 49 void findAndReplaceFunction( Type *&type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) { 52 PassVisitor<FindFunction>finder( functions, tyVars, true, predicate );50 FindFunction finder( functions, tyVars, true, predicate ); 53 51 type = type->acceptMutator( finder ); 54 52 } … … 59 57 60 58 void FindFunction::handleForall( const Type::ForallList &forall ) { 61 for ( const Declaration * td : forall) {62 TyVarMap::iterator var = tyVars.find( td->name);59 for ( Type::ForallList::const_iterator i = forall.begin(); i != forall.end(); ++i ) { 60 TyVarMap::iterator var = tyVars.find( (*i)->get_name() ); 63 61 if ( var != tyVars.end() ) { 64 62 tyVars.erase( var->first ); … … 67 65 } 68 66 69 void FindFunction::premutate( FunctionType * functionType ) { 70 visit_children = false; 71 GuardScope( tyVars ); 67 Type * FindFunction::mutate( FunctionType *functionType ) { 68 tyVars.beginScope(); 72 69 handleForall( functionType->get_forall() ); 73 mutateAll( functionType->get_returnVals(), *visitor ); 74 } 75 76 Type * FindFunction::postmutate( FunctionType * functionType ) { 70 mutateAll( functionType->get_returnVals(), *this ); 77 71 Type *ret = functionType; 78 72 if ( predicate( functionType, tyVars ) ) { … … 83 77 } // if 84 78 } // if 79 tyVars.endScope(); 85 80 return ret; 86 81 } 87 82 88 void FindFunction::premutate( PointerType *pointerType ) {89 GuardScope( tyVars);83 Type * FindFunction::mutate( PointerType *pointerType ) { 84 tyVars.beginScope(); 90 85 handleForall( pointerType->get_forall() ); 86 Type *ret = Mutator::mutate( pointerType ); 87 tyVars.endScope(); 88 return ret; 91 89 } 92 90 } // namespace GenPoly -
src/GenPoly/Specialize.cc
r7821d6c re1ff775 147 147 148 148 Expression * Specialize::doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams ) { 149 assertf( actual-> result, "attempting to specialize an untyped expression" );149 assertf( actual->has_result(), "attempting to specialize an untyped expression" ); 150 150 if ( needsSpecialization( formalType, actual->get_result(), env ) ) { 151 151 if ( FunctionType *funType = getFunctionType( formalType ) ) { -
src/InitTweak/FixInit.cc
r7821d6c re1ff775 390 390 assert( env ); 391 391 CP_CTOR_PRINT( std::cerr << "Type Substitution: " << *env << std::endl; ) 392 assert( arg-> result);392 assert( arg->has_result() ); 393 393 Type * result = arg->get_result(); 394 394 if ( skipCopyConstruct( result ) ) return; // skip certain non-copyable types … … 552 552 Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) ); 553 553 // move env from callExpr to retExpr 554 std::swap( retExpr->env, callExpr->env ); 554 retExpr->set_env( callExpr->get_env() ); 555 callExpr->set_env( nullptr ); 555 556 return retExpr; 556 557 } else { … … 1125 1126 static UniqueName tempNamer( "_tmp_ctor_expr" ); 1126 1127 // xxx - is the size check necessary? 1127 assert( ctorExpr-> result&& ctorExpr->get_result()->size() == 1 );1128 assert( ctorExpr->has_result() && ctorExpr->get_result()->size() == 1 ); 1128 1129 1129 1130 // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary. -
src/Parser/ExpressionNode.cc
r7821d6c re1ff775 87 87 } else { 88 88 assertf( false, "internal error, bad integral length %s", str.c_str() ); 89 } // if 89 } // if 90 90 posn += 1; 91 91 } // if … … 397 397 398 398 NameExpr * build_varref( const string * name ) { 399 NameExpr * expr = new NameExpr( *name );399 NameExpr * expr = new NameExpr( *name, nullptr ); 400 400 delete name; 401 401 return expr; … … 488 488 list< Expression * > args; 489 489 buildMoveList( expr_node, args ); 490 return new UntypedExpr( maybeMoveBuild< Expression >(function), args );490 return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr ); 491 491 } // build_func 492 492 -
src/ResolvExpr/AdjustExprType.cc
r7821d6c re1ff775 14 14 // 15 15 16 #include "Common/PassVisitor.h"17 16 #include "SymTab/Indexer.h" // for Indexer 18 17 #include "SynTree/Declaration.h" // for TypeDecl, TypeDecl::Kind::Ftype … … 22 21 23 22 namespace ResolvExpr { 24 class AdjustExprType : public WithShortCircuiting { 23 class AdjustExprType : public Mutator { 24 typedef Mutator Parent; 25 using Parent::mutate; 25 26 public: 26 27 AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer ); 27 void premutate( VoidType * ) { visit_children = false; } 28 void premutate( BasicType * ) { visit_children = false; } 29 void premutate( PointerType * ) { visit_children = false; } 30 void premutate( FunctionType * ) { visit_children = false; } 31 void premutate( StructInstType * ) { visit_children = false; } 32 void premutate( UnionInstType * ) { visit_children = false; } 33 void premutate( EnumInstType * ) { visit_children = false; } 34 void premutate( TraitInstType * ) { visit_children = false; } 35 void premutate( TypeInstType * ) { visit_children = false; } 36 void premutate( TupleType * ) { visit_children = false; } 37 void premutate( VarArgsType * ) { visit_children = false; } 38 void premutate( ZeroType * ) { visit_children = false; } 39 void premutate( OneType * ) { visit_children = false; } 28 private: 29 virtual Type* mutate( VoidType *voidType ); 30 virtual Type* mutate( BasicType *basicType ); 31 virtual Type* mutate( PointerType *pointerType ); 32 virtual Type* mutate( ArrayType *arrayType ); 33 virtual Type* mutate( FunctionType *functionType ); 34 virtual Type* mutate( StructInstType *aggregateUseType ); 35 virtual Type* mutate( UnionInstType *aggregateUseType ); 36 virtual Type* mutate( EnumInstType *aggregateUseType ); 37 virtual Type* mutate( TraitInstType *aggregateUseType ); 38 virtual Type* mutate( TypeInstType *aggregateUseType ); 39 virtual Type* mutate( TupleType *tupleType ); 40 virtual Type* mutate( VarArgsType *varArgsType ); 41 virtual Type* mutate( ZeroType *zeroType ); 42 virtual Type* mutate( OneType *oneType ); 40 43 41 Type * postmutate( ArrayType *arrayType );42 Type * postmutate( FunctionType *functionType );43 Type * postmutate( TypeInstType *aggregateUseType );44 45 private:46 44 const TypeEnvironment &env; 47 45 const SymTab::Indexer &indexer; … … 49 47 50 48 void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { 51 PassVisitor<AdjustExprType>adjuster( env, indexer );49 AdjustExprType adjuster( env, indexer ); 52 50 Type *newType = type->acceptMutator( adjuster ); 53 51 type = newType; … … 58 56 } 59 57 60 Type * AdjustExprType::postmutate( ArrayType * arrayType ) { 58 Type *AdjustExprType::mutate( VoidType *voidType ) { 59 return voidType; 60 } 61 62 Type *AdjustExprType::mutate( BasicType *basicType ) { 63 return basicType; 64 } 65 66 Type *AdjustExprType::mutate( PointerType *pointerType ) { 67 return pointerType; 68 } 69 70 Type *AdjustExprType::mutate( ArrayType *arrayType ) { 61 71 // need to recursively mutate the base type in order for multi-dimensional arrays to work. 62 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base ); 63 arrayType->base = nullptr; 72 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone()->acceptMutator( *this ) ); 64 73 delete arrayType; 65 74 return pointerType; 66 75 } 67 76 68 Type * AdjustExprType::postmutate( FunctionType * functionType ) { 69 return new PointerType( Type::Qualifiers(), functionType ); 77 Type *AdjustExprType::mutate( FunctionType *functionType ) { 78 PointerType *pointerType = new PointerType( Type::Qualifiers(), functionType ); 79 return pointerType; 70 80 } 71 81 72 Type * AdjustExprType::postmutate( TypeInstType * typeInst ) { 82 Type *AdjustExprType::mutate( StructInstType *aggregateUseType ) { 83 return aggregateUseType; 84 } 85 86 Type *AdjustExprType::mutate( UnionInstType *aggregateUseType ) { 87 return aggregateUseType; 88 } 89 90 Type *AdjustExprType::mutate( EnumInstType *aggregateUseType ) { 91 return aggregateUseType; 92 } 93 94 Type *AdjustExprType::mutate( TraitInstType *aggregateUseType ) { 95 return aggregateUseType; 96 } 97 98 Type *AdjustExprType::mutate( TypeInstType *typeInst ) { 73 99 EqvClass eqvClass; 74 100 if ( env.lookup( typeInst->get_name(), eqvClass ) ) { … … 87 113 return typeInst; 88 114 } 115 116 Type *AdjustExprType::mutate( TupleType *tupleType ) { 117 return tupleType; 118 } 119 120 Type *AdjustExprType::mutate( VarArgsType *varArgsType ) { 121 return varArgsType; 122 } 123 124 Type *AdjustExprType::mutate( ZeroType *zeroType ) { 125 return zeroType; 126 } 127 128 Type *AdjustExprType::mutate( OneType *oneType ) { 129 return oneType; 130 } 89 131 } // namespace ResolvExpr 90 132 -
src/ResolvExpr/Alternative.cc
r7821d6c re1ff775 66 66 } 67 67 68 void Alternative::print( std::ostream &os, Indenterindent ) const {69 os << "Cost " << cost << ": ";68 void Alternative::print( std::ostream &os, int indent ) const { 69 os << std::string( indent, ' ' ) << "Cost " << cost << ": "; 70 70 if ( expr ) { 71 expr->print( os, indent +1);72 os << std::endl << indent <<"(types:" << std::endl;73 os << indent+1;74 expr-> result->print( os, indent+1);75 os << std::endl << indent <<")" << std::endl;71 expr->print( os, indent ); 72 os << "(types:" << std::endl; 73 os << std::string( indent+4, ' ' ); 74 expr->get_result()->print( os, indent + 4 ); 75 os << std::endl << ")" << std::endl; 76 76 } else { 77 77 os << "Null expression!" << std::endl; 78 78 } // if 79 os << indent<< "Environment: ";80 env.print( os, indent+ 1);79 os << std::string( indent, ' ' ) << "Environment: "; 80 env.print( os, indent+2 ); 81 81 os << std::endl; 82 82 } -
src/ResolvExpr/Alternative.h
r7821d6c re1ff775 39 39 ~Alternative(); 40 40 41 void print( std::ostream &os, Indenter indent = {}) const;41 void print( std::ostream &os, int indent = 0 ) const; 42 42 43 43 Cost cost; -
src/ResolvExpr/AlternativeFinder.cc
r7821d6c re1ff775 75 75 76 76 namespace { 77 void printAlts( const AltList &list, std::ostream &os, unsigned int indentAmt = 0 ) { 78 Indenter indent = { Indenter::tabsize, indentAmt }; 77 void printAlts( const AltList &list, std::ostream &os, int indent = 0 ) { 79 78 for ( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) { 80 79 i->print( os, indent ); … … 196 195 AltList winners; 197 196 findMinCost( alternatives.begin(), alternatives.end(), back_inserter( winners ) ); 198 stream << "Cannot choose between " << winners.size() << " alternatives for expression \n";197 stream << "Cannot choose between " << winners.size() << " alternatives for expression "; 199 198 expr->print( stream ); 200 stream << "Alternatives are: \n";201 printAlts( winners, stream, 1);199 stream << "Alternatives are:"; 200 printAlts( winners, stream, 8 ); 202 201 throw SemanticError( stream.str() ); 203 202 } … … 729 728 PRINT( 730 729 std::cerr << "known function ops:" << std::endl; 731 printAlts( funcOpFinder.alternatives, std::cerr, 1);730 printAlts( funcOpFinder.alternatives, std::cerr, 8 ); 732 731 ) 733 732 … … 839 838 bool isLvalue( Expression *expr ) { 840 839 // xxx - recurse into tuples? 841 return expr-> result&& ( expr->get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result() ) );840 return expr->has_result() && ( expr->get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result() ) ); 842 841 } 843 842 … … 973 972 PRINT( std::cerr << "nameExpr is " << nameExpr->get_name() << std::endl; ) 974 973 for ( std::list< DeclarationWithType* >::iterator i = declList.begin(); i != declList.end(); ++i ) { 975 VariableExpr newExpr( *i );974 VariableExpr newExpr( *i, nameExpr->get_argName() ); 976 975 alternatives.push_back( Alternative( newExpr.clone(), env, Cost::zero ) ); 977 976 PRINT( -
src/ResolvExpr/ResolveTypeof.cc
r7821d6c re1ff775 18 18 #include <cassert> // for assert 19 19 20 #include "Common/PassVisitor.h" // for PassVisitor21 20 #include "Resolver.h" // for resolveInVoidContext 22 21 #include "SynTree/Expression.h" // for Expression … … 42 41 } 43 42 44 class ResolveTypeof : public WithShortCircuiting{43 class ResolveTypeof : public Mutator { 45 44 public: 46 45 ResolveTypeof( const SymTab::Indexer &indexer ) : indexer( indexer ) {} 47 void premutate( TypeofType *typeofType ); 48 Type * postmutate( TypeofType *typeofType ); 46 Type *mutate( TypeofType *typeofType ); 49 47 50 48 private: … … 52 50 }; 53 51 54 Type * resolveTypeof( Type *type, const SymTab::Indexer &indexer ) {55 PassVisitor<ResolveTypeof>mutator( indexer );52 Type *resolveTypeof( Type *type, const SymTab::Indexer &indexer ) { 53 ResolveTypeof mutator( indexer ); 56 54 return type->acceptMutator( mutator ); 57 55 } 58 56 59 void ResolveTypeof::premutate( TypeofType * ) { 60 visit_children = false; 61 } 62 63 Type * ResolveTypeof::postmutate( TypeofType *typeofType ) { 57 Type *ResolveTypeof::mutate( TypeofType *typeofType ) { 64 58 #if 0 65 std::c err<< "resolving typeof: ";66 typeofType->print( std::c err);67 std::c err<< std::endl;59 std::cout << "resolving typeof: "; 60 typeofType->print( std::cout ); 61 std::cout << std::endl; 68 62 #endif 69 if ( typeofType-> expr) {70 Expression * newExpr = resolveInVoidContext( typeofType->expr, indexer );71 assert( newExpr-> result && ! newExpr->result->isVoid() );72 Type * newType = newExpr->result;73 newExpr-> result = nullptr;63 if ( typeofType->get_expr() ) { 64 Expression *newExpr = resolveInVoidContext( typeofType->get_expr(), indexer ); 65 assert( newExpr->has_result() && ! newExpr->get_result()->isVoid() ); 66 Type *newType = newExpr->get_result(); 67 newExpr->set_result( nullptr ); 74 68 delete typeofType; 75 69 delete newExpr; -
src/ResolvExpr/TypeEnvironment.cc
r7821d6c re1ff775 68 68 } 69 69 70 void EqvClass::print( std::ostream &os, Indenterindent ) const {71 os << "( ";70 void EqvClass::print( std::ostream &os, int indent ) const { 71 os << std::string( indent, ' ' ) << "( "; 72 72 std::copy( vars.begin(), vars.end(), std::ostream_iterator< std::string >( os, " " ) ); 73 73 os << ")"; 74 74 if ( type ) { 75 75 os << " -> "; 76 type->print( os, indent +1);76 type->print( os, indent ); 77 77 } // if 78 78 if ( ! allowWidening ) { … … 144 144 } 145 145 146 void TypeEnvironment::print( std::ostream &os, Indenterindent ) const {146 void TypeEnvironment::print( std::ostream &os, int indent ) const { 147 147 for ( std::list< EqvClass >::const_iterator i = env.begin(); i != env.end(); ++i ) { 148 148 i->print( os, indent ); -
src/ResolvExpr/TypeEnvironment.h
r7821d6c re1ff775 68 68 EqvClass &operator=( const EqvClass &other ); 69 69 ~EqvClass(); 70 void print( std::ostream &os, Indenter indent = {}) const;70 void print( std::ostream &os, int indent = 0 ) const; 71 71 }; 72 72 … … 80 80 void makeSubstitution( TypeSubstitution &result ) const; 81 81 bool isEmpty() const { return env.empty(); } 82 void print( std::ostream &os, Indenter indent = {}) const;82 void print( std::ostream &os, int indent = 0 ) const; 83 83 void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) ); 84 84 void simpleCombine( const TypeEnvironment &second ); -
src/ResolvExpr/Unify.cc
r7821d6c re1ff775 22 22 #include <utility> // for pair 23 23 24 #include "Common/PassVisitor.h" // for PassVisitor25 24 #include "FindOpenVars.h" // for findOpenVars 26 25 #include "Parser/LinkageSpec.h" // for C … … 538 537 /// If this isn't done then argument lists can have wildly different 539 538 /// size and structure, when they should be compatible. 540 struct TtypeExpander : public WithShortCircuiting { 541 TypeEnvironment & tenv; 542 TtypeExpander( TypeEnvironment & tenv ) : tenv( tenv ) {} 543 void premutate( TypeInstType * ) { visit_children = false; } 544 Type * postmutate( TypeInstType * typeInst ) { 539 struct TtypeExpander : public Mutator { 540 TypeEnvironment & env; 541 TtypeExpander( TypeEnvironment & env ) : env( env ) {} 542 Type * mutate( TypeInstType * typeInst ) { 545 543 EqvClass eqvClass; 546 if ( tenv.lookup( typeInst->get_name(), eqvClass ) ) {544 if ( env.lookup( typeInst->get_name(), eqvClass ) ) { 547 545 if ( eqvClass.data.kind == TypeDecl::Ttype ) { 548 546 // expand ttype parameter into its actual type … … 562 560 dst.clear(); 563 561 for ( DeclarationWithType * dcl : src ) { 564 PassVisitor<TtypeExpander>expander( env );562 TtypeExpander expander( env ); 565 563 dcl->acceptMutator( expander ); 566 564 std::list< Type * > types; … … 752 750 std::list<Type *> types1, types2; 753 751 754 PassVisitor<TtypeExpander>expander( env );752 TtypeExpander expander( env ); 755 753 flat1->acceptMutator( expander ); 756 754 flat2->acceptMutator( expander ); -
src/SymTab/FixFunction.cc
r7821d6c re1ff775 26 26 FixFunction::FixFunction() : isVoid( false ) {} 27 27 28 29 DeclarationWithType * FixFunction::postmutate(FunctionDecl *functionDecl) { 28 DeclarationWithType * FixFunction::mutate(FunctionDecl *functionDecl) { 30 29 // can't delete function type because it may contain assertions, so transfer ownership to new object 31 ObjectDecl *pointer = new ObjectDecl( functionDecl-> name, functionDecl->get_storageClasses(), functionDecl->linkage, nullptr, new PointerType( Type::Qualifiers(), functionDecl->type ), nullptr, functionDecl->attributes);32 functionDecl-> attributes.clear();30 ObjectDecl *pointer = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClasses(), functionDecl->get_linkage(), 0, new PointerType( Type::Qualifiers(), functionDecl->get_type() ), 0, functionDecl->get_attributes() ); 31 functionDecl->get_attributes().clear(); 33 32 functionDecl->type = nullptr; 34 33 delete functionDecl; … … 36 35 } 37 36 38 Type * FixFunction::postmutate(ArrayType *arrayType) { 37 Type * FixFunction::mutate(VoidType *voidType) { 38 isVoid = true; 39 return voidType; 40 } 41 42 Type * FixFunction::mutate(BasicType *basicType) { 43 return basicType; 44 } 45 46 Type * FixFunction::mutate(PointerType *pointerType) { 47 return pointerType; 48 } 49 50 Type * FixFunction::mutate(ArrayType *arrayType) { 39 51 // need to recursively mutate the base type in order for multi-dimensional arrays to work. 40 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base, arrayType->dimension, arrayType->isVarLen, arrayType->isStatic ); 41 arrayType->base = nullptr; 42 arrayType->dimension = nullptr; 52 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone()->acceptMutator( *this ), maybeClone( arrayType->get_dimension() ), arrayType->get_isVarLen(), arrayType->get_isStatic() ); 43 53 delete arrayType; 44 54 return pointerType; 45 55 } 46 56 47 void FixFunction::premutate(VoidType *) {48 isVoid = true;57 Type * FixFunction::mutate(StructInstType *aggregateUseType) { 58 return aggregateUseType; 49 59 } 50 60 51 void FixFunction::premutate(FunctionDecl *) { visit_children = false; } 52 void FixFunction::premutate(BasicType *) { visit_children = false; } 53 void FixFunction::premutate(PointerType *) { visit_children = false; } 54 void FixFunction::premutate(StructInstType *) { visit_children = false; } 55 void FixFunction::premutate(UnionInstType *) { visit_children = false; } 56 void FixFunction::premutate(EnumInstType *) { visit_children = false; } 57 void FixFunction::premutate(TraitInstType *) { visit_children = false; } 58 void FixFunction::premutate(TypeInstType *) { visit_children = false; } 59 void FixFunction::premutate(TupleType *) { visit_children = false; } 60 void FixFunction::premutate(VarArgsType *) { visit_children = false; } 61 void FixFunction::premutate(ZeroType *) { visit_children = false; } 62 void FixFunction::premutate(OneType *) { visit_children = false; } 61 Type * FixFunction::mutate(UnionInstType *aggregateUseType) { 62 return aggregateUseType; 63 } 64 65 Type * FixFunction::mutate(EnumInstType *aggregateUseType) { 66 return aggregateUseType; 67 } 68 69 Type * FixFunction::mutate(TraitInstType *aggregateUseType) { 70 return aggregateUseType; 71 } 72 73 Type * FixFunction::mutate(TypeInstType *aggregateUseType) { 74 return aggregateUseType; 75 } 76 77 Type * FixFunction::mutate(TupleType *tupleType) { 78 return tupleType; 79 } 80 81 Type * FixFunction::mutate(VarArgsType *varArgsType) { 82 return varArgsType; 83 } 84 85 Type * FixFunction::mutate(ZeroType *zeroType) { 86 return zeroType; 87 } 88 89 Type * FixFunction::mutate(OneType *oneType) { 90 return oneType; 91 } 63 92 } // namespace SymTab 64 93 -
src/SymTab/FixFunction.h
r7821d6c re1ff775 16 16 #pragma once 17 17 18 #include " Common/PassVisitor.h" // for PassVisitor19 #include "SynTree/SynTree.h" // for Types18 #include "SynTree/Mutator.h" // for Mutator 19 #include "SynTree/SynTree.h" // for Types 20 20 21 21 namespace SymTab { 22 22 /// Replaces function and array types by equivalent pointer types. 23 class FixFunction : public WithShortCircuiting{23 class FixFunction : public Mutator { 24 24 typedef Mutator Parent; 25 25 public: 26 26 FixFunction(); 27 27 28 void premutate(FunctionDecl *functionDecl); 29 DeclarationWithType* postmutate(FunctionDecl *functionDecl); 28 bool get_isVoid() const { return isVoid; } 29 void set_isVoid( bool newValue ) { isVoid = newValue; } 30 private: 31 virtual DeclarationWithType* mutate(FunctionDecl *functionDecl); 30 32 31 Type * postmutate(ArrayType * arrayType); 32 33 void premutate(VoidType * voidType); 34 void premutate(BasicType * basicType); 35 void premutate(PointerType * pointerType); 36 void premutate(StructInstType * aggregateUseType); 37 void premutate(UnionInstType * aggregateUseType); 38 void premutate(EnumInstType * aggregateUseType); 39 void premutate(TraitInstType * aggregateUseType); 40 void premutate(TypeInstType * aggregateUseType); 41 void premutate(TupleType * tupleType); 42 void premutate(VarArgsType * varArgsType); 43 void premutate(ZeroType * zeroType); 44 void premutate(OneType * oneType); 33 virtual Type* mutate(VoidType *voidType); 34 virtual Type* mutate(BasicType *basicType); 35 virtual Type* mutate(PointerType *pointerType); 36 virtual Type* mutate(ArrayType *arrayType); 37 virtual Type* mutate(StructInstType *aggregateUseType); 38 virtual Type* mutate(UnionInstType *aggregateUseType); 39 virtual Type* mutate(EnumInstType *aggregateUseType); 40 virtual Type* mutate(TraitInstType *aggregateUseType); 41 virtual Type* mutate(TypeInstType *aggregateUseType); 42 virtual Type* mutate(TupleType *tupleType); 43 virtual Type* mutate(VarArgsType *varArgsType); 44 virtual Type* mutate(ZeroType *zeroType); 45 virtual Type* mutate(OneType *oneType); 45 46 46 47 bool isVoid; -
src/SymTab/Validate.cc
r7821d6c re1ff775 369 369 DWTIterator begin( dwts.begin() ), end( dwts.end() ); 370 370 if ( begin == end ) return; 371 PassVisitor<FixFunction>fixer;371 FixFunction fixer; 372 372 DWTIterator i = begin; 373 373 *i = (*i)->acceptMutator( fixer ); 374 if ( fixer. pass.isVoid) {374 if ( fixer.get_isVoid() ) { 375 375 DWTIterator j = i; 376 376 ++i; … … 383 383 ++i; 384 384 for ( ; i != end; ++i ) { 385 PassVisitor<FixFunction>fixer;385 FixFunction fixer; 386 386 *i = (*i)->acceptMutator( fixer ); 387 if ( fixer. pass.isVoid) {387 if ( fixer.get_isVoid() ) { 388 388 throw SemanticError( "invalid type void in function type ", func ); 389 389 } // if … … 597 597 // apply FixFunction to every assertion to check for invalid void type 598 598 for ( DeclarationWithType *& assertion : type->assertions ) { 599 PassVisitor<FixFunction>fixer;599 FixFunction fixer; 600 600 assertion = assertion->acceptMutator( fixer ); 601 if ( fixer. pass.isVoid) {601 if ( fixer.get_isVoid() ) { 602 602 throw SemanticError( "invalid type void in assertion of function ", node ); 603 603 } // if -
src/SynTree/AddressExpr.cc
r7821d6c re1ff775 33 33 Type * addrType( Type * type ) { 34 34 if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( type ) ) { 35 return new ReferenceType( refType->get_qualifiers(), addrType( refType-> base) );35 return new ReferenceType( refType->get_qualifiers(), addrType( refType->get_base() ) ); 36 36 } else { 37 37 return new PointerType( Type::Qualifiers(), type->clone() ); … … 40 40 } 41 41 42 AddressExpr::AddressExpr( Expression *arg ) : Expression(), arg( arg ) {43 if ( arg-> result) {44 if ( arg-> result->get_lvalue() ) {42 AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) { 43 if ( arg->has_result() ) { 44 if ( arg->get_result()->get_lvalue() ) { 45 45 // lvalue, retains all layers of reference and gains a pointer inside the references 46 set_result( addrType( arg-> result) );46 set_result( addrType( arg->get_result() ) ); 47 47 } else { 48 48 // taking address of non-lvalue -- must be a reference, loses one layer of reference 49 ReferenceType * refType = strict_dynamic_cast< ReferenceType * >( arg-> result);50 set_result( addrType( refType-> base) );49 ReferenceType * refType = strict_dynamic_cast< ReferenceType * >( arg->get_result() ); 50 set_result( addrType( refType->get_base() ) ); 51 51 } 52 52 // result of & is never an lvalue … … 62 62 } 63 63 64 void AddressExpr::print( std::ostream &os, Indenterindent ) const {64 void AddressExpr::print( std::ostream &os, int indent ) const { 65 65 os << "Address of:" << std::endl; 66 66 if ( arg ) { 67 os << indent+1;68 arg->print( os, indent+ 1);67 os << std::string( indent+2, ' ' ); 68 arg->print( os, indent+2 ); 69 69 } // if 70 70 } … … 77 77 LabelAddressExpr::~LabelAddressExpr() {} 78 78 79 void LabelAddressExpr::print( std::ostream & os, Indenter) const {80 os << "Address of label:" << arg;79 void LabelAddressExpr::print( std::ostream & os, int indent ) const { 80 os << "Address of label:" << std::endl << std::string( indent+2, ' ' ) << arg; 81 81 } 82 82 -
src/SynTree/AggregateDecl.cc
r7821d6c re1ff775 41 41 } 42 42 43 void AggregateDecl::print( std::ostream &os, Indenterindent ) const {43 void AggregateDecl::print( std::ostream &os, int indent ) const { 44 44 using std::string; 45 45 using std::endl; 46 46 47 os << typeString() << " " << name<< ":";47 os << typeString() << " " << get_name() << ":"; 48 48 if ( get_linkage() != LinkageSpec::Cforall ) { 49 os << " " << LinkageSpec::linkageName( linkage);49 os << " " << LinkageSpec::linkageName( get_linkage() ); 50 50 } // if 51 os << " with body " << has_body() ;51 os << " with body " << has_body() << endl; 52 52 53 53 if ( ! parameters.empty() ) { 54 os << endl << indent << "...with parameters" << endl;55 printAll( parameters, os, indent+ 1);54 os << endl << string( indent+2, ' ' ) << "with parameters" << endl; 55 printAll( parameters, os, indent+4 ); 56 56 } // if 57 57 if ( ! members.empty() ) { 58 os << endl << indent << "...with members" << endl;59 printAll( members, os, indent+ 1);58 os << endl << string( indent+2, ' ' ) << "with members" << endl; 59 printAll( members, os, indent+4 ); 60 60 } // if 61 61 if ( ! attributes.empty() ) { 62 os << endl << indent << "...with attributes" << endl;63 printAll( attributes, os, indent+ 1);62 os << endl << string( indent+2, ' ' ) << "with attributes" << endl; 63 printAll( attributes, os, indent+4 ); 64 64 } // if 65 os << endl;66 65 } 67 66 68 void AggregateDecl::printShort( std::ostream &os, Indenterindent ) const {67 void AggregateDecl::printShort( std::ostream &os, int indent ) const { 69 68 using std::string; 70 69 using std::endl; 71 70 72 os << typeString() << " " << name << " with body " << has_body() << endl; 71 os << typeString() << " " << get_name(); 72 os << string( indent+2, ' ' ) << "with body " << has_body() << endl; 73 73 74 74 if ( ! parameters.empty() ) { 75 os << indent << "...with parameters" << endl;76 printAll( parameters, os, indent+ 1);75 os << endl << string( indent+2, ' ' ) << "with parameters" << endl; 76 printAll( parameters, os, indent+4 ); 77 77 } // if 78 78 } -
src/SynTree/ApplicationExpr.cc
r7821d6c re1ff775 55 55 set_result( ResolvExpr::extractResultType( function ) ); 56 56 57 assert( result);57 assert( has_result() ); 58 58 } 59 59 … … 68 68 } 69 69 70 void printInferParams( const InferredParams & inferParams, std::ostream &os, Indenterindent, int level ) {70 void printInferParams( const InferredParams & inferParams, std::ostream &os, int indent, int level ) { 71 71 if ( ! inferParams.empty() ) { 72 os << indent<< "with inferred parameters " << level << ":" << std::endl;72 os << std::string(indent, ' ') << "with inferred parameters " << level << ":" << std::endl; 73 73 for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) { 74 os << indent+1;75 Declaration::declFromId( i->second.decl )->printShort( os, indent+ 1);74 os << std::string(indent+2, ' '); 75 Declaration::declFromId( i->second.decl )->printShort( os, indent+2 ); 76 76 os << std::endl; 77 printInferParams( *i->second.inferParams, os, indent+ 1, level+1 );77 printInferParams( *i->second.inferParams, os, indent+2, level+1 ); 78 78 } // for 79 79 } // if 80 80 } 81 81 82 void ApplicationExpr::print( std::ostream &os, Indenter indent ) const { 83 os << "Application of" << std::endl << indent+1; 84 function->print( os, indent+1 ); 85 os << std::endl; 82 void ApplicationExpr::print( std::ostream &os, int indent ) const { 83 os << "Application of" << std::endl << std::string(indent+2, ' '); 84 function->print( os, indent+2 ); 86 85 if ( ! args.empty() ) { 87 os << indent << "...to arguments" << std::endl;88 printAll( args, os, indent+ 1);86 os << std::string( indent, ' ' ) << "to arguments" << std::endl; 87 printAll( args, os, indent+2 ); 89 88 } // if 90 printInferParams( inferParams, os, indent+ 1, 0 );89 printInferParams( inferParams, os, indent+2, 0 ); 91 90 Expression::print( os, indent ); 92 91 } -
src/SynTree/ArrayType.cc
r7821d6c re1ff775 39 39 } 40 40 41 void ArrayType::print( std::ostream &os, Indenterindent ) const {41 void ArrayType::print( std::ostream &os, int indent ) const { 42 42 Type::print( os, indent ); 43 43 if ( isStatic ) { -
src/SynTree/AttrType.cc
r7821d6c re1ff775 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // AttrType.cc.cc -- 7 // AttrType.cc.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 42 42 } 43 43 44 void AttrType::print( std::ostream &os, Indenterindent ) const {44 void AttrType::print( std::ostream &os, int indent ) const { 45 45 Type::print( os, indent ); 46 46 os << "attribute " << name << " applied to "; -
src/SynTree/Attribute.cc
r7821d6c re1ff775 28 28 } 29 29 30 void Attribute::print( std::ostream &os, Indenterindent ) const {30 void Attribute::print( std::ostream &os, int indent ) const { 31 31 using std::endl; 32 32 using std::string; … … 36 36 if ( ! parameters.empty() ) { 37 37 os << " with parameters: " << endl; 38 printAll( parameters, os, indent +1);38 printAll( parameters, os, indent ); 39 39 } 40 40 } -
src/SynTree/Attribute.h
r7821d6c re1ff775 46 46 virtual void accept( Visitor & v ) override { v.visit( this ); } 47 47 virtual Attribute * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 48 virtual void print( std::ostream & os, Indenter indent = {}) const override;48 virtual void print( std::ostream & os, int indent = 0 ) const override; 49 49 }; 50 50 -
src/SynTree/BaseSyntaxNode.h
r7821d6c re1ff775 17 17 18 18 #include "Common/CodeLocation.h" 19 #include "Common/Indenter.h"20 19 class Visitor; 21 20 class Mutator; … … 30 29 virtual void accept( Visitor & v ) = 0; 31 30 virtual BaseSyntaxNode * acceptMutator( Mutator & m ) = 0; 32 /// Notes: 33 /// * each node is responsible for indenting its children. 34 /// * Expressions should not finish with a newline, since the expression's parent has better information. 35 virtual void print( std::ostream & os, Indenter indent = {} ) const = 0; 36 void print( std::ostream & os, unsigned int indent ) { 37 print( os, Indenter{ Indenter::tabsize, indent }); 38 } 31 virtual void print( std::ostream & os, int indent = 0 ) const = 0; 39 32 }; 40 33 -
src/SynTree/BasicType.cc
r7821d6c re1ff775 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // BasicType.cc -- 7 // BasicType.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 24 24 BasicType::BasicType( const Type::Qualifiers &tq, Kind bt, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), kind( bt ) {} 25 25 26 void BasicType::print( std::ostream &os, Indenterindent ) const {26 void BasicType::print( std::ostream &os, int indent ) const { 27 27 Type::print( os, indent ); 28 28 os << BasicType::typeNames[ kind ]; -
src/SynTree/CommaExpr.cc
r7821d6c re1ff775 21 21 #include "Type.h" // for Type 22 22 23 CommaExpr::CommaExpr( Expression *arg1, Expression *arg2 )24 : Expression( ), arg1( arg1 ), arg2( arg2 ) {23 CommaExpr::CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname ) 24 : Expression( _aname ), arg1( arg1 ), arg2( arg2 ) { 25 25 // xxx - result of a comma expression is never an lvalue, so should set lvalue 26 26 // to false on all result types. Actually doing this causes some strange things … … 39 39 } 40 40 41 void CommaExpr::print( std::ostream &os, Indenterindent ) const {41 void CommaExpr::print( std::ostream &os, int indent ) const { 42 42 os << "Comma Expression:" << std::endl; 43 os << (indent+1);44 arg1->print( os, indent+ 1);43 os << std::string( indent+2, ' ' ); 44 arg1->print( os, indent+2 ); 45 45 os << std::endl; 46 os << (indent+1);47 arg2->print( os, indent+ 1);46 os << std::string( indent+2, ' ' ); 47 arg2->print( os, indent+2 ); 48 48 Expression::print( os, indent ); 49 49 } -
src/SynTree/CompoundStmt.cc
r7821d6c re1ff775 73 73 } 74 74 75 void CompoundStmt::print( std::ostream &os, Indenterindent ) const {76 os << "CompoundStmt" << endl ;77 printAll( kids, os, indent +1);75 void CompoundStmt::print( std::ostream &os, int indent ) const { 76 os << "CompoundStmt" << endl ; 77 printAll( kids, os, indent + 2 ); 78 78 } 79 79 -
src/SynTree/DeclStmt.cc
r7821d6c re1ff775 33 33 } 34 34 35 void DeclStmt::print( std::ostream &os, Indenterindent ) const {35 void DeclStmt::print( std::ostream &os, int indent ) const { 36 36 assert( decl != 0 ); 37 37 os << "Declaration of "; -
src/SynTree/Declaration.cc
r7821d6c re1ff775 70 70 } 71 71 72 void AsmDecl::print( std::ostream &os, Indenterindent ) const {72 void AsmDecl::print( std::ostream &os, int indent ) const { 73 73 stmt->print( os, indent ); 74 74 } 75 75 76 void AsmDecl::printShort( std::ostream &os, Indenterindent ) const {76 void AsmDecl::printShort( std::ostream &os, int indent ) const { 77 77 stmt->print( os, indent ); 78 78 } -
src/SynTree/Declaration.h
r7821d6c re1ff775 64 64 virtual void accept( Visitor &v ) override = 0; 65 65 virtual Declaration *acceptMutator( Mutator &m ) override = 0; 66 virtual void print( std::ostream &os, Indenter indent = {}) const override = 0;67 virtual void printShort( std::ostream &os, Indenter indent = {}) const = 0;66 virtual void print( std::ostream &os, int indent = 0 ) const override = 0; 67 virtual void printShort( std::ostream &os, int indent = 0 ) const = 0; 68 68 69 69 static void dumpIds( std::ostream &os ); … … 142 142 virtual void accept( Visitor &v ) override { v.visit( this ); } 143 143 virtual DeclarationWithType *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 144 virtual void print( std::ostream &os, Indenter indent = {}) const override;145 virtual void printShort( std::ostream &os, Indenter indent = {}) const override;144 virtual void print( std::ostream &os, int indent = 0 ) const override; 145 virtual void printShort( std::ostream &os, int indent = 0 ) const override; 146 146 }; 147 147 … … 170 170 virtual void accept( Visitor &v ) override { v.visit( this ); } 171 171 virtual DeclarationWithType *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 172 virtual void print( std::ostream &os, Indenter indent = {}) const override;173 virtual void printShort( std::ostream &os, Indenter indent = {}) const override;172 virtual void print( std::ostream &os, int indent = 0 ) const override; 173 virtual void printShort( std::ostream &os, int indent = 0 ) const override; 174 174 }; 175 175 … … 193 193 194 194 virtual NamedTypeDecl *clone() const override = 0; 195 virtual void print( std::ostream &os, Indenter indent = {}) const override;196 virtual void printShort( std::ostream &os, Indenter indent = {}) const override;195 virtual void print( std::ostream &os, int indent = 0 ) const override; 196 virtual void printShort( std::ostream &os, int indent = 0 ) const override; 197 197 }; 198 198 … … 235 235 virtual void accept( Visitor &v ) override { v.visit( this ); } 236 236 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 237 virtual void print( std::ostream &os, Indenter indent = {}) const override;237 virtual void print( std::ostream &os, int indent = 0 ) const override; 238 238 239 239 private: … … 276 276 AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; } 277 277 278 virtual void print( std::ostream &os, Indenter indent = {}) const override;279 virtual void printShort( std::ostream &os, Indenter indent = {}) const override;278 virtual void print( std::ostream &os, int indent = 0 ) const override; 279 virtual void printShort( std::ostream &os, int indent = 0 ) const override; 280 280 protected: 281 281 virtual std::string typeString() const = 0; … … 355 355 virtual void accept( Visitor &v ) override { v.visit( this ); } 356 356 virtual AsmDecl *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 357 virtual void print( std::ostream &os, Indenter indent = {}) const override;358 virtual void printShort( std::ostream &os, Indenter indent = {}) const override;357 virtual void print( std::ostream &os, int indent = 0 ) const override; 358 virtual void printShort( std::ostream &os, int indent = 0 ) const override; 359 359 }; 360 360 -
src/SynTree/Expression.cc
r7821d6c re1ff775 33 33 #include "GenPoly/Lvalue.h" 34 34 35 Expression::Expression( ) : result( 0 ), env( 0) {}36 37 Expression::Expression( const Expression &other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), extension( other.extension ) {35 Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {} 36 37 Expression::Expression( const Expression &other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) { 38 38 } 39 39 40 40 Expression::~Expression() { 41 41 delete env; 42 delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix 42 43 delete result; 43 44 } 44 45 45 void Expression::print( std::ostream &os, Indenterindent ) const {46 void Expression::print( std::ostream &os, int indent ) const { 46 47 if ( env ) { 47 os << std:: endl << indent << "...with environment:" << std::endl;48 env->print( os, indent+ 1);48 os << std::string( indent, ' ' ) << "with environment:" << std::endl; 49 env->print( os, indent+2 ); 49 50 } // if 50 51 52 if ( argName ) { 53 os << std::string( indent, ' ' ) << "with designator:"; 54 argName->print( os, indent+2 ); 55 } // if 56 51 57 if ( extension ) { 52 os << std:: endl << indent << "...with extension:";58 os << std::string( indent, ' ' ) << "with extension:"; 53 59 } // if 54 60 } 55 61 56 ConstantExpr::ConstantExpr( Constant _c ) : Expression(), constant( _c ) {62 ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) { 57 63 set_result( constant.get_type()->clone() ); 58 64 } … … 63 69 ConstantExpr::~ConstantExpr() {} 64 70 65 void ConstantExpr::print( std::ostream &os, Indenterindent ) const {71 void ConstantExpr::print( std::ostream &os, int indent ) const { 66 72 os << "constant expression " ; 67 73 constant.print( os ); … … 69 75 } 70 76 71 VariableExpr::VariableExpr( DeclarationWithType *_var ) : Expression(), var( _var ) {77 VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) { 72 78 assert( var ); 73 79 assert( var->get_type() ); … … 90 96 } 91 97 92 void VariableExpr::print( std::ostream &os, Indenterindent ) const {98 void VariableExpr::print( std::ostream &os, int indent ) const { 93 99 os << "Variable Expression: "; 94 var->printShort(os, indent); 95 Expression::print( os, indent ); 96 } 97 98 SizeofExpr::SizeofExpr( Expression *expr_ ) : 99 Expression(), expr(expr_), type(0), isType(false) { 100 101 Declaration *decl = get_var(); 102 if ( decl != 0) decl->printShort(os, indent + 2); 103 os << std::endl; 104 Expression::print( os, indent ); 105 } 106 107 SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) : 108 Expression( _aname ), expr(expr_), type(0), isType(false) { 100 109 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 101 110 } 102 111 103 SizeofExpr::SizeofExpr( Type *type_ ) :104 Expression( ), expr(0), type(type_), isType(true) {112 SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) : 113 Expression( _aname ), expr(0), type(type_), isType(true) { 105 114 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 106 115 } … … 115 124 } 116 125 117 void SizeofExpr::print( std::ostream &os, Indenterindent) const {126 void SizeofExpr::print( std::ostream &os, int indent) const { 118 127 os << "Sizeof Expression on: "; 119 if (isType) type->print(os, indent+1); 120 else expr->print(os, indent+1); 121 Expression::print( os, indent ); 122 } 123 124 AlignofExpr::AlignofExpr( Expression *expr_ ) : 125 Expression(), expr(expr_), type(0), isType(false) { 128 129 if (isType) 130 type->print(os, indent + 2); 131 else 132 expr->print(os, indent + 2); 133 134 os << std::endl; 135 Expression::print( os, indent ); 136 } 137 138 AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) : 139 Expression( _aname ), expr(expr_), type(0), isType(false) { 126 140 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 127 141 } 128 142 129 AlignofExpr::AlignofExpr( Type *type_ ) :130 Expression( ), expr(0), type(type_), isType(true) {143 AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) : 144 Expression( _aname ), expr(0), type(type_), isType(true) { 131 145 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 132 146 } … … 141 155 } 142 156 143 void AlignofExpr::print( std::ostream &os, Indenterindent) const {157 void AlignofExpr::print( std::ostream &os, int indent) const { 144 158 os << "Alignof Expression on: "; 145 if (isType) type->print(os, indent+1); 146 else expr->print(os, indent+1); 147 Expression::print( os, indent ); 148 } 149 150 UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type, const std::string &member ) : 151 Expression(), type(type), member(member) { 152 assert( type ); 159 160 if (isType) 161 type->print(os, indent + 2); 162 else 163 expr->print(os, indent + 2); 164 165 os << std::endl; 166 Expression::print( os, indent ); 167 } 168 169 UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) : 170 Expression( _aname ), type(type_), member(member_) { 153 171 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 154 172 } … … 161 179 } 162 180 163 void UntypedOffsetofExpr::print( std::ostream &os, Indenter indent) const { 164 os << "Untyped Offsetof Expression on member " << member << " of "; 165 type->print(os, indent+1); 166 Expression::print( os, indent ); 167 } 168 169 OffsetofExpr::OffsetofExpr( Type *type, DeclarationWithType *member ) : 170 Expression(), type(type), member(member) { 171 assert( member ); 172 assert( type ); 181 void UntypedOffsetofExpr::print( std::ostream &os, int indent) const { 182 os << std::string( indent, ' ' ) << "Untyped Offsetof Expression on member " << member << " of "; 183 184 if ( type ) { 185 type->print(os, indent + 2); 186 } else { 187 os << "<NULL>"; 188 } 189 190 os << std::endl; 191 Expression::print( os, indent ); 192 } 193 194 OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) : 195 Expression( _aname ), type(type_), member(member_) { 173 196 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 174 197 } … … 181 204 } 182 205 183 void OffsetofExpr::print( std::ostream &os, Indenter indent) const { 184 os << "Offsetof Expression on member " << member->name << " of "; 185 type->print(os, indent+1); 186 Expression::print( os, indent ); 187 } 188 189 OffsetPackExpr::OffsetPackExpr( StructInstType *type ) : Expression(), type( type ) { 190 assert( type ); 206 void OffsetofExpr::print( std::ostream &os, int indent) const { 207 os << std::string( indent, ' ' ) << "Offsetof Expression on member "; 208 209 if ( member ) { 210 os << member->get_name(); 211 } else { 212 os << "<NULL>"; 213 } 214 215 os << " of "; 216 217 if ( type ) { 218 type->print(os, indent + 2); 219 } else { 220 os << "<NULL>"; 221 } 222 223 os << std::endl; 224 Expression::print( os, indent ); 225 } 226 227 OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) { 191 228 set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) ); 192 229 } … … 196 233 OffsetPackExpr::~OffsetPackExpr() { delete type; } 197 234 198 void OffsetPackExpr::print( std::ostream &os, Indenter indent ) const { 199 os << "Offset pack expression on "; 200 type->print(os, indent+1); 201 Expression::print( os, indent ); 202 } 203 204 AttrExpr::AttrExpr( Expression *attr, Expression *expr_ ) : 205 Expression(), attr( attr ), expr(expr_), type(0), isType(false) { 206 } 207 208 AttrExpr::AttrExpr( Expression *attr, Type *type_ ) : 209 Expression(), attr( attr ), expr(0), type(type_), isType(true) { 235 void OffsetPackExpr::print( std::ostream &os, int indent ) const { 236 os << std::string( indent, ' ' ) << "Offset pack expression on "; 237 238 if ( type ) { 239 type->print(os, indent + 2); 240 } else { 241 os << "<NULL>"; 242 } 243 244 os << std::endl; 245 Expression::print( os, indent ); 246 } 247 248 AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) : 249 Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) { 250 } 251 252 AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) : 253 Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) { 210 254 } 211 255 … … 220 264 } 221 265 222 void AttrExpr::print( std::ostream &os, Indenterindent) const {266 void AttrExpr::print( std::ostream &os, int indent) const { 223 267 os << "Attr "; 224 attr->print( os, indent +1);268 attr->print( os, indent + 2 ); 225 269 if ( isType || expr ) { 226 270 os << "applied to: "; 227 if (isType) type->print(os, indent+1); 228 else expr->print(os, indent+1); 271 272 if (isType) 273 type->print(os, indent + 2); 274 else 275 expr->print(os, indent + 2); 229 276 } // if 230 Expression::print( os, indent ); 231 } 232 233 CastExpr::CastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) { 277 278 os << std::endl; 279 Expression::print( os, indent ); 280 } 281 282 CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) { 234 283 set_result(toType); 235 284 } 236 285 237 CastExpr::CastExpr( Expression *arg_ ) : Expression(), arg(arg_) {286 CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) { 238 287 set_result( new VoidType( Type::Qualifiers() ) ); 239 288 } … … 246 295 } 247 296 248 void CastExpr::print( std::ostream &os, Indenter indent ) const { 249 os << "Cast of:" << std::endl << indent+1; 250 arg->print(os, indent+1); 251 os << std::endl << indent << "... to:"; 297 void CastExpr::print( std::ostream &os, int indent ) const { 298 os << "Cast of:" << std::endl << std::string( indent+2, ' ' ); 299 arg->print(os, indent+2); 300 os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl; 301 os << std::string( indent+2, ' ' ); 252 302 if ( result->isVoid() ) { 253 os << " nothing";303 os << "nothing"; 254 304 } else { 255 os << std::endl << indent+1; 256 result->print( os, indent+1 ); 305 result->print( os, indent+2 ); 257 306 } // if 307 os << std::endl; 258 308 Expression::print( os, indent ); 259 309 } … … 270 320 } 271 321 272 void VirtualCastExpr::print( std::ostream &os, Indenter indent ) const { 273 os << "Virtual Cast of:" << std::endl << indent+1; 274 arg->print(os, indent+1); 275 os << std::endl << indent << "... to:"; 322 void VirtualCastExpr::print( std::ostream &os, int indent ) const { 323 os << "Virtual Cast of:" << std::endl << std::string( indent+2, ' ' ); 324 arg->print(os, indent+2); 325 os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl; 326 os << std::string( indent+2, ' ' ); 276 327 if ( ! result ) { 277 os << " unknown";328 os << "unknown"; 278 329 } else { 279 os << std::endl << indent+1; 280 result->print( os, indent+1 ); 330 result->print( os, indent+2 ); 281 331 } // if 282 Expression::print( os, indent ); 283 } 284 285 UntypedMemberExpr::UntypedMemberExpr( Expression * member, Expression *aggregate ) : 286 Expression(), member(member), aggregate(aggregate) { 287 assert( aggregate ); 288 } 332 os << std::endl; 333 Expression::print( os, indent ); 334 } 335 336 UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) : 337 Expression( _aname ), member(_member), aggregate(_aggregate) {} 289 338 290 339 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) : … … 297 346 } 298 347 299 void UntypedMemberExpr::print( std::ostream &os, Indenter indent ) const { 300 os << "Untyped Member Expression, with field: " << std::endl << indent+1; 301 member->print(os, indent+1 ); 302 os << indent << "... from aggregate: " << std::endl << indent+1; 303 aggregate->print(os, indent+1); 348 void UntypedMemberExpr::print( std::ostream &os, int indent ) const { 349 os << "Untyped Member Expression, with field: " << std::endl; 350 os << std::string( indent+2, ' ' ); 351 get_member()->print(os, indent+4); 352 os << std::string( indent+2, ' ' ); 353 354 Expression *agg = get_aggregate(); 355 os << "from aggregate: " << std::endl; 356 if (agg != 0) { 357 os << std::string( indent + 4, ' ' ); 358 agg->print(os, indent + 4); 359 } 360 os << std::string( indent+2, ' ' ); 304 361 Expression::print( os, indent ); 305 362 } … … 320 377 321 378 322 MemberExpr::MemberExpr( DeclarationWithType *member, Expression *aggregate ) : 323 Expression(), member(member), aggregate(aggregate) { 324 assert( member ); 325 assert( aggregate ); 379 MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) : 380 Expression( _aname ), member(_member), aggregate(_aggregate) { 326 381 327 382 TypeSubstitution sub( makeSub( aggregate->get_result() ) ); … … 341 396 } 342 397 343 void MemberExpr::print( std::ostream &os, Indenterindent ) const {398 void MemberExpr::print( std::ostream &os, int indent ) const { 344 399 os << "Member Expression, with field: " << std::endl; 345 os << indent+1; 346 member->print( os, indent+1 ); 347 os << std::endl << indent << "... from aggregate: " << std::endl << indent+1; 348 aggregate->print(os, indent + 1); 349 Expression::print( os, indent ); 350 } 351 352 UntypedExpr::UntypedExpr( Expression *function, const std::list<Expression *> &args ) : 353 Expression(), function(function), args(args) {} 400 401 assert( member ); 402 os << std::string( indent + 2, ' ' ); 403 member->print( os, indent + 2 ); 404 os << std::endl; 405 406 Expression *agg = get_aggregate(); 407 os << std::string( indent, ' ' ) << "from aggregate: " << std::endl; 408 if (agg != 0) { 409 os << std::string( indent + 2, ' ' ); 410 agg->print(os, indent + 2); 411 } 412 os << std::string( indent+2, ' ' ); 413 Expression::print( os, indent ); 414 } 415 416 UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) : 417 Expression( _aname ), function(_function), args(_args) {} 354 418 355 419 UntypedExpr::UntypedExpr( const UntypedExpr &other ) : … … 392 456 393 457 394 void UntypedExpr::print( std::ostream &os, Indenterindent ) const {458 void UntypedExpr::print( std::ostream &os, int indent ) const { 395 459 os << "Applying untyped: " << std::endl; 396 os << indent+1; 397 function->print(os, indent+1); 398 os << std::endl << indent << "...to: " << std::endl; 399 printAll(args, os, indent+1); 400 Expression::print( os, indent ); 401 } 402 403 NameExpr::NameExpr( std::string name ) : Expression(), name(name) { 404 assertf(name != "0", "Zero is not a valid name"); 405 assertf(name != "1", "One is not a valid name"); 460 os << std::string( indent+2, ' ' ); 461 function->print(os, indent + 2); 462 os << std::string( indent, ' ' ) << "...to: " << std::endl; 463 printAll(args, os, indent + 2); 464 Expression::print( os, indent ); 465 } 466 467 void UntypedExpr::printArgs( std::ostream &os, int indent ) const { 468 std::list<Expression *>::const_iterator i; 469 for (i = args.begin(); i != args.end(); i++) { 470 os << std::string(indent, ' ' ); 471 (*i)->print(os, indent); 472 } 473 } 474 475 NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) { 476 assertf(_name != "0", "Zero is not a valid name\n"); 477 assertf(_name != "1", "One is not a valid name\n"); 406 478 } 407 479 … … 411 483 NameExpr::~NameExpr() {} 412 484 413 void NameExpr::print( std::ostream &os, Indenterindent ) const {414 os << "Name: " << get_name() ;415 Expression::print( os, indent ); 416 } 417 418 LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp ) :419 Expression( ), arg1(arg1_), arg2(arg2_), isAnd(andp) {485 void NameExpr::print( std::ostream &os, int indent ) const { 486 os << "Name: " << get_name() << std::endl; 487 Expression::print( os, indent ); 488 } 489 490 LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) : 491 Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) { 420 492 set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 421 493 } … … 430 502 } 431 503 432 void LogicalExpr::print( std::ostream &os, Indenterindent )const {433 os << "Short-circuited operation (" << (isAnd ? "and" :"or") << ") on: ";504 void LogicalExpr::print( std::ostream &os, int indent )const { 505 os << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: "; 434 506 arg1->print(os); 435 507 os << " and "; 436 508 arg2->print(os); 437 Expression::print( os, indent ); 438 } 439 440 ConditionalExpr::ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 ) : 441 Expression(), arg1(arg1), arg2(arg2), arg3(arg3) {} 509 os << std::endl; 510 Expression::print( os, indent ); 511 } 512 513 ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) : 514 Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {} 442 515 443 516 ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) : … … 451 524 } 452 525 453 void ConditionalExpr::print( std::ostream &os, Indenter indent ) const { 454 os << "Conditional expression on: " << std::endl << indent+1; 455 arg1->print( os, indent+1 ); 456 os << indent << "First alternative:" << std::endl << indent+1; 457 arg2->print( os, indent+1 ); 458 os << indent << "Second alternative:" << std::endl << indent+1; 459 arg3->print( os, indent+1 ); 526 void ConditionalExpr::print( std::ostream &os, int indent ) const { 527 os << "Conditional expression on: " << std::endl; 528 os << std::string( indent+2, ' ' ); 529 arg1->print( os, indent+2 ); 530 os << std::string( indent, ' ' ) << "First alternative:" << std::endl; 531 os << std::string( indent+2, ' ' ); 532 arg2->print( os, indent+2 ); 533 os << std::string( indent, ' ' ) << "Second alternative:" << std::endl; 534 os << std::string( indent+2, ' ' ); 535 arg3->print( os, indent+2 ); 536 os << std::endl; 460 537 Expression::print( os, indent ); 461 538 } … … 464 541 465 542 466 void AsmExpr::print( std::ostream &os, Indenterindent ) const {543 void AsmExpr::print( std::ostream &os, int indent ) const { 467 544 os << "Asm Expression: " << std::endl; 468 if ( inout ) inout->print( os, indent +1);469 if ( constraint ) constraint->print( os, indent +1);470 if ( operand ) operand->print( os, indent +1);545 if ( inout ) inout->print( os, indent + 2 ); 546 if ( constraint ) constraint->print( os, indent + 2 ); 547 if ( operand ) operand->print( os, indent + 2 ); 471 548 } 472 549 … … 474 551 ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) { 475 552 assert( callExpr ); 476 assert( callExpr-> result);553 assert( callExpr->has_result() ); 477 554 set_result( callExpr->get_result()->clone() ); 478 555 } … … 492 569 } 493 570 494 void ImplicitCopyCtorExpr::print( std::ostream &os, Indenter indent ) const { 495 os << "Implicit Copy Constructor Expression: " << std::endl << indent+1; 496 callExpr->print( os, indent+1 ); 497 os << std::endl << indent << "... with temporaries:" << std::endl; 498 printAll( tempDecls, os, indent+1 ); 499 os << std::endl << indent << "... with return temporaries:" << std::endl; 500 printAll( returnDecls, os, indent+1 ); 571 void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const { 572 os << "Implicit Copy Constructor Expression: " << std::endl; 573 assert( callExpr ); 574 os << std::string( indent+2, ' ' ); 575 callExpr->print( os, indent + 2 ); 576 os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl; 577 printAll(tempDecls, os, indent+2); 578 os << std::endl << std::string( indent, ' ' ) << "with return temporaries:" << std::endl; 579 printAll(returnDecls, os, indent+2); 501 580 Expression::print( os, indent ); 502 581 } … … 508 587 Expression * arg = InitTweak::getCallArg( callExpr, 0 ); 509 588 assert( arg ); 510 set_result( maybeClone( arg-> result) );589 set_result( maybeClone( arg->get_result() ) ); 511 590 } 512 591 … … 518 597 } 519 598 520 void ConstructorExpr::print( std::ostream &os, Indenter indent ) const { 521 os << "Constructor Expression: " << std::endl << indent+1; 599 void ConstructorExpr::print( std::ostream &os, int indent ) const { 600 os << "Constructor Expression: " << std::endl; 601 assert( callExpr ); 602 os << std::string( indent+2, ' ' ); 522 603 callExpr->print( os, indent + 2 ); 523 604 Expression::print( os, indent ); … … 537 618 } 538 619 539 void CompoundLiteralExpr::print( std::ostream &os, Indenter indent ) const { 540 os << "Compound Literal Expression: " << std::endl << indent+1; 541 result->print( os, indent+1 ); 542 os << indent+1; 543 initializer->print( os, indent+1 ); 620 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const { 621 os << "Compound Literal Expression: " << std::endl; 622 os << std::string( indent+2, ' ' ); 623 get_result()->print( os, indent + 2 ); 624 os << std::string( indent+2, ' ' ); 625 initializer->print( os, indent + 2 ); 544 626 Expression::print( os, indent ); 545 627 } … … 547 629 RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {} 548 630 RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {} 549 void RangeExpr::print( std::ostream &os, Indenterindent ) const {631 void RangeExpr::print( std::ostream &os, int indent ) const { 550 632 os << "Range Expression: "; 551 633 low->print( os, indent ); … … 577 659 deleteAll( returnDecls ); 578 660 } 579 void StmtExpr::print( std::ostream &os, Indenterindent ) const {580 os << "Statement Expression: " << std::endl << indent+1;581 statements->print( os, indent+ 1);661 void StmtExpr::print( std::ostream &os, int indent ) const { 662 os << "Statement Expression: " << std::endl << std::string( indent, ' ' ); 663 statements->print( os, indent+2 ); 582 664 if ( ! returnDecls.empty() ) { 583 os << indent+1 << "...with returnDecls: ";584 printAll( returnDecls, os, indent+ 1);665 os << std::string( indent+2, ' ' ) << "with returnDecls: "; 666 printAll( returnDecls, os, indent+2 ); 585 667 } 586 668 if ( ! dtors.empty() ) { 587 os << indent+1 << "...with dtors: ";588 printAll( dtors, os, indent+ 1);669 os << std::string( indent+2, ' ' ) << "with dtors: "; 670 printAll( dtors, os, indent+2 ); 589 671 } 590 672 Expression::print( os, indent ); … … 608 690 delete var; 609 691 } 610 void UniqueExpr::print( std::ostream &os, Indenterindent ) const {611 os << "Unique Expression with id:" << id << std::endl << indent+1;612 expr->print( os, indent+1);613 if ( object) {614 os << indent << "...with decl: ";615 get_object()->printShort( os, indent+ 1);692 void UniqueExpr::print( std::ostream &os, int indent ) const { 693 os << "Unique Expression with id:" << id << std::endl << std::string( indent+2, ' ' ); 694 get_expr()->print( os, indent+2 ); 695 if ( get_object() ) { 696 os << std::string( indent+2, ' ' ) << "with decl: "; 697 get_object()->printShort( os, indent+2 ); 616 698 } 617 699 Expression::print( os, indent ); … … 631 713 } 632 714 633 void UntypedInitExpr::print( std::ostream & os, Indenterindent ) const {634 os << "Untyped Init Expression" << std::endl << indent+1;635 expr->print( os, indent+ 1);715 void UntypedInitExpr::print( std::ostream & os, int indent ) const { 716 os << "Untyped Init Expression" << std::endl << std::string( indent+2, ' ' ); 717 expr->print( os, indent+2 ); 636 718 if ( ! initAlts.empty() ) { 637 719 for ( const InitAlternative & alt : initAlts ) { 638 os << indent+1<< "InitAlternative: ";639 alt.type->print( os, indent+ 1);640 alt.designation->print( os, indent+ 1);720 os << std::string( indent+2, ' ' ) << "InitAlternative: "; 721 alt.type->print( os, indent+2 ); 722 alt.designation->print( os, indent+2 ); 641 723 } 642 724 } … … 652 734 } 653 735 654 void InitExpr::print( std::ostream & os, Indenterindent ) const {655 os << "Init Expression" << std::endl << indent+1;656 expr->print( os, indent+ 1);657 os << indent+1 << "...with designation: ";658 designation->print( os, indent+ 1);736 void InitExpr::print( std::ostream & os, int indent ) const { 737 os << "Init Expression" << std::endl << std::string( indent+2, ' ' ); 738 expr->print( os, indent+2 ); 739 os << std::string( indent+2, ' ' ) << "with designation: "; 740 designation->print( os, indent+2 ); 659 741 } 660 742 -
src/SynTree/Expression.h
r7821d6c re1ff775 36 36 Type * result; 37 37 TypeSubstitution * env; 38 Expression * argName; // if expression is used as an argument, it can be "designated" by this name 38 39 bool extension = false; 39 40 40 Expression( );41 Expression( Expression * _aname = nullptr ); 41 42 Expression( const Expression & other ); 42 43 virtual ~Expression(); … … 45 46 const Type * get_result() const { return result; } 46 47 void set_result( Type * newValue ) { result = newValue; } 48 bool has_result() const { return result != nullptr; } 47 49 48 50 TypeSubstitution * get_env() const { return env; } 49 51 void set_env( TypeSubstitution * newValue ) { env = newValue; } 52 Expression * get_argName() const { return argName; } 53 void set_argName( Expression * name ) { argName = name; } 50 54 bool get_extension() const { return extension; } 51 55 Expression * set_extension( bool exten ) { extension = exten; return this; } … … 54 58 virtual void accept( Visitor & v ) override = 0; 55 59 virtual Expression * acceptMutator( Mutator & m ) override = 0; 56 virtual void print( std::ostream & os, Indenter indent = {}) const override;60 virtual void print( std::ostream & os, int indent = 0 ) const override; 57 61 }; 58 62 … … 97 101 virtual void accept( Visitor & v ) { v.visit( this ); } 98 102 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 99 virtual void print( std::ostream & os, Indenter indent = {}) const;103 virtual void print( std::ostream & os, int indent = 0 ) const; 100 104 }; 101 105 … … 108 112 std::list<Expression*> args; 109 113 110 UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() );114 UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >(), Expression *_aname = nullptr ); 111 115 UntypedExpr( const UntypedExpr & other ); 112 116 virtual ~UntypedExpr(); … … 115 119 void set_function( Expression * newValue ) { function = newValue; } 116 120 121 void set_args( std::list<Expression *> & listArgs ) { args = listArgs; } 117 122 std::list<Expression*>::iterator begin_args() { return args.begin(); } 118 123 std::list<Expression*>::iterator end_args() { return args.end(); } … … 125 130 virtual void accept( Visitor & v ) { v.visit( this ); } 126 131 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 127 virtual void print( std::ostream & os, Indenter indent = {} ) const; 132 virtual void print( std::ostream & os, int indent = 0 ) const; 133 virtual void printArgs(std::ostream & os, int indent = 0) const; 128 134 }; 129 135 … … 133 139 std::string name; 134 140 135 NameExpr( std::string name );141 NameExpr( std::string name, Expression *_aname = nullptr ); 136 142 NameExpr( const NameExpr & other ); 137 143 virtual ~NameExpr(); … … 143 149 virtual void accept( Visitor & v ) { v.visit( this ); } 144 150 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 145 virtual void print( std::ostream & os, Indenter indent = {}) const;151 virtual void print( std::ostream & os, int indent = 0 ) const; 146 152 }; 147 153 … … 154 160 Expression * arg; 155 161 156 AddressExpr( Expression * arg );162 AddressExpr( Expression * arg, Expression *_aname = nullptr ); 157 163 AddressExpr( const AddressExpr & other ); 158 164 virtual ~AddressExpr(); … … 164 170 virtual void accept( Visitor & v ) { v.visit( this ); } 165 171 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 166 virtual void print( std::ostream & os, Indenter indent = {}) const;172 virtual void print( std::ostream & os, int indent = 0 ) const; 167 173 }; 168 174 … … 180 186 virtual void accept( Visitor & v ) { v.visit( this ); } 181 187 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 182 virtual void print( std::ostream & os, Indenter indent = {}) const;188 virtual void print( std::ostream & os, int indent = 0 ) const; 183 189 }; 184 190 … … 188 194 Expression * arg; 189 195 190 CastExpr( Expression * arg );191 CastExpr( Expression * arg, Type * toType );196 CastExpr( Expression * arg, Expression *_aname = nullptr ); 197 CastExpr( Expression * arg, Type * toType, Expression *_aname = nullptr ); 192 198 CastExpr( const CastExpr & other ); 193 199 virtual ~CastExpr(); … … 199 205 virtual void accept( Visitor & v ) { v.visit( this ); } 200 206 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 201 virtual void print( std::ostream & os, Indenter indent = {}) const;207 virtual void print( std::ostream & os, int indent = 0 ) const; 202 208 }; 203 209 … … 217 223 virtual void accept( Visitor & v ) { v.visit( this ); } 218 224 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 219 virtual void print( std::ostream & os, Indenter indent = {}) const;225 virtual void print( std::ostream & os, int indent = 0 ) const; 220 226 }; 221 227 … … 226 232 Expression * aggregate; 227 233 228 UntypedMemberExpr( Expression * member, Expression * aggregate );234 UntypedMemberExpr( Expression * member, Expression * aggregate, Expression *_aname = nullptr ); 229 235 UntypedMemberExpr( const UntypedMemberExpr & other ); 230 236 virtual ~UntypedMemberExpr(); … … 238 244 virtual void accept( Visitor & v ) { v.visit( this ); } 239 245 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 240 virtual void print( std::ostream & os, Indenter indent = {}) const;246 virtual void print( std::ostream & os, int indent = 0 ) const; 241 247 }; 242 248 … … 248 254 Expression * aggregate; 249 255 250 MemberExpr( DeclarationWithType * member, Expression * aggregate );256 MemberExpr( DeclarationWithType * member, Expression * aggregate, Expression *_aname = nullptr ); 251 257 MemberExpr( const MemberExpr & other ); 252 258 virtual ~MemberExpr(); … … 260 266 virtual void accept( Visitor & v ) { v.visit( this ); } 261 267 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 262 virtual void print( std::ostream & os, Indenter indent = {}) const;268 virtual void print( std::ostream & os, int indent = 0 ) const; 263 269 }; 264 270 … … 269 275 DeclarationWithType * var; 270 276 271 VariableExpr( DeclarationWithType * var );277 VariableExpr( DeclarationWithType * var, Expression *_aname = nullptr ); 272 278 VariableExpr( const VariableExpr & other ); 273 279 virtual ~VariableExpr(); … … 281 287 virtual void accept( Visitor & v ) { v.visit( this ); } 282 288 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 283 virtual void print( std::ostream & os, Indenter indent = {}) const;289 virtual void print( std::ostream & os, int indent = 0 ) const; 284 290 }; 285 291 … … 289 295 Constant constant; 290 296 291 ConstantExpr( Constant constant );297 ConstantExpr( Constant constant, Expression *_aname = nullptr ); 292 298 ConstantExpr( const ConstantExpr & other ); 293 299 virtual ~ConstantExpr(); … … 299 305 virtual void accept( Visitor & v ) { v.visit( this ); } 300 306 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 301 virtual void print( std::ostream & os, Indenter indent = {}) const;307 virtual void print( std::ostream & os, int indent = 0 ) const; 302 308 }; 303 309 … … 309 315 bool isType; 310 316 311 SizeofExpr( Expression * expr );317 SizeofExpr( Expression * expr, Expression *_aname = nullptr ); 312 318 SizeofExpr( const SizeofExpr & other ); 313 SizeofExpr( Type * type );319 SizeofExpr( Type * type, Expression *_aname = nullptr ); 314 320 virtual ~SizeofExpr(); 315 321 … … 324 330 virtual void accept( Visitor & v ) { v.visit( this ); } 325 331 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 326 virtual void print( std::ostream & os, Indenter indent = {}) const;332 virtual void print( std::ostream & os, int indent = 0 ) const; 327 333 }; 328 334 … … 334 340 bool isType; 335 341 336 AlignofExpr( Expression * expr );342 AlignofExpr( Expression * expr, Expression *_aname = nullptr ); 337 343 AlignofExpr( const AlignofExpr & other ); 338 AlignofExpr( Type * type );344 AlignofExpr( Type * type, Expression *_aname = nullptr ); 339 345 virtual ~AlignofExpr(); 340 346 … … 349 355 virtual void accept( Visitor & v ) { v.visit( this ); } 350 356 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 351 virtual void print( std::ostream & os, Indenter indent = {}) const;357 virtual void print( std::ostream & os, int indent = 0 ) const; 352 358 }; 353 359 … … 358 364 std::string member; 359 365 360 UntypedOffsetofExpr( Type * type, const std::string & member );366 UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr ); 361 367 UntypedOffsetofExpr( const UntypedOffsetofExpr & other ); 362 368 virtual ~UntypedOffsetofExpr(); … … 370 376 virtual void accept( Visitor & v ) { v.visit( this ); } 371 377 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 372 virtual void print( std::ostream & os, Indenter indent = {}) const;378 virtual void print( std::ostream & os, int indent = 0 ) const; 373 379 }; 374 380 … … 379 385 DeclarationWithType * member; 380 386 381 OffsetofExpr( Type * type, DeclarationWithType * member );387 OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr ); 382 388 OffsetofExpr( const OffsetofExpr & other ); 383 389 virtual ~OffsetofExpr(); … … 391 397 virtual void accept( Visitor & v ) { v.visit( this ); } 392 398 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 393 virtual void print( std::ostream & os, Indenter indent = {}) const;399 virtual void print( std::ostream & os, int indent = 0 ) const; 394 400 }; 395 401 … … 399 405 StructInstType * type; 400 406 401 OffsetPackExpr( StructInstType * type );407 OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 ); 402 408 OffsetPackExpr( const OffsetPackExpr & other ); 403 409 virtual ~OffsetPackExpr(); … … 409 415 virtual void accept( Visitor & v ) { v.visit( this ); } 410 416 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 411 virtual void print( std::ostream & os, Indenter indent = {}) const;417 virtual void print( std::ostream & os, int indent = 0 ) const; 412 418 }; 413 419 … … 420 426 bool isType; 421 427 422 AttrExpr(Expression * attr, Expression * expr );428 AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr ); 423 429 AttrExpr( const AttrExpr & other ); 424 AttrExpr( Expression * attr, Type * type );430 AttrExpr( Expression * attr, Type * type, Expression *_aname = nullptr ); 425 431 virtual ~AttrExpr(); 426 432 … … 437 443 virtual void accept( Visitor & v ) { v.visit( this ); } 438 444 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 439 virtual void print( std::ostream & os, Indenter indent = {}) const;445 virtual void print( std::ostream & os, int indent = 0 ) const; 440 446 }; 441 447 … … 446 452 Expression * arg2; 447 453 448 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true );454 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr ); 449 455 LogicalExpr( const LogicalExpr & other ); 450 456 virtual ~LogicalExpr(); … … 459 465 virtual void accept( Visitor & v ) { v.visit( this ); } 460 466 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 461 virtual void print( std::ostream & os, Indenter indent = {}) const;467 virtual void print( std::ostream & os, int indent = 0 ) const; 462 468 463 469 private: … … 472 478 Expression * arg3; 473 479 474 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 );480 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr ); 475 481 ConditionalExpr( const ConditionalExpr & other ); 476 482 virtual ~ConditionalExpr(); … … 486 492 virtual void accept( Visitor & v ) { v.visit( this ); } 487 493 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 488 virtual void print( std::ostream & os, Indenter indent = {}) const;494 virtual void print( std::ostream & os, int indent = 0 ) const; 489 495 }; 490 496 … … 495 501 Expression * arg2; 496 502 497 CommaExpr( Expression * arg1, Expression * arg2 );503 CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr ); 498 504 CommaExpr( const CommaExpr & other ); 499 505 virtual ~CommaExpr(); … … 507 513 virtual void accept( Visitor & v ) { v.visit( this ); } 508 514 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 509 virtual void print( std::ostream & os, Indenter indent = {}) const;515 virtual void print( std::ostream & os, int indent = 0 ) const; 510 516 }; 511 517 … … 525 531 virtual void accept( Visitor & v ) { v.visit( this ); } 526 532 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 527 virtual void print( std::ostream & os, Indenter indent = {}) const;533 virtual void print( std::ostream & os, int indent = 0 ) const; 528 534 }; 529 535 … … 551 557 virtual void accept( Visitor & v ) { v.visit( this ); } 552 558 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 553 virtual void print( std::ostream & os, Indenter indent = {}) const;559 virtual void print( std::ostream & os, int indent = 0 ) const; 554 560 555 561 // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints … … 579 585 virtual void accept( Visitor & v ) { v.visit( this ); } 580 586 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 581 virtual void print( std::ostream & os, Indenter indent = {}) const;587 virtual void print( std::ostream & os, int indent = 0 ) const; 582 588 }; 583 589 … … 597 603 virtual void accept( Visitor & v ) { v.visit( this ); } 598 604 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 599 virtual void print( std::ostream & os, Indenter indent = {}) const;605 virtual void print( std::ostream & os, int indent = 0 ) const; 600 606 }; 601 607 … … 615 621 virtual void accept( Visitor & v ) { v.visit( this ); } 616 622 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 617 virtual void print( std::ostream & os, Indenter indent = {}) const;623 virtual void print( std::ostream & os, int indent = 0 ) const; 618 624 }; 619 625 … … 634 640 virtual void accept( Visitor & v ) { v.visit( this ); } 635 641 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 636 virtual void print( std::ostream & os, Indenter indent = {}) const;642 virtual void print( std::ostream & os, int indent = 0 ) const; 637 643 }; 638 644 … … 642 648 std::list<Expression*> exprs; 643 649 644 UntypedTupleExpr( const std::list< Expression * > & exprs );650 UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr ); 645 651 UntypedTupleExpr( const UntypedTupleExpr & other ); 646 652 virtual ~UntypedTupleExpr(); … … 651 657 virtual void accept( Visitor & v ) { v.visit( this ); } 652 658 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 653 virtual void print( std::ostream & os, Indenter indent = {}) const;659 virtual void print( std::ostream & os, int indent = 0 ) const; 654 660 }; 655 661 … … 659 665 std::list<Expression*> exprs; 660 666 661 TupleExpr( const std::list< Expression * > & exprs );667 TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr ); 662 668 TupleExpr( const TupleExpr & other ); 663 669 virtual ~TupleExpr(); … … 668 674 virtual void accept( Visitor & v ) { v.visit( this ); } 669 675 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 670 virtual void print( std::ostream & os, Indenter indent = {}) const;676 virtual void print( std::ostream & os, int indent = 0 ) const; 671 677 }; 672 678 … … 689 695 virtual void accept( Visitor & v ) { v.visit( this ); } 690 696 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 691 virtual void print( std::ostream & os, Indenter indent = {}) const;697 virtual void print( std::ostream & os, int indent = 0 ) const; 692 698 }; 693 699 … … 697 703 StmtExpr * stmtExpr = nullptr; 698 704 699 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls );705 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr ); 700 706 TupleAssignExpr( const TupleAssignExpr & other ); 701 707 virtual ~TupleAssignExpr(); … … 707 713 virtual void accept( Visitor & v ) { v.visit( this ); } 708 714 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 709 virtual void print( std::ostream & os, Indenter indent = {}) const;715 virtual void print( std::ostream & os, int indent = 0 ) const; 710 716 }; 711 717 … … 730 736 virtual void accept( Visitor & v ) { v.visit( this ); } 731 737 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 732 virtual void print( std::ostream & os, Indenter indent = {}) const;738 virtual void print( std::ostream & os, int indent = 0 ) const; 733 739 }; 734 740 … … 757 763 virtual void accept( Visitor & v ) { v.visit( this ); } 758 764 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 759 virtual void print( std::ostream & os, Indenter indent = {}) const;765 virtual void print( std::ostream & os, int indent = 0 ) const; 760 766 761 767 private: … … 791 797 virtual void accept( Visitor & v ) { v.visit( this ); } 792 798 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 793 virtual void print( std::ostream & os, Indenter indent = {}) const;799 virtual void print( std::ostream & os, int indent = 0 ) const; 794 800 }; 795 801 … … 812 818 virtual void accept( Visitor & v ) { v.visit( this ); } 813 819 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 814 virtual void print( std::ostream & os, Indenter indent = {}) const;820 virtual void print( std::ostream & os, int indent = 0 ) const; 815 821 }; 816 822 -
src/SynTree/FunctionDecl.cc
r7821d6c re1ff775 63 63 } 64 64 65 void FunctionDecl::print( std::ostream &os, Indenterindent ) const {65 void FunctionDecl::print( std::ostream &os, int indent ) const { 66 66 using std::endl; 67 67 using std::string; 68 68 69 if ( name!= "" ) {70 os << name<< ": ";69 if ( get_name() != "" ) { 70 os << get_name() << ": "; 71 71 } // if 72 if ( linkage!= LinkageSpec::Cforall ) {73 os << LinkageSpec::linkageName( linkage) << " ";72 if ( get_linkage() != LinkageSpec::Cforall ) { 73 os << LinkageSpec::linkageName( get_linkage() ) << " "; 74 74 } // if 75 75 76 printAll( attributes, os, indent );76 printAll( get_attributes(), os, indent ); 77 77 78 78 get_storageClasses().print( os ); 79 79 get_funcSpec().print( os ); 80 80 81 if ( type) {82 type->print( os, indent );81 if ( get_type() ) { 82 get_type()->print( os, indent ); 83 83 } else { 84 84 os << "untyped entity "; … … 86 86 87 87 if ( statements ) { 88 os << indent << "... with body " << endl << indent+1; 89 statements->print( os, indent+1 ); 88 os << string( indent + 2, ' ' ) << "with body " << endl; 89 os << string( indent + 4, ' ' ); 90 statements->print( os, indent + 4 ); 90 91 } // if 91 92 } 92 93 93 void FunctionDecl::printShort( std::ostream &os, Indenterindent ) const {94 void FunctionDecl::printShort( std::ostream &os, int indent ) const { 94 95 using std::endl; 95 96 using std::string; 96 97 97 if ( name!= "" ) {98 os << name<< ": ";98 if ( get_name() != "" ) { 99 os << get_name() << ": "; 99 100 } // if 101 102 // xxx - should printShort print attributes? 100 103 101 104 get_storageClasses().print( os ); 102 105 get_funcSpec().print( os ); 103 106 104 if ( type) {105 type->print( os, indent );107 if ( get_type() ) { 108 get_type()->print( os, indent ); 106 109 } else { 107 110 os << "untyped entity "; -
src/SynTree/FunctionType.cc
r7821d6c re1ff775 51 51 } 52 52 53 void FunctionType::print( std::ostream &os, Indenterindent ) const {53 void FunctionType::print( std::ostream &os, int indent ) const { 54 54 using std::string; 55 55 using std::endl; … … 58 58 os << "function" << endl; 59 59 if ( ! parameters.empty() ) { 60 os << indent << "...with parameters" << endl;61 printAll( parameters, os, indent +1);60 os << string( indent + 2, ' ' ) << "with parameters" << endl; 61 printAll( parameters, os, indent + 4 ); 62 62 if ( isVarArgs ) { 63 os << indent+1<< "and a variable number of other arguments" << endl;63 os << string( indent + 4, ' ' ) << "and a variable number of other arguments" << endl; 64 64 } // if 65 65 } else if ( isVarArgs ) { 66 os << indent+1<< "accepting unspecified arguments" << endl;66 os << string( indent + 4, ' ' ) << "accepting unspecified arguments" << endl; 67 67 } // if 68 os << indent << "...returning ";68 os << string( indent + 2, ' ' ) << "returning "; 69 69 if ( returnVals.empty() ) { 70 os << "nothing " << endl;70 os << endl << string( indent + 4, ' ' ) << "nothing " << endl; 71 71 } else { 72 72 os << endl; 73 printAll( returnVals, os, indent +1);73 printAll( returnVals, os, indent + 4 ); 74 74 } // if 75 75 } -
src/SynTree/Initializer.cc
r7821d6c re1ff775 38 38 } 39 39 40 void Designation::print( std::ostream &os, Indenterindent ) const {40 void Designation::print( std::ostream &os, int indent ) const { 41 41 if ( ! designators.empty() ) { 42 os << "... designated by: " << std::endl; 43 for ( const Expression * d : designators ) { 44 os << indent+1; 45 d->print(os, indent+1 ); 46 os << std::endl; 42 os << std::string(indent + 2, ' ' ) << "designated by: " << std::endl; 43 for ( std::list < Expression * >::const_iterator i = designators.begin(); i != designators.end(); i++ ) { 44 os << std::string(indent + 4, ' ' ); 45 ( *i )->print(os, indent + 4 ); 47 46 } 47 os << std::endl; 48 48 } // if 49 49 } … … 64 64 } 65 65 66 void SingleInit::print( std::ostream &os, Indenter indent ) const { 67 os << "Simple Initializer: "; 68 value->print( os, indent ); 66 void SingleInit::print( std::ostream &os, int indent ) const { 67 os << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl; 68 os << std::string(indent+4, ' ' ); 69 value->print( os, indent+4 ); 69 70 } 70 71 … … 92 93 } 93 94 94 void ListInit::print( std::ostream &os, Indenter indent ) const { 95 os << "Compound initializer: " << std::endl; 96 for ( auto p : group_iterate( designations, initializers ) ) { 97 const Designation * d = std::get<0>(p); 98 const Initializer * init = std::get<1>(p); 99 os << indent+1; 100 init->print( os, indent+1 ); 95 void ListInit::print( std::ostream &os, int indent ) const { 96 os << std::string(indent, ' ') << "Compound initializer: " << std::endl; 97 for ( Designation * d : designations ) { 98 d->print( os, indent + 2 ); 99 } 100 101 for ( const Initializer * init : initializers ) { 102 init->print( os, indent + 2 ); 101 103 os << std::endl; 102 if ( ! d->designators.empty() ) {103 os << indent+1;104 d->print( os, indent+1 );105 }106 104 } 107 105 } … … 118 116 } 119 117 120 void ConstructorInit::print( std::ostream &os, Indenterindent ) const {121 os << "Constructor initializer: " << std::endl;118 void ConstructorInit::print( std::ostream &os, int indent ) const { 119 os << std::endl << std::string(indent, ' ') << "Constructor initializer: " << std::endl; 122 120 if ( ctor ) { 123 os << indent << "... initially constructed with "; 124 ctor->print( os, indent+1 ); 121 os << std::string(indent+2, ' '); 122 os << "initially constructed with "; 123 ctor->print( os, indent+4 ); 125 124 } // if 126 125 127 126 if ( dtor ) { 128 os << indent << "... destructed with "; 129 dtor->print( os, indent+1 ); 127 os << std::string(indent+2, ' '); 128 os << "destructed with "; 129 dtor->print( os, indent+4 ); 130 130 } 131 131 132 132 if ( init ) { 133 os << indent << "... with fallback C-style initializer: "; 134 init->print( os, indent+1 ); 133 os << std::string(indent+2, ' '); 134 os << "with fallback C-style initializer: "; 135 init->print( os, indent+4 ); 135 136 } 136 137 } -
src/SynTree/Initializer.h
r7821d6c re1ff775 40 40 virtual void accept( Visitor &v ) override { v.visit( this ); } 41 41 virtual Designation * acceptMutator( Mutator &m ) override { return m.mutate( this ); } 42 virtual void print( std::ostream &os, Indenter indent = {}) const override;42 virtual void print( std::ostream &os, int indent = 0 ) const override; 43 43 }; 44 44 … … 57 57 virtual void accept( Visitor &v ) override = 0; 58 58 virtual Initializer *acceptMutator( Mutator &m ) override = 0; 59 virtual void print( std::ostream &os, Indenter indent = {}) const override = 0;59 virtual void print( std::ostream &os, int indent = 0 ) const override = 0; 60 60 private: 61 61 bool maybeConstructed; … … 78 78 virtual void accept( Visitor &v ) override { v.visit( this ); } 79 79 virtual Initializer *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 80 virtual void print( std::ostream &os, Indenter indent = {}) const override;80 virtual void print( std::ostream &os, int indent = 0 ) const override; 81 81 }; 82 82 … … 106 106 virtual void accept( Visitor &v ) override { v.visit( this ); } 107 107 virtual Initializer *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 108 virtual void print( std::ostream &os, Indenter indent = {}) const override;108 virtual void print( std::ostream &os, int indent = 0 ) const override; 109 109 }; 110 110 … … 135 135 virtual void accept( Visitor &v ) override { v.visit( this ); } 136 136 virtual Initializer *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 137 virtual void print( std::ostream &os, Indenter indent = {}) const override;137 virtual void print( std::ostream &os, int indent = 0 ) const override; 138 138 139 139 private: -
src/SynTree/NamedTypeDecl.cc
r7821d6c re1ff775 38 38 } 39 39 40 void NamedTypeDecl::print( std::ostream &os, Indenterindent ) const {40 void NamedTypeDecl::print( std::ostream &os, int indent ) const { 41 41 using namespace std; 42 42 43 if ( name != "" ) os << name << ": "; 44 45 if ( linkage != LinkageSpec::Cforall ) { 46 os << LinkageSpec::linkageName( linkage ) << " "; 43 if ( get_name() != "" ) { 44 os << get_name() << ": "; 45 } // if 46 if ( get_linkage() != LinkageSpec::Cforall ) { 47 os << LinkageSpec::linkageName( get_linkage() ) << " "; 47 48 } // if 48 49 get_storageClasses().print( os ); … … 50 51 if ( base ) { 51 52 os << " for "; 52 base->print( os, indent +1);53 base->print( os, indent ); 53 54 } // if 54 55 if ( ! parameters.empty() ) { 55 os << endl << indent << "...with parameters" << endl;56 printAll( parameters, os, indent+ 1);56 os << endl << string( indent, ' ' ) << "with parameters" << endl; 57 printAll( parameters, os, indent+2 ); 57 58 } // if 58 59 if ( ! assertions.empty() ) { 59 os << endl << indent << "...with assertions" << endl;60 printAll( assertions, os, indent+ 1);60 os << endl << string( indent, ' ' ) << "with assertions" << endl; 61 printAll( assertions, os, indent+2 ); 61 62 } // if 62 63 } 63 64 64 void NamedTypeDecl::printShort( std::ostream &os, Indenterindent ) const {65 void NamedTypeDecl::printShort( std::ostream &os, int indent ) const { 65 66 using namespace std; 66 67 67 if ( name != "" ) os << name << ": "; 68 if ( get_name() != "" ) { 69 os << get_name() << ": "; 70 } // if 68 71 get_storageClasses().print( os ); 69 72 os << typeString(); 70 73 if ( base ) { 71 74 os << " for "; 72 base->print( os, indent +1);75 base->print( os, indent ); 73 76 } // if 74 77 if ( ! parameters.empty() ) { 75 os << endl << indent << "...with parameters" << endl;76 printAll( parameters, os, indent+ 1);78 os << endl << string( indent, ' ' ) << "with parameters" << endl; 79 printAll( parameters, os, indent+2 ); 77 80 } // if 78 81 } -
src/SynTree/ObjectDecl.cc
r7821d6c re1ff775 44 44 } 45 45 46 void ObjectDecl::print( std::ostream &os, Indenter indent ) const { 47 if ( name != "" ) os << name << ": "; 46 void ObjectDecl::print( std::ostream &os, int indent ) const { 47 if ( get_name() != "" ) { 48 os << get_name() << ": "; 49 } // if 48 50 49 if ( linkage!= LinkageSpec::Cforall ) {50 os << LinkageSpec::linkageName( linkage) << " ";51 if ( get_linkage() != LinkageSpec::Cforall ) { 52 os << LinkageSpec::linkageName( get_linkage() ) << " "; 51 53 } // if 54 55 printAll( get_attributes(), os, indent ); 52 56 53 57 get_storageClasses().print( os ); 54 58 55 if ( type) {56 type->print( os, indent );59 if ( get_type() ) { 60 get_type()->print( os, indent ); 57 61 } else { 58 62 os << " untyped entity "; … … 60 64 61 65 if ( init ) { 62 os << " with initializer (" << (init->get_maybeConstructed() ? "maybe constructed" : "not constructed") << ")" << std::endl << indent+1; 63 init->print( os, indent+1 ); 64 os << std::endl; 66 os << " with initializer " << std::endl; 67 init->print( os, indent+2 ); 68 os << std::endl << std::string(indent+2, ' '); 69 os << "maybeConstructed? " << init->get_maybeConstructed(); 65 70 } // if 66 71 67 if ( ! attributes.empty() ) {68 os << std::endl << indent << "... with attributes: " << std::endl;69 printAll( attributes, os, indent+1 );70 }71 72 72 if ( bitfieldWidth ) { 73 os << indent << " with bitfield width "; 73 os << std::string(indent, ' '); 74 os << " with bitfield width "; 74 75 bitfieldWidth->print( os ); 75 76 } // if 76 77 } 77 78 78 void ObjectDecl::printShort( std::ostream &os, Indenterindent ) const {79 void ObjectDecl::printShort( std::ostream &os, int indent ) const { 79 80 #if 0 80 81 if ( get_mangleName() != "") { … … 82 83 } else 83 84 #endif 84 if ( name != "" ) os << name << ": "; 85 if ( get_name() != "" ) { 86 os << get_name() << ": "; 87 } // if 88 89 // xxx - should printShort print attributes? 85 90 86 91 get_storageClasses().print( os ); 87 92 88 if ( type) {89 type->print( os, indent );93 if ( get_type() ) { 94 get_type()->print( os, indent ); 90 95 } else { 91 96 os << "untyped entity "; -
src/SynTree/PointerType.cc
r7821d6c re1ff775 41 41 } 42 42 43 void PointerType::print( std::ostream &os, Indenterindent ) const {43 void PointerType::print( std::ostream &os, int indent ) const { 44 44 Type::print( os, indent ); 45 45 if ( ! is_array() ) { -
src/SynTree/ReferenceToType.cc
r7821d6c re1ff775 14 14 // 15 15 16 #include <stddef.h> // for NULL 16 17 #include <cassert> // for assert 17 18 #include <list> // for list, _List_const_iterator, list<>::cons... … … 37 38 } 38 39 39 void ReferenceToType::print( std::ostream &os, Indenterindent ) const {40 void ReferenceToType::print( std::ostream &os, int indent ) const { 40 41 using std::endl; 41 42 … … 43 44 os << "instance of " << typeString() << " " << name << " "; 44 45 if ( ! parameters.empty() ) { 45 os << endl << indent << "...with parameters" << endl;46 printAll( parameters, os, indent+ 1);46 os << endl << std::string( indent, ' ' ) << "with parameters" << endl; 47 printAll( parameters, os, indent+2 ); 47 48 } // if 48 49 } … … 64 65 65 66 std::list<TypeDecl*>* StructInstType::get_baseParameters() { 66 if ( ! baseStruct ) return nullptr;67 if ( ! baseStruct ) return NULL; 67 68 return &baseStruct->get_parameters(); 68 69 } … … 75 76 } 76 77 77 void StructInstType::print( std::ostream &os, Indenterindent ) const {78 void StructInstType::print( std::ostream &os, int indent ) const { 78 79 using std::endl; 79 80 80 if ( baseStruct == nullptr) ReferenceToType::print( os, indent );81 if ( baseStruct == NULL ) ReferenceToType::print( os, indent ); 81 82 else { 82 83 Type::print( os, indent ); 83 84 os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " "; 84 85 if ( ! parameters.empty() ) { 85 os << endl << indent << "...with parameters" << endl;86 printAll( parameters, os, indent+ 1);86 os << endl << std::string( indent, ' ' ) << "with parameters" << endl; 87 printAll( parameters, os, indent+2 ); 87 88 } // if 88 89 } // if … … 96 97 97 98 std::list< TypeDecl * > * UnionInstType::get_baseParameters() { 98 if ( ! baseUnion ) return nullptr;99 if ( ! baseUnion ) return NULL; 99 100 return &baseUnion->get_parameters(); 100 101 } … … 107 108 } 108 109 109 void UnionInstType::print( std::ostream &os, Indenterindent ) const {110 void UnionInstType::print( std::ostream &os, int indent ) const { 110 111 using std::endl; 111 112 112 if ( baseUnion == nullptr) ReferenceToType::print( os, indent );113 if ( baseUnion == NULL ) ReferenceToType::print( os, indent ); 113 114 else { 114 115 Type::print( os, indent ); 115 116 os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " "; 116 117 if ( ! parameters.empty() ) { 117 os << endl << indent << "...with parameters" << endl;118 printAll( parameters, os, indent+ 1);118 os << endl << std::string( indent, ' ' ) << "with parameters" << endl; 119 printAll( parameters, os, indent+2 ); 119 120 } // if 120 121 } // if … … 165 166 bool TypeInstType::isComplete() const { return baseType->isComplete(); } 166 167 167 void TypeInstType::print( std::ostream &os, Indenterindent ) const {168 void TypeInstType::print( std::ostream &os, int indent ) const { 168 169 using std::endl; 169 170 … … 171 172 os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) "; 172 173 if ( ! parameters.empty() ) { 173 os << endl << indent << "...with parameters" << endl;174 printAll( parameters, os, indent+ 1);174 os << endl << std::string( indent, ' ' ) << "with parameters" << endl; 175 printAll( parameters, os, indent+2 ); 175 176 } // if 176 177 } -
src/SynTree/ReferenceType.cc
r7821d6c re1ff775 35 35 } 36 36 37 void ReferenceType::print( std::ostream &os, Indenterindent ) const {37 void ReferenceType::print( std::ostream &os, int indent ) const { 38 38 Type::print( os, indent ); 39 39 os << "reference to "; -
src/SynTree/Statement.cc
r7821d6c re1ff775 34 34 Statement::Statement( std::list<Label> labels ) : labels( labels ) {} 35 35 36 void Statement::print( std::ostream & os, Indenter ) const { 37 if ( ! labels.empty() ) { 38 os << "Labels: {"; 39 for ( const Label & l : labels ) { 40 os << l << ","; 41 } 42 os << "}" << endl; 43 } 44 } 36 void Statement::print( __attribute__((unused)) std::ostream &, __attribute__((unused)) int indent ) const {} 45 37 46 38 Statement::~Statement() {} … … 54 46 } 55 47 56 void ExprStmt::print( std::ostream &os, Indenterindent ) const {57 os << "Expression Statement:" << endl << indent+1;58 expr->print( os, indent +1);48 void ExprStmt::print( std::ostream &os, int indent ) const { 49 os << "Expression Statement:" << endl << std::string( indent + 2, ' ' ); 50 expr->print( os, indent + 2 ); 59 51 } 60 52 … … 75 67 } 76 68 77 void AsmStmt::print( std::ostream &os, Indenterindent ) const {69 void AsmStmt::print( std::ostream &os, int indent ) const { 78 70 os << "Assembler Statement:" << endl; 79 os << indent+1 << "instruction: " << endl << indent;80 instruction->print( os, indent +1);71 os << std::string( indent, ' ' ) << "instruction: " << endl << std::string( indent, ' ' ); 72 instruction->print( os, indent + 2 ); 81 73 if ( ! output.empty() ) { 82 os << endl << indent+1<< "output: " << endl;83 printAll( output, os, indent +1);74 os << endl << std::string( indent, ' ' ) << "output: " << endl; 75 printAll( output, os, indent + 2 ); 84 76 } // if 85 77 if ( ! input.empty() ) { 86 os << indent+1 << "input: " << endl;87 printAll( input, os, indent +1);78 os << std::string( indent, ' ' ) << "input: " << endl << std::string( indent, ' ' ); 79 printAll( input, os, indent + 2 ); 88 80 } // if 89 81 if ( ! clobber.empty() ) { 90 os << indent+1<< "clobber: " << endl;91 printAll( clobber, os, indent +1);82 os << std::string( indent, ' ' ) << "clobber: " << endl; 83 printAll( clobber, os, indent + 2 ); 92 84 } // if 93 85 } … … 111 103 } 112 104 113 void BranchStmt::print( std::ostream &os, Indenterindent ) const {114 os << "Branch (" << brType[type] << ")" << endl ;115 if ( target != "" ) os << indent+1<< "with target: " << target << endl;116 if ( originalTarget != "" ) os << indent+1<< "with original target: " << originalTarget << endl;117 if ( computedTarget != nullptr ) os << indent+1<< "with computed target: " << computedTarget << endl;105 void BranchStmt::print( std::ostream &os, int indent ) const { 106 os << string( indent, ' ' ) << "Branch (" << brType[type] << ")" << endl ; 107 if ( target != "" ) os << string( indent+2, ' ' ) << "with target: " << target << endl; 108 if ( originalTarget != "" ) os << string( indent+2, ' ' ) << "with original target: " << originalTarget << endl; 109 if ( computedTarget != nullptr ) os << string( indent+2, ' ' ) << "with computed target: " << computedTarget << endl; 118 110 } 119 111 … … 126 118 } 127 119 128 void ReturnStmt::print( std::ostream &os, Indenterindent ) const {129 os << "Return Statement, returning: ";130 if ( expr != nullptr) {131 os << endl << indent+1;132 expr->print( os, indent +1);120 void ReturnStmt::print( std::ostream &os, int indent ) const { 121 os << "Return Statement, returning: "; 122 if ( expr != 0 ) { 123 os << endl << string( indent+2, ' ' ); 124 expr->print( os, indent + 2 ); 133 125 } 134 126 os << endl; … … 150 142 } 151 143 152 void IfStmt::print( std::ostream &os, Indenterindent ) const {153 os << "If on condition: " << endl ;154 os << indent+1;155 condition->print( os, indent +1);144 void IfStmt::print( std::ostream &os, int indent ) const { 145 os << "If on condition: " << endl ; 146 os << string( indent+4, ' ' ); 147 condition->print( os, indent + 4 ); 156 148 157 149 if ( !initialization.empty() ) { 158 os << indent << "... withinitialization: \n";159 for ( const Statement * stmt : initialization) {160 os << indent+1;161 stmt->print( os, indent+1);150 os << string( indent + 2, ' ' ) << "initialization: \n"; 151 for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { 152 os << string( indent + 4, ' ' ); 153 (*it)->print( os, indent + 4 ); 162 154 } 163 155 os << endl; 164 156 } 165 157 166 os << indent<< "... then: " << endl;167 168 os << indent+1;169 thenPart->print( os, indent +1);158 os << string( indent+2, ' ' ) << "... then: " << endl; 159 160 os << string( indent+4, ' ' ); 161 thenPart->print( os, indent + 4 ); 170 162 171 163 if ( elsePart != 0 ) { 172 os << indent<< "... else: " << endl;173 os << indent+1;174 elsePart->print( os, indent +1);164 os << string( indent+2, ' ' ) << "... else: " << endl; 165 os << string( indent+4, ' ' ); 166 elsePart->print( os, indent + 4 ); 175 167 } // if 176 168 } … … 191 183 } 192 184 193 void SwitchStmt::print( std::ostream &os, Indenterindent ) const {185 void SwitchStmt::print( std::ostream &os, int indent ) const { 194 186 os << "Switch on condition: "; 195 187 condition->print( os ); 196 188 os << endl; 197 189 198 for ( const Statement * stmt : statements ) { 199 stmt->print( os, indent+1 ); 200 } 190 // statements 191 std::list<Statement *>::const_iterator i; 192 for ( i = statements.begin(); i != statements.end(); i++) 193 (*i)->print( os, indent + 4 ); 194 195 //for_each( statements.begin(), statements.end(), mem_fun( bind1st(&Statement::print ), os )); 201 196 } 202 197 203 198 CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) : 204 199 Statement( labels ), condition( condition ), stmts( statements ), _isDefault( deflt ) { 205 if ( isDefault() && condition != 0 ) throw SemanticError("default case with condition: ", condition); 200 if ( isDefault() && condition != 0 ) 201 throw SemanticError("default with conditions"); 206 202 } 207 203 … … 220 216 } 221 217 222 void CaseStmt::print( std::ostream &os, Indenter indent ) const { 223 if ( isDefault() ) os << "Default "; 218 void CaseStmt::print( std::ostream &os, int indent ) const { 219 os << string( indent, ' ' ); 220 221 if ( isDefault() ) 222 os << "Default "; 224 223 else { 225 224 os << "Case "; 226 condition->print( os , indent);225 condition->print( os ); 227 226 } // if 227 228 228 os << endl; 229 229 230 for ( Statement * stmt : stmts ) {231 stmt->print( os, indent+1 );232 }230 std::list<Statement *>::const_iterator i; 231 for ( i = stmts.begin(); i != stmts.end(); i++) 232 (*i )->print( os, indent + 4 ); 233 233 } 234 234 … … 246 246 } 247 247 248 void WhileStmt::print( std::ostream &os, Indenterindent ) const {248 void WhileStmt::print( std::ostream &os, int indent ) const { 249 249 os << "While on condition: " << endl ; 250 condition->print( os, indent +1);251 252 os << indent << "... with body: " << endl;253 254 if ( body != 0 ) body->print( os, indent +1);250 condition->print( os, indent + 4 ); 251 252 os << string( indent, ' ' ) << ".... with body: " << endl; 253 254 if ( body != 0 ) body->print( os, indent + 4 ); 255 255 } 256 256 … … 272 272 } 273 273 274 void ForStmt::print( std::ostream &os, Indenter indent ) const { 275 Statement::print( os, indent ); // print labels 276 277 os << "For Statement" << endl; 278 279 if ( ! initialization.empty() ) { 280 os << indent << "... initialization: \n"; 281 for ( Statement * stmt : initialization ) { 282 os << indent+1; 283 stmt->print( os, indent+1 ); 284 } 285 } 286 287 if ( condition != nullptr ) { 288 os << indent << "... condition: \n" << indent+1; 289 condition->print( os, indent+1 ); 290 } 291 292 if ( increment != nullptr ) { 293 os << "\n" << indent << "... increment: \n" << indent+1; 294 increment->print( os, indent+1 ); 295 } 296 274 void ForStmt::print( std::ostream &os, int indent ) const { 275 os << "Labels: {"; 276 for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) { 277 os << *it << ","; 278 } 279 os << "}" << endl; 280 281 os << string( indent, ' ' ) << "For Statement" << endl ; 282 283 os << string( indent + 2, ' ' ) << "initialization: \n"; 284 for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { 285 os << string( indent + 4, ' ' ); 286 (*it)->print( os, indent + 4 ); 287 } 288 289 os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; 290 if ( condition != 0 ) { 291 os << string( indent + 4, ' ' ); 292 condition->print( os, indent + 4 ); 293 } 294 295 os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; 296 if ( increment != 0 ) { 297 os << string( indent + 4, ' ' ); 298 increment->print( os, indent + 4 ); 299 } 300 301 os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; 297 302 if ( body != 0 ) { 298 os << "\n" << indent << "... with body: \n" << indent+1; 299 body->print( os, indent+1 ); 300 } 303 os << string( indent + 4, ' ' ); 304 body->print( os, indent + 4 ); 305 } 306 301 307 os << endl; 302 308 } … … 316 322 } 317 323 318 void ThrowStmt::print( std::ostream &os, Indenter indent) const { 319 if ( target ) os << "Non-Local "; 324 void ThrowStmt::print( std::ostream &os, int indent) const { 325 if ( target ) { 326 os << "Non-Local "; 327 } 320 328 os << "Throw Statement, raising: "; 321 expr->print(os, indent +1);329 expr->print(os, indent + 4); 322 330 if ( target ) { 323 os << " ... at: ";324 target->print(os, indent +1);331 os << "At: "; 332 target->print(os, indent + 4); 325 333 } 326 334 } … … 340 348 } 341 349 342 void TryStmt::print( std::ostream &os, Indenterindent ) const {350 void TryStmt::print( std::ostream &os, int indent ) const { 343 351 os << "Try Statement" << endl; 344 os << indent << "... with block:" << endl << indent+1; 345 block->print( os, indent+1 ); 352 os << string( indent + 2, ' ' ) << "with block:" << endl; 353 os << string( indent + 4, ' ' ); 354 block->print( os, indent + 4 ); 346 355 347 356 // handlers 348 os << indent << "...and handlers:" << endl;349 for ( const CatchStmt * stmt : handlers) {350 os << indent+1;351 stmt->print( os, indent+1);357 os << string( indent + 2, ' ' ) << "and handlers:" << endl; 358 for ( std::list<CatchStmt *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) { 359 os << string( indent + 4, ' ' ); 360 (*i )->print( os, indent + 4 ); 352 361 } 353 362 354 363 // finally block 355 364 if ( finallyBlock != 0 ) { 356 os << indent << "... and finally:" << endl << indent+1;357 finallyBlock->print( os, indent +1);365 os << string( indent + 2, ' ' ) << "and finally:" << endl; 366 finallyBlock->print( os, indent + 4 ); 358 367 } // if 359 368 } … … 361 370 CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) : 362 371 Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) { 363 assertf( decl, "Catch clause must have a declaration." );364 372 } 365 373 … … 373 381 } 374 382 375 void CatchStmt::print( std::ostream &os, Indenterindent ) const {383 void CatchStmt::print( std::ostream &os, int indent ) const { 376 384 os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl; 377 385 378 os << indent << "... catching: "; 379 decl->printShort( os, indent+1 ); 380 os << endl; 386 os << string( indent + 2, ' ' ) << "... catching: "; 387 if ( decl ) { 388 decl->printShort( os, indent + 4 ); 389 os << endl; 390 } 391 else 392 os << string( indent + 4 , ' ' ) << ">>> Error: this catch clause must have a declaration <<<" << endl; 381 393 382 394 if ( cond ) { 383 os << indent << "... with conditional:" << endl << indent+1; 384 cond->print( os, indent+1 ); 385 } 386 387 os << indent << "... with block:" << endl; 388 os << indent+1; 389 body->print( os, indent+1 ); 395 os << string( indent + 2, ' ' ) << "with conditional:" << endl; 396 os << string( indent + 4, ' ' ); 397 cond->print( os, indent + 4 ); 398 } 399 else 400 os << string( indent + 2, ' ' ) << "with no conditional" << endl; 401 402 os << string( indent + 2, ' ' ) << "with block:" << endl; 403 os << string( indent + 4, ' ' ); 404 body->print( os, indent + 4 ); 390 405 } 391 406 … … 402 417 } 403 418 404 void FinallyStmt::print( std::ostream &os, Indenterindent ) const {419 void FinallyStmt::print( std::ostream &os, int indent ) const { 405 420 os << "Finally Statement" << endl; 406 os << indent << "... with block:" << endl << indent+1; 407 block->print( os, indent+1 ); 421 os << string( indent + 2, ' ' ) << "with block:" << endl; 422 os << string( indent + 4, ' ' ); 423 block->print( os, indent + 4 ); 408 424 } 409 425 … … 449 465 } 450 466 451 void WaitForStmt::print( std::ostream &os, Indenterindent ) const {467 void WaitForStmt::print( std::ostream &os, int indent ) const { 452 468 os << "Waitfor Statement" << endl; 453 os << indent << "... with block:" << endl << indent+1; 469 os << string( indent + 2, ' ' ) << "with block:" << endl; 470 os << string( indent + 4, ' ' ); 454 471 // block->print( os, indent + 4 ); 455 472 } … … 458 475 NullStmt::NullStmt() : Statement( std::list<Label>() ) {} 459 476 460 void NullStmt::print( std::ostream &os, Indenter) const {461 os << "Null Statement" << endl ;477 void NullStmt::print( std::ostream &os, __attribute__((unused)) int indent ) const { 478 os << "Null Statement" << endl ; 462 479 } 463 480 … … 473 490 } 474 491 475 void ImplicitCtorDtorStmt::print( std::ostream &os, Indenterindent ) const {492 void ImplicitCtorDtorStmt::print( std::ostream &os, int indent ) const { 476 493 os << "Implicit Ctor Dtor Statement" << endl; 477 os << indent << "...with Ctor/Dtor: ";478 callStmt->print( os, indent +1);494 os << string( indent + 2, ' ' ) << "with Ctor/Dtor: "; 495 callStmt->print( os, indent + 2); 479 496 os << endl; 480 497 } -
src/SynTree/Statement.h
r7821d6c re1ff775 46 46 virtual void accept( Visitor &v ) override = 0; 47 47 virtual Statement *acceptMutator( Mutator &m ) override = 0; 48 virtual void print( std::ostream &os, Indenter indent = {}) const override;48 virtual void print( std::ostream &os, int indent = 0 ) const override; 49 49 }; 50 50 … … 65 65 virtual void accept( Visitor &v ) override { v.visit( this ); } 66 66 virtual CompoundStmt *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 67 virtual void print( std::ostream &os, Indenter indent = {}) const override;67 virtual void print( std::ostream &os, int indent = 0 ) const override; 68 68 }; 69 69 … … 76 76 virtual void accept( Visitor &v ) override { v.visit( this ); } 77 77 virtual NullStmt *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 78 virtual void print( std::ostream &os, Indenter indent = {}) const override;78 virtual void print( std::ostream &os, int indent = 0 ) const override; 79 79 }; 80 80 … … 93 93 virtual void accept( Visitor &v ) override { v.visit( this ); } 94 94 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 95 virtual void print( std::ostream &os, Indenter indent = {}) const override;95 virtual void print( std::ostream &os, int indent = 0 ) const override; 96 96 }; 97 97 … … 124 124 virtual void accept( Visitor & v ) { v.visit( this ); } 125 125 virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); } 126 virtual void print( std::ostream & os, Indenter indent = {}) const;126 virtual void print( std::ostream & os, int indent = 0 ) const; 127 127 }; 128 128 … … 150 150 virtual void accept( Visitor &v ) override { v.visit( this ); } 151 151 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 152 virtual void print( std::ostream &os, Indenter indent = {}) const override;152 virtual void print( std::ostream &os, int indent = 0 ) const override; 153 153 }; 154 154 … … 171 171 172 172 virtual SwitchStmt *clone() const override { return new SwitchStmt( *this ); } 173 virtual void print( std::ostream &os, Indenter indent = {}) const override;173 virtual void print( std::ostream &os, int indent = 0 ) const override; 174 174 175 175 }; … … 199 199 200 200 virtual CaseStmt *clone() const override { return new CaseStmt( *this ); } 201 virtual void print( std::ostream &os, Indenter indent = {}) const override;201 virtual void print( std::ostream &os, int indent = 0 ) const override; 202 202 private: 203 203 bool _isDefault; … … 225 225 virtual void accept( Visitor &v ) override { v.visit( this ); } 226 226 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 227 virtual void print( std::ostream &os, Indenter indent = {}) const override;227 virtual void print( std::ostream &os, int indent = 0 ) const override; 228 228 }; 229 229 … … 251 251 virtual void accept( Visitor &v ) override { v.visit( this ); } 252 252 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 253 virtual void print( std::ostream &os, Indenter indent = {}) const override;253 virtual void print( std::ostream &os, int indent = 0 ) const override; 254 254 }; 255 255 … … 280 280 virtual void accept( Visitor &v ) override { v.visit( this ); } 281 281 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 282 virtual void print( std::ostream &os, Indenter indent = {}) const override;282 virtual void print( std::ostream &os, int indent = 0 ) const override; 283 283 private: 284 284 static const char *brType[]; … … 299 299 virtual void accept( Visitor &v ) override { v.visit( this ); } 300 300 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 301 virtual void print( std::ostream &os, Indenter indent = {}) const override;301 virtual void print( std::ostream &os, int indent = 0 ) const override; 302 302 }; 303 303 … … 323 323 virtual void accept( Visitor &v ) override { v.visit( this ); } 324 324 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 325 virtual void print( std::ostream &os, Indenter indent = {}) const override;325 virtual void print( std::ostream &os, int indent = 0 ) const override; 326 326 }; 327 327 … … 346 346 virtual void accept( Visitor &v ) override { v.visit( this ); } 347 347 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 348 virtual void print( std::ostream &os, Indenter indent = {}) const override;348 virtual void print( std::ostream &os, int indent = 0 ) const override; 349 349 }; 350 350 … … 374 374 virtual void accept( Visitor &v ) override { v.visit( this ); } 375 375 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 376 virtual void print( std::ostream &os, Indenter indent = {}) const override;376 virtual void print( std::ostream &os, int indent = 0 ) const override; 377 377 }; 378 378 … … 391 391 virtual void accept( Visitor &v ) override { v.visit( this ); } 392 392 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 393 virtual void print( std::ostream &os, Indenter indent = {}) const override;393 virtual void print( std::ostream &os, int indent = 0 ) const override; 394 394 }; 395 395 … … 428 428 virtual void accept( Visitor &v ) override { v.visit( this ); } 429 429 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 430 virtual void print( std::ostream &os, Indenter indent = {}) const override;430 virtual void print( std::ostream &os, int indent = 0 ) const override; 431 431 432 432 }; … … 448 448 virtual void accept( Visitor &v ) override { v.visit( this ); } 449 449 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 450 virtual void print( std::ostream &os, Indenter indent = {}) const override;450 virtual void print( std::ostream &os, int indent = 0 ) const override; 451 451 }; 452 452 … … 470 470 virtual void accept( Visitor &v ) override { v.visit( this ); } 471 471 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 472 virtual void print( std::ostream &os, Indenter indent = {}) const override;472 virtual void print( std::ostream &os, int indent = 0 ) const override; 473 473 }; 474 474 -
src/SynTree/TupleExpr.cc
r7821d6c re1ff775 28 28 #include "Type.h" // for TupleType, Type 29 29 30 UntypedTupleExpr::UntypedTupleExpr( const std::list< Expression * > & exprs ) : Expression(), exprs( exprs ) {30 UntypedTupleExpr::UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) { 31 31 } 32 32 … … 39 39 } 40 40 41 void UntypedTupleExpr::print( std::ostream &os, Indenterindent ) const {41 void UntypedTupleExpr::print( std::ostream &os, int indent ) const { 42 42 os << "Untyped Tuple:" << std::endl; 43 printAll( exprs, os, indent+ 1);43 printAll( exprs, os, indent+2 ); 44 44 Expression::print( os, indent ); 45 45 } 46 46 47 TupleExpr::TupleExpr( const std::list< Expression * > & exprs ) : Expression(), exprs( exprs ) {47 TupleExpr::TupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) { 48 48 set_result( Tuples::makeTupleType( exprs ) ); 49 49 } … … 57 57 } 58 58 59 void TupleExpr::print( std::ostream &os, Indenterindent ) const {59 void TupleExpr::print( std::ostream &os, int indent ) const { 60 60 os << "Tuple:" << std::endl; 61 printAll( exprs, os, indent+ 1);61 printAll( exprs, os, indent+2 ); 62 62 Expression::print( os, indent ); 63 63 } … … 78 78 } 79 79 80 void TupleIndexExpr::print( std::ostream &os, Indenterindent ) const {80 void TupleIndexExpr::print( std::ostream &os, int indent ) const { 81 81 os << "Tuple Index Expression, with tuple:" << std::endl; 82 os << indent+1;83 tuple->print( os, indent+ 1);84 os << indent+1<< "with index: " << index << std::endl;82 os << std::string( indent+2, ' ' ); 83 tuple->print( os, indent+2 ); 84 os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl; 85 85 Expression::print( os, indent ); 86 86 } 87 87 88 TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls ) : Expression() {88 TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ) { 89 89 // convert internally into a StmtExpr which contains the declarations and produces the tuple of the assignments 90 90 set_result( Tuples::makeTupleType( assigns ) ); … … 109 109 } 110 110 111 void TupleAssignExpr::print( std::ostream &os, Indenterindent ) const {111 void TupleAssignExpr::print( std::ostream &os, int indent ) const { 112 112 os << "Tuple Assignment Expression, with stmt expr:" << std::endl; 113 os << indent+1;114 stmtExpr->print( os, indent+ 1);113 os << std::string( indent+2, ' ' ); 114 stmtExpr->print( os, indent+4 ); 115 115 Expression::print( os, indent ); 116 116 } -
src/SynTree/TupleType.cc
r7821d6c re1ff775 48 48 } 49 49 50 void TupleType::print( std::ostream &os, Indenterindent ) const {50 void TupleType::print( std::ostream &os, int indent ) const { 51 51 Type::print( os, indent ); 52 52 os << "tuple of types" << std::endl; 53 printAll( types, os, indent+ 1);53 printAll( types, os, indent+2 ); 54 54 } 55 55 -
src/SynTree/Type.cc
r7821d6c re1ff775 75 75 Type * type; 76 76 ReferenceType * ref; 77 for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref-> base);77 for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->get_base() ); 78 78 return type; 79 79 } … … 81 81 int Type::referenceDepth() const { return 0; } 82 82 83 void Type::print( std::ostream &os, Indenterindent ) const {83 void Type::print( std::ostream &os, int indent ) const { 84 84 if ( ! forall.empty() ) { 85 85 os << "forall" << std::endl; 86 printAll( forall, os, indent +1);87 os << ++indent;86 printAll( forall, os, indent + 4 ); 87 os << std::string( indent+2, ' ' ); 88 88 } // if 89 89 90 90 if ( ! attributes.empty() ) { 91 os << "with attributes" << endl;92 printAll( attributes, os, indent+ 1);91 os << endl << string( indent+2, ' ' ) << "with attributes" << endl; 92 printAll( attributes, os, indent+4 ); 93 93 } // if 94 94 -
src/SynTree/Type.h
r7821d6c re1ff775 181 181 virtual void accept( Visitor & v ) = 0; 182 182 virtual Type *acceptMutator( Mutator & m ) = 0; 183 virtual void print( std::ostream & os, Indenter indent = {}) const;183 virtual void print( std::ostream & os, int indent = 0 ) const; 184 184 }; 185 185 … … 198 198 virtual void accept( Visitor & v ) override { v.visit( this ); } 199 199 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 200 virtual void print( std::ostream & os, Indenter indent = {}) const override;200 virtual void print( std::ostream & os, int indent = 0 ) const override; 201 201 }; 202 202 … … 240 240 virtual void accept( Visitor & v ) override { v.visit( this ); } 241 241 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 242 virtual void print( std::ostream & os, Indenter indent = {}) const override;242 virtual void print( std::ostream & os, int indent = 0 ) const override; 243 243 244 244 bool isInteger() const; … … 275 275 virtual void accept( Visitor & v ) override { v.visit( this ); } 276 276 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 277 virtual void print( std::ostream & os, Indenter indent = {}) const override;277 virtual void print( std::ostream & os, int indent = 0 ) const override; 278 278 }; 279 279 … … 303 303 virtual void accept( Visitor & v ) override { v.visit( this ); } 304 304 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 305 virtual void print( std::ostream & os, Indenter indent = {}) const override;305 virtual void print( std::ostream & os, int indent = 0 ) const override; 306 306 }; 307 307 … … 327 327 virtual void accept( Visitor & v ) override { v.visit( this ); } 328 328 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 329 virtual void print( std::ostream & os, Indenter indent = {}) const override;329 virtual void print( std::ostream & os, int indent = 0 ) const override; 330 330 }; 331 331 … … 354 354 virtual void accept( Visitor & v ) override { v.visit( this ); } 355 355 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 356 virtual void print( std::ostream & os, Indenter indent = {}) const override;356 virtual void print( std::ostream & os, int indent = 0 ) const override; 357 357 }; 358 358 … … 376 376 virtual void accept( Visitor & v ) override = 0; 377 377 virtual Type *acceptMutator( Mutator & m ) override = 0; 378 virtual void print( std::ostream & os, Indenter indent = {}) const override;378 virtual void print( std::ostream & os, int indent = 0 ) const override; 379 379 380 380 virtual void lookup( __attribute__((unused)) const std::string & name, __attribute__((unused)) std::list< Declaration* > & foundDecls ) const {} … … 410 410 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 411 411 412 virtual void print( std::ostream & os, Indenter indent = {}) const override;412 virtual void print( std::ostream & os, int indent = 0 ) const override; 413 413 private: 414 414 virtual std::string typeString() const override; … … 442 442 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 443 443 444 virtual void print( std::ostream & os, Indenter indent = {}) const override;444 virtual void print( std::ostream & os, int indent = 0 ) const override; 445 445 private: 446 446 virtual std::string typeString() const override; … … 514 514 virtual void accept( Visitor & v ) override { v.visit( this ); } 515 515 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 516 virtual void print( std::ostream & os, Indenter indent = {}) const override;516 virtual void print( std::ostream & os, int indent = 0 ) const override; 517 517 private: 518 518 virtual std::string typeString() const override; … … 551 551 virtual void accept( Visitor & v ) override { v.visit( this ); } 552 552 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 553 virtual void print( std::ostream & os, Indenter indent = {}) const override;553 virtual void print( std::ostream & os, int indent = 0 ) const override; 554 554 }; 555 555 … … 570 570 virtual void accept( Visitor & v ) override { v.visit( this ); } 571 571 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 572 virtual void print( std::ostream & os, Indenter indent = {}) const override;572 virtual void print( std::ostream & os, int indent = 0 ) const override; 573 573 }; 574 574 … … 599 599 virtual void accept( Visitor & v ) override { v.visit( this ); } 600 600 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 601 virtual void print( std::ostream & os, Indenter indent = {}) const override;601 virtual void print( std::ostream & os, int indent = 0 ) const override; 602 602 }; 603 603 … … 613 613 virtual void accept( Visitor & v ) override { v.visit( this ); } 614 614 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 615 virtual void print( std::ostream & os, Indenter indent = {}) const override;615 virtual void print( std::ostream & os, int indent = 0 ) const override; 616 616 }; 617 617 … … 625 625 virtual void accept( Visitor & v ) override { v.visit( this ); } 626 626 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 627 virtual void print( std::ostream & os, Indenter indent = {}) const override;627 virtual void print( std::ostream & os, int indent = 0 ) const override; 628 628 }; 629 629 … … 637 637 virtual void accept( Visitor & v ) override { v.visit( this ); } 638 638 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 639 virtual void print( std::ostream & os, Indenter indent = {}) const override;639 virtual void print( std::ostream & os, int indent = 0 ) const override; 640 640 }; 641 641 -
src/SynTree/TypeDecl.cc
r7821d6c re1ff775 41 41 } 42 42 43 void TypeDecl::print( std::ostream &os, Indenterindent ) const {43 void TypeDecl::print( std::ostream &os, int indent ) const { 44 44 NamedTypeDecl::print( os, indent ); 45 45 if ( init ) { 46 os << std::endl << indent<< "with type initializer: ";47 init->print( os, indent + 1);46 os << std::endl << std::string( indent, ' ' ) << "with type initializer: "; 47 init->print( os, indent + 2 ); 48 48 } 49 49 } -
src/SynTree/TypeExpr.cc
r7821d6c re1ff775 30 30 } 31 31 32 void TypeExpr::print( std::ostream &os, Indenterindent ) const {32 void TypeExpr::print( std::ostream &os, int indent ) const { 33 33 if ( type ) type->print( os, indent ); 34 34 Expression::print( os, indent ); -
src/SynTree/TypeSubstitution.cc
r7821d6c re1ff775 243 243 } 244 244 245 void TypeSubstitution::print( std::ostream &os, Indenterindent ) const {246 os << indent<< "Types:" << std::endl;245 void TypeSubstitution::print( std::ostream &os, int indent ) const { 246 os << std::string( indent, ' ' ) << "Types:" << std::endl; 247 247 for ( TypeEnvType::const_iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 248 os << indent+1<< i->first << " -> ";249 i->second->print( os, indent+ 2);248 os << std::string( indent+2, ' ' ) << i->first << " -> "; 249 i->second->print( os, indent+4 ); 250 250 os << std::endl; 251 251 } // for 252 os << indent<< "Non-types:" << std::endl;252 os << std::string( indent, ' ' ) << "Non-types:" << std::endl; 253 253 for ( VarEnvType::const_iterator i = varEnv.begin(); i != varEnv.end(); ++i ) { 254 os << indent+1<< i->first << " -> ";255 i->second->print( os, indent+ 2);254 os << std::string( indent+2, ' ' ) << i->first << " -> "; 255 i->second->print( os, indent+4 ); 256 256 os << std::endl; 257 257 } // for -
src/SynTree/TypeSubstitution.h
r7821d6c re1ff775 61 61 TypeSubstitution * acceptMutator( Mutator & mutator ); 62 62 63 void print( std::ostream &os, Indenter indent = {}) const;63 void print( std::ostream &os, int indent = 0 ) const; 64 64 TypeSubstitution *clone() const { return new TypeSubstitution( *this ); } 65 65 private: -
src/SynTree/TypeofType.cc
r7821d6c re1ff775 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // TypeofType.cc -- 7 // TypeofType.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 33 33 } 34 34 35 void TypeofType::print( std::ostream &os, Indenterindent ) const {35 void TypeofType::print( std::ostream &os, int indent ) const { 36 36 Type::print( os, indent ); 37 37 os << "type-of expression "; -
src/SynTree/VarArgsType.cc
r7821d6c re1ff775 25 25 VarArgsType::VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes ) : Type( tq, attributes ) {} 26 26 27 void VarArgsType::print( std::ostream &os, Indenterindent ) const {27 void VarArgsType::print( std::ostream &os, int indent ) const { 28 28 Type::print( os, indent ); 29 29 os << "builtin var args pack"; -
src/SynTree/VoidType.cc
r7821d6c re1ff775 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // VoidType.cc -- 7 // VoidType.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 24 24 } 25 25 26 void VoidType::print( std::ostream &os, Indenterindent ) const {26 void VoidType::print( std::ostream &os, int indent ) const { 27 27 Type::print( os, indent ); 28 28 os << "void "; -
src/SynTree/ZeroOneType.cc
r7821d6c re1ff775 25 25 ZeroType::ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes ) : Type( tq, attributes ) {} 26 26 27 void ZeroType::print( std::ostream &os, Indenter) const {27 void ZeroType::print( std::ostream &os, __attribute__((unused)) int indent ) const { 28 28 os << "zero_t"; 29 29 } … … 33 33 OneType::OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes ) : Type( tq, attributes ) {} 34 34 35 void OneType::print( std::ostream &os, Indenter) const {35 void OneType::print( std::ostream &os, __attribute__((unused)) int indent ) const { 36 36 os << "one_t"; 37 37 } -
src/Tuples/TupleAssignment.cc
r7821d6c re1ff775 84 84 bool isTuple( Expression *expr ) { 85 85 if ( ! expr ) return false; 86 assert( expr-> result);86 assert( expr->has_result() ); 87 87 return dynamic_cast< TupleType * >( expr->get_result()->stripReferences() ); 88 88 } … … 238 238 239 239 ObjectDecl * TupleAssignSpotter::Matcher::newObject( UniqueName & namer, Expression * expr ) { 240 assert( expr-> result&& ! expr->get_result()->isVoid() );240 assert( expr->has_result() && ! expr->get_result()->isVoid() ); 241 241 ObjectDecl * ret = new ObjectDecl( namer.newName(), Type::StorageClasses(), LinkageSpec::Cforall, nullptr, expr->get_result()->clone(), new SingleInit( expr->clone() ) ); 242 242 // if expression type is a reference, don't need to construct anything, a simple initializer is sufficient. -
src/tests/.expect/castError.txt
r7821d6c re1ff775 1 castError.c:7:1 error: Cannot choose between 3 alternatives for expression 2 Cast of: 1 castError.c:7:1 error: Cannot choose between 3 alternatives for expression Cast of: 3 2 Name: f 4 ... to:5 charAlternatives are:6 Cost ( 1, 0, 0, 0 ): Cast of:7 Variable Expression: f: function8 accepting unspecified arguments9 ... returning nothing10 3 11 ... to: 12 char 13 (types: 14 char 15 ) 16 Environment: 17 18 Cost ( 1, 0, 0, 0 ): Cast of: 19 Variable Expression: f: signed int 20 ... to: 21 char 22 (types: 23 char 24 ) 25 Environment: 26 27 Cost ( 1, 0, 0, 0 ): Cast of: 28 Variable Expression: f: double 29 ... to: 30 char 31 (types: 32 char 33 ) 34 Environment: 4 to: 5 char 6 Alternatives are: Cost ( 1, 0, 0, 0 ): Cast of: 7 Variable Expression: f: function 8 accepting unspecified arguments 9 returning 10 nothing 35 11 36 12 13 to: 14 char 15 (types: 16 char 17 ) 18 Environment: 19 20 Cost ( 1, 0, 0, 0 ): Cast of: 21 Variable Expression: f: signed int 22 23 to: 24 char 25 (types: 26 char 27 ) 28 Environment: 29 30 Cost ( 1, 0, 0, 0 ): Cast of: 31 Variable Expression: f: double 32 33 to: 34 char 35 (types: 36 char 37 ) 38 Environment: 39 40 -
src/tests/.expect/scopeErrors.txt
r7821d6c re1ff775 1 1 scopeErrors.c:2:1 error: duplicate object definition for thisIsAnError: signed int 2 2 scopeErrors.c:20:1 error: duplicate function definition for butThisIsAnError: function 3 ... with parameters 4 double 5 ... returning 6 _retval_butThisIsAnError: double 7 ... with attributes: 8 Attribute with name: unused 3 with parameters 4 double 5 returning 6 _retval_butThisIsAnError: Attribute with name: unused 7 double 8 with body 9 CompoundStmt 9 10 10 ... with body11 CompoundStmt12
Note:
See TracChangeset
for help on using the changeset viewer.