mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Add :print_decl <name> option to the REPL.
This REPL option is great for taking a quick peek at APIs, especially
imported ones. For example, NSMutableArray:
swift> :print_decl NSMutableArray
class [objc] NSMutableArray {
func [objc] addObject(anObject : id)
func [objc] insertObject(anObject : id, atIndex : NSUInteger)
func [objc] removeLastObject()
func [objc] removeObjectAtIndex(index : NSUInteger)
func [objc] replaceObjectAtIndex(index : NSUInteger, withObject :
id)
}
extension NSMutableArray {
func [objc] filterUsingPredicate(predicate : NSPredicate)
}
extension NSMutableArray {
func [objc] sortUsingDescriptors(sortDescriptors : NSArray)
}
extension NSMutableArray {
static func [objc] arrayWithCapacity(numItems : NSUInteger) -> id
constructor (initWithCapacity : NSUInteger)
func [objc] initWithCapacity(numItems : NSUInteger) -> id
}
extension NSMutableArray {
func [objc] addObjectsFromArray(otherArray : NSArray)
func [objc] exchangeObjectAtIndex(idx1 : NSUInteger,
withObjectAtIndex : NSUInteger)
func [objc] removeAllObjects()
func [objc] removeObject(anObject : id, inRange : NSRange)
func [objc] removeObject(anObject : id)
func [objc] removeObjectIdenticalTo(anObject : id, inRange :
NSRange)
func [objc] removeObjectIdenticalTo(anObject : id)
func [objc] removeObjectsFromIndices(indices : CPointer<NSUInteger>,
numIndices : NSUInteger)
func [objc] removeObjectsInArray(otherArray : NSArray)
func [objc] removeObjectsInRange(range : NSRange)
func [objc] replaceObjectsInRange(range : NSRange,
withObjectsFromArray : NSArray, range : NSRange)
func [objc] replaceObjectsInRange(range : NSRange,
withObjectsFromArray : NSArray)
func [objc] setArray(otherArray : NSArray)
func [objc] insertObjects(objects : NSArray, atIndexes : NSIndexSet)
func [objc] removeObjectsAtIndexes(indexes : NSIndexSet)
func [objc] replaceObjectsAtIndexes(indexes : NSIndexSet,
withObjects : NSArray)
subscript (idx : NSUInteger) : id {
get
set
}
func [objc] setObject(obj : id, atIndexedSubscript : NSUInteger)
func [objc] sortUsingComparator(cmptr : NSComparator)
func [objc] sortWithOptions(opts : NSSortOptions, usingComparator :
NSComparator)
}
Swift SVN r3581
This commit is contained in:
@@ -393,6 +393,8 @@ void swift::REPL(ASTContext &Context) {
|
||||
"named declarations\n"
|
||||
" :dump_source - dump the user input (ignoring"
|
||||
" lines with errors)\n"
|
||||
" :print_decl <name> - print the AST representation of the"
|
||||
"named declarations\n"
|
||||
"API documentation etc. will be here eventually.\n");
|
||||
} else if (L.peekNextToken().getText() == "quit" ||
|
||||
L.peekNextToken().getText() == "exit") {
|
||||
@@ -401,13 +403,19 @@ void swift::REPL(ASTContext &Context) {
|
||||
DumpModule.dump();
|
||||
} else if (L.peekNextToken().getText() == "dump_ast") {
|
||||
TU->dump();
|
||||
} else if (L.peekNextToken().getText() == "dump_decl") {
|
||||
} else if (L.peekNextToken().getText() == "dump_decl" ||
|
||||
L.peekNextToken().getText() == "print_decl") {
|
||||
bool doPrint = (L.peekNextToken().getText() == "print_decl");
|
||||
L.lex(Tok);
|
||||
L.lex(Tok);
|
||||
UnqualifiedLookup lookup(Context.getIdentifier(Tok.getText()), TU);
|
||||
for (auto result : lookup.Results) {
|
||||
if (result.hasValueDecl()) {
|
||||
result.getValueDecl()->dump();
|
||||
if (doPrint) {
|
||||
result.getValueDecl()->print(llvm::outs());
|
||||
llvm::outs() << '\n';
|
||||
} else
|
||||
result.getValueDecl()->dump();
|
||||
|
||||
if (auto typeDecl = dyn_cast<TypeDecl>(result.getValueDecl())) {
|
||||
// FIXME: Hack!
|
||||
@@ -436,8 +444,13 @@ void swift::REPL(ASTContext &Context) {
|
||||
}
|
||||
}
|
||||
|
||||
for (auto ext : extensions)
|
||||
ext->dump();
|
||||
for (auto ext : extensions) {
|
||||
if (doPrint) {
|
||||
ext->print(llvm::outs());
|
||||
llvm::outs() << '\n';
|
||||
} else
|
||||
ext->dump();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user