2006-11-04 15:16:25 +08:00
|
|
|
//===--- StmtPrinter.cpp - Printing implementation for Stmt ASTs ----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-11-04 15:16:25 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2007-08-09 06:51:59 +08:00
|
|
|
// This file implements the Stmt::dumpPretty/Stmt::printPretty methods, which
|
|
|
|
// pretty print the AST back out to C code.
|
2006-11-04 15:16:25 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-07-05 04:19:54 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2012-12-01 23:09:41 +08:00
|
|
|
#include "clang/AST/Attr.h"
|
2009-01-06 13:10:23 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2007-10-18 02:36:42 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2011-01-15 09:15:58 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2010-09-08 08:15:04 +08:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
2012-12-01 23:09:41 +08:00
|
|
|
#include "clang/AST/PrettyPrinter.h"
|
|
|
|
#include "clang/AST/StmtVisitor.h"
|
2013-02-09 06:30:27 +08:00
|
|
|
#include "clang/Basic/CharInfo.h"
|
2012-02-04 21:45:25 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2013-02-09 06:30:27 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2006-11-04 15:16:25 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// StmtPrinter Visitor
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
2009-11-29 03:03:38 +08:00
|
|
|
class StmtPrinter : public StmtVisitor<StmtPrinter> {
|
2011-07-23 18:55:15 +08:00
|
|
|
raw_ostream &OS;
|
2006-11-04 15:16:25 +08:00
|
|
|
unsigned IndentLevel;
|
2007-09-01 05:30:12 +08:00
|
|
|
clang::PrinterHelper* Helper;
|
2009-05-30 04:38:28 +08:00
|
|
|
PrintingPolicy Policy;
|
|
|
|
|
2006-11-04 15:16:25 +08:00
|
|
|
public:
|
2012-08-16 11:56:14 +08:00
|
|
|
StmtPrinter(raw_ostream &os, PrinterHelper* helper,
|
2009-06-30 09:26:17 +08:00
|
|
|
const PrintingPolicy &Policy,
|
2009-05-30 04:38:28 +08:00
|
|
|
unsigned Indentation = 0)
|
2012-08-16 11:56:14 +08:00
|
|
|
: OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy) {}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-30 04:38:28 +08:00
|
|
|
void PrintStmt(Stmt *S) {
|
|
|
|
PrintStmt(S, Policy.Indentation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintStmt(Stmt *S, int SubIndent) {
|
2007-05-21 06:52:15 +08:00
|
|
|
IndentLevel += SubIndent;
|
2007-06-01 02:21:33 +08:00
|
|
|
if (S && isa<Expr>(S)) {
|
2006-11-05 02:52:07 +08:00
|
|
|
// If this is an expr used in a stmt context, indent and newline it.
|
|
|
|
Indent();
|
2007-08-21 12:04:25 +08:00
|
|
|
Visit(S);
|
2007-05-31 01:57:36 +08:00
|
|
|
OS << ";\n";
|
2006-11-05 02:52:07 +08:00
|
|
|
} else if (S) {
|
2007-08-21 12:04:25 +08:00
|
|
|
Visit(S);
|
2006-11-05 02:52:07 +08:00
|
|
|
} else {
|
2007-05-28 09:47:47 +08:00
|
|
|
Indent() << "<<<NULL STATEMENT>>>\n";
|
2006-11-05 02:52:07 +08:00
|
|
|
}
|
2007-05-21 06:52:15 +08:00
|
|
|
IndentLevel -= SubIndent;
|
2006-11-05 02:52:07 +08:00
|
|
|
}
|
2009-05-30 08:19:54 +08:00
|
|
|
|
2007-05-21 07:04:55 +08:00
|
|
|
void PrintRawCompoundStmt(CompoundStmt *S);
|
2007-06-06 04:52:47 +08:00
|
|
|
void PrintRawDecl(Decl *D);
|
2012-10-17 07:45:15 +08:00
|
|
|
void PrintRawDeclStmt(const DeclStmt *S);
|
Pretty print if/else/elseif chains nicer, like this:
void printutf8(unsigned int X) {
if (X <= 127)
printf("%c", (char)X);
else if (X <= 2047)
printf("%d %d ", 128 + 64 + (X >> 6), 128 + (X & ((1 << 6) - 1)));
else if (X <= 65535)
printf("%c%c%c", 128 + 64 + 32 + (X >> 12), 128 + ((X >> 6) & 63), 128 + (X & 63));
else
printf("UNKNOWN %d\n", X);
instead of:
if (X <= 127)
printf("%c", (char)X);
else
if (X <= 2047)
printf("%d %d ", 128 + 64 + (X >> 6), 128 + (X & ((1 << 6) - 1)));
else
if (X <= 65535)
printf("%c%c%c", 128 + 64 + 32 + (X >> 12), 128 + ((X >> 6) & 63), 128 + (X & 63));
else
printf("UNKNOWN %d\n", X);
llvm-svn: 39648
2007-06-12 06:26:23 +08:00
|
|
|
void PrintRawIfStmt(IfStmt *If);
|
2008-12-23 05:35:02 +08:00
|
|
|
void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
|
2011-02-09 05:17:54 +08:00
|
|
|
void PrintCallArgs(CallExpr *E);
|
2011-04-28 09:08:34 +08:00
|
|
|
void PrintRawSEHExceptHandler(SEHExceptStmt *S);
|
|
|
|
void PrintRawSEHFinallyStmt(SEHFinallyStmt *S);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-11-05 02:52:07 +08:00
|
|
|
void PrintExpr(Expr *E) {
|
|
|
|
if (E)
|
2007-08-21 12:04:25 +08:00
|
|
|
Visit(E);
|
2006-11-04 15:16:25 +08:00
|
|
|
else
|
2006-11-05 02:52:07 +08:00
|
|
|
OS << "<null expr>";
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
raw_ostream &Indent(int Delta = 0) {
|
2009-05-30 04:38:28 +08:00
|
|
|
for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
|
|
|
|
OS << " ";
|
2006-11-04 15:16:25 +08:00
|
|
|
return OS;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
void Visit(Stmt* S) {
|
2007-09-01 05:30:12 +08:00
|
|
|
if (Helper && Helper->handledStmt(S,OS))
|
|
|
|
return;
|
|
|
|
else StmtVisitor<StmtPrinter>::Visit(S);
|
|
|
|
}
|
2010-08-15 09:15:33 +08:00
|
|
|
|
2010-10-23 16:21:37 +08:00
|
|
|
void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
|
2010-08-15 09:15:33 +08:00
|
|
|
Indent() << "<<unknown stmt type>>\n";
|
|
|
|
}
|
2010-10-23 16:21:37 +08:00
|
|
|
void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
|
2010-08-15 09:15:33 +08:00
|
|
|
OS << "<<unknown expr type>>";
|
|
|
|
}
|
|
|
|
void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-08-15 09:15:33 +08:00
|
|
|
#define ABSTRACT_STMT(CLASS)
|
2008-11-14 20:46:07 +08:00
|
|
|
#define STMT(CLASS, PARENT) \
|
2007-08-21 12:04:25 +08:00
|
|
|
void Visit##CLASS(CLASS *Node);
|
2010-05-05 23:24:00 +08:00
|
|
|
#include "clang/AST/StmtNodes.inc"
|
2006-11-05 04:18:38 +08:00
|
|
|
};
|
2006-11-05 02:52:07 +08:00
|
|
|
}
|
|
|
|
|
2006-11-05 04:18:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Stmt printing methods.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-05-21 07:04:55 +08:00
|
|
|
/// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
|
|
|
|
/// with no newline after the }.
|
|
|
|
void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
|
|
|
|
OS << "{\n";
|
2006-11-04 15:16:25 +08:00
|
|
|
for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end();
|
2006-11-05 02:52:07 +08:00
|
|
|
I != E; ++I)
|
|
|
|
PrintStmt(*I);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-05-21 07:04:55 +08:00
|
|
|
Indent() << "}";
|
|
|
|
}
|
|
|
|
|
2007-06-06 04:52:47 +08:00
|
|
|
void StmtPrinter::PrintRawDecl(Decl *D) {
|
2009-06-30 10:35:04 +08:00
|
|
|
D->print(OS, Policy, IndentLevel);
|
2009-02-11 04:16:46 +08:00
|
|
|
}
|
|
|
|
|
2012-10-17 07:45:15 +08:00
|
|
|
void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
|
|
|
|
DeclStmt::const_decl_iterator Begin = S->decl_begin(), End = S->decl_end();
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<Decl*, 2> Decls;
|
2009-09-09 23:08:12 +08:00
|
|
|
for ( ; Begin != End; ++Begin)
|
2009-05-30 12:20:30 +08:00
|
|
|
Decls.push_back(*Begin);
|
2009-05-30 08:19:54 +08:00
|
|
|
|
2009-06-30 10:35:04 +08:00
|
|
|
Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
|
2008-10-07 02:39:36 +08:00
|
|
|
}
|
2007-06-06 04:52:47 +08:00
|
|
|
|
|
|
|
void StmtPrinter::VisitNullStmt(NullStmt *Node) {
|
|
|
|
Indent() << ";\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
|
2009-05-30 08:19:54 +08:00
|
|
|
Indent();
|
|
|
|
PrintRawDeclStmt(Node);
|
|
|
|
OS << ";\n";
|
2007-05-30 06:59:26 +08:00
|
|
|
}
|
|
|
|
|
2007-05-21 07:04:55 +08:00
|
|
|
void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
|
|
|
|
Indent();
|
|
|
|
PrintRawCompoundStmt(Node);
|
2007-05-31 13:08:56 +08:00
|
|
|
OS << "\n";
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
|
|
|
|
2006-11-05 08:19:50 +08:00
|
|
|
void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
|
2007-05-21 06:52:15 +08:00
|
|
|
Indent(-1) << "case ";
|
2006-11-05 08:19:50 +08:00
|
|
|
PrintExpr(Node->getLHS());
|
|
|
|
if (Node->getRHS()) {
|
|
|
|
OS << " ... ";
|
|
|
|
PrintExpr(Node->getRHS());
|
|
|
|
}
|
|
|
|
OS << ":\n";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-05-21 06:52:15 +08:00
|
|
|
PrintStmt(Node->getSubStmt(), 0);
|
2006-11-05 08:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
|
2007-05-21 06:52:15 +08:00
|
|
|
Indent(-1) << "default:\n";
|
|
|
|
PrintStmt(Node->getSubStmt(), 0);
|
2006-11-05 08:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
|
2007-05-28 14:56:27 +08:00
|
|
|
Indent(-1) << Node->getName() << ":\n";
|
2007-05-21 06:52:15 +08:00
|
|
|
PrintStmt(Node->getSubStmt(), 0);
|
2006-11-05 08:19:50 +08:00
|
|
|
}
|
|
|
|
|
2012-04-14 08:33:13 +08:00
|
|
|
void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) {
|
|
|
|
OS << "[[";
|
|
|
|
bool first = true;
|
2012-07-09 18:04:07 +08:00
|
|
|
for (ArrayRef<const Attr*>::iterator it = Node->getAttrs().begin(),
|
|
|
|
end = Node->getAttrs().end();
|
|
|
|
it != end; ++it) {
|
2012-04-14 08:33:13 +08:00
|
|
|
if (!first) {
|
|
|
|
OS << ", ";
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
// TODO: check this
|
2012-08-16 10:43:29 +08:00
|
|
|
(*it)->printPretty(OS, Policy);
|
2012-04-14 08:33:13 +08:00
|
|
|
}
|
|
|
|
OS << "]] ";
|
|
|
|
PrintStmt(Node->getSubStmt(), 0);
|
|
|
|
}
|
|
|
|
|
Pretty print if/else/elseif chains nicer, like this:
void printutf8(unsigned int X) {
if (X <= 127)
printf("%c", (char)X);
else if (X <= 2047)
printf("%d %d ", 128 + 64 + (X >> 6), 128 + (X & ((1 << 6) - 1)));
else if (X <= 65535)
printf("%c%c%c", 128 + 64 + 32 + (X >> 12), 128 + ((X >> 6) & 63), 128 + (X & 63));
else
printf("UNKNOWN %d\n", X);
instead of:
if (X <= 127)
printf("%c", (char)X);
else
if (X <= 2047)
printf("%d %d ", 128 + 64 + (X >> 6), 128 + (X & ((1 << 6) - 1)));
else
if (X <= 65535)
printf("%c%c%c", 128 + 64 + 32 + (X >> 12), 128 + ((X >> 6) & 63), 128 + (X & 63));
else
printf("UNKNOWN %d\n", X);
llvm-svn: 39648
2007-06-12 06:26:23 +08:00
|
|
|
void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
|
2009-02-08 04:05:48 +08:00
|
|
|
OS << "if (";
|
2012-10-17 07:45:15 +08:00
|
|
|
if (const DeclStmt *DS = If->getConditionVariableDeclStmt())
|
|
|
|
PrintRawDeclStmt(DS);
|
|
|
|
else
|
|
|
|
PrintExpr(If->getCond());
|
2009-02-08 04:05:48 +08:00
|
|
|
OS << ')';
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-05-21 07:04:55 +08:00
|
|
|
if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
|
|
|
|
OS << ' ';
|
|
|
|
PrintRawCompoundStmt(CS);
|
|
|
|
OS << (If->getElse() ? ' ' : '\n');
|
|
|
|
} else {
|
|
|
|
OS << '\n';
|
|
|
|
PrintStmt(If->getThen());
|
|
|
|
if (If->getElse()) Indent();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-05-21 07:04:55 +08:00
|
|
|
if (Stmt *Else = If->getElse()) {
|
|
|
|
OS << "else";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-05-21 07:04:55 +08:00
|
|
|
if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
|
|
|
|
OS << ' ';
|
|
|
|
PrintRawCompoundStmt(CS);
|
|
|
|
OS << '\n';
|
Pretty print if/else/elseif chains nicer, like this:
void printutf8(unsigned int X) {
if (X <= 127)
printf("%c", (char)X);
else if (X <= 2047)
printf("%d %d ", 128 + 64 + (X >> 6), 128 + (X & ((1 << 6) - 1)));
else if (X <= 65535)
printf("%c%c%c", 128 + 64 + 32 + (X >> 12), 128 + ((X >> 6) & 63), 128 + (X & 63));
else
printf("UNKNOWN %d\n", X);
instead of:
if (X <= 127)
printf("%c", (char)X);
else
if (X <= 2047)
printf("%d %d ", 128 + 64 + (X >> 6), 128 + (X & ((1 << 6) - 1)));
else
if (X <= 65535)
printf("%c%c%c", 128 + 64 + 32 + (X >> 12), 128 + ((X >> 6) & 63), 128 + (X & 63));
else
printf("UNKNOWN %d\n", X);
llvm-svn: 39648
2007-06-12 06:26:23 +08:00
|
|
|
} else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
|
|
|
|
OS << ' ';
|
|
|
|
PrintRawIfStmt(ElseIf);
|
2007-05-21 07:04:55 +08:00
|
|
|
} else {
|
|
|
|
OS << '\n';
|
|
|
|
PrintStmt(If->getElse());
|
|
|
|
}
|
2006-11-05 02:52:07 +08:00
|
|
|
}
|
2006-11-05 04:40:44 +08:00
|
|
|
}
|
|
|
|
|
Pretty print if/else/elseif chains nicer, like this:
void printutf8(unsigned int X) {
if (X <= 127)
printf("%c", (char)X);
else if (X <= 2047)
printf("%d %d ", 128 + 64 + (X >> 6), 128 + (X & ((1 << 6) - 1)));
else if (X <= 65535)
printf("%c%c%c", 128 + 64 + 32 + (X >> 12), 128 + ((X >> 6) & 63), 128 + (X & 63));
else
printf("UNKNOWN %d\n", X);
instead of:
if (X <= 127)
printf("%c", (char)X);
else
if (X <= 2047)
printf("%d %d ", 128 + 64 + (X >> 6), 128 + (X & ((1 << 6) - 1)));
else
if (X <= 65535)
printf("%c%c%c", 128 + 64 + 32 + (X >> 12), 128 + ((X >> 6) & 63), 128 + (X & 63));
else
printf("UNKNOWN %d\n", X);
llvm-svn: 39648
2007-06-12 06:26:23 +08:00
|
|
|
void StmtPrinter::VisitIfStmt(IfStmt *If) {
|
|
|
|
Indent();
|
|
|
|
PrintRawIfStmt(If);
|
|
|
|
}
|
|
|
|
|
2006-11-05 04:59:27 +08:00
|
|
|
void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
|
|
|
|
Indent() << "switch (";
|
2012-10-17 07:45:15 +08:00
|
|
|
if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
|
|
|
|
PrintRawDeclStmt(DS);
|
|
|
|
else
|
|
|
|
PrintExpr(Node->getCond());
|
2007-05-21 07:04:55 +08:00
|
|
|
OS << ")";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-05-21 07:04:55 +08:00
|
|
|
// Pretty print compoundstmt bodies (very common).
|
|
|
|
if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
|
|
|
|
OS << " ";
|
|
|
|
PrintRawCompoundStmt(CS);
|
|
|
|
OS << "\n";
|
|
|
|
} else {
|
|
|
|
OS << "\n";
|
|
|
|
PrintStmt(Node->getBody());
|
|
|
|
}
|
2006-11-05 04:59:27 +08:00
|
|
|
}
|
|
|
|
|
2006-11-05 04:40:44 +08:00
|
|
|
void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
|
|
|
|
Indent() << "while (";
|
2012-10-17 07:45:15 +08:00
|
|
|
if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
|
|
|
|
PrintRawDeclStmt(DS);
|
|
|
|
else
|
|
|
|
PrintExpr(Node->getCond());
|
2006-11-05 04:40:44 +08:00
|
|
|
OS << ")\n";
|
|
|
|
PrintStmt(Node->getBody());
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitDoStmt(DoStmt *Node) {
|
2007-09-16 05:49:37 +08:00
|
|
|
Indent() << "do ";
|
|
|
|
if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
|
|
|
|
PrintRawCompoundStmt(CS);
|
|
|
|
OS << " ";
|
|
|
|
} else {
|
|
|
|
OS << "\n";
|
|
|
|
PrintStmt(Node->getBody());
|
|
|
|
Indent();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-17 09:05:34 +08:00
|
|
|
OS << "while (";
|
2006-11-05 04:40:44 +08:00
|
|
|
PrintExpr(Node->getCond());
|
2009-05-17 09:05:34 +08:00
|
|
|
OS << ");\n";
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
|
|
|
|
2006-11-05 04:18:38 +08:00
|
|
|
void StmtPrinter::VisitForStmt(ForStmt *Node) {
|
|
|
|
Indent() << "for (";
|
2007-06-06 04:52:47 +08:00
|
|
|
if (Node->getInit()) {
|
|
|
|
if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
|
2008-10-07 02:39:36 +08:00
|
|
|
PrintRawDeclStmt(DS);
|
2007-06-06 04:52:47 +08:00
|
|
|
else
|
|
|
|
PrintExpr(cast<Expr>(Node->getInit()));
|
|
|
|
}
|
2007-09-16 05:49:37 +08:00
|
|
|
OS << ";";
|
|
|
|
if (Node->getCond()) {
|
|
|
|
OS << " ";
|
2007-06-06 04:52:47 +08:00
|
|
|
PrintExpr(Node->getCond());
|
2007-09-16 05:49:37 +08:00
|
|
|
}
|
|
|
|
OS << ";";
|
|
|
|
if (Node->getInc()) {
|
|
|
|
OS << " ";
|
2007-06-06 04:52:47 +08:00
|
|
|
PrintExpr(Node->getInc());
|
2007-09-16 05:49:37 +08:00
|
|
|
}
|
|
|
|
OS << ") ";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-09-16 05:49:37 +08:00
|
|
|
if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
|
|
|
|
PrintRawCompoundStmt(CS);
|
|
|
|
OS << "\n";
|
|
|
|
} else {
|
|
|
|
OS << "\n";
|
|
|
|
PrintStmt(Node->getBody());
|
|
|
|
}
|
2006-11-05 04:18:38 +08:00
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
|
2008-01-03 06:54:34 +08:00
|
|
|
Indent() << "for (";
|
|
|
|
if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
|
2008-10-07 02:39:36 +08:00
|
|
|
PrintRawDeclStmt(DS);
|
2008-01-03 06:54:34 +08:00
|
|
|
else
|
|
|
|
PrintExpr(cast<Expr>(Node->getElement()));
|
|
|
|
OS << " in ";
|
|
|
|
PrintExpr(Node->getCollection());
|
|
|
|
OS << ") ";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-03 06:54:34 +08:00
|
|
|
if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
|
|
|
|
PrintRawCompoundStmt(CS);
|
|
|
|
OS << "\n";
|
|
|
|
} else {
|
|
|
|
OS << "\n";
|
|
|
|
PrintStmt(Node->getBody());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-15 06:09:26 +08:00
|
|
|
void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) {
|
|
|
|
Indent() << "for (";
|
|
|
|
PrintingPolicy SubPolicy(Policy);
|
|
|
|
SubPolicy.SuppressInitializers = true;
|
|
|
|
Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel);
|
|
|
|
OS << " : ";
|
|
|
|
PrintExpr(Node->getRangeInit());
|
|
|
|
OS << ") {\n";
|
|
|
|
PrintStmt(Node->getBody());
|
|
|
|
Indent() << "}\n";
|
|
|
|
}
|
|
|
|
|
2011-10-25 09:33:02 +08:00
|
|
|
void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
|
|
|
|
Indent();
|
|
|
|
if (Node->isIfExists())
|
|
|
|
OS << "__if_exists (";
|
|
|
|
else
|
|
|
|
OS << "__if_not_exists (";
|
|
|
|
|
|
|
|
if (NestedNameSpecifier *Qualifier
|
|
|
|
= Node->getQualifierLoc().getNestedNameSpecifier())
|
|
|
|
Qualifier->print(OS, Policy);
|
|
|
|
|
|
|
|
OS << Node->getNameInfo() << ") ";
|
|
|
|
|
|
|
|
PrintRawCompoundStmt(Node->getSubStmt());
|
|
|
|
}
|
|
|
|
|
2006-11-05 09:46:01 +08:00
|
|
|
void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
|
2007-05-28 14:56:27 +08:00
|
|
|
Indent() << "goto " << Node->getLabel()->getName() << ";\n";
|
2006-11-05 09:46:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
|
2006-11-05 09:51:06 +08:00
|
|
|
Indent() << "goto *";
|
2006-11-05 09:46:01 +08:00
|
|
|
PrintExpr(Node->getTarget());
|
2007-05-31 14:00:14 +08:00
|
|
|
OS << ";\n";
|
2006-11-05 09:46:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
|
2007-05-31 14:00:14 +08:00
|
|
|
Indent() << "continue;\n";
|
2006-11-05 09:46:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
|
2007-05-31 14:00:14 +08:00
|
|
|
Indent() << "break;\n";
|
2006-11-05 09:46:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-05 02:52:07 +08:00
|
|
|
void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
|
|
|
|
Indent() << "return";
|
|
|
|
if (Node->getRetValue()) {
|
|
|
|
OS << " ";
|
|
|
|
PrintExpr(Node->getRetValue());
|
|
|
|
}
|
2007-05-31 14:00:14 +08:00
|
|
|
OS << ";\n";
|
2006-11-05 02:52:07 +08:00
|
|
|
}
|
2006-11-04 15:16:25 +08:00
|
|
|
|
2007-10-29 12:04:16 +08:00
|
|
|
|
2012-08-25 08:11:56 +08:00
|
|
|
void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) {
|
2007-11-24 07:12:25 +08:00
|
|
|
Indent() << "asm ";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-24 07:12:25 +08:00
|
|
|
if (Node->isVolatile())
|
|
|
|
OS << "volatile ";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-24 07:12:25 +08:00
|
|
|
OS << "(";
|
2007-11-21 03:21:03 +08:00
|
|
|
VisitStringLiteral(Node->getAsmString());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-22 09:36:19 +08:00
|
|
|
// Outputs
|
|
|
|
if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
|
|
|
|
Node->getNumClobbers() != 0)
|
|
|
|
OS << " : ";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-22 09:36:19 +08:00
|
|
|
for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
|
|
|
|
if (i != 0)
|
|
|
|
OS << ", ";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-22 09:36:19 +08:00
|
|
|
if (!Node->getOutputName(i).empty()) {
|
|
|
|
OS << '[';
|
|
|
|
OS << Node->getOutputName(i);
|
|
|
|
OS << "] ";
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-10 12:59:06 +08:00
|
|
|
VisitStringLiteral(Node->getOutputConstraintLiteral(i));
|
2007-11-22 09:36:19 +08:00
|
|
|
OS << " ";
|
|
|
|
Visit(Node->getOutputExpr(i));
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-22 09:36:19 +08:00
|
|
|
// Inputs
|
|
|
|
if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
|
|
|
|
OS << " : ";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-22 09:36:19 +08:00
|
|
|
for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
|
|
|
|
if (i != 0)
|
|
|
|
OS << ", ";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-22 09:36:19 +08:00
|
|
|
if (!Node->getInputName(i).empty()) {
|
|
|
|
OS << '[';
|
|
|
|
OS << Node->getInputName(i);
|
|
|
|
OS << "] ";
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-10 12:59:06 +08:00
|
|
|
VisitStringLiteral(Node->getInputConstraintLiteral(i));
|
2007-11-22 09:36:19 +08:00
|
|
|
OS << " ";
|
|
|
|
Visit(Node->getInputExpr(i));
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-22 09:36:19 +08:00
|
|
|
// Clobbers
|
|
|
|
if (Node->getNumClobbers() != 0)
|
|
|
|
OS << " : ";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-22 09:36:19 +08:00
|
|
|
for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
|
|
|
|
if (i != 0)
|
|
|
|
OS << ", ";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-08-28 07:28:41 +08:00
|
|
|
VisitStringLiteral(Node->getClobberStringLiteral(i));
|
2007-11-22 09:36:19 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-21 03:21:03 +08:00
|
|
|
OS << ");\n";
|
2007-10-29 12:04:16 +08:00
|
|
|
}
|
|
|
|
|
2012-06-12 04:47:18 +08:00
|
|
|
void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {
|
|
|
|
// FIXME: Implement MS style inline asm statement printer.
|
2012-08-16 00:53:30 +08:00
|
|
|
Indent() << "__asm ";
|
|
|
|
if (Node->hasBraces())
|
|
|
|
OS << "{\n";
|
|
|
|
OS << *(Node->getAsmString()) << "\n";
|
|
|
|
if (Node->hasBraces())
|
|
|
|
Indent() << "}\n";
|
2012-06-12 04:47:18 +08:00
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
|
2007-11-03 02:16:07 +08:00
|
|
|
Indent() << "@try";
|
|
|
|
if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
|
|
|
|
PrintRawCompoundStmt(TS);
|
|
|
|
OS << "\n";
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-04-24 06:50:49 +08:00
|
|
|
for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) {
|
|
|
|
ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I);
|
2007-11-03 02:16:07 +08:00
|
|
|
Indent() << "@catch(";
|
2009-03-04 03:52:17 +08:00
|
|
|
if (catchStmt->getCatchParamDecl()) {
|
|
|
|
if (Decl *DS = catchStmt->getCatchParamDecl())
|
|
|
|
PrintRawDecl(DS);
|
2007-11-03 02:16:07 +08:00
|
|
|
}
|
|
|
|
OS << ")";
|
2009-09-09 23:08:12 +08:00
|
|
|
if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
|
|
|
|
PrintRawCompoundStmt(CS);
|
|
|
|
OS << "\n";
|
|
|
|
}
|
2007-11-03 02:16:07 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
if (ObjCAtFinallyStmt *FS = static_cast<ObjCAtFinallyStmt *>(
|
|
|
|
Node->getFinallyStmt())) {
|
2007-11-07 08:46:42 +08:00
|
|
|
Indent() << "@finally";
|
|
|
|
PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
|
2007-11-03 02:16:07 +08:00
|
|
|
OS << "\n";
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2007-11-02 05:12:44 +08:00
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
|
2007-11-02 05:12:44 +08:00
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
|
2007-11-02 05:12:44 +08:00
|
|
|
Indent() << "@catch (...) { /* todo */ } \n";
|
|
|
|
}
|
|
|
|
|
2008-01-31 01:38:29 +08:00
|
|
|
void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
|
2007-11-07 10:00:49 +08:00
|
|
|
Indent() << "@throw";
|
|
|
|
if (Node->getThrowExpr()) {
|
|
|
|
OS << " ";
|
|
|
|
PrintExpr(Node->getThrowExpr());
|
|
|
|
}
|
|
|
|
OS << ";\n";
|
|
|
|
}
|
|
|
|
|
2008-01-31 01:38:29 +08:00
|
|
|
void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
|
2008-01-30 02:21:32 +08:00
|
|
|
Indent() << "@synchronized (";
|
|
|
|
PrintExpr(Node->getSynchExpr());
|
|
|
|
OS << ")";
|
2008-01-31 01:38:29 +08:00
|
|
|
PrintRawCompoundStmt(Node->getSynchBody());
|
|
|
|
OS << "\n";
|
2008-01-30 02:21:32 +08:00
|
|
|
}
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
|
|
|
|
Indent() << "@autoreleasepool";
|
|
|
|
PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt()));
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
2008-12-23 05:35:02 +08:00
|
|
|
void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
|
|
|
|
OS << "catch (";
|
2008-12-23 03:15:10 +08:00
|
|
|
if (Decl *ExDecl = Node->getExceptionDecl())
|
|
|
|
PrintRawDecl(ExDecl);
|
|
|
|
else
|
|
|
|
OS << "...";
|
|
|
|
OS << ") ";
|
|
|
|
PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
|
2008-12-23 05:35:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
|
|
|
|
Indent();
|
|
|
|
PrintRawCXXCatchStmt(Node);
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
|
|
|
|
Indent() << "try ";
|
|
|
|
PrintRawCompoundStmt(Node->getTryBlock());
|
2009-09-09 23:08:12 +08:00
|
|
|
for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
|
2008-12-23 05:35:02 +08:00
|
|
|
OS << " ";
|
|
|
|
PrintRawCXXCatchStmt(Node->getHandler(i));
|
|
|
|
}
|
2008-12-23 03:15:10 +08:00
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
2011-04-28 09:08:34 +08:00
|
|
|
void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) {
|
|
|
|
Indent() << (Node->getIsCXXTry() ? "try " : "__try ");
|
|
|
|
PrintRawCompoundStmt(Node->getTryBlock());
|
|
|
|
SEHExceptStmt *E = Node->getExceptHandler();
|
|
|
|
SEHFinallyStmt *F = Node->getFinallyHandler();
|
|
|
|
if(E)
|
|
|
|
PrintRawSEHExceptHandler(E);
|
|
|
|
else {
|
|
|
|
assert(F && "Must have a finally block...");
|
|
|
|
PrintRawSEHFinallyStmt(F);
|
|
|
|
}
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
|
|
|
|
OS << "__finally ";
|
|
|
|
PrintRawCompoundStmt(Node->getBlock());
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
|
|
|
|
OS << "__except (";
|
|
|
|
VisitExpr(Node->getFilterExpr());
|
2012-09-05 01:49:35 +08:00
|
|
|
OS << ")\n";
|
2011-04-28 09:08:34 +08:00
|
|
|
PrintRawCompoundStmt(Node->getBlock());
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) {
|
|
|
|
Indent();
|
|
|
|
PrintRawSEHExceptHandler(Node);
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) {
|
|
|
|
Indent();
|
|
|
|
PrintRawSEHFinallyStmt(Node);
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
2006-11-05 04:18:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Expr printing methods.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2006-11-04 15:16:25 +08:00
|
|
|
|
2006-11-05 02:52:07 +08:00
|
|
|
void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
|
2009-10-24 02:54:35 +08:00
|
|
|
if (NestedNameSpecifier *Qualifier = Node->getQualifier())
|
|
|
|
Qualifier->print(OS, Policy);
|
2012-01-27 17:46:47 +08:00
|
|
|
if (Node->hasTemplateKeyword())
|
|
|
|
OS << "template ";
|
2010-08-12 06:01:17 +08:00
|
|
|
OS << Node->getNameInfo();
|
2010-08-20 07:49:38 +08:00
|
|
|
if (Node->hasExplicitTemplateArgs())
|
2013-02-22 23:46:01 +08:00
|
|
|
TemplateSpecializationType::PrintTemplateArgumentList(
|
|
|
|
OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
|
2009-01-06 13:10:23 +08:00
|
|
|
}
|
|
|
|
|
2009-11-20 06:55:06 +08:00
|
|
|
void StmtPrinter::VisitDependentScopeDeclRefExpr(
|
|
|
|
DependentScopeDeclRefExpr *Node) {
|
2011-01-24 23:44:00 +08:00
|
|
|
if (NestedNameSpecifier *Qualifier = Node->getQualifier())
|
|
|
|
Qualifier->print(OS, Policy);
|
2012-01-27 17:46:47 +08:00
|
|
|
if (Node->hasTemplateKeyword())
|
|
|
|
OS << "template ";
|
2010-08-12 06:01:17 +08:00
|
|
|
OS << Node->getNameInfo();
|
2009-11-25 03:00:30 +08:00
|
|
|
if (Node->hasExplicitTemplateArgs())
|
2013-02-22 23:46:01 +08:00
|
|
|
TemplateSpecializationType::PrintTemplateArgumentList(
|
|
|
|
OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
|
Introduce a new expression type, UnresolvedDeclRefExpr, that describes
dependent qualified-ids such as
Fibonacci<N - 1>::value
where N is a template parameter. These references are "unresolved"
because the name is dependent and, therefore, cannot be resolved to a
declaration node (as we would do for a DeclRefExpr or
QualifiedDeclRefExpr). UnresolvedDeclRefExprs instantiate to
DeclRefExprs, QualifiedDeclRefExprs, etc.
Also, be a bit more careful about keeping only a single set of
specializations for a class template, and instantiating from the
definition of that template rather than a previous declaration. In
general, we need a better solution for this for all TagDecls, because
it's too easy to accidentally look at a declaration that isn't the
definition.
We can now process a simple Fibonacci computation described as a
template metaprogram.
llvm-svn: 67308
2009-03-20 01:26:29 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 16:51:07 +08:00
|
|
|
void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
|
2009-07-01 06:34:41 +08:00
|
|
|
if (Node->getQualifier())
|
|
|
|
Node->getQualifier()->print(OS, Policy);
|
2012-01-27 17:46:47 +08:00
|
|
|
if (Node->hasTemplateKeyword())
|
|
|
|
OS << "template ";
|
2010-08-12 06:01:17 +08:00
|
|
|
OS << Node->getNameInfo();
|
2009-11-25 03:00:30 +08:00
|
|
|
if (Node->hasExplicitTemplateArgs())
|
2013-02-22 23:46:01 +08:00
|
|
|
TemplateSpecializationType::PrintTemplateArgumentList(
|
|
|
|
OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
|
2009-07-01 06:34:41 +08:00
|
|
|
}
|
|
|
|
|
2007-11-12 22:29:37 +08:00
|
|
|
void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
|
2007-11-13 06:29:28 +08:00
|
|
|
if (Node->getBase()) {
|
|
|
|
PrintExpr(Node->getBase());
|
|
|
|
OS << (Node->isArrow() ? "->" : ".");
|
|
|
|
}
|
2011-10-15 02:45:37 +08:00
|
|
|
OS << *Node->getDecl();
|
2007-11-12 22:29:37 +08:00
|
|
|
}
|
|
|
|
|
2008-05-30 08:40:33 +08:00
|
|
|
void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
|
2010-10-15 00:04:05 +08:00
|
|
|
if (Node->isSuperReceiver())
|
|
|
|
OS << "super.";
|
|
|
|
else if (Node->getBase()) {
|
2008-05-30 08:40:33 +08:00
|
|
|
PrintExpr(Node->getBase());
|
|
|
|
OS << ".";
|
|
|
|
}
|
2010-10-15 00:04:05 +08:00
|
|
|
|
2010-12-02 09:19:52 +08:00
|
|
|
if (Node->isImplicitProperty())
|
|
|
|
OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
|
|
|
|
else
|
|
|
|
OS << Node->getExplicitProperty()->getName();
|
2008-11-23 02:39:36 +08:00
|
|
|
}
|
|
|
|
|
2012-03-07 04:05:56 +08:00
|
|
|
void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
|
|
|
|
|
|
|
|
PrintExpr(Node->getBaseExpr());
|
|
|
|
OS << "[";
|
|
|
|
PrintExpr(Node->getKeyExpr());
|
|
|
|
OS << "]";
|
|
|
|
}
|
|
|
|
|
2008-08-10 09:53:14 +08:00
|
|
|
void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
|
2007-07-21 13:21:51 +08:00
|
|
|
switch (Node->getIdentType()) {
|
|
|
|
default:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("unknown case");
|
2008-08-10 09:53:14 +08:00
|
|
|
case PredefinedExpr::Func:
|
2007-07-21 13:21:51 +08:00
|
|
|
OS << "__func__";
|
|
|
|
break;
|
2008-08-10 09:53:14 +08:00
|
|
|
case PredefinedExpr::Function:
|
2007-07-21 13:21:51 +08:00
|
|
|
OS << "__FUNCTION__";
|
|
|
|
break;
|
2012-06-23 10:07:59 +08:00
|
|
|
case PredefinedExpr::LFunction:
|
|
|
|
OS << "L__FUNCTION__";
|
|
|
|
break;
|
2008-08-10 09:53:14 +08:00
|
|
|
case PredefinedExpr::PrettyFunction:
|
2007-07-21 13:21:51 +08:00
|
|
|
OS << "__PRETTY_FUNCTION__";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-27 04:39:23 +08:00
|
|
|
void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
|
2007-07-13 13:18:11 +08:00
|
|
|
unsigned value = Node->getValue();
|
2011-07-27 13:40:30 +08:00
|
|
|
|
|
|
|
switch (Node->getKind()) {
|
|
|
|
case CharacterLiteral::Ascii: break; // no prefix.
|
|
|
|
case CharacterLiteral::Wide: OS << 'L'; break;
|
|
|
|
case CharacterLiteral::UTF16: OS << 'u'; break;
|
|
|
|
case CharacterLiteral::UTF32: OS << 'U'; break;
|
|
|
|
}
|
|
|
|
|
2007-07-14 07:58:20 +08:00
|
|
|
switch (value) {
|
|
|
|
case '\\':
|
|
|
|
OS << "'\\\\'";
|
|
|
|
break;
|
|
|
|
case '\'':
|
|
|
|
OS << "'\\''";
|
|
|
|
break;
|
|
|
|
case '\a':
|
|
|
|
// TODO: K&R: the meaning of '\\a' is different in traditional C
|
|
|
|
OS << "'\\a'";
|
|
|
|
break;
|
|
|
|
case '\b':
|
|
|
|
OS << "'\\b'";
|
|
|
|
break;
|
|
|
|
// Nonstandard escape sequence.
|
|
|
|
/*case '\e':
|
|
|
|
OS << "'\\e'";
|
|
|
|
break;*/
|
|
|
|
case '\f':
|
|
|
|
OS << "'\\f'";
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
OS << "'\\n'";
|
|
|
|
break;
|
|
|
|
case '\r':
|
|
|
|
OS << "'\\r'";
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
OS << "'\\t'";
|
|
|
|
break;
|
|
|
|
case '\v':
|
|
|
|
OS << "'\\v'";
|
|
|
|
break;
|
|
|
|
default:
|
2013-02-09 06:30:27 +08:00
|
|
|
if (value < 256 && isPrintable((unsigned char)value))
|
2007-07-14 07:58:20 +08:00
|
|
|
OS << "'" << (char)value << "'";
|
2013-02-09 06:30:27 +08:00
|
|
|
else if (value < 256)
|
|
|
|
OS << "'\\x" << llvm::format("%02x", value) << "'";
|
|
|
|
else if (value <= 0xFFFF)
|
|
|
|
OS << "'\\u" << llvm::format("%04x", value) << "'";
|
|
|
|
else
|
|
|
|
OS << "'\\U" << llvm::format("%08x", value) << "'";
|
2007-07-13 13:18:11 +08:00
|
|
|
}
|
2007-04-27 04:39:23 +08:00
|
|
|
}
|
|
|
|
|
2007-02-22 07:46:25 +08:00
|
|
|
void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
|
2007-05-21 13:45:03 +08:00
|
|
|
bool isSigned = Node->getType()->isSignedIntegerType();
|
|
|
|
OS << Node->getValue().toString(10, isSigned);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-05-21 13:45:03 +08:00
|
|
|
// Emit suffixes. Integer literals are always a builtin integer type.
|
2009-09-22 07:43:11 +08:00
|
|
|
switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
|
2011-09-23 13:06:16 +08:00
|
|
|
default: llvm_unreachable("Unexpected type for integer literal!");
|
2011-11-08 02:40:31 +08:00
|
|
|
// FIXME: The Short and UShort cases are to handle cases where a short
|
|
|
|
// integeral literal is formed during template instantiation. They should
|
|
|
|
// be removed when template instantiation no longer needs integer literals.
|
|
|
|
case BuiltinType::Short:
|
|
|
|
case BuiltinType::UShort:
|
2007-05-21 13:45:03 +08:00
|
|
|
case BuiltinType::Int: break; // no suffix.
|
|
|
|
case BuiltinType::UInt: OS << 'U'; break;
|
|
|
|
case BuiltinType::Long: OS << 'L'; break;
|
|
|
|
case BuiltinType::ULong: OS << "UL"; break;
|
|
|
|
case BuiltinType::LongLong: OS << "LL"; break;
|
|
|
|
case BuiltinType::ULongLong: OS << "ULL"; break;
|
2011-11-08 02:40:31 +08:00
|
|
|
case BuiltinType::Int128: OS << "i128"; break;
|
|
|
|
case BuiltinType::UInt128: OS << "Ui128"; break;
|
2007-05-21 13:45:03 +08:00
|
|
|
}
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
2012-09-20 22:07:17 +08:00
|
|
|
|
|
|
|
static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node,
|
|
|
|
bool PrintSuffix) {
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<16> Str;
|
2011-10-06 04:32:03 +08:00
|
|
|
Node->getValue().toString(Str);
|
|
|
|
OS << Str;
|
2012-09-20 22:07:17 +08:00
|
|
|
if (Str.find_first_not_of("-0123456789") == StringRef::npos)
|
|
|
|
OS << '.'; // Trailing dot in order to separate from ints.
|
|
|
|
|
|
|
|
if (!PrintSuffix)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Emit suffixes. Float literals are always a builtin float type.
|
|
|
|
switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
|
|
|
|
default: llvm_unreachable("Unexpected type for float literal!");
|
|
|
|
case BuiltinType::Half: break; // FIXME: suffix?
|
|
|
|
case BuiltinType::Double: break; // no suffix.
|
|
|
|
case BuiltinType::Float: OS << 'F'; break;
|
|
|
|
case BuiltinType::LongDouble: OS << 'L'; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
|
|
|
|
PrintFloatingLiteral(OS, Node, /*PrintSuffix=*/true);
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
2007-08-26 11:42:43 +08:00
|
|
|
|
|
|
|
void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
|
|
|
|
PrintExpr(Node->getSubExpr());
|
|
|
|
OS << "i";
|
|
|
|
}
|
|
|
|
|
2007-02-22 07:46:25 +08:00
|
|
|
void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
|
2012-06-14 04:25:24 +08:00
|
|
|
Str->outputString(OS);
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
2006-11-05 02:52:07 +08:00
|
|
|
void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
|
|
|
|
OS << "(";
|
|
|
|
PrintExpr(Node->getSubExpr());
|
2007-06-01 02:21:33 +08:00
|
|
|
OS << ")";
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
2006-11-05 02:52:07 +08:00
|
|
|
void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
|
2007-08-24 05:46:40 +08:00
|
|
|
if (!Node->isPostfix()) {
|
2006-11-06 07:54:51 +08:00
|
|
|
OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-15 06:39:26 +08:00
|
|
|
// Print a space if this is an "identifier operator" like __real, or if
|
|
|
|
// it might be concatenated incorrectly like '+'.
|
2007-08-24 05:46:40 +08:00
|
|
|
switch (Node->getOpcode()) {
|
|
|
|
default: break;
|
2010-08-25 19:45:40 +08:00
|
|
|
case UO_Real:
|
|
|
|
case UO_Imag:
|
|
|
|
case UO_Extension:
|
2007-08-24 05:46:40 +08:00
|
|
|
OS << ' ';
|
|
|
|
break;
|
2010-08-25 19:45:40 +08:00
|
|
|
case UO_Plus:
|
|
|
|
case UO_Minus:
|
2009-06-15 06:39:26 +08:00
|
|
|
if (isa<UnaryOperator>(Node->getSubExpr()))
|
|
|
|
OS << ' ';
|
|
|
|
break;
|
2007-08-24 05:46:40 +08:00
|
|
|
}
|
|
|
|
}
|
2006-11-05 02:52:07 +08:00
|
|
|
PrintExpr(Node->getSubExpr());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-11-06 07:54:51 +08:00
|
|
|
if (Node->isPostfix())
|
|
|
|
OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
|
2007-08-31 01:59:59 +08:00
|
|
|
}
|
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
|
|
|
|
OS << "__builtin_offsetof(";
|
2013-02-22 22:19:01 +08:00
|
|
|
Node->getTypeSourceInfo()->getType().print(OS, Policy);
|
|
|
|
OS << ", ";
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
bool PrintedSomething = false;
|
|
|
|
for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
|
|
|
|
OffsetOfExpr::OffsetOfNode ON = Node->getComponent(i);
|
|
|
|
if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Array) {
|
|
|
|
// Array node
|
|
|
|
OS << "[";
|
|
|
|
PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
|
|
|
|
OS << "]";
|
|
|
|
PrintedSomething = true;
|
|
|
|
continue;
|
|
|
|
}
|
2010-04-29 08:18:15 +08:00
|
|
|
|
|
|
|
// Skip implicit base indirections.
|
|
|
|
if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Base)
|
|
|
|
continue;
|
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
// Field or identifier node.
|
|
|
|
IdentifierInfo *Id = ON.getFieldName();
|
|
|
|
if (!Id)
|
|
|
|
continue;
|
2010-05-05 23:23:54 +08:00
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
if (PrintedSomething)
|
|
|
|
OS << ".";
|
|
|
|
else
|
|
|
|
PrintedSomething = true;
|
2010-05-05 23:23:54 +08:00
|
|
|
OS << Id->getName();
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
}
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2011-03-12 03:24:49 +08:00
|
|
|
void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node){
|
|
|
|
switch(Node->getKind()) {
|
|
|
|
case UETT_SizeOf:
|
|
|
|
OS << "sizeof";
|
|
|
|
break;
|
|
|
|
case UETT_AlignOf:
|
2012-07-01 05:33:57 +08:00
|
|
|
if (Policy.LangOpts.CPlusPlus)
|
|
|
|
OS << "alignof";
|
|
|
|
else if (Policy.LangOpts.C11)
|
|
|
|
OS << "_Alignof";
|
|
|
|
else
|
|
|
|
OS << "__alignof";
|
2011-03-12 03:24:49 +08:00
|
|
|
break;
|
|
|
|
case UETT_VecStep:
|
|
|
|
OS << "vec_step";
|
|
|
|
break;
|
|
|
|
}
|
2013-02-22 22:19:01 +08:00
|
|
|
if (Node->isArgumentType()) {
|
|
|
|
OS << '(';
|
|
|
|
Node->getArgumentType().print(OS, Policy);
|
|
|
|
OS << ')';
|
|
|
|
} else {
|
2008-11-12 01:56:53 +08:00
|
|
|
OS << " ";
|
|
|
|
PrintExpr(Node->getArgumentExpr());
|
|
|
|
}
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
2011-04-15 08:35:48 +08:00
|
|
|
|
|
|
|
void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) {
|
|
|
|
OS << "_Generic(";
|
|
|
|
PrintExpr(Node->getControllingExpr());
|
|
|
|
for (unsigned i = 0; i != Node->getNumAssocs(); ++i) {
|
|
|
|
OS << ", ";
|
|
|
|
QualType T = Node->getAssocType(i);
|
|
|
|
if (T.isNull())
|
|
|
|
OS << "default";
|
|
|
|
else
|
2013-02-22 22:19:01 +08:00
|
|
|
T.print(OS, Policy);
|
2011-04-15 08:35:48 +08:00
|
|
|
OS << ": ";
|
|
|
|
PrintExpr(Node->getAssocExpr(i));
|
|
|
|
}
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2006-11-05 02:52:07 +08:00
|
|
|
void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
|
2007-08-21 00:18:38 +08:00
|
|
|
PrintExpr(Node->getLHS());
|
2006-11-05 02:52:07 +08:00
|
|
|
OS << "[";
|
2007-08-21 00:18:38 +08:00
|
|
|
PrintExpr(Node->getRHS());
|
2006-11-05 02:52:07 +08:00
|
|
|
OS << "]";
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
|
|
|
|
2011-02-09 05:17:54 +08:00
|
|
|
void StmtPrinter::PrintCallArgs(CallExpr *Call) {
|
2006-11-05 02:52:07 +08:00
|
|
|
for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
|
2008-04-08 12:40:51 +08:00
|
|
|
if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
|
|
|
|
// Don't print any defaulted arguments
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-11-05 02:52:07 +08:00
|
|
|
if (i) OS << ", ";
|
|
|
|
PrintExpr(Call->getArg(i));
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
2011-02-09 05:17:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitCallExpr(CallExpr *Call) {
|
|
|
|
PrintExpr(Call->getCallee());
|
|
|
|
OS << "(";
|
|
|
|
PrintCallArgs(Call);
|
2006-11-05 02:52:07 +08:00
|
|
|
OS << ")";
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
2006-11-05 02:52:07 +08:00
|
|
|
void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
|
2009-01-09 06:45:41 +08:00
|
|
|
// FIXME: Suppress printing implicit bases (like "this")
|
|
|
|
PrintExpr(Node->getBase());
|
2012-11-13 03:12:12 +08:00
|
|
|
|
|
|
|
MemberExpr *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
|
2012-11-13 03:32:32 +08:00
|
|
|
FieldDecl *ParentDecl = ParentMember
|
|
|
|
? dyn_cast<FieldDecl>(ParentMember->getMemberDecl()) : NULL;
|
2012-11-13 03:12:12 +08:00
|
|
|
|
2012-11-13 03:32:32 +08:00
|
|
|
if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion())
|
2012-11-13 03:12:12 +08:00
|
|
|
OS << (Node->isArrow() ? "->" : ".");
|
|
|
|
|
2010-01-12 05:17:32 +08:00
|
|
|
if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
|
|
|
|
if (FD->isAnonymousStructOrUnion())
|
|
|
|
return;
|
2012-11-13 03:12:12 +08:00
|
|
|
|
2009-09-01 07:41:50 +08:00
|
|
|
if (NestedNameSpecifier *Qualifier = Node->getQualifier())
|
|
|
|
Qualifier->print(OS, Policy);
|
2012-01-27 17:46:47 +08:00
|
|
|
if (Node->hasTemplateKeyword())
|
|
|
|
OS << "template ";
|
2010-08-12 06:01:17 +08:00
|
|
|
OS << Node->getMemberNameInfo();
|
2010-08-20 07:49:38 +08:00
|
|
|
if (Node->hasExplicitTemplateArgs())
|
2013-02-22 23:46:01 +08:00
|
|
|
TemplateSpecializationType::PrintTemplateArgumentList(
|
|
|
|
OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
2009-07-25 01:54:45 +08:00
|
|
|
void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
|
|
|
|
PrintExpr(Node->getBase());
|
|
|
|
OS << (Node->isArrow() ? "->isa" : ".isa");
|
|
|
|
}
|
|
|
|
|
2008-04-19 07:10:10 +08:00
|
|
|
void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
|
2007-07-29 07:10:27 +08:00
|
|
|
PrintExpr(Node->getBase());
|
|
|
|
OS << ".";
|
|
|
|
OS << Node->getAccessor().getName();
|
|
|
|
}
|
2008-10-28 23:36:24 +08:00
|
|
|
void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
|
2013-02-22 22:19:01 +08:00
|
|
|
OS << '(';
|
|
|
|
Node->getTypeAsWritten().print(OS, Policy);
|
|
|
|
OS << ')';
|
2006-11-05 02:52:07 +08:00
|
|
|
PrintExpr(Node->getSubExpr());
|
|
|
|
}
|
2007-07-20 05:32:11 +08:00
|
|
|
void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
|
2013-02-22 22:19:01 +08:00
|
|
|
OS << '(';
|
|
|
|
Node->getType().print(OS, Policy);
|
|
|
|
OS << ')';
|
2007-07-20 05:32:11 +08:00
|
|
|
PrintExpr(Node->getInitializer());
|
|
|
|
}
|
2007-07-14 00:58:59 +08:00
|
|
|
void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
|
2007-07-14 07:32:42 +08:00
|
|
|
// No need to print anything, simply forward to the sub expression.
|
|
|
|
PrintExpr(Node->getSubExpr());
|
2007-07-14 00:58:59 +08:00
|
|
|
}
|
2006-11-05 02:52:07 +08:00
|
|
|
void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
|
|
|
|
PrintExpr(Node->getLHS());
|
|
|
|
OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
|
2007-08-25 10:00:02 +08:00
|
|
|
PrintExpr(Node->getRHS());
|
|
|
|
}
|
|
|
|
void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
|
|
|
|
PrintExpr(Node->getLHS());
|
|
|
|
OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
|
2006-11-05 02:52:07 +08:00
|
|
|
PrintExpr(Node->getRHS());
|
|
|
|
}
|
|
|
|
void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
|
|
|
|
PrintExpr(Node->getCond());
|
2011-02-17 18:25:35 +08:00
|
|
|
OS << " ? ";
|
|
|
|
PrintExpr(Node->getLHS());
|
|
|
|
OS << " : ";
|
2006-11-05 02:52:07 +08:00
|
|
|
PrintExpr(Node->getRHS());
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
|
|
|
|
2007-05-28 14:56:27 +08:00
|
|
|
// GNU extensions.
|
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
void
|
|
|
|
StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) {
|
|
|
|
PrintExpr(Node->getCommon());
|
|
|
|
OS << " ?: ";
|
|
|
|
PrintExpr(Node->getFalseExpr());
|
|
|
|
}
|
2007-08-04 01:31:20 +08:00
|
|
|
void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
|
2007-05-28 14:56:27 +08:00
|
|
|
OS << "&&" << Node->getLabel()->getName();
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:58:17 +08:00
|
|
|
void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
|
|
|
|
OS << "(";
|
|
|
|
PrintRawCompoundStmt(E->getSubStmt());
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2007-08-04 05:21:27 +08:00
|
|
|
void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
|
|
|
|
OS << "__builtin_choose_expr(";
|
|
|
|
PrintExpr(Node->getCond());
|
2007-08-04 08:20:15 +08:00
|
|
|
OS << ", ";
|
2007-08-04 05:21:27 +08:00
|
|
|
PrintExpr(Node->getLHS());
|
2007-08-04 08:20:15 +08:00
|
|
|
OS << ", ";
|
2007-08-04 05:21:27 +08:00
|
|
|
PrintExpr(Node->getRHS());
|
|
|
|
OS << ")";
|
|
|
|
}
|
2007-07-25 00:58:17 +08:00
|
|
|
|
2008-11-29 12:51:27 +08:00
|
|
|
void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
|
|
|
|
OS << "__null";
|
|
|
|
}
|
|
|
|
|
2008-05-15 03:38:39 +08:00
|
|
|
void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
|
|
|
|
OS << "__builtin_shufflevector(";
|
|
|
|
for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
|
|
|
|
if (i) OS << ", ";
|
|
|
|
PrintExpr(Node->getExpr(i));
|
|
|
|
}
|
|
|
|
OS << ")";
|
2008-01-18 01:46:27 +08:00
|
|
|
}
|
|
|
|
|
2007-08-31 12:56:16 +08:00
|
|
|
void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
|
2009-05-30 08:56:08 +08:00
|
|
|
if (Node->getSyntacticForm()) {
|
|
|
|
Visit(Node->getSyntacticForm());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-31 12:56:16 +08:00
|
|
|
OS << "{ ";
|
|
|
|
for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
|
|
|
|
if (i) OS << ", ";
|
2009-01-29 05:54:33 +08:00
|
|
|
if (Node->getInit(i))
|
|
|
|
PrintExpr(Node->getInit(i));
|
|
|
|
else
|
|
|
|
OS << "0";
|
2007-08-31 12:56:16 +08:00
|
|
|
}
|
|
|
|
OS << " }";
|
|
|
|
}
|
|
|
|
|
2009-08-11 07:49:36 +08:00
|
|
|
void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
|
|
|
|
OS << "( ";
|
|
|
|
for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
|
|
|
|
if (i) OS << ", ";
|
|
|
|
PrintExpr(Node->getExpr(i));
|
|
|
|
}
|
|
|
|
OS << " )";
|
|
|
|
}
|
|
|
|
|
2009-01-22 08:58:24 +08:00
|
|
|
void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
|
2009-01-29 05:54:33 +08:00
|
|
|
for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(),
|
|
|
|
DEnd = Node->designators_end();
|
|
|
|
D != DEnd; ++D) {
|
|
|
|
if (D->isFieldDesignator()) {
|
|
|
|
if (D->getDotLoc().isInvalid())
|
|
|
|
OS << D->getFieldName()->getName() << ":";
|
|
|
|
else
|
|
|
|
OS << "." << D->getFieldName()->getName();
|
|
|
|
} else {
|
|
|
|
OS << "[";
|
|
|
|
if (D->isArrayDesignator()) {
|
|
|
|
PrintExpr(Node->getArrayIndex(*D));
|
|
|
|
} else {
|
|
|
|
PrintExpr(Node->getArrayRangeStart(*D));
|
|
|
|
OS << " ... ";
|
2009-09-09 23:08:12 +08:00
|
|
|
PrintExpr(Node->getArrayRangeEnd(*D));
|
2009-01-29 05:54:33 +08:00
|
|
|
}
|
|
|
|
OS << "]";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << " = ";
|
|
|
|
PrintExpr(Node->getInit());
|
2009-01-22 08:58:24 +08:00
|
|
|
}
|
|
|
|
|
2009-01-30 01:44:32 +08:00
|
|
|
void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
|
2013-02-22 22:19:01 +08:00
|
|
|
if (Policy.LangOpts.CPlusPlus) {
|
|
|
|
OS << "/*implicit*/";
|
|
|
|
Node->getType().print(OS, Policy);
|
|
|
|
OS << "()";
|
|
|
|
} else {
|
|
|
|
OS << "/*implicit*/(";
|
|
|
|
Node->getType().print(OS, Policy);
|
|
|
|
OS << ')';
|
2009-05-30 08:08:05 +08:00
|
|
|
if (Node->getType()->isRecordType())
|
|
|
|
OS << "{}";
|
|
|
|
else
|
|
|
|
OS << 0;
|
|
|
|
}
|
2009-01-30 01:44:32 +08:00
|
|
|
}
|
|
|
|
|
2007-10-16 04:28:48 +08:00
|
|
|
void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
|
2009-05-30 12:20:30 +08:00
|
|
|
OS << "__builtin_va_arg(";
|
2007-10-16 04:28:48 +08:00
|
|
|
PrintExpr(Node->getSubExpr());
|
|
|
|
OS << ", ";
|
2013-02-22 22:19:01 +08:00
|
|
|
Node->getType().print(OS, Policy);
|
2007-10-16 04:28:48 +08:00
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:30 +08:00
|
|
|
void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) {
|
|
|
|
PrintExpr(Node->getSyntacticForm());
|
|
|
|
}
|
|
|
|
|
2011-10-11 10:20:01 +08:00
|
|
|
void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
|
2011-10-12 04:00:47 +08:00
|
|
|
const char *Name = 0;
|
2011-10-11 10:20:01 +08:00
|
|
|
switch (Node->getOp()) {
|
2012-04-12 13:08:17 +08:00
|
|
|
#define BUILTIN(ID, TYPE, ATTRS)
|
|
|
|
#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
|
|
|
|
case AtomicExpr::AO ## ID: \
|
|
|
|
Name = #ID "("; \
|
|
|
|
break;
|
|
|
|
#include "clang/Basic/Builtins.def"
|
2011-10-11 10:20:01 +08:00
|
|
|
}
|
|
|
|
OS << Name;
|
2012-04-12 13:08:17 +08:00
|
|
|
|
|
|
|
// AtomicExpr stores its subexpressions in a permuted order.
|
2011-10-11 10:20:01 +08:00
|
|
|
PrintExpr(Node->getPtr());
|
|
|
|
OS << ", ";
|
2012-04-12 13:08:17 +08:00
|
|
|
if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
|
|
|
|
Node->getOp() != AtomicExpr::AO__atomic_load_n) {
|
2011-10-11 10:20:01 +08:00
|
|
|
PrintExpr(Node->getVal1());
|
|
|
|
OS << ", ";
|
|
|
|
}
|
2012-04-12 13:08:17 +08:00
|
|
|
if (Node->getOp() == AtomicExpr::AO__atomic_exchange ||
|
|
|
|
Node->isCmpXChg()) {
|
2011-10-11 10:20:01 +08:00
|
|
|
PrintExpr(Node->getVal2());
|
|
|
|
OS << ", ";
|
|
|
|
}
|
2012-04-12 13:08:17 +08:00
|
|
|
if (Node->getOp() == AtomicExpr::AO__atomic_compare_exchange ||
|
|
|
|
Node->getOp() == AtomicExpr::AO__atomic_compare_exchange_n) {
|
|
|
|
PrintExpr(Node->getWeak());
|
|
|
|
OS << ", ";
|
|
|
|
}
|
|
|
|
if (Node->getOp() != AtomicExpr::AO__c11_atomic_init)
|
2012-01-17 01:27:18 +08:00
|
|
|
PrintExpr(Node->getOrder());
|
2011-10-11 10:20:01 +08:00
|
|
|
if (Node->isCmpXChg()) {
|
|
|
|
OS << ", ";
|
|
|
|
PrintExpr(Node->getOrderFail());
|
|
|
|
}
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2007-05-28 14:56:27 +08:00
|
|
|
// C++
|
2008-11-15 00:09:21 +08:00
|
|
|
void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
|
|
|
|
const char *OpStrings[NUM_OVERLOADED_OPERATORS] = {
|
|
|
|
"",
|
|
|
|
#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
|
|
|
|
Spelling,
|
|
|
|
#include "clang/Basic/OperatorKinds.def"
|
|
|
|
};
|
|
|
|
|
|
|
|
OverloadedOperatorKind Kind = Node->getOperator();
|
|
|
|
if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
|
|
|
|
if (Node->getNumArgs() == 1) {
|
|
|
|
OS << OpStrings[Kind] << ' ';
|
|
|
|
PrintExpr(Node->getArg(0));
|
|
|
|
} else {
|
|
|
|
PrintExpr(Node->getArg(0));
|
|
|
|
OS << ' ' << OpStrings[Kind];
|
|
|
|
}
|
2012-10-13 06:45:14 +08:00
|
|
|
} else if (Kind == OO_Arrow) {
|
|
|
|
PrintExpr(Node->getArg(0));
|
2008-11-15 00:09:21 +08:00
|
|
|
} else if (Kind == OO_Call) {
|
|
|
|
PrintExpr(Node->getArg(0));
|
|
|
|
OS << '(';
|
|
|
|
for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
|
|
|
|
if (ArgIdx > 1)
|
|
|
|
OS << ", ";
|
|
|
|
if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
|
|
|
|
PrintExpr(Node->getArg(ArgIdx));
|
|
|
|
}
|
|
|
|
OS << ')';
|
|
|
|
} else if (Kind == OO_Subscript) {
|
|
|
|
PrintExpr(Node->getArg(0));
|
|
|
|
OS << '[';
|
|
|
|
PrintExpr(Node->getArg(1));
|
|
|
|
OS << ']';
|
|
|
|
} else if (Node->getNumArgs() == 1) {
|
|
|
|
OS << OpStrings[Kind] << ' ';
|
|
|
|
PrintExpr(Node->getArg(0));
|
|
|
|
} else if (Node->getNumArgs() == 2) {
|
|
|
|
PrintExpr(Node->getArg(0));
|
|
|
|
OS << ' ' << OpStrings[Kind] << ' ';
|
|
|
|
PrintExpr(Node->getArg(1));
|
|
|
|
} else {
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("unknown overloaded operator");
|
2008-11-15 00:09:21 +08:00
|
|
|
}
|
|
|
|
}
|
2007-05-28 14:56:27 +08:00
|
|
|
|
2008-12-22 13:46:06 +08:00
|
|
|
void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
|
|
|
|
VisitCallExpr(cast<CallExpr>(Node));
|
|
|
|
}
|
|
|
|
|
2011-02-10 05:07:24 +08:00
|
|
|
void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
|
|
|
|
PrintExpr(Node->getCallee());
|
|
|
|
OS << "<<<";
|
|
|
|
PrintCallArgs(Node->getConfig());
|
|
|
|
OS << ">>>(";
|
|
|
|
PrintCallArgs(Node);
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2008-10-28 03:41:14 +08:00
|
|
|
void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
|
|
|
|
OS << Node->getCastName() << '<';
|
2013-02-22 22:19:01 +08:00
|
|
|
Node->getTypeAsWritten().print(OS, Policy);
|
|
|
|
OS << ">(";
|
2007-05-28 14:56:27 +08:00
|
|
|
PrintExpr(Node->getSubExpr());
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2008-10-28 03:41:14 +08:00
|
|
|
void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
|
|
|
|
VisitCXXNamedCastExpr(Node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
|
|
|
|
VisitCXXNamedCastExpr(Node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
|
|
|
|
VisitCXXNamedCastExpr(Node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
|
|
|
|
VisitCXXNamedCastExpr(Node);
|
|
|
|
}
|
|
|
|
|
2008-11-11 19:37:55 +08:00
|
|
|
void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
|
|
|
|
OS << "typeid(";
|
|
|
|
if (Node->isTypeOperand()) {
|
2013-02-22 22:19:01 +08:00
|
|
|
Node->getTypeOperand().print(OS, Policy);
|
2008-11-11 19:37:55 +08:00
|
|
|
} else {
|
|
|
|
PrintExpr(Node->getExprOperand());
|
|
|
|
}
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:20:18 +08:00
|
|
|
void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
|
|
|
|
OS << "__uuidof(";
|
|
|
|
if (Node->isTypeOperand()) {
|
2013-02-22 22:19:01 +08:00
|
|
|
Node->getTypeOperand().print(OS, Policy);
|
2010-09-08 20:20:18 +08:00
|
|
|
} else {
|
|
|
|
PrintExpr(Node->getExprOperand());
|
|
|
|
}
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2012-03-07 16:35:16 +08:00
|
|
|
void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
|
|
|
|
switch (Node->getLiteralOperatorKind()) {
|
|
|
|
case UserDefinedLiteral::LOK_Raw:
|
2012-03-09 18:10:02 +08:00
|
|
|
OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString();
|
2012-03-07 16:35:16 +08:00
|
|
|
break;
|
|
|
|
case UserDefinedLiteral::LOK_Template: {
|
2012-03-09 18:10:02 +08:00
|
|
|
DeclRefExpr *DRE = cast<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts());
|
|
|
|
const TemplateArgumentList *Args =
|
|
|
|
cast<FunctionDecl>(DRE->getDecl())->getTemplateSpecializationArgs();
|
|
|
|
assert(Args);
|
|
|
|
const TemplateArgument &Pack = Args->get(0);
|
|
|
|
for (TemplateArgument::pack_iterator I = Pack.pack_begin(),
|
|
|
|
E = Pack.pack_end(); I != E; ++I) {
|
2012-06-07 23:09:51 +08:00
|
|
|
char C = (char)I->getAsIntegral().getZExtValue();
|
2012-03-07 16:35:16 +08:00
|
|
|
OS << C;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-03-08 17:02:38 +08:00
|
|
|
case UserDefinedLiteral::LOK_Integer: {
|
|
|
|
// Print integer literal without suffix.
|
|
|
|
IntegerLiteral *Int = cast<IntegerLiteral>(Node->getCookedLiteral());
|
|
|
|
OS << Int->getValue().toString(10, /*isSigned*/false);
|
|
|
|
break;
|
|
|
|
}
|
2012-09-20 22:07:17 +08:00
|
|
|
case UserDefinedLiteral::LOK_Floating: {
|
|
|
|
// Print floating literal without suffix.
|
|
|
|
FloatingLiteral *Float = cast<FloatingLiteral>(Node->getCookedLiteral());
|
|
|
|
PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false);
|
|
|
|
break;
|
|
|
|
}
|
2012-03-07 16:35:16 +08:00
|
|
|
case UserDefinedLiteral::LOK_String:
|
|
|
|
case UserDefinedLiteral::LOK_Character:
|
|
|
|
PrintExpr(Node->getCookedLiteral());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
OS << Node->getUDSuffix()->getName();
|
|
|
|
}
|
|
|
|
|
2007-05-28 14:56:27 +08:00
|
|
|
void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
|
|
|
|
OS << (Node->getValue() ? "true" : "false");
|
|
|
|
}
|
|
|
|
|
2009-05-11 02:38:11 +08:00
|
|
|
void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
|
|
|
|
OS << "nullptr";
|
|
|
|
}
|
|
|
|
|
2008-11-04 22:32:21 +08:00
|
|
|
void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
|
|
|
|
OS << "this";
|
|
|
|
}
|
|
|
|
|
2008-02-26 08:51:44 +08:00
|
|
|
void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
|
|
|
|
if (Node->getSubExpr() == 0)
|
|
|
|
OS << "throw";
|
|
|
|
else {
|
|
|
|
OS << "throw ";
|
|
|
|
PrintExpr(Node->getSubExpr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-08 12:40:51 +08:00
|
|
|
void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
|
|
|
|
// Nothing to print: we picked up the default argument
|
|
|
|
}
|
|
|
|
|
2008-08-22 23:38:55 +08:00
|
|
|
void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
|
2013-02-22 22:19:01 +08:00
|
|
|
Node->getType().print(OS, Policy);
|
2008-08-22 23:38:55 +08:00
|
|
|
OS << "(";
|
|
|
|
PrintExpr(Node->getSubExpr());
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2009-05-31 04:03:25 +08:00
|
|
|
void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
|
2010-01-29 10:39:32 +08:00
|
|
|
PrintExpr(Node->getSubExpr());
|
|
|
|
}
|
|
|
|
|
2009-01-17 02:33:17 +08:00
|
|
|
void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
|
2013-02-22 22:19:01 +08:00
|
|
|
Node->getType().print(OS, Policy);
|
2009-01-17 02:33:17 +08:00
|
|
|
OS << "(";
|
|
|
|
for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
|
2009-09-09 23:08:12 +08:00
|
|
|
ArgEnd = Node->arg_end();
|
2009-01-17 02:33:17 +08:00
|
|
|
Arg != ArgEnd; ++Arg) {
|
|
|
|
if (Arg != Node->arg_begin())
|
|
|
|
OS << ", ";
|
|
|
|
PrintExpr(*Arg);
|
|
|
|
}
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2012-02-07 18:09:13 +08:00
|
|
|
void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
|
|
|
|
OS << '[';
|
|
|
|
bool NeedComma = false;
|
|
|
|
switch (Node->getCaptureDefault()) {
|
|
|
|
case LCD_None:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LCD_ByCopy:
|
|
|
|
OS << '=';
|
|
|
|
NeedComma = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LCD_ByRef:
|
|
|
|
OS << '&';
|
|
|
|
NeedComma = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (LambdaExpr::capture_iterator C = Node->explicit_capture_begin(),
|
|
|
|
CEnd = Node->explicit_capture_end();
|
|
|
|
C != CEnd;
|
|
|
|
++C) {
|
|
|
|
if (NeedComma)
|
|
|
|
OS << ", ";
|
|
|
|
NeedComma = true;
|
|
|
|
|
|
|
|
switch (C->getCaptureKind()) {
|
|
|
|
case LCK_This:
|
|
|
|
OS << "this";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LCK_ByRef:
|
|
|
|
if (Node->getCaptureDefault() != LCD_ByRef)
|
|
|
|
OS << '&';
|
|
|
|
OS << C->getCapturedVar()->getName();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LCK_ByCopy:
|
|
|
|
if (Node->getCaptureDefault() != LCD_ByCopy)
|
|
|
|
OS << '=';
|
|
|
|
OS << C->getCapturedVar()->getName();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OS << ']';
|
|
|
|
|
|
|
|
if (Node->hasExplicitParameters()) {
|
|
|
|
OS << " (";
|
|
|
|
CXXMethodDecl *Method = Node->getCallOperator();
|
|
|
|
NeedComma = false;
|
|
|
|
for (CXXMethodDecl::param_iterator P = Method->param_begin(),
|
|
|
|
PEnd = Method->param_end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
if (NeedComma) {
|
|
|
|
OS << ", ";
|
|
|
|
} else {
|
|
|
|
NeedComma = true;
|
|
|
|
}
|
|
|
|
std::string ParamStr = (*P)->getNameAsString();
|
2013-02-22 22:19:01 +08:00
|
|
|
(*P)->getOriginalType().print(OS, Policy, ParamStr);
|
2012-02-07 18:09:13 +08:00
|
|
|
}
|
|
|
|
if (Method->isVariadic()) {
|
|
|
|
if (NeedComma)
|
|
|
|
OS << ", ";
|
|
|
|
OS << "...";
|
|
|
|
}
|
|
|
|
OS << ')';
|
|
|
|
|
|
|
|
if (Node->isMutable())
|
|
|
|
OS << " mutable";
|
|
|
|
|
|
|
|
const FunctionProtoType *Proto
|
|
|
|
= Method->getType()->getAs<FunctionProtoType>();
|
2013-02-22 23:46:01 +08:00
|
|
|
Proto->printExceptionSpecification(OS, Policy);
|
2012-02-07 18:09:13 +08:00
|
|
|
|
2012-12-21 03:22:21 +08:00
|
|
|
// FIXME: Attributes
|
2012-02-07 18:09:13 +08:00
|
|
|
|
2012-02-14 06:00:16 +08:00
|
|
|
// Print the trailing return type if it was specified in the source.
|
2013-02-22 22:19:01 +08:00
|
|
|
if (Node->hasExplicitResultType()) {
|
|
|
|
OS << " -> ";
|
|
|
|
Proto->getResultType().print(OS, Policy);
|
|
|
|
}
|
2012-02-07 18:09:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Print the body.
|
|
|
|
CompoundStmt *Body = Node->getBody();
|
|
|
|
OS << ' ';
|
|
|
|
PrintStmt(Body);
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:14:04 +08:00
|
|
|
void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
|
2010-09-08 08:15:04 +08:00
|
|
|
if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
|
2013-02-22 22:19:01 +08:00
|
|
|
TSInfo->getType().print(OS, Policy);
|
2010-09-08 08:15:04 +08:00
|
|
|
else
|
2013-02-22 22:19:01 +08:00
|
|
|
Node->getType().print(OS, Policy);
|
|
|
|
OS << "()";
|
2008-08-22 23:38:55 +08:00
|
|
|
}
|
|
|
|
|
2008-11-22 03:14:01 +08:00
|
|
|
void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
|
|
|
|
if (E->isGlobalNew())
|
|
|
|
OS << "::";
|
|
|
|
OS << "new ";
|
|
|
|
unsigned NumPlace = E->getNumPlacementArgs();
|
2012-10-19 04:54:37 +08:00
|
|
|
if (NumPlace > 0 && !isa<CXXDefaultArgExpr>(E->getPlacementArg(0))) {
|
2008-11-22 03:14:01 +08:00
|
|
|
OS << "(";
|
|
|
|
PrintExpr(E->getPlacementArg(0));
|
|
|
|
for (unsigned i = 1; i < NumPlace; ++i) {
|
2012-10-19 04:54:37 +08:00
|
|
|
if (isa<CXXDefaultArgExpr>(E->getPlacementArg(i)))
|
|
|
|
break;
|
2008-11-22 03:14:01 +08:00
|
|
|
OS << ", ";
|
|
|
|
PrintExpr(E->getPlacementArg(i));
|
|
|
|
}
|
|
|
|
OS << ") ";
|
|
|
|
}
|
|
|
|
if (E->isParenTypeId())
|
|
|
|
OS << "(";
|
2008-12-03 06:08:59 +08:00
|
|
|
std::string TypeS;
|
|
|
|
if (Expr *Size = E->getArraySize()) {
|
|
|
|
llvm::raw_string_ostream s(TypeS);
|
2013-02-22 22:19:01 +08:00
|
|
|
s << '[';
|
2012-08-16 11:56:14 +08:00
|
|
|
Size->printPretty(s, Helper, Policy);
|
2013-02-22 22:19:01 +08:00
|
|
|
s << ']';
|
2008-12-03 06:08:59 +08:00
|
|
|
}
|
2013-02-22 22:19:01 +08:00
|
|
|
E->getAllocatedType().print(OS, Policy, TypeS);
|
2008-11-22 03:14:01 +08:00
|
|
|
if (E->isParenTypeId())
|
|
|
|
OS << ")";
|
|
|
|
|
2012-02-16 20:22:20 +08:00
|
|
|
CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle();
|
|
|
|
if (InitStyle) {
|
|
|
|
if (InitStyle == CXXNewExpr::CallInit)
|
|
|
|
OS << "(";
|
|
|
|
PrintExpr(E->getInitializer());
|
|
|
|
if (InitStyle == CXXNewExpr::CallInit)
|
|
|
|
OS << ")";
|
2008-11-22 03:14:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
|
|
|
|
if (E->isGlobalDelete())
|
|
|
|
OS << "::";
|
|
|
|
OS << "delete ";
|
|
|
|
if (E->isArrayForm())
|
|
|
|
OS << "[] ";
|
|
|
|
PrintExpr(E->getArgument());
|
|
|
|
}
|
|
|
|
|
2009-09-05 01:36:40 +08:00
|
|
|
void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
|
|
|
|
PrintExpr(E->getBase());
|
|
|
|
if (E->isArrow())
|
|
|
|
OS << "->";
|
|
|
|
else
|
|
|
|
OS << '.';
|
|
|
|
if (E->getQualifier())
|
|
|
|
E->getQualifier()->print(OS, Policy);
|
2012-10-24 04:26:57 +08:00
|
|
|
OS << "~";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-02-25 09:56:36 +08:00
|
|
|
if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
|
|
|
|
OS << II->getName();
|
|
|
|
else
|
2013-02-22 22:19:01 +08:00
|
|
|
E->getDestroyedType().print(OS, Policy);
|
2009-09-05 01:36:40 +08:00
|
|
|
}
|
|
|
|
|
2009-04-23 10:32:43 +08:00
|
|
|
void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
|
2012-12-19 09:39:02 +08:00
|
|
|
if (E->isListInitialization())
|
|
|
|
OS << "{ ";
|
|
|
|
|
2011-01-25 01:25:03 +08:00
|
|
|
for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
|
|
|
|
if (isa<CXXDefaultArgExpr>(E->getArg(i))) {
|
|
|
|
// Don't print any defaulted arguments
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i) OS << ", ";
|
|
|
|
PrintExpr(E->getArg(i));
|
2010-01-14 05:41:11 +08:00
|
|
|
}
|
2012-12-19 09:39:02 +08:00
|
|
|
|
|
|
|
if (E->isListInitialization())
|
|
|
|
OS << " }";
|
2009-04-23 10:32:43 +08:00
|
|
|
}
|
|
|
|
|
2010-12-06 16:20:24 +08:00
|
|
|
void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
|
2009-04-25 06:47:04 +08:00
|
|
|
// Just forward to the sub expression.
|
|
|
|
PrintExpr(E->getSubExpr());
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void
|
Introduce a new expression type, CXXUnresolvedConstructExpr, to
describe the construction of a value of a given type using function
syntax, e.g.,
T(a1, a2, ..., aN)
when the type or any of its arguments are type-dependent. In this
case, we don't know what kind of type-construction this will be: it
might construct a temporary of type 'T' (which might be a class or
non-class type) or might perform a conversion to type 'T'. Also,
implement printing of and template instantiation for this new
expression type. Due to the change in Sema::ActOnCXXTypeConstructExpr,
our existing tests cover template instantiation of this new expression
node.
llvm-svn: 72176
2009-05-21 02:46:25 +08:00
|
|
|
StmtPrinter::VisitCXXUnresolvedConstructExpr(
|
|
|
|
CXXUnresolvedConstructExpr *Node) {
|
2013-02-22 22:19:01 +08:00
|
|
|
Node->getTypeAsWritten().print(OS, Policy);
|
Introduce a new expression type, CXXUnresolvedConstructExpr, to
describe the construction of a value of a given type using function
syntax, e.g.,
T(a1, a2, ..., aN)
when the type or any of its arguments are type-dependent. In this
case, we don't know what kind of type-construction this will be: it
might construct a temporary of type 'T' (which might be a class or
non-class type) or might perform a conversion to type 'T'. Also,
implement printing of and template instantiation for this new
expression type. Due to the change in Sema::ActOnCXXTypeConstructExpr,
our existing tests cover template instantiation of this new expression
node.
llvm-svn: 72176
2009-05-21 02:46:25 +08:00
|
|
|
OS << "(";
|
|
|
|
for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
|
2009-09-09 23:08:12 +08:00
|
|
|
ArgEnd = Node->arg_end();
|
Introduce a new expression type, CXXUnresolvedConstructExpr, to
describe the construction of a value of a given type using function
syntax, e.g.,
T(a1, a2, ..., aN)
when the type or any of its arguments are type-dependent. In this
case, we don't know what kind of type-construction this will be: it
might construct a temporary of type 'T' (which might be a class or
non-class type) or might perform a conversion to type 'T'. Also,
implement printing of and template instantiation for this new
expression type. Due to the change in Sema::ActOnCXXTypeConstructExpr,
our existing tests cover template instantiation of this new expression
node.
llvm-svn: 72176
2009-05-21 02:46:25 +08:00
|
|
|
Arg != ArgEnd; ++Arg) {
|
|
|
|
if (Arg != Node->arg_begin())
|
|
|
|
OS << ", ";
|
|
|
|
PrintExpr(*Arg);
|
|
|
|
}
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2009-11-20 06:55:06 +08:00
|
|
|
void StmtPrinter::VisitCXXDependentScopeMemberExpr(
|
|
|
|
CXXDependentScopeMemberExpr *Node) {
|
2009-12-02 06:10:20 +08:00
|
|
|
if (!Node->isImplicitAccess()) {
|
|
|
|
PrintExpr(Node->getBase());
|
|
|
|
OS << (Node->isArrow() ? "->" : ".");
|
|
|
|
}
|
2009-09-04 00:14:30 +08:00
|
|
|
if (NestedNameSpecifier *Qualifier = Node->getQualifier())
|
|
|
|
Qualifier->print(OS, Policy);
|
2012-01-27 17:46:47 +08:00
|
|
|
if (Node->hasTemplateKeyword())
|
2009-09-09 08:23:06 +08:00
|
|
|
OS << "template ";
|
2010-08-12 06:01:17 +08:00
|
|
|
OS << Node->getMemberNameInfo();
|
2013-02-22 23:46:01 +08:00
|
|
|
if (Node->hasExplicitTemplateArgs())
|
|
|
|
TemplateSpecializationType::PrintTemplateArgumentList(
|
|
|
|
OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
|
2009-05-23 05:13:27 +08:00
|
|
|
}
|
|
|
|
|
2009-12-01 06:42:35 +08:00
|
|
|
void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
|
2009-12-02 06:10:20 +08:00
|
|
|
if (!Node->isImplicitAccess()) {
|
|
|
|
PrintExpr(Node->getBase());
|
|
|
|
OS << (Node->isArrow() ? "->" : ".");
|
|
|
|
}
|
2009-12-01 06:42:35 +08:00
|
|
|
if (NestedNameSpecifier *Qualifier = Node->getQualifier())
|
|
|
|
Qualifier->print(OS, Policy);
|
2012-01-27 17:46:47 +08:00
|
|
|
if (Node->hasTemplateKeyword())
|
|
|
|
OS << "template ";
|
2010-08-12 06:01:17 +08:00
|
|
|
OS << Node->getMemberNameInfo();
|
2013-02-22 23:46:01 +08:00
|
|
|
if (Node->hasExplicitTemplateArgs())
|
|
|
|
TemplateSpecializationType::PrintTemplateArgumentList(
|
|
|
|
OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
|
2009-12-01 06:42:35 +08:00
|
|
|
}
|
|
|
|
|
2009-01-06 04:52:13 +08:00
|
|
|
static const char *getTypeTraitName(UnaryTypeTrait UTT) {
|
|
|
|
switch (UTT) {
|
|
|
|
case UTT_HasNothrowAssign: return "__has_nothrow_assign";
|
2013-03-27 09:34:16 +08:00
|
|
|
case UTT_HasNothrowMoveAssign: return "__has_nothrow_move_assign";
|
2009-01-06 04:52:13 +08:00
|
|
|
case UTT_HasNothrowConstructor: return "__has_nothrow_constructor";
|
2011-04-28 07:09:49 +08:00
|
|
|
case UTT_HasNothrowCopy: return "__has_nothrow_copy";
|
2009-01-06 04:52:13 +08:00
|
|
|
case UTT_HasTrivialAssign: return "__has_trivial_assign";
|
2013-03-27 09:34:16 +08:00
|
|
|
case UTT_HasTrivialMoveAssign: return "__has_trivial_move_assign";
|
|
|
|
case UTT_HasTrivialMoveConstructor: return "__has_trivial_move_constructor";
|
2011-05-10 02:22:59 +08:00
|
|
|
case UTT_HasTrivialDefaultConstructor: return "__has_trivial_constructor";
|
2011-04-28 07:09:49 +08:00
|
|
|
case UTT_HasTrivialCopy: return "__has_trivial_copy";
|
2009-01-06 04:52:13 +08:00
|
|
|
case UTT_HasTrivialDestructor: return "__has_trivial_destructor";
|
|
|
|
case UTT_HasVirtualDestructor: return "__has_virtual_destructor";
|
|
|
|
case UTT_IsAbstract: return "__is_abstract";
|
2011-04-28 07:09:49 +08:00
|
|
|
case UTT_IsArithmetic: return "__is_arithmetic";
|
|
|
|
case UTT_IsArray: return "__is_array";
|
2009-01-06 04:52:13 +08:00
|
|
|
case UTT_IsClass: return "__is_class";
|
2011-04-28 07:09:49 +08:00
|
|
|
case UTT_IsCompleteType: return "__is_complete_type";
|
|
|
|
case UTT_IsCompound: return "__is_compound";
|
|
|
|
case UTT_IsConst: return "__is_const";
|
2009-01-06 04:52:13 +08:00
|
|
|
case UTT_IsEmpty: return "__is_empty";
|
|
|
|
case UTT_IsEnum: return "__is_enum";
|
2011-12-04 02:14:24 +08:00
|
|
|
case UTT_IsFinal: return "__is_final";
|
2011-04-28 07:09:49 +08:00
|
|
|
case UTT_IsFloatingPoint: return "__is_floating_point";
|
|
|
|
case UTT_IsFunction: return "__is_function";
|
|
|
|
case UTT_IsFundamental: return "__is_fundamental";
|
|
|
|
case UTT_IsIntegral: return "__is_integral";
|
2012-09-25 15:32:49 +08:00
|
|
|
case UTT_IsInterfaceClass: return "__is_interface_class";
|
2011-05-01 15:23:20 +08:00
|
|
|
case UTT_IsLiteral: return "__is_literal";
|
2011-04-28 07:09:49 +08:00
|
|
|
case UTT_IsLvalueReference: return "__is_lvalue_reference";
|
|
|
|
case UTT_IsMemberFunctionPointer: return "__is_member_function_pointer";
|
|
|
|
case UTT_IsMemberObjectPointer: return "__is_member_object_pointer";
|
|
|
|
case UTT_IsMemberPointer: return "__is_member_pointer";
|
|
|
|
case UTT_IsObject: return "__is_object";
|
2009-01-06 04:52:13 +08:00
|
|
|
case UTT_IsPOD: return "__is_pod";
|
2011-04-28 07:09:49 +08:00
|
|
|
case UTT_IsPointer: return "__is_pointer";
|
2009-01-06 04:52:13 +08:00
|
|
|
case UTT_IsPolymorphic: return "__is_polymorphic";
|
2011-04-28 07:09:49 +08:00
|
|
|
case UTT_IsReference: return "__is_reference";
|
|
|
|
case UTT_IsRvalueReference: return "__is_rvalue_reference";
|
|
|
|
case UTT_IsScalar: return "__is_scalar";
|
|
|
|
case UTT_IsSigned: return "__is_signed";
|
|
|
|
case UTT_IsStandardLayout: return "__is_standard_layout";
|
|
|
|
case UTT_IsTrivial: return "__is_trivial";
|
2011-05-13 08:31:07 +08:00
|
|
|
case UTT_IsTriviallyCopyable: return "__is_trivially_copyable";
|
2009-01-06 04:52:13 +08:00
|
|
|
case UTT_IsUnion: return "__is_union";
|
2011-04-28 07:09:49 +08:00
|
|
|
case UTT_IsUnsigned: return "__is_unsigned";
|
|
|
|
case UTT_IsVoid: return "__is_void";
|
|
|
|
case UTT_IsVolatile: return "__is_volatile";
|
2009-01-06 04:52:13 +08:00
|
|
|
}
|
2011-05-01 15:23:20 +08:00
|
|
|
llvm_unreachable("Type trait not covered by switch statement");
|
2010-12-07 08:08:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *getTypeTraitName(BinaryTypeTrait BTT) {
|
|
|
|
switch (BTT) {
|
2012-02-23 15:33:15 +08:00
|
|
|
case BTT_IsBaseOf: return "__is_base_of";
|
|
|
|
case BTT_IsConvertible: return "__is_convertible";
|
|
|
|
case BTT_IsSame: return "__is_same";
|
|
|
|
case BTT_TypeCompatible: return "__builtin_types_compatible_p";
|
|
|
|
case BTT_IsConvertibleTo: return "__is_convertible_to";
|
|
|
|
case BTT_IsTriviallyAssignable: return "__is_trivially_assignable";
|
2010-12-07 08:08:36 +08:00
|
|
|
}
|
2011-05-01 15:23:23 +08:00
|
|
|
llvm_unreachable("Binary type trait not covered by switch");
|
2009-01-06 04:52:13 +08:00
|
|
|
}
|
|
|
|
|
2012-02-24 15:38:34 +08:00
|
|
|
static const char *getTypeTraitName(TypeTrait TT) {
|
|
|
|
switch (TT) {
|
|
|
|
case clang::TT_IsTriviallyConstructible:return "__is_trivially_constructible";
|
|
|
|
}
|
|
|
|
llvm_unreachable("Type trait not covered by switch");
|
|
|
|
}
|
|
|
|
|
2011-04-28 08:16:57 +08:00
|
|
|
static const char *getTypeTraitName(ArrayTypeTrait ATT) {
|
|
|
|
switch (ATT) {
|
|
|
|
case ATT_ArrayRank: return "__array_rank";
|
|
|
|
case ATT_ArrayExtent: return "__array_extent";
|
|
|
|
}
|
2011-05-01 15:23:23 +08:00
|
|
|
llvm_unreachable("Array type trait not covered by switch");
|
2011-04-28 08:16:57 +08:00
|
|
|
}
|
|
|
|
|
2011-04-25 14:54:41 +08:00
|
|
|
static const char *getExpressionTraitName(ExpressionTrait ET) {
|
|
|
|
switch (ET) {
|
|
|
|
case ET_IsLValueExpr: return "__is_lvalue_expr";
|
|
|
|
case ET_IsRValueExpr: return "__is_rvalue_expr";
|
|
|
|
}
|
2011-05-01 15:23:23 +08:00
|
|
|
llvm_unreachable("Expression type trait not covered by switch");
|
2011-04-25 14:54:41 +08:00
|
|
|
}
|
|
|
|
|
2009-01-06 04:52:13 +08:00
|
|
|
void StmtPrinter::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
|
2013-02-22 22:19:01 +08:00
|
|
|
OS << getTypeTraitName(E->getTrait()) << '(';
|
|
|
|
E->getQueriedType().print(OS, Policy);
|
|
|
|
OS << ')';
|
2009-01-06 04:52:13 +08:00
|
|
|
}
|
|
|
|
|
2010-12-07 08:08:36 +08:00
|
|
|
void StmtPrinter::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
|
2013-02-22 22:19:01 +08:00
|
|
|
OS << getTypeTraitName(E->getTrait()) << '(';
|
|
|
|
E->getLhsType().print(OS, Policy);
|
|
|
|
OS << ',';
|
|
|
|
E->getRhsType().print(OS, Policy);
|
|
|
|
OS << ')';
|
2010-12-07 08:08:36 +08:00
|
|
|
}
|
|
|
|
|
2012-02-24 15:38:34 +08:00
|
|
|
void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) {
|
|
|
|
OS << getTypeTraitName(E->getTrait()) << "(";
|
|
|
|
for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
|
|
|
|
if (I > 0)
|
|
|
|
OS << ", ";
|
2013-02-22 22:19:01 +08:00
|
|
|
E->getArg(I)->getType().print(OS, Policy);
|
2012-02-24 15:38:34 +08:00
|
|
|
}
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2011-04-28 08:16:57 +08:00
|
|
|
void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
|
2013-02-22 22:19:01 +08:00
|
|
|
OS << getTypeTraitName(E->getTrait()) << '(';
|
|
|
|
E->getQueriedType().print(OS, Policy);
|
|
|
|
OS << ')';
|
2011-04-28 08:16:57 +08:00
|
|
|
}
|
|
|
|
|
2011-04-25 14:54:41 +08:00
|
|
|
void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
|
2013-02-22 22:19:01 +08:00
|
|
|
OS << getExpressionTraitName(E->getTrait()) << '(';
|
|
|
|
PrintExpr(E->getQueriedExpression());
|
|
|
|
OS << ')';
|
2011-04-25 14:54:41 +08:00
|
|
|
}
|
|
|
|
|
2010-09-11 04:55:43 +08:00
|
|
|
void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
|
|
|
|
OS << "noexcept(";
|
|
|
|
PrintExpr(E->getOperand());
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2011-01-05 01:33:58 +08:00
|
|
|
void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
|
2011-01-04 01:17:50 +08:00
|
|
|
PrintExpr(E->getPattern());
|
|
|
|
OS << "...";
|
|
|
|
}
|
|
|
|
|
2011-01-05 01:33:58 +08:00
|
|
|
void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
|
2012-02-07 19:57:57 +08:00
|
|
|
OS << "sizeof...(" << *E->getPack() << ")";
|
2011-01-05 01:33:58 +08:00
|
|
|
}
|
|
|
|
|
2011-01-15 09:15:58 +08:00
|
|
|
void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
|
|
|
|
SubstNonTypeTemplateParmPackExpr *Node) {
|
2012-02-07 19:57:57 +08:00
|
|
|
OS << *Node->getParameterPack();
|
2011-01-15 09:15:58 +08:00
|
|
|
}
|
|
|
|
|
2011-07-15 13:09:51 +08:00
|
|
|
void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(
|
|
|
|
SubstNonTypeTemplateParmExpr *Node) {
|
|
|
|
Visit(Node->getReplacement());
|
|
|
|
}
|
|
|
|
|
2012-09-12 08:56:43 +08:00
|
|
|
void StmtPrinter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
|
|
|
|
OS << *E->getParameterPack();
|
|
|
|
}
|
|
|
|
|
2011-06-22 01:03:29 +08:00
|
|
|
void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){
|
|
|
|
PrintExpr(Node->GetTemporaryExpr());
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
// Obj-C
|
2007-08-22 01:43:55 +08:00
|
|
|
|
|
|
|
void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
|
|
|
|
OS << "@";
|
|
|
|
VisitStringLiteral(Node->getString());
|
|
|
|
}
|
2007-05-28 14:56:27 +08:00
|
|
|
|
2012-04-19 08:25:12 +08:00
|
|
|
void StmtPrinter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
|
2012-03-07 04:05:56 +08:00
|
|
|
OS << "@";
|
2012-04-19 08:25:12 +08:00
|
|
|
Visit(E->getSubExpr());
|
2012-03-07 04:05:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
|
|
|
|
OS << "@[ ";
|
|
|
|
StmtRange ch = E->children();
|
|
|
|
if (ch.first != ch.second) {
|
|
|
|
while (1) {
|
|
|
|
Visit(*ch.first);
|
|
|
|
++ch.first;
|
|
|
|
if (ch.first == ch.second) break;
|
|
|
|
OS << ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OS << " ]";
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtPrinter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
|
|
|
|
OS << "@{ ";
|
|
|
|
for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
|
|
|
|
if (I > 0)
|
|
|
|
OS << ", ";
|
|
|
|
|
|
|
|
ObjCDictionaryElement Element = E->getKeyValueElement(I);
|
|
|
|
Visit(Element.Key);
|
|
|
|
OS << " : ";
|
|
|
|
Visit(Element.Value);
|
|
|
|
if (Element.isPackExpansion())
|
|
|
|
OS << "...";
|
|
|
|
}
|
|
|
|
OS << " }";
|
|
|
|
}
|
|
|
|
|
2007-08-22 23:14:15 +08:00
|
|
|
void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
|
2013-02-22 22:19:01 +08:00
|
|
|
OS << "@encode(";
|
|
|
|
Node->getEncodedType().print(OS, Policy);
|
|
|
|
OS << ')';
|
2007-08-22 23:14:15 +08:00
|
|
|
}
|
|
|
|
|
2007-10-17 04:40:23 +08:00
|
|
|
void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
|
2008-11-24 12:00:27 +08:00
|
|
|
OS << "@selector(" << Node->getSelector().getAsString() << ')';
|
2007-10-17 04:40:23 +08:00
|
|
|
}
|
|
|
|
|
2007-10-18 00:58:11 +08:00
|
|
|
void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
|
2011-10-15 02:45:37 +08:00
|
|
|
OS << "@protocol(" << *Node->getProtocol() << ')';
|
2007-10-18 00:58:11 +08:00
|
|
|
}
|
|
|
|
|
2007-09-19 07:55:05 +08:00
|
|
|
void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
|
|
|
|
OS << "[";
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
llvm-svn: 101972
2010-04-21 08:45:42 +08:00
|
|
|
switch (Mess->getReceiverKind()) {
|
|
|
|
case ObjCMessageExpr::Instance:
|
|
|
|
PrintExpr(Mess->getInstanceReceiver());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ObjCMessageExpr::Class:
|
2013-02-22 22:19:01 +08:00
|
|
|
Mess->getClassReceiver().print(OS, Policy);
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
llvm-svn: 101972
2010-04-21 08:45:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ObjCMessageExpr::SuperInstance:
|
|
|
|
case ObjCMessageExpr::SuperClass:
|
|
|
|
OS << "Super";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-03 01:32:38 +08:00
|
|
|
OS << ' ';
|
2008-04-16 12:30:16 +08:00
|
|
|
Selector selector = Mess->getSelector();
|
2007-10-03 04:01:56 +08:00
|
|
|
if (selector.isUnarySelector()) {
|
2011-02-19 06:29:55 +08:00
|
|
|
OS << selector.getNameForSlot(0);
|
2007-10-03 04:01:56 +08:00
|
|
|
} else {
|
|
|
|
for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
|
2008-05-03 01:32:38 +08:00
|
|
|
if (i < selector.getNumArgs()) {
|
|
|
|
if (i > 0) OS << ' ';
|
|
|
|
if (selector.getIdentifierInfoForSlot(i))
|
2008-11-24 12:00:27 +08:00
|
|
|
OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
|
2008-05-03 01:32:38 +08:00
|
|
|
else
|
|
|
|
OS << ":";
|
|
|
|
}
|
|
|
|
else OS << ", "; // Handle variadic methods.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-03 04:01:56 +08:00
|
|
|
PrintExpr(Mess->getArg(i));
|
|
|
|
}
|
2007-09-19 07:55:05 +08:00
|
|
|
}
|
|
|
|
OS << "]";
|
|
|
|
}
|
|
|
|
|
2012-03-07 04:05:56 +08:00
|
|
|
void StmtPrinter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
|
|
|
|
OS << (Node->getValue() ? "__objc_yes" : "__objc_no");
|
|
|
|
}
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
void
|
|
|
|
StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
|
|
|
|
PrintExpr(E->getSubExpr());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
|
2013-02-22 22:19:01 +08:00
|
|
|
OS << '(' << E->getBridgeKindName();
|
|
|
|
E->getType().print(OS, Policy);
|
|
|
|
OS << ')';
|
2011-06-16 07:02:42 +08:00
|
|
|
PrintExpr(E->getSubExpr());
|
|
|
|
}
|
2008-11-04 22:56:14 +08:00
|
|
|
|
2008-09-04 02:15:37 +08:00
|
|
|
void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
|
2008-10-09 01:01:13 +08:00
|
|
|
BlockDecl *BD = Node->getBlockDecl();
|
2008-09-04 02:15:37 +08:00
|
|
|
OS << "^";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-09-04 02:15:37 +08:00
|
|
|
const FunctionType *AFT = Node->getFunctionType();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-27 07:50:07 +08:00
|
|
|
if (isa<FunctionNoProtoType>(AFT)) {
|
2008-09-04 02:15:37 +08:00
|
|
|
OS << "()";
|
2009-02-27 07:50:07 +08:00
|
|
|
} else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
|
2008-09-04 02:15:37 +08:00
|
|
|
OS << '(';
|
2008-10-09 01:01:13 +08:00
|
|
|
for (BlockDecl::param_iterator AI = BD->param_begin(),
|
|
|
|
E = BD->param_end(); AI != E; ++AI) {
|
|
|
|
if (AI != BD->param_begin()) OS << ", ";
|
2013-02-22 22:19:01 +08:00
|
|
|
std::string ParamStr = (*AI)->getNameAsString();
|
|
|
|
(*AI)->getType().print(OS, Policy, ParamStr);
|
2008-09-04 02:15:37 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-27 07:50:07 +08:00
|
|
|
const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
|
2008-09-04 02:15:37 +08:00
|
|
|
if (FT->isVariadic()) {
|
2008-10-09 01:01:13 +08:00
|
|
|
if (!BD->param_empty()) OS << ", ";
|
2008-09-04 02:15:37 +08:00
|
|
|
OS << "...";
|
|
|
|
}
|
|
|
|
OS << ')';
|
|
|
|
}
|
2012-12-05 05:15:23 +08:00
|
|
|
OS << "{ }";
|
2008-09-04 02:15:37 +08:00
|
|
|
}
|
|
|
|
|
2011-12-01 06:08:08 +08:00
|
|
|
void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
|
|
|
|
PrintExpr(Node->getSourceExpr());
|
|
|
|
}
|
2010-11-16 07:31:06 +08:00
|
|
|
|
2011-06-04 08:47:47 +08:00
|
|
|
void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
|
|
|
|
OS << "__builtin_astype(";
|
|
|
|
PrintExpr(Node->getSrcExpr());
|
2013-02-22 22:19:01 +08:00
|
|
|
OS << ", ";
|
|
|
|
Node->getType().print(OS, Policy);
|
2011-06-04 08:47:47 +08:00
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2006-11-04 15:16:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Stmt method implementations
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-08-16 11:56:14 +08:00
|
|
|
void Stmt::dumpPretty(ASTContext &Context) const {
|
|
|
|
printPretty(llvm::errs(), 0, PrintingPolicy(Context.getLangOpts()));
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
|
|
|
|
2012-08-16 11:56:14 +08:00
|
|
|
void Stmt::printPretty(raw_ostream &OS,
|
|
|
|
PrinterHelper *Helper,
|
2009-05-30 04:38:28 +08:00
|
|
|
const PrintingPolicy &Policy,
|
|
|
|
unsigned Indentation) const {
|
2006-11-05 02:52:07 +08:00
|
|
|
if (this == 0) {
|
|
|
|
OS << "<NULL>";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-16 11:56:14 +08:00
|
|
|
StmtPrinter P(OS, Helper, Policy, Indentation);
|
2007-08-21 12:04:25 +08:00
|
|
|
P.Visit(const_cast<Stmt*>(this));
|
2006-11-04 15:16:25 +08:00
|
|
|
}
|
2007-09-01 05:30:12 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PrinterHelper
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Implement virtual destructor.
|
2007-09-11 23:32:40 +08:00
|
|
|
PrinterHelper::~PrinterHelper() {}
|