forked from OSchip/llvm-project
[AST] Let DeclarationNameInfo printing use PrintingPolicy, and fix const-correctness
This commit is contained in:
parent
28a5dc7fc5
commit
575e09d9f8
|
@ -528,7 +528,7 @@ public:
|
|||
|
||||
static int compare(DeclarationName LHS, DeclarationName RHS);
|
||||
|
||||
void print(raw_ostream &OS, const PrintingPolicy &Policy);
|
||||
void print(raw_ostream &OS, const PrintingPolicy &Policy) const;
|
||||
|
||||
void dump() const;
|
||||
};
|
||||
|
@ -792,7 +792,7 @@ public:
|
|||
std::string getAsString() const;
|
||||
|
||||
/// printName - Print the human-readable name to a stream.
|
||||
void printName(raw_ostream &OS) const;
|
||||
void printName(raw_ostream &OS, PrintingPolicy Policy) const;
|
||||
|
||||
/// getBeginLoc - Retrieve the location of the first token.
|
||||
SourceLocation getBeginLoc() const { return NameLoc; }
|
||||
|
@ -829,11 +829,7 @@ inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
|
|||
return PD;
|
||||
}
|
||||
|
||||
inline raw_ostream &operator<<(raw_ostream &OS,
|
||||
DeclarationNameInfo DNInfo) {
|
||||
DNInfo.printName(OS);
|
||||
return OS;
|
||||
}
|
||||
raw_ostream &operator<<(raw_ostream &OS, DeclarationNameInfo DNInfo);
|
||||
|
||||
} // namespace clang
|
||||
|
||||
|
|
|
@ -625,13 +625,13 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
|
|||
if (Policy.FullyQualifiedName) {
|
||||
Proto += D->getQualifiedNameAsString();
|
||||
} else {
|
||||
llvm::raw_string_ostream OS(Proto);
|
||||
if (!Policy.SuppressScope) {
|
||||
if (const NestedNameSpecifier *NS = D->getQualifier()) {
|
||||
llvm::raw_string_ostream OS(Proto);
|
||||
NS->print(OS, Policy);
|
||||
}
|
||||
}
|
||||
Proto += D->getNameInfo().getAsString();
|
||||
D->getNameInfo().printName(OS, Policy);
|
||||
}
|
||||
|
||||
if (GuideDecl)
|
||||
|
|
|
@ -134,7 +134,8 @@ static void printCXXConstructorDestructorName(QualType ClassType,
|
|||
ClassType.print(OS, Policy);
|
||||
}
|
||||
|
||||
void DeclarationName::print(raw_ostream &OS, const PrintingPolicy &Policy) {
|
||||
void DeclarationName::print(raw_ostream &OS,
|
||||
const PrintingPolicy &Policy) const {
|
||||
switch (getNameKind()) {
|
||||
case DeclarationName::Identifier:
|
||||
if (const IdentifierInfo *II = getAsIdentifierInfo())
|
||||
|
@ -447,11 +448,17 @@ bool DeclarationNameInfo::isInstantiationDependent() const {
|
|||
std::string DeclarationNameInfo::getAsString() const {
|
||||
std::string Result;
|
||||
llvm::raw_string_ostream OS(Result);
|
||||
printName(OS);
|
||||
OS << *this;
|
||||
return OS.str();
|
||||
}
|
||||
|
||||
void DeclarationNameInfo::printName(raw_ostream &OS) const {
|
||||
raw_ostream &clang::operator<<(raw_ostream &OS, DeclarationNameInfo DNInfo) {
|
||||
LangOptions LO;
|
||||
DNInfo.printName(OS, PrintingPolicy(LangOptions()));
|
||||
return OS;
|
||||
}
|
||||
|
||||
void DeclarationNameInfo::printName(raw_ostream &OS, PrintingPolicy Policy) const {
|
||||
switch (Name.getNameKind()) {
|
||||
case DeclarationName::Identifier:
|
||||
case DeclarationName::ObjCZeroArgSelector:
|
||||
|
@ -461,7 +468,7 @@ void DeclarationNameInfo::printName(raw_ostream &OS) const {
|
|||
case DeclarationName::CXXLiteralOperatorName:
|
||||
case DeclarationName::CXXUsingDirective:
|
||||
case DeclarationName::CXXDeductionGuideName:
|
||||
OS << Name;
|
||||
Name.print(OS, Policy);
|
||||
return;
|
||||
|
||||
case DeclarationName::CXXConstructorName:
|
||||
|
@ -473,13 +480,11 @@ void DeclarationNameInfo::printName(raw_ostream &OS) const {
|
|||
else if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName)
|
||||
OS << "operator ";
|
||||
LangOptions LO;
|
||||
LO.CPlusPlus = true;
|
||||
LO.Bool = true;
|
||||
PrintingPolicy PP(LO);
|
||||
PP.SuppressScope = true;
|
||||
OS << TInfo->getType().getAsString(PP);
|
||||
Policy.adjustForCPlusPlus();
|
||||
Policy.SuppressScope = true;
|
||||
OS << TInfo->getType().getAsString(Policy);
|
||||
} else
|
||||
OS << Name;
|
||||
Name.print(OS, Policy);
|
||||
return;
|
||||
}
|
||||
llvm_unreachable("Unexpected declaration name kind");
|
||||
|
|
|
@ -697,7 +697,7 @@ void StmtPrinter::VisitOMPCriticalDirective(OMPCriticalDirective *Node) {
|
|||
Indent() << "#pragma omp critical";
|
||||
if (Node->getDirectiveName().getName()) {
|
||||
OS << " (";
|
||||
Node->getDirectiveName().printName(OS);
|
||||
Node->getDirectiveName().printName(OS, Policy);
|
||||
OS << ")";
|
||||
}
|
||||
PrintOMPExecutableDirective(Node);
|
||||
|
|
Loading…
Reference in New Issue