- Timestamp:
- Jun 4, 2019, 4:45:04 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- de8dfac2
- Parents:
- 4ae2364
- Location:
- src/AST
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Expr.cpp
r4ae2364 ree574a2 65 65 // base type 66 66 ret->result = base; 67 add_ lvalue( ret->result);67 add_qualifiers( ret->result, CV::Lvalue ); 68 68 } 69 69 } … … 165 165 genericSubsitution( aggregate->result ).apply( result ); 166 166 // ensure lvalue and appropriate restrictions from aggregate type 167 result.get_and_mutate()->qualifiers |= aggregate->result->qualifiers | CV::Lvalue;167 add_qualifiers( result, aggregate->result->qualifiers | CV::Lvalue ); 168 168 } 169 169 … … 175 175 assert( var->get_type() ); 176 176 result = var->get_type(); 177 add_ lvalue( result);177 add_qualifiers( result, CV::Lvalue ); 178 178 } 179 179 … … 309 309 assert( t && i ); 310 310 result = t; 311 add_ lvalue( result);311 add_qualifiers( result, CV::Lvalue ); 312 312 } 313 313 … … 326 326 // like MemberExpr, TupleIndexExpr is always an lvalue 327 327 result = type->types[ index ]; 328 add_ lvalue( result);328 add_qualifiers( result, CV::Lvalue ); 329 329 } 330 330 -
src/AST/Node.hpp
r4ae2364 ree574a2 166 166 const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); } 167 167 168 /// wrapper for convenient access to strict_dynamic_cast 169 template<typename o_node_t> 170 const o_node_t * strict_as() const { return strict_dynamic_cast<const o_node_t *>(node); } 171 168 172 /// Returns a mutable version of the pointer in this node. 169 173 node_t * get_and_mutate(); -
src/AST/Type.hpp
r4ae2364 ree574a2 77 77 }; 78 78 79 /// Set the `is_lvalue` qualifieron this type, cloning only if necessary79 /// Clear/reset the qualifiers on this type, cloning only if necessary 80 80 template< enum Node::ref_type ref_t > 81 void add_lvalue( ptr_base< Type, ref_t > & p) {82 if ( ! p->qualifiers.is_lvalue ) p.get_and_mutate()->qualifiers.is_lvalue = true;81 void reset_qualifiers( ptr_base< Type, ref_t > & p, CV::Qualifiers q = {} ) { 82 if ( p->qualifiers.val != q.val ) p.get_and_mutate()->qualifiers = q; 83 83 } 84 84 85 /// Clear the qualifiers onthis type, cloning only if necessary85 /// Add the specified qualifiers to this type, cloning only if necessary 86 86 template< enum Node::ref_type ref_t > 87 void clear_qualifiers( ptr_base< Type, ref_t > & p ) { 88 if ( p->qualifiers != CV::Qualifiers{} ) p.get_and_mutate()->qualifiers = CV::Qualifiers{}; 87 void add_qualifiers( ptr_base< Type, ref_t > & p, CV::Qualifiers q ) { 88 if ( ( p->qualifiers.val & q.val ) != q.val ) p.get_and_mutate()->qualifiers |= q; 89 } 90 91 /// Remove the specified qualifiers from this type, cloning only if necessary 92 template< enum Node::ref_type ref_t > 93 void remove_qualifiers( ptr_base< Type, ref_t > & p, CV::Qualifiers q ) { 94 if ( ( p->qualifiers.val & q.val ) != 0 ) p.get_and_mutate()->qualifiers -= q; 89 95 } 90 96 -
src/AST/TypeEnvironment.cpp
r4ae2364 ree574a2 235 235 } 236 236 237 /// true if a type is a function type 238 bool isFtype( const Type * type ) { 239 if ( dynamic_cast< const FunctionType * >( type ) ) { 240 return true; 241 } else if ( auto typeInst = dynamic_cast< const TypeInstType * >( type ) ) { 242 return typeInst->kind == TypeVar::Ftype; 243 } else return false; 244 } 245 237 246 namespace { 238 /// true if a type is a function type239 bool isFtype( const Type * type ) {240 if ( dynamic_cast< const FunctionType * >( type ) ) {241 return true;242 } else if ( auto typeInst = dynamic_cast< const TypeInstType * >( type ) ) {243 return typeInst->kind == TypeVar::Ftype;244 } else return false;245 }246 247 247 /// true if the given type can be bound to the given type variable 248 248 bool tyVarCompatible( const TypeDecl::Data & data, const Type * type ) { … … 285 285 ptr<Type> common; 286 286 ptr<Type> newType = it->bound; 287 newType.get_and_mutate()->qualifiers = typeInst->qualifiers;287 reset_qualifiers( newType, typeInst->qualifiers ); 288 288 if ( unifyInexact( 289 289 newType, target, *this, need, have, open, … … 291 291 if ( common ) { 292 292 it->bound = std::move(common); 293 clear_qualifiers( it->bound );293 reset_qualifiers( it->bound ); 294 294 } 295 295 } else return false; 296 296 } else { 297 297 it->bound = std::move(target); 298 clear_qualifiers( it->bound );298 reset_qualifiers( it->bound ); 299 299 it->allowWidening = widen.first && widen.second; 300 300 } … … 351 351 if ( common ) { 352 352 c1->bound = std::move(common); 353 clear_qualifiers( c1->bound );353 reset_qualifiers( c1->bound ); 354 354 } 355 355 c1->data.isComplete |= data.isComplete; … … 411 411 if ( common ) { 412 412 to.bound = std::move(common); 413 clear_qualifiers( to.bound );413 reset_qualifiers( to.bound ); 414 414 } 415 415 } else return false; // cannot unify -
src/AST/TypeEnvironment.hpp
r4ae2364 ree574a2 112 112 EqvClass( const std::string & v, const Type * b, bool w, const TypeDecl::Data & d ) 113 113 : vars{ v }, bound( b ), allowWidening( w ), data( d ) { 114 clear_qualifiers( bound );114 reset_qualifiers( bound ); 115 115 } 116 116
Note: See TracChangeset
for help on using the changeset viewer.