/// Language - The language for this linkage specification.
LanguageIDs Language;
- /// HadBraces - Whether this linkage specification had curly braces or not.
- bool HadBraces : 1;
+ /// LBraceLoc - The source location for the left brace (if valid).
+ SourceLocation LBraceLoc;
+ /// RBraceLoc - The source location for the right brace (if valid).
+ SourceLocation RBraceLoc;
LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
- bool Braces)
- : Decl(LinkageSpec, DC, L),
- DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
+ SourceLocation LBLoc, SourceLocation RBLoc)
+ : Decl(LinkageSpec, DC, L), DeclContext(LinkageSpec),
+ Language(lang), LBraceLoc(LBLoc), RBraceLoc(RBLoc) { }
public:
static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, LanguageIDs Lang,
- bool Braces);
+ SourceLocation LBraceLoc,
+ SourceLocation RBraceLoc = SourceLocation());
/// \brief Return the language specified by this linkage specification.
LanguageIDs getLanguage() const { return Language; }
/// \brief Determines whether this linkage specification had braces in
/// its syntactic form.
- bool hasBraces() const { return HadBraces; }
+ bool hasBraces() const { return RBraceLoc.isValid(); }
+ SourceLocation getLBraceLoc() const { return LBraceLoc; }
+ SourceLocation getRBraceLoc() const { return RBraceLoc; }
+ void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
+ void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
- /// \brief Set whether this linkage specification has braces in its
- /// syntactic form.
- void setHasBraces(bool B) { HadBraces = B; }
+ SourceLocation getLocEnd() const {
+ if (hasBraces())
+ return getRBraceLoc();
+ // No braces: get the end location of the (only) declaration in context
+ // (if present).
+ return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
+ }
+
+ SourceRange getSourceRange() const {
+ return SourceRange(getLocation(), getLocEnd());
+ }
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classof(const LinkageSpecDecl *D) { return true; }
LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
DeclContext *DC,
SourceLocation L,
- LanguageIDs Lang, bool Braces) {
- return new (C) LinkageSpecDecl(DC, L, Lang, Braces);
+ LanguageIDs Lang,
+ SourceLocation LBraceLoc,
+ SourceLocation RBraceLoc) {
+ return new (C) LinkageSpecDecl(DC, L, Lang, LBraceLoc, RBraceLoc);
}
UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
LinkageSpecDecl *D = LinkageSpecDecl::Create(Context, CurContext,
LangLoc, Language,
- LBraceLoc.isValid());
+ LBraceLoc);
CurContext->addDecl(D);
PushDeclContext(S, D);
return D;
/// valid, it's the position of the closing '}' brace in a linkage
/// specification that uses braces.
Decl *Sema::ActOnFinishLinkageSpecification(Scope *S,
- Decl *LinkageSpec,
- SourceLocation RBraceLoc) {
- if (LinkageSpec)
+ Decl *LinkageSpec,
+ SourceLocation RBraceLoc) {
+ if (LinkageSpec) {
+ if (RBraceLoc.isValid()) {
+ LinkageSpecDecl* LSDecl = cast<LinkageSpecDecl>(LinkageSpec);
+ LSDecl->setRBraceLoc(RBraceLoc);
+ }
PopDeclContext();
+ }
return LinkageSpec;
}
void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
VisitDecl(D);
D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
- D->setHasBraces(Record[Idx++]);
+ D->setLBraceLoc(ReadSourceLocation(Record, Idx));
+ D->setRBraceLoc(ReadSourceLocation(Record, Idx));
}
void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
case DECL_LINKAGE_SPEC:
D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
(LinkageSpecDecl::LanguageIDs)0,
- false);
+ SourceLocation(), SourceLocation());
break;
case DECL_LABEL:
D = LabelDecl::Create(*Context, 0, SourceLocation(), 0);
void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
VisitDecl(D);
- // FIXME: It might be nice to serialize the brace locations for this
- // declaration, which don't seem to be readily available in the AST.
Record.push_back(D->getLanguage());
- Record.push_back(D->hasBraces());
+ Writer.AddSourceLocation(D->getLBraceLoc(), Record);
+ Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Code = serialization::DECL_LINKAGE_SPEC;
}
// CHECK: 4:20: TemplateTypeParameter=_T1:4:20 (Definition) Extent=[4:20 - 4:23]
// CHECK: 4:31: TemplateTypeParameter=_T2:4:31 (Definition) Extent=[4:31 - 4:34]
// CHECK: 4:55: FieldDecl=second:4:55 (Definition) Extent=[4:55 - 4:61]
-// CHECK: 6:8: UnexposedDecl=:6:8 (Definition) Extent=[6:8 - 6:11]
+// CHECK: 6:8: UnexposedDecl=:6:8 (Definition) Extent=[6:8 - 9:2]
// CHECK: 7:7: FunctionDecl=memcmp:7:7 Extent=[7:7 - 7:49]
// CHECK: 7:26: ParmDecl=:7:26 (Definition) Extent=[7:20 - 7:27]
// CHECK: 7:40: ParmDecl=:7:40 (Definition) Extent=[7:34 - 7:41]