summaryrefslogtreecommitdiffstats
path: root/clang/AST
diff options
context:
space:
mode:
Diffstat (limited to 'clang/AST')
-rw-r--r--clang/AST/ASTStreamer.cpp4
-rw-r--r--clang/AST/Expr.cpp22
-rw-r--r--clang/AST/Sema.cpp36
3 files changed, 56 insertions, 6 deletions
diff --git a/clang/AST/ASTStreamer.cpp b/clang/AST/ASTStreamer.cpp
index bd192040d7b..7db53f3ae6f 100644
--- a/clang/AST/ASTStreamer.cpp
+++ b/clang/AST/ASTStreamer.cpp
@@ -19,7 +19,7 @@ using namespace clang;
/// Interface to the Builder.cpp file.
///
-Action *CreateASTBuilderActions(bool FullLocInfo);
+Action *CreateASTBuilderActions(Preprocessor &PP, bool FullLocInfo);
namespace {
@@ -27,7 +27,7 @@ namespace {
Parser P;
public:
ASTStreamer(Preprocessor &PP, unsigned MainFileID, bool FullLocInfo)
- : P(PP, *CreateASTBuilderActions(FullLocInfo)) {
+ : P(PP, *CreateASTBuilderActions(PP, FullLocInfo)) {
PP.EnterSourceFile(MainFileID, 0, true);
// Initialize the parser.
diff --git a/clang/AST/Expr.cpp b/clang/AST/Expr.cpp
index 46051574491..f00301c759f 100644
--- a/clang/AST/Expr.cpp
+++ b/clang/AST/Expr.cpp
@@ -43,6 +43,28 @@ void FloatingConstant::dump_impl() const {
std::cerr << "1.0";
}
+
+
+StringExpr::StringExpr(const char *strData, unsigned byteLength, bool Wide) {
+ // OPTIMIZE: could allocate this appended to the StringExpr.
+ char *AStrData = new char[byteLength];
+ memcpy(AStrData, strData, byteLength);
+ StrData = AStrData;
+ ByteLength = byteLength;
+ isWide = Wide;
+}
+
+StringExpr::~StringExpr() {
+ delete[] StrData;
+}
+
+void StringExpr::dump_impl() const {
+ if (isWide) std::cerr << 'L';
+ std::cerr << '"' << StrData << '"';
+}
+
+
+
void ParenExpr::dump_impl() const {
std::cerr << "'('";
Val->dump();
diff --git a/clang/AST/Sema.cpp b/clang/AST/Sema.cpp
index 06eed86d442..cae97fc2bd6 100644
--- a/clang/AST/Sema.cpp
+++ b/clang/AST/Sema.cpp
@@ -18,18 +18,23 @@
#include "clang/Parse/Scope.h"
#include "clang/Lex/IdentifierTable.h"
#include "clang/Lex/LexerToken.h"
-#include "llvm/Support/Visibility.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/Support/Compiler.h"
using namespace llvm;
using namespace clang;
/// ASTBuilder
namespace {
class VISIBILITY_HIDDEN ASTBuilder : public Action {
+ Preprocessor &PP;
+
/// FullLocInfo - If this is true, the ASTBuilder constructs AST Nodes that
/// capture maximal location information for each source-language construct.
bool FullLocInfo;
public:
- ASTBuilder(bool fullLocInfo) : FullLocInfo(fullLocInfo) {}
+ ASTBuilder(Preprocessor &pp, bool fullLocInfo)
+ : PP(pp), FullLocInfo(fullLocInfo) {}
+
//===--------------------------------------------------------------------===//
// Symbol table tracking callbacks.
//
@@ -47,6 +52,9 @@ public:
virtual ExprResult ParseFloatingConstant(const LexerToken &Tok);
virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
ExprTy *Val);
+ virtual ExprResult ParseStringExpr(const char *StrData, unsigned StrLen,
+ bool isWide,
+ const LexerToken *Toks, unsigned NumToks);
// Binary/Unary Operators. 'Tok' is the token for the operator.
virtual ExprResult ParseUnaryOp(const LexerToken &Tok, ExprTy *Input);
@@ -166,6 +174,26 @@ Action::ExprResult ASTBuilder::ParseParenExpr(SourceLocation L,
return new ParenExpr(L, R, (Expr*)Val);
}
+/// ParseStringExpr - This accepts a string after semantic analysis. This string
+/// may be the result of string concatenation ([C99 5.1.1.2, translation phase
+/// #6]), so it may come from multiple tokens.
+///
+Action::ExprResult ASTBuilder::
+ParseStringExpr(const char *StrData, unsigned StrLen, bool isWide,
+ const LexerToken *Toks, unsigned NumToks) {
+ assert(NumToks && "Must have at least one string!");
+
+ if (!FullLocInfo)
+ return new StringExpr(StrData, StrLen, isWide);
+ else {
+ SmallVector<SourceLocation, 4> Locs;
+ for (unsigned i = 0; i != NumToks; ++i)
+ Locs.push_back(Toks[i].getLocation());
+ return new StringExprLOC(StrData, StrLen, isWide, &Locs[0], Locs.size());
+ }
+}
+
+
// Unary Operators. 'Tok' is the token for the operator.
Action::ExprResult ASTBuilder::ParseUnaryOp(const LexerToken &Tok,
ExprTy *Input) {
@@ -326,8 +354,8 @@ Action::ExprResult ASTBuilder::ParseConditionalOp(SourceLocation QuestionLoc,
/// Interface to the Builder.cpp file.
///
-Action *CreateASTBuilderActions(bool FullLocInfo) {
- return new ASTBuilder(FullLocInfo);
+Action *CreateASTBuilderActions(Preprocessor &PP, bool FullLocInfo) {
+ return new ASTBuilder(PP, FullLocInfo);
}
OpenPOWER on IntegriCloud