[cfe-commits] r41299 - /cfe/trunk/AST/CFG.cpp
Ted Kremenek
kremenek at apple.com
Wed Aug 22 14:51:58 PDT 2007
Author: kremenek
Date: Wed Aug 22 16:51:58 2007
New Revision: 41299
URL: http://llvm.org/viewvc/llvm-project?rev=41299&view=rev
Log:
Added support for "break" statements in source-level ASTs.
Some comment cleanups.
Modified:
cfe/trunk/AST/CFG.cpp
Modified: cfe/trunk/AST/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/CFG.cpp?rev=41299&r1=41298&r2=41299&view=diff
==============================================================================
--- cfe/trunk/AST/CFG.cpp (original)
+++ cfe/trunk/AST/CFG.cpp Wed Aug 22 16:51:58 2007
@@ -56,6 +56,7 @@
CFGBlock* Exit;
CFGBlock* Succ;
CFGBlock* ContinueTargetBlock;
+ CFGBlock* BreakTargetBlock;
unsigned NumBlocks;
typedef llvm::DenseMap<LabelStmt*,CFGBlock*> LabelMapTy;
@@ -66,7 +67,7 @@
public:
explicit CFGBuilder() : cfg(NULL), Block(NULL), Exit(NULL), Succ(NULL),
- ContinueTargetBlock(NULL),
+ ContinueTargetBlock(NULL), BreakTargetBlock(NULL),
NumBlocks(0) {
// Create an empty CFG.
cfg = new CFG();
@@ -336,11 +337,15 @@
// Save the current values for Block, Succ, and ContinueTargetBlock
SaveAndRestore<CFGBlock*> save_Block(Block), save_Succ(Succ),
- save_continue(ContinueTargetBlock);
+ save_continue(ContinueTargetBlock),
+ save_break(BreakTargetBlock);
// All continues within this loop should go to the condition block
ContinueTargetBlock = ConditionBlock;
+ // All breaks should go to the code that follows the loop.
+ BreakTargetBlock = Block;
+
// create a new block to contain the body.
Block = createBlock();
@@ -389,11 +394,15 @@
// Save the current values for Block, Succ, and ContinueTargetBlock
SaveAndRestore<CFGBlock*> save_Block(Block), save_Succ(Succ),
- save_continue(ContinueTargetBlock);
+ save_continue(ContinueTargetBlock),
+ save_break(BreakTargetBlock);
// All continues within this loop should go to the condition block
ContinueTargetBlock = ConditionBlock;
+ // All breaks should go to the code that follows the loop.
+ BreakTargetBlock = Block;
+
// NULL out Block to force lazy instantiation of blocks for the body.
Block = NULL;
@@ -403,6 +412,8 @@
ConditionBlock->addSuccessor(BodyBlock);
}
+ // Link up the condition block with the code that follows the loop.
+ // (the false branch).
ConditionBlock->addSuccessor(Block);
// There can be no more statements in the condition block
@@ -414,7 +425,7 @@
}
CFGBlock* VisitContinueStmt(ContinueStmt* C) {
- // While is a control-flow statement. Thus we stop processing the
+ // "continue" is a control-flow statement. Thus we stop processing the
// current block.
if (Block) FinishBlock(Block);
@@ -429,6 +440,22 @@
return Block;
}
+ CFGBlock* VisitBreakStmt(BreakStmt* B) {
+ // "break" is a control-flow statement. Thus we stop processing the
+ // current block.
+ if (Block) FinishBlock(Block);
+
+ // Now create a new block that ends with the continue statement.
+ Block = createBlock(false);
+ Block->setTerminator(B);
+
+ // FIXME: We should gracefully handle breaks without resolved targets.
+ assert (BreakTargetBlock);
+
+ Block->addSuccessor(BreakTargetBlock);
+ return Block;
+ }
+
};
// BuildCFG - A helper function that builds CFGs from ASTS.
More information about the cfe-commits
mailing list