forked from OSchip/llvm-project
[AST] Add a print() method in DeclarationName that accepts a PrintingPolicy.
llvm-svn: 260833
This commit is contained in:
parent
f730a6bedc
commit
e91793c3a3
|
@ -30,6 +30,7 @@ namespace clang {
|
|||
class IdentifierInfo;
|
||||
class MultiKeywordSelector;
|
||||
enum OverloadedOperatorKind : int;
|
||||
struct PrintingPolicy;
|
||||
class QualType;
|
||||
class Type;
|
||||
class TypeSourceInfo;
|
||||
|
@ -302,7 +303,9 @@ public:
|
|||
}
|
||||
|
||||
static int compare(DeclarationName LHS, DeclarationName RHS);
|
||||
|
||||
|
||||
void print(raw_ostream &OS, const PrintingPolicy &Policy);
|
||||
|
||||
void dump() const;
|
||||
};
|
||||
|
||||
|
|
|
@ -133,36 +133,43 @@ int DeclarationName::compare(DeclarationName LHS, DeclarationName RHS) {
|
|||
llvm_unreachable("Invalid DeclarationName Kind!");
|
||||
}
|
||||
|
||||
raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) {
|
||||
static void printCXXConstructorDestructorName(QualType ClassType,
|
||||
raw_ostream &OS,
|
||||
const PrintingPolicy &Policy) {
|
||||
if (const RecordType *ClassRec = ClassType->getAs<RecordType>()) {
|
||||
OS << *ClassRec->getDecl();
|
||||
return;
|
||||
}
|
||||
if (!Policy.LangOpts.CPlusPlus) {
|
||||
// Passed policy is the default one from operator <<, use a C++ policy.
|
||||
LangOptions LO;
|
||||
LO.CPlusPlus = true;
|
||||
ClassType.print(OS, PrintingPolicy(LO));
|
||||
} else {
|
||||
ClassType.print(OS, Policy);
|
||||
}
|
||||
}
|
||||
|
||||
void DeclarationName::print(raw_ostream &OS, const PrintingPolicy &Policy) {
|
||||
DeclarationName &N = *this;
|
||||
switch (N.getNameKind()) {
|
||||
case DeclarationName::Identifier:
|
||||
if (const IdentifierInfo *II = N.getAsIdentifierInfo())
|
||||
OS << II->getName();
|
||||
return OS;
|
||||
return;
|
||||
|
||||
case DeclarationName::ObjCZeroArgSelector:
|
||||
case DeclarationName::ObjCOneArgSelector:
|
||||
case DeclarationName::ObjCMultiArgSelector:
|
||||
N.getObjCSelector().print(OS);
|
||||
return OS;
|
||||
return;
|
||||
|
||||
case DeclarationName::CXXConstructorName: {
|
||||
QualType ClassType = N.getCXXNameType();
|
||||
if (const RecordType *ClassRec = ClassType->getAs<RecordType>())
|
||||
return OS << *ClassRec->getDecl();
|
||||
LangOptions LO;
|
||||
LO.CPlusPlus = true;
|
||||
return OS << ClassType.getAsString(PrintingPolicy(LO));
|
||||
}
|
||||
case DeclarationName::CXXConstructorName:
|
||||
return printCXXConstructorDestructorName(N.getCXXNameType(), OS, Policy);
|
||||
|
||||
case DeclarationName::CXXDestructorName: {
|
||||
OS << '~';
|
||||
QualType Type = N.getCXXNameType();
|
||||
if (const RecordType *Rec = Type->getAs<RecordType>())
|
||||
return OS << *Rec->getDecl();
|
||||
LangOptions LO;
|
||||
LO.CPlusPlus = true;
|
||||
return OS << Type.getAsString(PrintingPolicy(LO));
|
||||
return printCXXConstructorDestructorName(N.getCXXNameType(), OS, Policy);
|
||||
}
|
||||
|
||||
case DeclarationName::CXXOperatorName: {
|
||||
|
@ -178,29 +185,46 @@ raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) {
|
|||
OS << "operator";
|
||||
if (OpName[0] >= 'a' && OpName[0] <= 'z')
|
||||
OS << ' ';
|
||||
return OS << OpName;
|
||||
OS << OpName;
|
||||
return;
|
||||
}
|
||||
|
||||
case DeclarationName::CXXLiteralOperatorName:
|
||||
return OS << "operator\"\"" << N.getCXXLiteralIdentifier()->getName();
|
||||
OS << "operator\"\"" << N.getCXXLiteralIdentifier()->getName();
|
||||
return;
|
||||
|
||||
case DeclarationName::CXXConversionFunctionName: {
|
||||
OS << "operator ";
|
||||
QualType Type = N.getCXXNameType();
|
||||
if (const RecordType *Rec = Type->getAs<RecordType>())
|
||||
return OS << *Rec->getDecl();
|
||||
LangOptions LO;
|
||||
LO.CPlusPlus = true;
|
||||
LO.Bool = true;
|
||||
return OS << Type.getAsString(PrintingPolicy(LO));
|
||||
if (const RecordType *Rec = Type->getAs<RecordType>()) {
|
||||
OS << *Rec->getDecl();
|
||||
return;
|
||||
}
|
||||
if (!Policy.LangOpts.CPlusPlus) {
|
||||
// Passed policy is the default one from operator <<, use a C++ policy.
|
||||
LangOptions LO;
|
||||
LO.CPlusPlus = true;
|
||||
LO.Bool = true;
|
||||
Type.print(OS, PrintingPolicy(LO));
|
||||
} else {
|
||||
Type.print(OS, Policy);
|
||||
}
|
||||
return;
|
||||
}
|
||||
case DeclarationName::CXXUsingDirective:
|
||||
return OS << "<using-directive>";
|
||||
OS << "<using-directive>";
|
||||
return;
|
||||
}
|
||||
|
||||
llvm_unreachable("Unexpected declaration name kind");
|
||||
}
|
||||
|
||||
raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) {
|
||||
LangOptions LO;
|
||||
N.print(OS, PrintingPolicy(LO));
|
||||
return OS;
|
||||
}
|
||||
|
||||
} // end namespace clang
|
||||
|
||||
DeclarationName::NameKind DeclarationName::getNameKind() const {
|
||||
|
|
Loading…
Reference in New Issue