forked from OSchip/llvm-project
Extend InitListExpr API/IMPL to support arbitrary add/remove (in support of the initializer rewrite I am doing).
llvm-svn: 50511
This commit is contained in:
parent
7cf18862c2
commit
20348b5653
|
@ -21,6 +21,7 @@
|
|||
#include "clang/Basic/IdentifierTable.h"
|
||||
#include "llvm/ADT/APSInt.h"
|
||||
#include "llvm/ADT/APFloat.h"
|
||||
#include <vector>
|
||||
|
||||
namespace clang {
|
||||
class IdentifierInfo;
|
||||
|
@ -1280,32 +1281,42 @@ public:
|
|||
/// int x = { 1 }; int y[2] = { {1}, {2} };
|
||||
///
|
||||
class InitListExpr : public Expr {
|
||||
Expr **InitExprs;
|
||||
unsigned NumInits;
|
||||
std::vector<Expr *> InitExprs;
|
||||
SourceLocation LBraceLoc, RBraceLoc;
|
||||
public:
|
||||
InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
|
||||
SourceLocation rbraceloc);
|
||||
~InitListExpr() {
|
||||
delete [] InitExprs;
|
||||
}
|
||||
|
||||
unsigned getNumInits() const { return NumInits; }
|
||||
unsigned getNumInits() const { return InitExprs.size(); }
|
||||
|
||||
const Expr* getInit(unsigned Init) const {
|
||||
assert(Init < NumInits && "Initializer access out of range!");
|
||||
assert(Init < getNumInits() && "Initializer access out of range!");
|
||||
return InitExprs[Init];
|
||||
}
|
||||
|
||||
Expr* getInit(unsigned Init) {
|
||||
assert(Init < NumInits && "Initializer access out of range!");
|
||||
assert(Init < getNumInits() && "Initializer access out of range!");
|
||||
return InitExprs[Init];
|
||||
}
|
||||
|
||||
void setInit(unsigned Init, Expr *expr) {
|
||||
assert(Init < NumInits && "Initializer access out of range!");
|
||||
assert(Init < getNumInits() && "Initializer access out of range!");
|
||||
InitExprs[Init] = expr;
|
||||
}
|
||||
|
||||
// Dynamic removal/addition (for constructing implicit InitExpr's).
|
||||
void removeInit(unsigned Init) {
|
||||
InitExprs.erase(InitExprs.begin()+Init);
|
||||
}
|
||||
void addInit(unsigned Init, Expr *expr) {
|
||||
InitExprs.insert(InitExprs.begin()+Init, expr);
|
||||
}
|
||||
|
||||
// Explicit InitListExpr's originate from source code (and have valid source
|
||||
// locations). Implicit InitListExpr's are created by the semantic analyzer.
|
||||
bool isExplicit() {
|
||||
return LBraceLoc.isValid() && RBraceLoc.isValid();
|
||||
}
|
||||
|
||||
virtual SourceRange getSourceRange() const {
|
||||
return SourceRange(LBraceLoc, RBraceLoc);
|
||||
|
@ -1325,7 +1336,7 @@ public:
|
|||
private:
|
||||
// Used by serializer.
|
||||
InitListExpr() : Expr(InitListExprClass, QualType()),
|
||||
InitExprs(NULL), NumInits(0) {}
|
||||
InitExprs(NULL) {}
|
||||
};
|
||||
|
||||
/// ObjCStringLiteral, used for Objective-C string literals
|
||||
|
|
|
@ -254,14 +254,11 @@ const char *BinaryOperator::getOpcodeStr(Opcode Op) {
|
|||
InitListExpr::InitListExpr(SourceLocation lbraceloc,
|
||||
Expr **initexprs, unsigned numinits,
|
||||
SourceLocation rbraceloc)
|
||||
: Expr(InitListExprClass, QualType())
|
||||
, NumInits(numinits)
|
||||
, LBraceLoc(lbraceloc)
|
||||
, RBraceLoc(rbraceloc)
|
||||
: Expr(InitListExprClass, QualType()),
|
||||
LBraceLoc(lbraceloc), RBraceLoc(rbraceloc)
|
||||
{
|
||||
InitExprs = new Expr*[numinits];
|
||||
for (unsigned i = 0; i != numinits; i++)
|
||||
InitExprs[i] = initexprs[i];
|
||||
InitExprs.push_back(initexprs[i]);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -1368,7 +1365,7 @@ Stmt::child_iterator InitListExpr::child_begin() {
|
|||
return reinterpret_cast<Stmt**>(&InitExprs[0]);
|
||||
}
|
||||
Stmt::child_iterator InitListExpr::child_end() {
|
||||
return reinterpret_cast<Stmt**>(&InitExprs[NumInits]);
|
||||
return reinterpret_cast<Stmt**>(&InitExprs[getNumInits()]);
|
||||
}
|
||||
|
||||
// ObjCStringLiteral
|
||||
|
|
|
@ -647,18 +647,20 @@ IndirectGotoStmt* IndirectGotoStmt::CreateImpl(Deserializer& D, ASTContext& C) {
|
|||
void InitListExpr::EmitImpl(Serializer& S) const {
|
||||
S.Emit(LBraceLoc);
|
||||
S.Emit(RBraceLoc);
|
||||
S.EmitInt(NumInits);
|
||||
S.BatchEmitOwnedPtrs(NumInits,InitExprs);
|
||||
S.EmitInt(InitExprs.size());
|
||||
if (!InitExprs.empty()) S.BatchEmitOwnedPtrs(InitExprs.size(), &InitExprs[0]);
|
||||
}
|
||||
|
||||
InitListExpr* InitListExpr::CreateImpl(Deserializer& D, ASTContext& C) {
|
||||
InitListExpr* expr = new InitListExpr();
|
||||
expr->LBraceLoc = SourceLocation::ReadVal(D);
|
||||
expr->RBraceLoc = SourceLocation::ReadVal(D);
|
||||
expr->NumInits = D.ReadInt();
|
||||
assert(expr->NumInits);
|
||||
expr->InitExprs = new Expr*[expr->NumInits];
|
||||
D.BatchReadOwnedPtrs(expr->NumInits, expr->InitExprs, C);
|
||||
unsigned size = D.ReadInt();
|
||||
assert(size);
|
||||
expr->InitExprs.reserve(size);
|
||||
for (unsigned i = 0 ; i < size; ++i) expr->InitExprs.push_back(0);
|
||||
|
||||
D.BatchReadOwnedPtrs(size, &expr->InitExprs[0], C);
|
||||
return expr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue