r175891 - StmtPrinter: Directly print types to the stream instead of taking a detour through getAsString.
Benjamin Kramer
benny.kra at googlemail.com
Fri Feb 22 06:19:02 PST 2013
Author: d0k
Date: Fri Feb 22 08:19:01 2013
New Revision: 175891
URL: http://llvm.org/viewvc/llvm-project?rev=175891&view=rev
Log:
StmtPrinter: Directly print types to the stream instead of taking a detour through getAsString.
Modified:
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=175891&r1=175890&r2=175891&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Fri Feb 22 08:19:01 2013
@@ -812,7 +812,8 @@ void StmtPrinter::VisitUnaryOperator(Una
void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
OS << "__builtin_offsetof(";
- OS << Node->getTypeSourceInfo()->getType().getAsString(Policy) << ", ";
+ Node->getTypeSourceInfo()->getType().print(OS, Policy);
+ OS << ", ";
bool PrintedSomething = false;
for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
OffsetOfExpr::OffsetOfNode ON = Node->getComponent(i);
@@ -860,9 +861,11 @@ void StmtPrinter::VisitUnaryExprOrTypeTr
OS << "vec_step";
break;
}
- if (Node->isArgumentType())
- OS << "(" << Node->getArgumentType().getAsString(Policy) << ")";
- else {
+ if (Node->isArgumentType()) {
+ OS << '(';
+ Node->getArgumentType().print(OS, Policy);
+ OS << ')';
+ } else {
OS << " ";
PrintExpr(Node->getArgumentExpr());
}
@@ -877,7 +880,7 @@ void StmtPrinter::VisitGenericSelectionE
if (T.isNull())
OS << "default";
else
- OS << T.getAsString(Policy);
+ T.print(OS, Policy);
OS << ": ";
PrintExpr(Node->getAssocExpr(i));
}
@@ -946,11 +949,15 @@ void StmtPrinter::VisitExtVectorElementE
OS << Node->getAccessor().getName();
}
void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
- OS << "(" << Node->getTypeAsWritten().getAsString(Policy) << ")";
+ OS << '(';
+ Node->getTypeAsWritten().print(OS, Policy);
+ OS << ')';
PrintExpr(Node->getSubExpr());
}
void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
- OS << "(" << Node->getType().getAsString(Policy) << ")";
+ OS << '(';
+ Node->getType().print(OS, Policy);
+ OS << ')';
PrintExpr(Node->getInitializer());
}
void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
@@ -1069,10 +1076,14 @@ void StmtPrinter::VisitDesignatedInitExp
}
void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
- if (Policy.LangOpts.CPlusPlus)
- OS << "/*implicit*/" << Node->getType().getAsString(Policy) << "()";
- else {
- OS << "/*implicit*/(" << Node->getType().getAsString(Policy) << ")";
+ if (Policy.LangOpts.CPlusPlus) {
+ OS << "/*implicit*/";
+ Node->getType().print(OS, Policy);
+ OS << "()";
+ } else {
+ OS << "/*implicit*/(";
+ Node->getType().print(OS, Policy);
+ OS << ')';
if (Node->getType()->isRecordType())
OS << "{}";
else
@@ -1084,7 +1095,7 @@ void StmtPrinter::VisitVAArgExpr(VAArgEx
OS << "__builtin_va_arg(";
PrintExpr(Node->getSubExpr());
OS << ", ";
- OS << Node->getType().getAsString(Policy);
+ Node->getType().print(OS, Policy);
OS << ")";
}
@@ -1193,7 +1204,8 @@ void StmtPrinter::VisitCUDAKernelCallExp
void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
OS << Node->getCastName() << '<';
- OS << Node->getTypeAsWritten().getAsString(Policy) << ">(";
+ Node->getTypeAsWritten().print(OS, Policy);
+ OS << ">(";
PrintExpr(Node->getSubExpr());
OS << ")";
}
@@ -1217,7 +1229,7 @@ void StmtPrinter::VisitCXXConstCastExpr(
void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
OS << "typeid(";
if (Node->isTypeOperand()) {
- OS << Node->getTypeOperand().getAsString(Policy);
+ Node->getTypeOperand().print(OS, Policy);
} else {
PrintExpr(Node->getExprOperand());
}
@@ -1227,7 +1239,7 @@ void StmtPrinter::VisitCXXTypeidExpr(CXX
void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
OS << "__uuidof(";
if (Node->isTypeOperand()) {
- OS << Node->getTypeOperand().getAsString(Policy);
+ Node->getTypeOperand().print(OS, Policy);
} else {
PrintExpr(Node->getExprOperand());
}
@@ -1298,7 +1310,7 @@ void StmtPrinter::VisitCXXDefaultArgExpr
}
void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
- OS << Node->getType().getAsString(Policy);
+ Node->getType().print(OS, Policy);
OS << "(";
PrintExpr(Node->getSubExpr());
OS << ")";
@@ -1309,7 +1321,7 @@ void StmtPrinter::VisitCXXBindTemporaryE
}
void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
- OS << Node->getType().getAsString(Policy);
+ Node->getType().print(OS, Policy);
OS << "(";
for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
ArgEnd = Node->arg_end();
@@ -1379,8 +1391,7 @@ void StmtPrinter::VisitLambdaExpr(Lambda
NeedComma = true;
}
std::string ParamStr = (*P)->getNameAsString();
- (*P)->getOriginalType().getAsStringInternal(ParamStr, Policy);
- OS << ParamStr;
+ (*P)->getOriginalType().print(OS, Policy, ParamStr);
}
if (Method->isVariadic()) {
if (NeedComma)
@@ -1403,8 +1414,10 @@ void StmtPrinter::VisitLambdaExpr(Lambda
// FIXME: Attributes
// Print the trailing return type if it was specified in the source.
- if (Node->hasExplicitResultType())
- OS << " -> " << Proto->getResultType().getAsString(Policy);
+ if (Node->hasExplicitResultType()) {
+ OS << " -> ";
+ Proto->getResultType().print(OS, Policy);
+ }
}
// Print the body.
@@ -1415,9 +1428,10 @@ void StmtPrinter::VisitLambdaExpr(Lambda
void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
- OS << TSInfo->getType().getAsString(Policy) << "()";
+ TSInfo->getType().print(OS, Policy);
else
- OS << Node->getType().getAsString(Policy) << "()";
+ Node->getType().print(OS, Policy);
+ OS << "()";
}
void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
@@ -1441,12 +1455,11 @@ void StmtPrinter::VisitCXXNewExpr(CXXNew
std::string TypeS;
if (Expr *Size = E->getArraySize()) {
llvm::raw_string_ostream s(TypeS);
+ s << '[';
Size->printPretty(s, Helper, Policy);
- s.flush();
- TypeS = "[" + TypeS + "]";
+ s << ']';
}
- E->getAllocatedType().getAsStringInternal(TypeS, Policy);
- OS << TypeS;
+ E->getAllocatedType().print(OS, Policy, TypeS);
if (E->isParenTypeId())
OS << ")";
@@ -1479,12 +1492,10 @@ void StmtPrinter::VisitCXXPseudoDestruct
E->getQualifier()->print(OS, Policy);
OS << "~";
- std::string TypeS;
if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
OS << II->getName();
else
- E->getDestroyedType().getAsStringInternal(TypeS, Policy);
- OS << TypeS;
+ E->getDestroyedType().print(OS, Policy);
}
void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
@@ -1513,7 +1524,7 @@ void StmtPrinter::VisitExprWithCleanups(
void
StmtPrinter::VisitCXXUnresolvedConstructExpr(
CXXUnresolvedConstructExpr *Node) {
- OS << Node->getTypeAsWritten().getAsString(Policy);
+ Node->getTypeAsWritten().print(OS, Policy);
OS << "(";
for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
ArgEnd = Node->arg_end();
@@ -1647,14 +1658,17 @@ static const char *getExpressionTraitNam
}
void StmtPrinter::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
- OS << getTypeTraitName(E->getTrait()) << "("
- << E->getQueriedType().getAsString(Policy) << ")";
+ OS << getTypeTraitName(E->getTrait()) << '(';
+ E->getQueriedType().print(OS, Policy);
+ OS << ')';
}
void StmtPrinter::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
- OS << getTypeTraitName(E->getTrait()) << "("
- << E->getLhsType().getAsString(Policy) << ","
- << E->getRhsType().getAsString(Policy) << ")";
+ OS << getTypeTraitName(E->getTrait()) << '(';
+ E->getLhsType().print(OS, Policy);
+ OS << ',';
+ E->getRhsType().print(OS, Policy);
+ OS << ')';
}
void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) {
@@ -1662,20 +1676,21 @@ void StmtPrinter::VisitTypeTraitExpr(Typ
for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
if (I > 0)
OS << ", ";
- OS << E->getArg(I)->getType().getAsString(Policy);
+ E->getArg(I)->getType().print(OS, Policy);
}
OS << ")";
}
void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
- OS << getTypeTraitName(E->getTrait()) << "("
- << E->getQueriedType().getAsString(Policy) << ")";
+ OS << getTypeTraitName(E->getTrait()) << '(';
+ E->getQueriedType().print(OS, Policy);
+ OS << ')';
}
void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
- OS << getExpressionTraitName(E->getTrait()) << "(";
- PrintExpr(E->getQueriedExpression());
- OS << ")";
+ OS << getExpressionTraitName(E->getTrait()) << '(';
+ PrintExpr(E->getQueriedExpression());
+ OS << ')';
}
void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
@@ -1754,7 +1769,9 @@ void StmtPrinter::VisitObjCDictionaryLit
}
void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
- OS << "@encode(" << Node->getEncodedType().getAsString(Policy) << ')';
+ OS << "@encode(";
+ Node->getEncodedType().print(OS, Policy);
+ OS << ')';
}
void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
@@ -1773,7 +1790,7 @@ void StmtPrinter::VisitObjCMessageExpr(O
break;
case ObjCMessageExpr::Class:
- OS << Mess->getClassReceiver().getAsString(Policy);
+ Mess->getClassReceiver().print(OS, Policy);
break;
case ObjCMessageExpr::SuperInstance:
@@ -1814,8 +1831,9 @@ StmtPrinter::VisitObjCIndirectCopyRestor
void
StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
- OS << "(" << E->getBridgeKindName() << E->getType().getAsString(Policy)
- << ")";
+ OS << '(' << E->getBridgeKindName();
+ E->getType().print(OS, Policy);
+ OS << ')';
PrintExpr(E->getSubExpr());
}
@@ -1829,13 +1847,11 @@ void StmtPrinter::VisitBlockExpr(BlockEx
OS << "()";
} else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
OS << '(';
- std::string ParamStr;
for (BlockDecl::param_iterator AI = BD->param_begin(),
E = BD->param_end(); AI != E; ++AI) {
if (AI != BD->param_begin()) OS << ", ";
- ParamStr = (*AI)->getNameAsString();
- (*AI)->getType().getAsStringInternal(ParamStr, Policy);
- OS << ParamStr;
+ std::string ParamStr = (*AI)->getNameAsString();
+ (*AI)->getType().print(OS, Policy, ParamStr);
}
const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
@@ -1855,7 +1871,8 @@ void StmtPrinter::VisitOpaqueValueExpr(O
void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
OS << "__builtin_astype(";
PrintExpr(Node->getSrcExpr());
- OS << ", " << Node->getType().getAsString();
+ OS << ", ";
+ Node->getType().print(OS, Policy);
OS << ")";
}
Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=175891&r1=175890&r2=175891&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Fri Feb 22 08:19:01 2013
@@ -1603,11 +1603,7 @@ void QualType::print(const Type *ty, Qua
raw_ostream &OS, const PrintingPolicy &policy,
const Twine &PlaceHolder) {
SmallString<128> PHBuf;
- StringRef PH;
- if (PlaceHolder.isSingleStringRef())
- PH = PlaceHolder.getSingleStringRef();
- else
- PH = PlaceHolder.toStringRef(PHBuf);
+ StringRef PH = PlaceHolder.toStringRef(PHBuf);
TypePrinter(policy).print(ty, qs, OS, PH);
}
More information about the cfe-commits
mailing list