- File:
-
- 1 edited
-
src/CodeTools/ResolvProtoDump.cc (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeTools/ResolvProtoDump.cc
r4c42a5f ra4a000d 196 196 } 197 197 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); 198 // default to just name 199 ss << pre << name; 202 200 } 203 201 204 202 /// ensures type inst names are uppercase 205 203 static void ti_name( const std::string& name, std::stringstream& ss ) { 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); 204 ss << (char)std::toupper( static_cast<unsigned char>(name[0]) ) 205 << (name.c_str() + 1); 214 206 } 215 207 … … 227 219 void previsit( BasicType* bt ) { ss << (int)bt->get_kind(); } 228 220 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 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 238 227 void previsit( ArrayType* at ) { 239 ss << "#$ ptr<";228 ss << "#$arr<"; 240 229 ++depth; 241 230 at->base->accept( *visitor ); … … 255 244 } 256 245 257 // print function types using prototype syntax 246 // encode function type as a 2-param generic type 247 // TODO handle forall functions 258 248 void previsit( FunctionType* ft ) { 259 ss << '[';249 ss << "#$fn<"; 260 250 ++depth; 261 build ( *visitor, from_decls( ft->returnVals ), ss, preceded);262 ss << " : ";263 build ( *visitor, from_decls( ft->parameters ), ss, terminated);251 buildAsTuple( *visitor, from_decls( ft->returnVals ), ss ); 252 ss << ' '; 253 buildAsTuple( *visitor, from_decls( ft->parameters ), ss ); 264 254 --depth; 265 ss << ' ]';255 ss << '>'; 266 256 visit_children = false; 267 257 } … … 351 341 } 352 342 353 // print variable declaration in prototype syntax343 // print variable declaration as zero-arg function 354 344 PassVisitor<TypePrinter> printTy{ closed, ss }; 355 345 norefs->accept( printTy ); 356 ss << " &";346 ss << ' '; 357 347 rp_name( name, ss ); 358 348 } … … 391 381 : closed(closed), ss(ss) {} 392 382 393 /// Names handled as n ame expressions383 /// Names handled as nullary function calls 394 384 void previsit( NameExpr* expr ) { 395 ss << '&';396 385 rp_name( expr->name, ss ); 386 ss << "()"; 397 387 } 398 388 … … 426 416 } 427 417 428 /// Already-resolved calls skipped429 void previsit( ApplicationExpr* ) {430 visit_children = false;431 }432 433 418 /// Address-of handled as operator 434 419 void previsit( AddressExpr* expr ) { … … 600 585 601 586 void previsit( FunctionDecl *decl ) { 602 // skip decls with ftype parameters603 for ( TypeDecl* tyvar : decl->type->forall ) {604 if ( tyvar->get_kind() == TypeDecl::Ftype ) {605 visit_children = false;606 return;607 }608 }609 610 587 // add function as declaration 611 588 std::stringstream ss;
Note:
See TracChangeset
for help on using the changeset viewer.