[AST] In IfConfigDecl/IfConfigStmt keep track of whether the IfBlock is active or not.

Swift SVN r15444
This commit is contained in:
Argyrios Kyrtzidis
2014-03-25 03:55:29 +00:00
parent 3064e04d47
commit 121bf14dd1
4 changed files with 26 additions and 20 deletions

View File

@@ -1463,20 +1463,22 @@ public:
class IfConfigDecl : public Decl {
ArrayRef<Decl*> ActiveMembers;
ArrayRef<Decl*> InactiveMembers;
bool IfBlockIsActive;
SourceLoc IfLoc;
SourceLoc ElseLoc;
SourceLoc EndLoc;
SourceRange InactiveSourceRange;
Expr *Cond;
public:
IfConfigDecl(DeclContext *Parent,
bool IfBlockIsActive,
SourceLoc ifLoc,
SourceLoc elseLoc,
SourceLoc endLoc,
Expr *cond):
Decl(DeclKind::IfConfig, Parent),
IfBlockIsActive(IfBlockIsActive),
IfLoc(ifLoc),
ElseLoc(elseLoc),
EndLoc(endLoc),
@@ -1494,6 +1496,7 @@ public:
Expr *getCond() { return Cond; }
bool isIfBlockActive() const { return IfBlockIsActive; }
bool hasElse() const { return ElseLoc.isValid(); }
SourceLoc getIfLoc() const { return IfLoc; }
@@ -1503,11 +1506,16 @@ public:
SourceRange getSourceRange() const;
void setInactiveSourceRange(SourceRange range) {
InactiveSourceRange = range;
SourceRange getInactiveSourceRange() const {
if (isIfBlockActive()) {
if (hasElse())
return SourceRange(ElseLoc, EndLoc);
else
return SourceRange();
}
return SourceRange(IfLoc, ElseLoc.isValid() ? ElseLoc : EndLoc);
}
SourceRange getInactiveSourceRange() const { return InactiveSourceRange; }
static bool classof(const Decl *D) {
return D->getKind() == DeclKind::IfConfig;
}