mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Comment parsing: attaching comments to declarations
We can attach comments to declarations. Right now we only support comments that precede the declarations (trailing comments will be supported later). The implementation approach is different from one we have in Clang. In Swift the Lexer attaches the comments to the next token, and parser checks if comments are present on the first token of the declaration. This is much cleaner, and faster than Clang's approach (where we perform a binary search on source locations and do ad-hoc fixups afterwards). The comment <-> decl correspondence is modeled as "virtual" attributes that can not be spelled in the source. These attributes are not serialized at the moment -- this will be implemented later. Swift SVN r14031
This commit is contained in:
@@ -63,6 +63,15 @@ unsigned SourceManager::getByteDistance(SourceLoc Start, SourceLoc End) const {
|
||||
return End.Value.getPointer() - Start.Value.getPointer();
|
||||
}
|
||||
|
||||
StringRef SourceManager::extractText(CharSourceRange Range) const {
|
||||
assert(Range.isValid() && "range should be valid");
|
||||
|
||||
unsigned BufferID = findBufferContainingLoc(Range.getStart());
|
||||
StringRef Buffer = LLVMSourceMgr.getMemoryBuffer(BufferID)->getBuffer();
|
||||
return Buffer.substr(getLocOffsetInBuffer(Range.getStart(), BufferID),
|
||||
Range.getByteLength());
|
||||
}
|
||||
|
||||
void SourceLoc::printLineAndColumn(raw_ostream &OS,
|
||||
const SourceManager &SM) const {
|
||||
if (isInvalid()) {
|
||||
|
||||
Reference in New Issue
Block a user