[cfe-commits] r101633 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclarationName.h lib/AST/Decl.cpp lib/AST/DeclarationName.cpp
Benjamin Kramer
benny.kra at googlemail.com
Sat Apr 17 02:56:45 PDT 2010
Author: d0k
Date: Sat Apr 17 04:56:45 2010
New Revision: 101633
URL: http://llvm.org/viewvc/llvm-project?rev=101633&view=rev
Log:
Add printName to DeclarationName which prints the human-readable name on a
raw_ostream. Use it in getAsString and NamedDecl's raw_ostream operator.
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclarationName.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclarationName.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=101633&r1=101632&r2=101633&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sat Apr 17 04:56:45 2010
@@ -217,7 +217,11 @@
static bool classofKind(Kind K) { return K >= NamedFirst && K <= NamedLast; }
};
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const NamedDecl *ND);
+inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
+ const NamedDecl *ND) {
+ ND->getDeclName().printName(OS);
+ return OS;
+}
/// NamespaceDecl - Represent a C++ namespace.
class NamespaceDecl : public NamedDecl, public DeclContext {
Modified: cfe/trunk/include/clang/AST/DeclarationName.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclarationName.h?rev=101633&r1=101632&r2=101633&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclarationName.h (original)
+++ cfe/trunk/include/clang/AST/DeclarationName.h Sat Apr 17 04:56:45 2010
@@ -198,9 +198,12 @@
/// callee in a call expression with dependent arguments.
bool isDependentName() const;
- /// getName - Retrieve the human-readable string for this name.
+ /// getNameAsString - Retrieve the human-readable string for this name.
std::string getAsString() const;
+ /// printName - Print the human-readable name to a stream.
+ void printName(llvm::raw_ostream &OS) const;
+
/// getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in
/// this declaration name, or NULL if this declaration name isn't a
/// simple identifier.
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=101633&r1=101632&r2=101633&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sat Apr 17 04:56:45 2010
@@ -512,12 +512,6 @@
return false;
}
-llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
- const NamedDecl *ND) {
- OS << ND->getNameAsString();
- return OS;
-}
-
//===----------------------------------------------------------------------===//
// DeclaratorDecl Implementation
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=101633&r1=101632&r2=101633&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclarationName.cpp (original)
+++ cfe/trunk/lib/AST/DeclarationName.cpp Sat Apr 17 04:56:45 2010
@@ -18,7 +18,7 @@
#include "clang/Basic/IdentifierTable.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h"
-#include <cstdio>
+#include "llvm/Support/raw_ostream.h"
using namespace clang;
namespace clang {
@@ -202,32 +202,42 @@
}
std::string DeclarationName::getAsString() const {
+ std::string Result;
+ llvm::raw_string_ostream OS(Result);
+ printName(OS);
+ return OS.str();
+}
+
+void DeclarationName::printName(llvm::raw_ostream &OS) const {
switch (getNameKind()) {
case Identifier:
if (const IdentifierInfo *II = getAsIdentifierInfo())
- return II->getName();
- return "";
+ OS << II->getName();
+ return;
case ObjCZeroArgSelector:
case ObjCOneArgSelector:
case ObjCMultiArgSelector:
- return getObjCSelector().getAsString();
+ OS << getObjCSelector().getAsString();
+ return;
case CXXConstructorName: {
QualType ClassType = getCXXNameType();
if (const RecordType *ClassRec = ClassType->getAs<RecordType>())
- return ClassRec->getDecl()->getNameAsString();
- return ClassType.getAsString();
+ OS << ClassRec->getDecl();
+ else
+ OS << ClassType.getAsString();
+ return;
}
case CXXDestructorName: {
- std::string Result = "~";
+ OS << '~';
QualType Type = getCXXNameType();
if (const RecordType *Rec = Type->getAs<RecordType>())
- Result += Rec->getDecl()->getNameAsString();
+ OS << Rec->getDecl();
else
- Result += Type.getAsString();
- return Result;
+ OS << Type.getAsString();
+ return;
}
case CXXOperatorName: {
@@ -240,32 +250,32 @@
const char *OpName = OperatorNames[getCXXOverloadedOperator()];
assert(OpName && "not an overloaded operator");
- std::string Result = "operator";
+ OS << "operator";
if (OpName[0] >= 'a' && OpName[0] <= 'z')
- Result += ' ';
- Result += OpName;
- return Result;
+ OS << ' ';
+ OS << OpName;
+ return;
}
- case CXXLiteralOperatorName: {
- return "operator \"\" " + std::string(getCXXLiteralIdentifier()->getName());
- }
+ case CXXLiteralOperatorName:
+ OS << "operator \"\" " << getCXXLiteralIdentifier()->getName();
+ return;
case CXXConversionFunctionName: {
- std::string Result = "operator ";
+ OS << "operator ";
QualType Type = getCXXNameType();
if (const RecordType *Rec = Type->getAs<RecordType>())
- Result += Rec->getDecl()->getNameAsString();
+ OS << Rec->getDecl();
else
- Result += Type.getAsString();
- return Result;
+ OS << Type.getAsString();
+ return;
}
case CXXUsingDirective:
- return "<using-directive>";
+ OS << "<using-directive>";
+ return;
}
assert(false && "Unexpected declaration name kind");
- return "";
}
QualType DeclarationName::getCXXNameType() const {
@@ -369,7 +379,8 @@
}
void DeclarationName::dump() const {
- fprintf(stderr, "%s\n", getAsString().c_str());
+ printName(llvm::errs());
+ llvm::errs() << '\n';
}
DeclarationNameTable::DeclarationNameTable() {
More information about the cfe-commits
mailing list