Changeset 8217e8f
- Timestamp:
- Aug 14, 2017, 2:07:34 PM (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:
- 6cfe8bb
- Parents:
- 36a5a77 (diff), bd46af4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 7 added
- 1 deleted
- 9 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/virtual.txt
r36a5a77 r8217e8f 147 147 148 148 This gives us an important extra feature, runtime checking of the parent-child 149 relationship with a C++ dynamic_cast like operation. Allowing checked 150 conversions from trait references to more particular references, which works 151 if the underlying type is, or is a child of, the new trait type. 149 relationship with virtual cast, where a pointer (and maybe a reference) to 150 a virtual type can be cast to another virtual cast. However the cast is 151 dynamicly check and only occurs if the underlying type is a child of the type 152 being cast to. Otherwise null is returned. 153 154 (virtual TYPE)EXPR 155 156 As an extention, the TYPE may be ommitted if it can be determained from 157 context, for instance if the cast occurs on the right hand side of an 158 assignment. 152 159 153 160 Extension: Multiple Parents … … 251 258 autogenerated and often unique. 252 259 260 It may be worth looking into a way to force the vtable pointer to be in a 261 particular location, which would save the storage to store the offset and 262 maybe the offset operation itself (offset = 0). However it may not be worth 263 introducing a new language feature for. 264 As of writing, exceptions actually use this system. 265 253 266 254 267 Keyword Usage: … … 276 289 Calling free on a trait reference will free the memory for the object. It will 277 290 leave the vtables alone, as those are (always?) statically allocated. 291 292 293 Special Traits: 294 295 trait is_virtual_parent(dtype parent, dtype child) { ... }; 296 297 There are others but I believe this one to be the most important. The trait 298 holds if the parent type is a strict virtual ancestor (any number of levels) 299 of child. It will have to exist at least internally to check for upcasts and 300 it can also be used to optimize virtual casts into upcasts. Or a null value or 301 error if the cast would never succeed. Exporting it to a special trait allows 302 users to express that requirement in their own polymorphic code. 303 304 305 Implementation: 306 307 Before we can generate any of the nessasary code, the compiler has to get some 308 additional information about the code that it currently does not collect. 309 310 First it should establish all child->parent links so that it may travel up the 311 hierarchy to grab the nessasary information, and create the actual parent 312 pointers in the strict virtual tables. It should also maintain the connections 313 between the virtual type (structure or trait), the vtable type and the vtable 314 instance (or default instance for relaxed virtual if multiple are allowed). To 315 this end a sub-node should be created with the nessasary pointers. Traits and 316 structs with virtual can create an instance and store all the nessasary data. 317 318 With the hierarchy in place it can generate the vtable type for each type, 319 it will generally have a function pointer field for each type assertion in 320 some consistant order. Strict virtual will also have a pointer to the parent's 321 vtable and intrusive vtables will also have the offset to recover the original 322 pointer. Sized types will also carry the size. 323 324 Wheither the vtable is intrusive or not should also be save so that the trait 325 object/reference/pointer knows if it has to store 1 or 2 pointers. A wrapper 326 function will have to be generated for each type assertion so that they may 327 be called on the trait type, these can probably be inlined. 328 329 The virtual parameter will also have to be marked (implicately or explicately) 330 until code generation so that the wrapper functions know where to go to get 331 the vtable for the function look up. That could probably be added as a 332 storageclass, although one that is only valid on type assertions. 333 334 The generated vtable will than have to have a vtable instance created and 335 filled with all the approprate values. Stricter matching may have to be used 336 to ensure that the functions used are stable. It will also have to use 337 ".gnu.linkonce" or equilant to ensure only one copy exists in the final code 338 base. -
src/Common/Indenter.h
r36a5a77 r8217e8f 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // utility.h --7 // Indenter.h -- 8 8 // 9 // Author : R ichard C. Bilson10 // Created On : Mon May 18 07:44:20 20159 // Author : Rob Schluntz 10 // Created On : Fri Jun 30 16:55:23 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri May 5 11:03:00 201713 // Update Count : 3212 // Last Modified On : Fri Aug 11 11:15:00 2017 13 // Update Count : 1 14 14 // 15 15 -
src/ControlStruct/MLEMutator.cc
r36a5a77 r8217e8f 154 154 return switchStmt; 155 155 } 156 157 void addUnused( Statement * stmt, const Label & originalTarget ) { 158 // break/continue without a label doesn't need unused attribute 159 if ( originalTarget == "" ) return; 160 // add unused attribute to the originalTarget of a labelled break/continue 161 for ( Label & l : stmt->get_labels() ) { 162 // find the label to add unused attribute to 163 if ( l == originalTarget ) { 164 for ( Attribute * attr : l.get_attributes() ) { 165 // ensure attribute isn't added twice 166 if ( attr->get_name() == "unused" ) return; 167 } 168 l.get_attributes().push_back( new Attribute( "unused" ) ); 169 return; 170 } 171 } 172 assertf( false, "Could not find label '%s' on statement %s", originalTarget.get_name().c_str(), toString( stmt ).c_str() ); 173 } 174 156 175 157 176 Statement *MLEMutator::mutate( BranchStmt *branchStmt ) throw ( SemanticError ) { … … 204 223 } // switch 205 224 225 // add unused attribute to label to silence warnings 226 addUnused( targetEntry->get_controlStructure(), branchStmt->get_originalTarget() ); 227 206 228 // transform break/continue statements into goto to simplify later handling of branches 207 229 delete branchStmt; -
src/Parser/DeclarationNode.cc
r36a5a77 r8217e8f 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jul 14 16:55:00 201713 // Update Count : 102 012 // Last Modified On : Thr Aug 10 17:02:00 2017 13 // Update Count : 1021 14 14 // 15 15 … … 275 275 return newnode; 276 276 } // DeclarationNode::newEnumConstant 277 278 DeclarationNode * DeclarationNode::newTreeStruct( Aggregate kind, const string * name, const string * parent, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {279 assert( name );280 DeclarationNode * newnode = new DeclarationNode;281 newnode->type = new TypeData( TypeData::Aggregate );282 newnode->type->aggregate.kind = kind;283 newnode->type->aggregate.name = name;284 newnode->type->aggregate.actuals = actuals;285 newnode->type->aggregate.fields = fields;286 newnode->type->aggregate.body = body;287 newnode->type->aggregate.tagged = true;288 newnode->type->aggregate.parent = parent;289 return newnode;290 } // DeclarationNode::newTreeStruct291 277 292 278 DeclarationNode * DeclarationNode::newName( string * name ) { -
src/Parser/ParseNode.h
r36a5a77 r8217e8f 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:28:16 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Jul 27 12:08:08201713 // Update Count : 78 811 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Aug 10 16:54:00 2017 13 // Update Count : 789 14 14 // 15 15 … … 248 248 static DeclarationNode * newAsmStmt( StatementNode * stmt ); // gcc external asm statement 249 249 250 // Perhaps this would best fold into newAggragate.251 static DeclarationNode * newTreeStruct( Aggregate kind, const std::string * name, const std::string * parent, ExpressionNode * actuals, DeclarationNode * fields, bool body );252 253 250 DeclarationNode(); 254 251 ~DeclarationNode(); … … 335 332 336 333 static UniqueName anonymous; 337 338 // Temp to test TreeStruct339 const std::string * parent_name;340 334 }; // DeclarationNode 341 335 -
src/Parser/TypeData.cc
r36a5a77 r8217e8f 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 9 13:50:00 201713 // Update Count : 56 712 // Last Modified On : Mon Aug 14 10:41:00 2017 13 // Update Count : 568 14 14 // 15 15 … … 64 64 aggregate.fields = nullptr; 65 65 aggregate.body = false; 66 aggregate.tagged = false;67 aggregate.parent = nullptr;68 66 break; 69 67 case AggregateInst: … … 125 123 delete aggregate.actuals; 126 124 delete aggregate.fields; 127 delete aggregate.parent;128 125 // delete aggregate; 129 126 break; … … 640 637 switch ( td->aggregate.kind ) { 641 638 case DeclarationNode::Struct: 642 if ( td->aggregate.tagged ) {643 at = new StructDecl( *td->aggregate.name, td->aggregate.parent, attributes, linkage );644 buildForall( td->aggregate.params, at->get_parameters() );645 break;646 }647 639 case DeclarationNode::Coroutine: 648 640 case DeclarationNode::Monitor: … … 652 644 break; 653 645 case DeclarationNode::Union: 654 at = new UnionDecl( *td->aggregate.name, attributes );646 at = new UnionDecl( *td->aggregate.name, attributes, linkage ); 655 647 buildForall( td->aggregate.params, at->get_parameters() ); 656 648 break; 657 649 case DeclarationNode::Trait: 658 at = new TraitDecl( *td->aggregate.name, attributes );650 at = new TraitDecl( *td->aggregate.name, attributes, linkage ); 659 651 buildList( td->aggregate.params, at->get_parameters() ); 660 652 break; … … 673 665 case TypeData::Enum: { 674 666 if ( type->enumeration.body ) { 675 EnumDecl * typedecl = buildEnum( type, attributes );667 EnumDecl * typedecl = buildEnum( type, attributes, linkage ); 676 668 return new EnumInstType( buildQualifiers( type ), typedecl ); 677 669 } else { … … 778 770 } // buildSymbolic 779 771 780 EnumDecl * buildEnum( const TypeData * td, std::list< Attribute * > attributes ) {772 EnumDecl * buildEnum( const TypeData * td, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) { 781 773 assert( td->kind == TypeData::Enum ); 782 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes );774 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage ); 783 775 buildList( td->enumeration.constants, ret->get_members() ); 784 776 list< Declaration * >::iterator members = ret->get_members().begin(); … … 831 823 return buildAggregate( td, attributes, linkage ); 832 824 } else if ( td->kind == TypeData::Enum ) { 833 return buildEnum( td, attributes );825 return buildEnum( td, attributes, linkage ); 834 826 } else if ( td->kind == TypeData::Symbolic ) { 835 827 return buildSymbolic( td, name, scs, linkage ); -
src/Parser/TypeData.h
r36a5a77 r8217e8f 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:18:36 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:32:47201713 // Update Count : 18 811 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Aug 14 10:38:00 2017 13 // Update Count : 189 14 14 // 15 15 … … 108 108 ReferenceToType * buildAggInst( const TypeData * ); 109 109 TypeDecl * buildVariable( const TypeData * ); 110 EnumDecl * buildEnum( const TypeData *, std::list< Attribute * > );110 EnumDecl * buildEnum( const TypeData *, std::list< Attribute * >, LinkageSpec::Spec ); 111 111 TypeInstType * buildSymbolicInst( const TypeData * ); 112 112 TupleType * buildTuple( const TypeData * ); -
src/SynTree/Declaration.h
r36a5a77 r8217e8f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 9 14:45:00 201713 // Update Count : 12 612 // Last Modified On : Mon Aug 14 10:15:00 2017 13 // Update Count : 128 14 14 // 15 15 … … 269 269 typedef AggregateDecl Parent; 270 270 public: 271 StructDecl( const std::string &name, DeclarationNode::Aggregate kind = DeclarationNode::Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( kind ), tagged( false ), parent_name( "" ) {} 272 StructDecl( const std::string &name, const std::string *parent, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( DeclarationNode::Struct ), tagged( true ), parent_name( parent ? *parent : "" ) {} 273 StructDecl( const StructDecl &other ) : Parent( other ) {} 271 StructDecl( const std::string &name, DeclarationNode::Aggregate kind = DeclarationNode::Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( kind ) {} 272 StructDecl( const StructDecl &other ) : Parent( other ), kind( other.kind ) {} 274 273 275 274 bool is_coroutine() { return kind == DeclarationNode::Coroutine; } … … 277 276 bool is_thread() { return kind == DeclarationNode::Thread; } 278 277 279 // Tagged/Tree Structure Excetion280 bool get_tagged() { return tagged; }281 void set_tagged( bool newValue ) { tagged = newValue; }282 bool has_parent() { return parent_name != ""; }283 std::string get_parentName() { return parent_name; }284 285 278 virtual StructDecl *clone() const { return new StructDecl( *this ); } 286 279 virtual void accept( Visitor &v ) { v.visit( this ); } … … 289 282 DeclarationNode::Aggregate kind; 290 283 virtual std::string typeString() const; 291 292 bool tagged;293 std::string parent_name;294 284 }; 295 285 … … 323 313 typedef AggregateDecl Parent; 324 314 public: 325 TraitDecl( const std::string &name, const std::list< Attribute * > & attributes ) : Parent( name ) {315 TraitDecl( const std::string &name, const std::list< Attribute * > & attributes, LinkageSpec::Spec linkage ) : Parent( name, attributes, linkage ) { 326 316 assertf( attributes.empty(), "attribute unsupported for traits" ); 327 317 } -
src/tests/.expect/32/math2.txt
r36a5a77 r8217e8f 1 fmod:1 1 1 1 1 12 remainder:-1 -1 -13 remquo:7 0.0999999 7 0.1 7 0.09999999999999999994 div:7, 0.2 7, 0.2 7, 0.25 fma:-2 -2 -26 fdim:2 2 27 nan:nan nan nan8 exp:2.71828 2.71828182845905 2.71828182845904524 1.46869+2.28736i 1.46869393991589+2.28735528717884i 1.46869393991588516+2.28735528717884239i9 exp2:2 2 210 expm1:1.71828 1.71828182845905 1.7182818284590452411 pow:1 1 1 0.273957+0.583701i 0.273957253830121+0.583700758758615i 0.273957253830121071+0.583700758758614628i12 16 25613 912673 256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i14 log:0 0 0 0.346574+0.785398i 0.346573590279973+0.785398163397448i 0.346573590279972655+0.78539816339744831i15 log2:3 3 316 log10:2 2 217 log1p:0.693147 0.693147180559945 0.69314718055994530918 ilogb:0 0 019 logb:3 3 320 sqrt:1 1 1 1.09868+0.45509i 1.09868411346781+0.455089860562227i 1.09868411346780997+0.455089860562227341i21 cbrt:3 3 322 hypot:1.41421 1.4142135623731 1.4142135623730950523 1 sin:0.841471 0.841470984807897 0.841470984807896507 1.29846+0.634964i 1.29845758141598+0.634963914784736i 1.29845758141597729+0.634963914784736108i 24 2 cos:0.540302 0.54030230586814 0.540302305868139717 0.83373-0.988898i 0.833730025131149-0.988897705762865i 0.833730025131149049-0.988897705762865096i … … 27 5 acos:0 0 0 0.904557-1.06128i 0.904556894302381-1.06127506190504i 0.904556894302381364-1.06127506190503565i 28 6 atan:0.785398 0.785398163397448 0.78539816339744831 1.01722+0.402359i 1.01722196789785+0.402359478108525i 1.01722196789785137+0.402359478108525094i 29 atan2:0.785398 0.785398163397448 0.78539816339744831 atan:0.785398 0.785398163397448 0.78539816339744831 sinh:1.1752 1.1752011936438 1.17520119364380146 0.634964+1.29846i 0.634963914784736+1.29845758141598i 0.634963914784736108+1.29845758141597729i 7 atan2:0.785398 0.785398163397448 0.78539816339744831 atan:0.785398 0.785398163397448 0.78539816339744831 8 sinh:1.1752 1.1752011936438 1.17520119364380146 0.634964+1.29846i 0.634963914784736+1.29845758141598i 0.634963914784736108+1.29845758141597729i 30 9 cosh:1.54308 1.54308063481524 1.54308063481524378 0.83373+0.988898i 0.833730025131149+0.988897705762865i 0.833730025131149049+0.988897705762865096i 31 10 tanh:0.761594 0.761594155955765 0.761594155955764888 1.08392+0.271753i 1.08392332733869+0.271752585319512i 1.08392332733869454+0.271752585319511717i … … 38 17 lgamma:1.79176 1 1.79175946922805 1 1.791759469228055 1 39 18 tgamma:6 6 6 40 floor:1 1 141 ceil:2 2 242 trunc:3 3 343 rint:2 2 244 rint:2 2 245 rint:2 2 246 lrint:2 2 247 llrint:2 2 248 nearbyint:4 4 449 round:2 2 250 round:2 2 251 round:2 2 252 lround:2 2 253 llround:2 2 254 copysign:-1 -1 -155 frexp:0.5 3 0.5 3 0.5 356 ldexp:8 8 857 modf:2 0.3 2 0.3 2 0.358 modf:2, 0.3 2, 0.3 2, 0.359 nextafter:2 2 260 nexttoward:2 2 261 scalbn:16 16 1662 scalbln:16 16 16 -
src/tests/.expect/64/math2.txt
r36a5a77 r8217e8f 1 fmod:1 1 1 1 1 12 remainder:-1 -1 -13 remquo:7 0.0999999 7 0.1 7 0.09999999999999999994 div:7, 0.2 7, 0.2 7, 0.25 fma:-2 -2 -26 fdim:2 2 27 nan:nan nan nan8 exp:2.71828 2.71828182845905 2.71828182845904524 1.46869+2.28736i 1.46869393991589+2.28735528717884i 1.46869393991588516+2.28735528717884239i9 exp2:2 2 210 expm1:1.71828 1.71828182845905 1.7182818284590452411 pow:1 1 1 0.273957+0.583701i 0.273957253830121+0.583700758758615i 0.273957253830121071+0.583700758758614627i12 16 25613 912673 256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i14 log:0 0 0 0.346574+0.785398i 0.346573590279973+0.785398163397448i 0.346573590279972655+0.78539816339744831i15 log2:3 3 316 log10:2 2 217 log1p:0.693147 0.693147180559945 0.69314718055994530918 ilogb:0 0 019 logb:3 3 320 sqrt:1 1 1 1.09868+0.45509i 1.09868411346781+0.455089860562227i 1.09868411346780997+0.455089860562227341i21 cbrt:3 3 322 hypot:1.41421 1.4142135623731 1.4142135623730950523 1 sin:0.841471 0.841470984807897 0.841470984807896507 1.29846+0.634964i 1.29845758141598+0.634963914784736i 1.29845758141597729+0.634963914784736108i 24 2 cos:0.540302 0.54030230586814 0.540302305868139717 0.83373-0.988898i 0.833730025131149-0.988897705762865i 0.833730025131149049-0.988897705762865096i … … 27 5 acos:0 0 0 0.904557-1.06128i 0.904556894302381-1.06127506190504i 0.904556894302381364-1.06127506190503565i 28 6 atan:0.785398 0.785398163397448 0.78539816339744831 1.01722+0.402359i 1.01722196789785+0.402359478108525i 1.01722196789785137+0.402359478108525094i 29 atan2:0.785398 0.785398163397448 0.78539816339744831 atan:0.785398 0.785398163397448 0.78539816339744831 sinh:1.1752 1.1752011936438 1.17520119364380146 0.634964+1.29846i 0.634963914784736+1.29845758141598i 0.634963914784736108+1.29845758141597729i 7 atan2:0.785398 0.785398163397448 0.78539816339744831 atan:0.785398 0.785398163397448 0.78539816339744831 8 sinh:1.1752 1.1752011936438 1.17520119364380146 0.634964+1.29846i 0.634963914784736+1.29845758141598i 0.634963914784736108+1.29845758141597729i 30 9 cosh:1.54308 1.54308063481524 1.54308063481524378 0.83373+0.988898i 0.833730025131149+0.988897705762865i 0.833730025131149049+0.988897705762865096i 31 10 tanh:0.761594 0.761594155955765 0.761594155955764888 1.08392+0.271753i 1.08392332733869+0.271752585319512i 1.08392332733869454+0.271752585319511717i … … 38 17 lgamma:1.79176 1 1.79175946922805 1 1.791759469228055 1 39 18 tgamma:6 6 6 40 floor:1 1 141 ceil:2 2 242 trunc:3 3 343 rint:2 2 244 rint:2 2 245 rint:2 2 246 lrint:2 2 247 llrint:2 2 248 nearbyint:4 4 449 round:2 2 250 round:2 2 251 round:2 2 252 lround:2 2 253 llround:2 2 254 copysign:-1 -1 -155 frexp:0.5 3 0.5 3 0.5 356 ldexp:8 8 857 modf:2 0.3 2 0.3 2 0.358 modf:2, 0.3 2, 0.3 2, 0.359 nextafter:2 2 260 nexttoward:2 2 261 scalbn:16 16 1662 scalbln:16 16 16 -
src/tests/pybin/tools.py
r36a5a77 r8217e8f 85 85 "--unchanged-group-format='%%=' \\" 86 86 "--changed-group-format='\t\texpected :\n" 87 "%%< \n"87 "%%<" 88 88 "\t\tgot :\n" 89 "%%> ' \\\n"89 "%%>\n' \\\n" 90 90 "--new-line-format='\t\t%%dn\t%%L' \\\n" 91 91 "--old-line-format='\t\t%%dn\t%%L' \\\n" … … 94 94 95 95 # fetch return code and error from the diff command 96 return sh(diff_cmd % (lhs, rhs), dry_run, False) 96 return sh(diff_cmd % (lhs, rhs), dry_run, False)
Note: See TracChangeset
for help on using the changeset viewer.