[IDE/ModuleInterface] Fix erroneously printed newline between a regular comment and the declaration it is 'attached' to.

Swift SVN r16293
This commit is contained in:
Argyrios Kyrtzidis
2014-04-14 03:28:05 +00:00
parent 5293ec9581
commit 31a620f1ee
5 changed files with 27 additions and 2 deletions

View File

@@ -43,6 +43,7 @@ namespace clang {
class MacroInfo; class MacroInfo;
class Module; class Module;
class SourceLocation; class SourceLocation;
class SourceRange;
} }
namespace swift { namespace swift {
@@ -114,6 +115,7 @@ public:
} }
clang::SourceLocation getLocation() const; clang::SourceLocation getLocation() const;
clang::SourceRange getSourceRange() const;
}; };
enum class DeclKind : uint8_t { enum class DeclKind : uint8_t {

View File

@@ -45,6 +45,15 @@ clang::SourceLocation ClangNode::getLocation() const {
return clang::SourceLocation(); return clang::SourceLocation();
} }
clang::SourceRange ClangNode::getSourceRange() const {
if (auto D = getAsDecl())
return D->getSourceRange();
if (auto M = getAsMacro())
return clang::SourceRange(M->getDefinitionLoc(), M->getDefinitionEndLoc());
return clang::SourceLocation();
}
// Only allow allocation of Decls using the allocator in ASTContext. // Only allow allocation of Decls using the allocator in ASTContext.
void *Decl::operator new(size_t Bytes, ASTContext &C, void *Decl::operator new(size_t Bytes, ASTContext &C,
unsigned Alignment) { unsigned Alignment) {

View File

@@ -362,7 +362,8 @@ void ClangCommentPrinter::printCommentsUntil(ClangNode Node) {
const auto &Ctx = ClangLoader.getClangASTContext(); const auto &Ctx = ClangLoader.getClangASTContext();
const auto &SM = Ctx.getSourceManager(); const auto &SM = Ctx.getSourceManager();
clang::SourceLocation NodeLoc = SM.getFileLoc(Node.getLocation()); clang::SourceLocation NodeLoc =
SM.getFileLoc(Node.getSourceRange().getBegin());
if (NodeLoc.isInvalid()) if (NodeLoc.isInvalid())
return; return;
unsigned NodeLineNo = SM.getSpellingLineNumber(NodeLoc); unsigned NodeLineNo = SM.getSpellingLineNumber(NodeLoc);
@@ -424,7 +425,8 @@ void ClangCommentPrinter::printCommentsUntil(ClangNode Node) {
} }
*this << CommentText << "\n"; *this << CommentText << "\n";
printIndent(); printIndent();
LastPrintedCommentLineNo = LineNo; LastPrintedCommentLineNo =
SM.getLineNumber(LocInfo.first, LocInfo.second + Tok.getLength());
} while (true); } while (true);

View File

@@ -63,9 +63,17 @@ extern int fooIntVar;
/// Aaa. fooFunc1. Bbb. /// Aaa. fooFunc1. Bbb.
int fooFunc1(int a); int fooFunc1(int a);
int fooFunc1AnonymousParam(int); int fooFunc1AnonymousParam(int);
int fooFunc3(int a, float b, double c, int *d); int fooFunc3(int a, float b, double c, int *d);
/*
Very good
fooFuncWithBlock function.
*/
extern
void fooFuncWithBlock(int (^blk)(float x)); void fooFuncWithBlock(int (^blk)(float x));
void fooFuncWithFunctionPointer(int (*fptr)(float x)); void fooFuncWithFunctionPointer(int (*fptr)(float x));
/** /**

View File

@@ -76,6 +76,10 @@ var fooIntVar: CInt
func fooFunc1(CInt) -> CInt func fooFunc1(CInt) -> CInt
func fooFunc1AnonymousParam(CInt) -> CInt func fooFunc1AnonymousParam(CInt) -> CInt
func fooFunc3(CInt, CFloat, CDouble, CMutablePointer<CInt>) -> CInt func fooFunc3(CInt, CFloat, CDouble, CMutablePointer<CInt>) -> CInt
/*
Very good
fooFuncWithBlock function.
*/
func fooFuncWithBlock((CFloat) -> CInt) func fooFuncWithBlock((CFloat) -> CInt)
/** /**