Changeset ce8c12f
- Timestamp:
- May 15, 2017, 11:30:26 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- d36c117
- Parents:
- 65aca88
- Location:
- src
- Files:
-
- 1 added
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/GenType.cc
r65aca88 rce8c12f 37 37 virtual void visit( PointerType *pointerType ); 38 38 virtual void visit( ArrayType *arrayType ); 39 virtual void visit( ReferenceType *refType ); 39 40 virtual void visit( StructInstType *structInst ); 40 41 virtual void visit( UnionInstType *unionInst ); … … 147 148 } 148 149 150 void GenType::visit( ReferenceType *refType ) { 151 assert( refType->get_base() != 0); 152 assertf( ! genC, "Reference types should not reach code generation." ); 153 handleQualifiers( refType ); 154 typeString = "&" + typeString; 155 refType->get_base()->accept( *this ); 156 } 157 149 158 void GenType::visit( FunctionType *funcType ) { 150 159 std::ostringstream os; -
src/Concurrency/Keywords.cc
r65aca88 rce8c12f 322 322 if( needs_main ) { 323 323 FunctionType * main_type = new FunctionType( noQualifiers, false ); 324 324 325 325 main_type->get_parameters().push_back( this_decl->clone() ); 326 326 … … 361 361 void ConcurrentSueKeyword::addRoutines( StructDecl * decl, ObjectDecl * field, FunctionDecl * func ) { 362 362 CompoundStmt * statement = new CompoundStmt( noLabels ); 363 statement->push_back( 363 statement->push_back( 364 364 new ReturnStmt( 365 365 noLabels, … … 386 386 //============================================================================================= 387 387 void MutexKeyword::visit(FunctionDecl* decl) { 388 Visitor::visit(decl); 388 Visitor::visit(decl); 389 389 390 390 std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl ); … … 510 510 void ThreadStarter::visit(FunctionDecl * decl) { 511 511 Visitor::visit(decl); 512 512 513 513 if( ! InitTweak::isConstructor(decl->get_name()) ) return; 514 514 515 515 DeclarationWithType * param = decl->get_functionType()->get_parameters().front(); 516 auto ptr = dynamic_cast< PointerType * >( param->get_type() ); 517 // if( ptr ) std::cerr << "FRED1" << std::endl; 518 auto type = dynamic_cast< StructInstType * >( ptr->get_base() ); 516 auto type = dynamic_cast< StructInstType * >( InitTweak::getPointerBase( param->get_type() ) ); 519 517 // if( type ) std::cerr << "FRED2" << std::endl; 520 518 if( type && type->get_baseStruct()->is_thread() ) { … … 528 526 if( ! stmt ) return; 529 527 530 stmt->push_back( 528 stmt->push_back( 531 529 new ExprStmt( 532 530 noLabels, -
src/GenPoly/Lvalue.cc
r65aca88 rce8c12f 32 32 #include "Common/UniqueName.h" 33 33 #include "Common/utility.h" 34 #include "InitTweak/InitTweak.h" 34 35 35 36 namespace GenPoly { … … 40 41 class Pass1 : public Mutator { 41 42 public: 43 typedef Mutator Parent; 42 44 Pass1(); 43 45 46 // xxx - should this happen to every expression with reference result type? probably just appexpr and varexpr? 47 virtual Type *mutate( ReferenceType * refType ); 48 virtual Expression *mutate( VariableExpr *varExpr ); 44 49 virtual Expression *mutate( ApplicationExpr *appExpr ); 45 50 virtual Statement *mutate( ReturnStmt *appExpr ); … … 105 110 } // if 106 111 return funcDecl; 112 } 113 114 Type * Pass1::mutate( ReferenceType * refType ) { 115 Type * base = refType->get_base(); 116 refType->set_base( nullptr ); 117 delete refType; 118 return new PointerType( Type::Qualifiers(), base ); 119 } 120 121 Expression * Pass1::mutate( VariableExpr *varExpr ) { 122 if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( varExpr->get_result() ) ) { 123 varExpr->set_result( refType->acceptMutator( *this ) ); 124 return UntypedExpr::createDeref( varExpr ); 125 } 126 return Parent::mutate( varExpr ); 107 127 } 108 128 … … 165 185 } 166 186 187 bool isDeref( Expression * expr ) { 188 if ( UntypedExpr * untyped = dynamic_cast< UntypedExpr * >( expr ) ) { 189 return InitTweak::getFunctionName( untyped ) == "*?"; 190 } else if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * > ( expr ) ) { 191 return InitTweak::getFunctionName( appExpr ) == "*?"; 192 } else { 193 return false; 194 } 195 } 196 167 197 Expression * GeneralizedLvalue::mutate( AddressExpr * addrExpr ) { 168 198 addrExpr = safe_dynamic_cast< AddressExpr * >( Parent::mutate( addrExpr ) ); … … 178 208 delete addrExpr; 179 209 return new ConditionalExpr( arg1, new AddressExpr( arg2 ), new AddressExpr( arg3 ) ); 210 } else if ( isDeref( addrExpr->get_arg() ) ) { 211 // xxx - this doesn't belong here -- move it somewhere else 212 Expression *& arg = InitTweak::getCallArg( addrExpr->get_arg(), 0 ); 213 Expression * inner = arg; 214 arg = nullptr; 215 delete addrExpr; 216 return inner; 180 217 } 181 218 return addrExpr; -
src/InitTweak/FixInit.cc
r65aca88 rce8c12f 400 400 401 401 bool ResolveCopyCtors::skipCopyConstruct( Type * type ) { 402 return dynamic_cast< VarArgsType * >( type ) || GenPoly::getFunctionType( type ) || Tuples::isTtype( type );402 return dynamic_cast< VarArgsType * >( type ) || dynamic_cast< ReferenceType * >( type ) || GenPoly::getFunctionType( type ) || Tuples::isTtype( type ); 403 403 } 404 404 -
src/InitTweak/GenInit.cc
r65aca88 rce8c12f 243 243 std::list< DeclarationWithType * > & params = GenPoly::getFunctionType( dwt->get_type() )->get_parameters(); 244 244 assert( ! params.empty() ); 245 PointerType * type = safe_dynamic_cast< PointerType * >( params.front()->get_type() ); 246 managedTypes.insert( SymTab::Mangler::mangle( type->get_base() ) ); 245 Type * type = InitTweak::getPointerBase( params.front()->get_type() ); 246 assert( type ); 247 managedTypes.insert( SymTab::Mangler::mangle( type ) ); 247 248 } 248 249 } -
src/InitTweak/InitTweak.cc
r65aca88 rce8c12f 461 461 } else if ( ArrayType * arrayType = dynamic_cast< ArrayType * >( type ) ) { 462 462 return arrayType->get_base(); 463 } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( type ) ) { 464 return refType->get_base(); 463 465 } else { 464 466 return NULL; … … 544 546 if ( ftype->get_parameters().size() != 2 ) return 0; 545 547 546 Type * t1 = ftype->get_parameters().front()->get_type();548 Type * t1 = getPointerBase( ftype->get_parameters().front()->get_type() ); 547 549 Type * t2 = ftype->get_parameters().back()->get_type(); 548 PointerType * ptrType = dynamic_cast< PointerType * > ( t1 ); 549 assert( ptrType ); 550 551 if ( ResolvExpr::typesCompatibleIgnoreQualifiers( ptrType->get_base(), t2, SymTab::Indexer() ) ) { 550 assert( t1 ); 551 552 if ( ResolvExpr::typesCompatibleIgnoreQualifiers( t1, t2, SymTab::Indexer() ) ) { 552 553 return function; 553 554 } else { -
src/Makefile.in
r65aca88 rce8c12f 173 173 SynTree/driver_cfa_cpp-PointerType.$(OBJEXT) \ 174 174 SynTree/driver_cfa_cpp-ArrayType.$(OBJEXT) \ 175 SynTree/driver_cfa_cpp-ReferenceType.$(OBJEXT) \ 175 176 SynTree/driver_cfa_cpp-FunctionType.$(OBJEXT) \ 176 177 SynTree/driver_cfa_cpp-ReferenceToType.$(OBJEXT) \ … … 419 420 SymTab/Autogen.cc SynTree/Type.cc SynTree/VoidType.cc \ 420 421 SynTree/BasicType.cc SynTree/PointerType.cc \ 421 SynTree/ArrayType.cc SynTree/ FunctionType.cc \422 SynTree/ ReferenceToType.cc SynTree/TupleType.cc \423 SynTree/T ypeofType.cc SynTree/AttrType.cc \422 SynTree/ArrayType.cc SynTree/ReferenceType.cc \ 423 SynTree/FunctionType.cc SynTree/ReferenceToType.cc \ 424 SynTree/TupleType.cc SynTree/TypeofType.cc SynTree/AttrType.cc \ 424 425 SynTree/VarArgsType.cc SynTree/ZeroOneType.cc \ 425 426 SynTree/Constant.cc SynTree/Expression.cc SynTree/TupleExpr.cc \ … … 757 758 SynTree/driver_cfa_cpp-ArrayType.$(OBJEXT): SynTree/$(am__dirstamp) \ 758 759 SynTree/$(DEPDIR)/$(am__dirstamp) 760 SynTree/driver_cfa_cpp-ReferenceType.$(OBJEXT): \ 761 SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp) 759 762 SynTree/driver_cfa_cpp-FunctionType.$(OBJEXT): \ 760 763 SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp) … … 930 933 -rm -f SynTree/driver_cfa_cpp-PointerType.$(OBJEXT) 931 934 -rm -f SynTree/driver_cfa_cpp-ReferenceToType.$(OBJEXT) 935 -rm -f SynTree/driver_cfa_cpp-ReferenceType.$(OBJEXT) 932 936 -rm -f SynTree/driver_cfa_cpp-Statement.$(OBJEXT) 933 937 -rm -f SynTree/driver_cfa_cpp-TupleExpr.$(OBJEXT) … … 1042 1046 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-PointerType.Po@am__quote@ 1043 1047 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-ReferenceToType.Po@am__quote@ 1048 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-ReferenceType.Po@am__quote@ 1044 1049 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-Statement.Po@am__quote@ 1045 1050 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-TupleExpr.Po@am__quote@ … … 2110 2115 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2111 2116 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-ArrayType.obj `if test -f 'SynTree/ArrayType.cc'; then $(CYGPATH_W) 'SynTree/ArrayType.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/ArrayType.cc'; fi` 2117 2118 SynTree/driver_cfa_cpp-ReferenceType.o: SynTree/ReferenceType.cc 2119 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-ReferenceType.o -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-ReferenceType.Tpo -c -o SynTree/driver_cfa_cpp-ReferenceType.o `test -f 'SynTree/ReferenceType.cc' || echo '$(srcdir)/'`SynTree/ReferenceType.cc 2120 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-ReferenceType.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-ReferenceType.Po 2121 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SynTree/ReferenceType.cc' object='SynTree/driver_cfa_cpp-ReferenceType.o' libtool=no @AMDEPBACKSLASH@ 2122 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2123 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-ReferenceType.o `test -f 'SynTree/ReferenceType.cc' || echo '$(srcdir)/'`SynTree/ReferenceType.cc 2124 2125 SynTree/driver_cfa_cpp-ReferenceType.obj: SynTree/ReferenceType.cc 2126 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-ReferenceType.obj -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-ReferenceType.Tpo -c -o SynTree/driver_cfa_cpp-ReferenceType.obj `if test -f 'SynTree/ReferenceType.cc'; then $(CYGPATH_W) 'SynTree/ReferenceType.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/ReferenceType.cc'; fi` 2127 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-ReferenceType.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-ReferenceType.Po 2128 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SynTree/ReferenceType.cc' object='SynTree/driver_cfa_cpp-ReferenceType.obj' libtool=no @AMDEPBACKSLASH@ 2129 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2130 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-ReferenceType.obj `if test -f 'SynTree/ReferenceType.cc'; then $(CYGPATH_W) 'SynTree/ReferenceType.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/ReferenceType.cc'; fi` 2112 2131 2113 2132 SynTree/driver_cfa_cpp-FunctionType.o: SynTree/FunctionType.cc -
src/Parser/DeclarationNode.cc
r65aca88 rce8c12f 326 326 } // DeclarationNode::newTypeDecl 327 327 328 DeclarationNode * DeclarationNode::newPointer( DeclarationNode * qualifiers ) {329 DeclarationNode * newnode = new DeclarationNode; 330 newnode->type = new TypeData( TypeData::Pointer);328 DeclarationNode * DeclarationNode::newPointer( DeclarationNode * qualifiers, OperKinds kind ) { 329 DeclarationNode * newnode = new DeclarationNode; 330 newnode->type = new TypeData( kind == OperKinds::PointTo ? TypeData::Pointer : TypeData::Reference ); 331 331 if ( qualifiers ) { 332 332 return newnode->addQualifiers( qualifiers ); … … 745 745 DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) { 746 746 if ( p ) { 747 assert( p->type->kind == TypeData::Pointer );747 assert( p->type->kind == TypeData::Pointer || TypeData::Reference ); 748 748 setBase( p->type ); 749 749 p->type = nullptr; -
src/Parser/ParseNode.h
r65aca88 rce8c12f 237 237 static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params ); 238 238 static DeclarationNode * newTypeDecl( std::string * name, DeclarationNode * typeParams ); 239 static DeclarationNode * newPointer( DeclarationNode * qualifiers );239 static DeclarationNode * newPointer( DeclarationNode * qualifiers, OperKinds kind ); 240 240 static DeclarationNode * newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic ); 241 241 static DeclarationNode * newVarArray( DeclarationNode * qualifiers ); -
src/Parser/TypeData.cc
r65aca88 rce8c12f 30 30 case Unknown: 31 31 case Pointer: 32 case Reference: 32 33 case EnumConstant: 33 34 // nothing else to initialize … … 99 100 case Unknown: 100 101 case Pointer: 102 case Reference: 101 103 case EnumConstant: 102 104 // nothing to destroy … … 165 167 case EnumConstant: 166 168 case Pointer: 169 case Reference: 167 170 // nothing else to copy 168 171 break; … … 434 437 case TypeData::Array: 435 438 return buildArray( td ); 439 case TypeData::Reference: 440 return buildReference( td ); 436 441 case TypeData::Function: 437 442 return buildFunction( td ); … … 612 617 buildForall( td->forall, at->get_forall() ); 613 618 return at; 614 } // buildPointer 619 } // buildArray 620 621 ReferenceType * buildReference( const TypeData * td ) { 622 ReferenceType * rt; 623 if ( td->base ) { 624 rt = new ReferenceType( buildQualifiers( td ), typebuild( td->base ) ); 625 } else { 626 rt = new ReferenceType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 627 } // if 628 buildForall( td->forall, rt->get_forall() ); 629 return rt; 630 } // buildReference 615 631 616 632 AggregateDecl * buildAggregate( const TypeData * td, std::list< Attribute * > attributes ) { -
src/Parser/TypeData.h
r65aca88 rce8c12f 21 21 22 22 struct TypeData { 23 enum Kind { Basic, Pointer, Array, Function, Aggregate, AggregateInst, Enum, EnumConstant, Symbolic,23 enum Kind { Basic, Pointer, Array, Reference, Function, Aggregate, AggregateInst, Enum, EnumConstant, Symbolic, 24 24 SymbolicInst, Tuple, Typeof, Builtin, Unknown }; 25 25 … … 101 101 PointerType * buildPointer( const TypeData * ); 102 102 ArrayType * buildArray( const TypeData * ); 103 ReferenceType * buildReference( const TypeData * ); 103 104 AggregateDecl * buildAggregate( const TypeData *, std::list< Attribute * > ); 104 105 ReferenceToType * buildComAggInst( const TypeData *, std::list< Attribute * > attributes ); -
src/Parser/parser.yy
r65aca88 rce8c12f 2377 2377 variable_ptr: 2378 2378 ptrref_operator variable_declarator 2379 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }2379 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2380 2380 | ptrref_operator type_qualifier_list variable_declarator 2381 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }2381 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2382 2382 | '(' variable_ptr ')' attribute_list_opt 2383 2383 { $$ = $2->addQualifiers( $4 ); } // redundant parenthesis … … 2425 2425 function_ptr: 2426 2426 ptrref_operator function_declarator 2427 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }2427 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2428 2428 | ptrref_operator type_qualifier_list function_declarator 2429 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }2429 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2430 2430 | '(' function_ptr ')' 2431 2431 { $$ = $2; } … … 2465 2465 KR_function_ptr: 2466 2466 ptrref_operator KR_function_declarator 2467 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }2467 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2468 2468 | ptrref_operator type_qualifier_list KR_function_declarator 2469 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }2469 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2470 2470 | '(' KR_function_ptr ')' 2471 2471 { $$ = $2; } … … 2509 2509 type_ptr: 2510 2510 ptrref_operator variable_type_redeclarator 2511 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }2511 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2512 2512 | ptrref_operator type_qualifier_list variable_type_redeclarator 2513 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }2513 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2514 2514 | '(' type_ptr ')' attribute_list_opt 2515 2515 { $$ = $2->addQualifiers( $4 ); } … … 2553 2553 identifier_parameter_ptr: 2554 2554 ptrref_operator identifier_parameter_declarator 2555 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }2555 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2556 2556 | ptrref_operator type_qualifier_list identifier_parameter_declarator 2557 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }2557 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2558 2558 | '(' identifier_parameter_ptr ')' attribute_list_opt 2559 2559 { $$ = $2->addQualifiers( $4 ); } … … 2613 2613 type_parameter_ptr: 2614 2614 ptrref_operator type_parameter_redeclarator 2615 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }2615 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2616 2616 | ptrref_operator type_qualifier_list type_parameter_redeclarator 2617 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }2617 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2618 2618 | '(' type_parameter_ptr ')' attribute_list_opt 2619 2619 { $$ = $2->addQualifiers( $4 ); } … … 2656 2656 abstract_ptr: 2657 2657 ptrref_operator 2658 { $$ = DeclarationNode::newPointer( 0 ); }2658 { $$ = DeclarationNode::newPointer( 0, $1 ); } 2659 2659 | ptrref_operator type_qualifier_list 2660 { $$ = DeclarationNode::newPointer( $2 ); }2660 { $$ = DeclarationNode::newPointer( $2, $1 ); } 2661 2661 | ptrref_operator abstract_declarator 2662 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }2662 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2663 2663 | ptrref_operator type_qualifier_list abstract_declarator 2664 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }2664 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2665 2665 | '(' abstract_ptr ')' attribute_list_opt 2666 2666 { $$ = $2->addQualifiers( $4 ); } … … 2745 2745 abstract_parameter_ptr: 2746 2746 ptrref_operator 2747 { $$ = DeclarationNode::newPointer( nullptr ); }2747 { $$ = DeclarationNode::newPointer( nullptr, $1 ); } 2748 2748 | ptrref_operator type_qualifier_list 2749 { $$ = DeclarationNode::newPointer( $2 ); }2749 { $$ = DeclarationNode::newPointer( $2, $1 ); } 2750 2750 | ptrref_operator abstract_parameter_declarator 2751 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr ) ); }2751 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 2752 2752 | ptrref_operator type_qualifier_list abstract_parameter_declarator 2753 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }2753 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2754 2754 | '(' abstract_parameter_ptr ')' attribute_list_opt 2755 2755 { $$ = $2->addQualifiers( $4 ); } … … 2824 2824 variable_abstract_ptr: 2825 2825 ptrref_operator 2826 { $$ = DeclarationNode::newPointer( 0 ); }2826 { $$ = DeclarationNode::newPointer( 0, $1 ); } 2827 2827 | ptrref_operator type_qualifier_list 2828 { $$ = DeclarationNode::newPointer( $2 ); }2828 { $$ = DeclarationNode::newPointer( $2, $1 ); } 2829 2829 | ptrref_operator variable_abstract_declarator 2830 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }2830 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2831 2831 | ptrref_operator type_qualifier_list variable_abstract_declarator 2832 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }2832 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2833 2833 | '(' variable_abstract_ptr ')' attribute_list_opt 2834 2834 { $$ = $2->addQualifiers( $4 ); } … … 2870 2870 // No SUE declaration in parameter list. 2871 2871 ptrref_operator type_specifier_nobody 2872 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }2872 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2873 2873 | type_qualifier_list ptrref_operator type_specifier_nobody 2874 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }2874 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); } 2875 2875 | ptrref_operator cfa_abstract_function 2876 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }2876 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2877 2877 | type_qualifier_list ptrref_operator cfa_abstract_function 2878 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }2878 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); } 2879 2879 | ptrref_operator cfa_identifier_parameter_declarator_tuple 2880 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }2880 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2881 2881 | type_qualifier_list ptrref_operator cfa_identifier_parameter_declarator_tuple 2882 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }2882 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); } 2883 2883 ; 2884 2884 … … 2958 2958 cfa_abstract_ptr: // CFA 2959 2959 ptrref_operator type_specifier 2960 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }2960 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2961 2961 | type_qualifier_list ptrref_operator type_specifier 2962 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }2962 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); } 2963 2963 | ptrref_operator cfa_abstract_function 2964 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }2964 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2965 2965 | type_qualifier_list ptrref_operator cfa_abstract_function 2966 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }2966 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); } 2967 2967 | ptrref_operator cfa_abstract_declarator_tuple 2968 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }2968 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); } 2969 2969 | type_qualifier_list ptrref_operator cfa_abstract_declarator_tuple 2970 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }2970 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); } 2971 2971 ; 2972 2972 -
src/ResolvExpr/Unify.cc
r65aca88 rce8c12f 42 42 virtual void visit(PointerType *pointerType); 43 43 virtual void visit(ArrayType *arrayType); 44 virtual void visit(ReferenceType *refType); 44 45 virtual void visit(FunctionType *functionType); 45 46 virtual void visit(StructInstType *aggregateUseType); … … 428 429 } 429 430 431 void Unify::visit(ReferenceType *refType) { 432 if ( ReferenceType *otherRef = dynamic_cast< ReferenceType* >( type2 ) ) { 433 result = unifyExact( refType->get_base(), otherRef->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 434 markAssertions( haveAssertions, needAssertions, refType ); 435 markAssertions( haveAssertions, needAssertions, otherRef ); 436 } // if 437 } 438 430 439 void Unify::visit(ArrayType *arrayType) { 431 440 ArrayType *otherArray = dynamic_cast< ArrayType* >( type2 ); … … 595 604 TypeExpr *otherParam = dynamic_cast< TypeExpr* >(*jt); 596 605 assertf(otherParam, "Aggregate parameters should be type expressions"); 597 606 598 607 Type* paramTy = param->get_type(); 599 608 Type* otherParamTy = otherParam->get_type(); -
src/SymTab/Autogen.cc
r65aca88 rce8c12f 176 176 FunctionType * ftype = funcDecl->get_functionType(); 177 177 assert( ! ftype->get_parameters().empty() ); 178 Type * t = safe_dynamic_cast< PointerType * >( ftype->get_parameters().front()->get_type() )->get_base(); 178 Type * t = InitTweak::getPointerBase( ftype->get_parameters().front()->get_type() ); 179 assert( t ); 179 180 map.insert( Mangler::mangleType( t ), true ); 180 181 } -
src/SymTab/Indexer.cc
r65aca88 rce8c12f 156 156 assert( ! params.empty() ); 157 157 // use base type of pointer, so that qualifiers on the pointer type aren't considered. 158 Type * base = safe_dynamic_cast< PointerType * >( params.front()->get_type() )->get_base(); 158 Type * base = InitTweak::getPointerBase( params.front()->get_type() ); 159 assert( base ); 159 160 funcMap[ Mangler::mangle( base ) ] += function; 160 161 } else { -
src/SymTab/Validate.cc
r65aca88 rce8c12f 818 818 } 819 819 PointerType * ptrType = dynamic_cast< PointerType * >( params.front()->get_type() ); 820 if ( ! ptrType || ptrType->is_array() ) { 820 ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() ); 821 if ( ( ! ptrType && ! refType ) || ( ptrType && ptrType->is_array() ) ) { 821 822 throw SemanticError( "First parameter of a constructor, destructor, or assignment function must be a pointer ", funcDecl ); 822 823 } -
src/SynTree/AddressExpr.cc
r65aca88 rce8c12f 20 20 AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) { 21 21 if ( arg->has_result() ) { 22 set_result( new PointerType( Type::Qualifiers(), arg->get_result()->clone() ) ); 22 if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( arg->get_result() ) ) { 23 // xxx - very temporary, make &ref look like ** 24 set_result( new PointerType( Type::Qualifiers( Type::Lvalue ), refType->get_base()->clone() ) ); 25 } else { 26 set_result( new PointerType( Type::Qualifiers(), arg->get_result()->clone() ) ); 27 } 23 28 } 24 29 } -
src/SynTree/Mutator.cc
r65aca88 rce8c12f 462 462 } 463 463 464 Type *Mutator::mutate( ReferenceType *refType ) { 465 mutateAll( refType->get_forall(), *this ); 466 refType->set_base( maybeMutate( refType->get_base(), *this ) ); 467 return refType; 468 } 469 464 470 Type *Mutator::mutate( FunctionType *functionType ) { 465 471 mutateAll( functionType->get_forall(), *this ); -
src/SynTree/Mutator.h
r65aca88 rce8c12f 91 91 virtual Type* mutate( PointerType *pointerType ); 92 92 virtual Type* mutate( ArrayType *arrayType ); 93 virtual Type* mutate( ReferenceType *refType ); 93 94 virtual Type* mutate( FunctionType *functionType ); 94 95 virtual Type* mutate( StructInstType *aggregateUseType ); -
src/SynTree/SynTree.h
r65aca88 rce8c12f 99 99 class PointerType; 100 100 class ArrayType; 101 class ReferenceType; 101 102 class FunctionType; 102 103 class ReferenceToType; -
src/SynTree/Type.h
r65aca88 rce8c12f 249 249 bool is_array() const { return isStatic || isVarLen || dimension; } 250 250 251 virtual bool isComplete() const { return ! isVarLen; } 252 251 253 virtual PointerType *clone() const { return new PointerType( *this ); } 252 254 virtual void accept( Visitor & v ) { v.visit( this ); } … … 290 292 }; 291 293 294 class ReferenceType : public Type { 295 public: 296 ReferenceType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 297 ReferenceType( const ReferenceType & ); 298 virtual ~ReferenceType(); 299 300 Type *get_base() { return base; } 301 void set_base( Type *newValue ) { base = newValue; } 302 303 virtual ReferenceType *clone() const { return new ReferenceType( *this ); } 304 virtual void accept( Visitor & v ) { v.visit( this ); } 305 virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } 306 virtual void print( std::ostream & os, int indent = 0 ) const; 307 private: 308 Type *base; 309 unsigned int level = 0; 310 }; 311 292 312 class FunctionType : public Type { 293 313 public: -
src/SynTree/Visitor.cc
r65aca88 rce8c12f 354 354 void Visitor::visit( PointerType *pointerType ) { 355 355 acceptAll( pointerType->get_forall(), *this ); 356 // xxx - should PointerType visit/mutate dimension? 356 357 maybeAccept( pointerType->get_base(), *this ); 357 358 } … … 361 362 maybeAccept( arrayType->get_dimension(), *this ); 362 363 maybeAccept( arrayType->get_base(), *this ); 364 } 365 366 void Visitor::visit( ReferenceType *refType ) { 367 acceptAll( refType->get_forall(), *this ); 368 maybeAccept( refType->get_base(), *this ); 363 369 } 364 370 -
src/SynTree/Visitor.h
r65aca88 rce8c12f 94 94 virtual void visit( PointerType *pointerType ); 95 95 virtual void visit( ArrayType *arrayType ); 96 virtual void visit( ReferenceType *refType ); 96 97 virtual void visit( FunctionType *functionType ); 97 98 virtual void visit( StructInstType *aggregateUseType ); … … 163 164 } // if 164 165 } catch( SemanticError &e ) { 165 e.set_location( (*i)->location ); 166 e.set_location( (*i)->location ); 166 167 errors.append( e ); 167 168 } // try -
src/SynTree/module.mk
r65aca88 rce8c12f 20 20 SynTree/PointerType.cc \ 21 21 SynTree/ArrayType.cc \ 22 SynTree/ReferenceType.cc \ 22 23 SynTree/FunctionType.cc \ 23 24 SynTree/ReferenceToType.cc \
Note: See TracChangeset
for help on using the changeset viewer.