Changeset 4c42a5f
- Timestamp:
- Sep 20, 2018, 3:01:43 PM (5 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 371ef1d
- Parents:
- 91a950c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeTools/ResolvProtoDump.cc
r91a950c r4c42a5f 196 196 } 197 197 198 // default to just name 199 ss << pre << name; 198 // default to just name, with first character in lowercase 199 ss << pre 200 << (char)std::tolower( static_cast<unsigned char>(name[0]) ) 201 << (name.c_str() + 1); 200 202 } 201 203 202 204 /// ensures type inst names are uppercase 203 205 static void ti_name( const std::string& name, std::stringstream& ss ) { 204 ss << (char)std::toupper( static_cast<unsigned char>(name[0]) ) 205 << (name.c_str() + 1); 206 unsigned i = 0; 207 while ( i < name.size() && name[i] == '_' ) { ++i; } 208 if ( i == name.size() ) { 209 ss << "Anon"; 210 return; 211 } 212 ss << (char)std::toupper( static_cast<unsigned char>(name[i]) ) 213 << (name.c_str() + i + 1); 206 214 } 207 215 … … 219 227 void previsit( BasicType* bt ) { ss << (int)bt->get_kind(); } 220 228 221 // pointers represented as generic type 222 // TODO except pointer to function 223 void previsit( PointerType* ) { ss << "#$ptr<"; ++depth; } 224 void postvisit( PointerType* ) { --depth; ss << '>'; } 225 226 // arrays represented as generic type 229 // pointers (except function pointers) represented as generic type 230 void previsit( PointerType* pt ) { 231 if ( ! dynamic_cast<FunctionType*>(pt->base) ) { ss << "#$ptr<"; ++depth; } 232 } 233 void postvisit( PointerType* pt ) { 234 if ( ! dynamic_cast<FunctionType*>(pt->base) ) { --depth; ss << '>'; } 235 } 236 237 // arrays represented as generic pointers 227 238 void previsit( ArrayType* at ) { 228 ss << "#$ arr<";239 ss << "#$ptr<"; 229 240 ++depth; 230 241 at->base->accept( *visitor ); … … 244 255 } 245 256 246 // encode function type as a 2-param generic type 247 // TODO handle forall functions 257 // print function types using prototype syntax 248 258 void previsit( FunctionType* ft ) { 249 ss << "#$fn<";259 ss << '['; 250 260 ++depth; 251 build AsTuple( *visitor, from_decls( ft->returnVals ), ss);252 ss << ' ';253 build AsTuple( *visitor, from_decls( ft->parameters ), ss);261 build( *visitor, from_decls( ft->returnVals ), ss, preceded ); 262 ss << " : "; 263 build( *visitor, from_decls( ft->parameters ), ss, terminated ); 254 264 --depth; 255 ss << ' >';265 ss << ']'; 256 266 visit_children = false; 257 267 } … … 341 351 } 342 352 343 // print variable declaration as zero-arg function353 // print variable declaration in prototype syntax 344 354 PassVisitor<TypePrinter> printTy{ closed, ss }; 345 355 norefs->accept( printTy ); 346 ss << ' ';356 ss << " &"; 347 357 rp_name( name, ss ); 348 358 } … … 381 391 : closed(closed), ss(ss) {} 382 392 383 /// Names handled as n ullary function calls393 /// Names handled as name expressions 384 394 void previsit( NameExpr* expr ) { 395 ss << '&'; 385 396 rp_name( expr->name, ss ); 386 ss << "()";387 397 } 388 398 … … 416 426 } 417 427 428 /// Already-resolved calls skipped 429 void previsit( ApplicationExpr* ) { 430 visit_children = false; 431 } 432 418 433 /// Address-of handled as operator 419 434 void previsit( AddressExpr* expr ) { … … 585 600 586 601 void previsit( FunctionDecl *decl ) { 602 // skip decls with ftype parameters 603 for ( TypeDecl* tyvar : decl->type->forall ) { 604 if ( tyvar->get_kind() == TypeDecl::Ftype ) { 605 visit_children = false; 606 return; 607 } 608 } 609 587 610 // add function as declaration 588 611 std::stringstream ss;
Note: See TracChangeset
for help on using the changeset viewer.