Transition EstimateCost() AST traversal to WalkAST() as well.

This commit is contained in:
Matt Pharr
2011-12-16 12:16:11 -08:00
parent 701334ccf2
commit f23d030e43
5 changed files with 61 additions and 69 deletions

16
ast.cpp
View File

@@ -273,3 +273,19 @@ Stmt *
TypeCheck(Stmt *stmt) {
return (Stmt *)TypeCheck((ASTNode *)stmt);
}
static bool
lCostCallback(ASTNode *node, void *c) {
int *cost = (int *)c;
*cost += node->EstimateCost();
return true;
}
int
EstimateCost(ASTNode *root) {
int cost = 0;
WalkAST(root, lCostCallback, NULL, &cost);
return cost;
}