Have WalkAST postorder callback function return an ASTNode *

In general, it should just return the original node pointer, but for type checking
and optimization passes, it can return a new value for the node (that will be
assigned where the old one was in the tree.)

Along the way, fixed some bugs in WalkAST() where the postorder callback wouldn't
end up being called for a few expr types (sizeof, dereference, address of, 
reference).
This commit is contained in:
Matt Pharr
2011-12-16 11:06:09 -08:00
parent 018aa96c8b
commit ced3f1f5fc
5 changed files with 73 additions and 59 deletions

22
ast.h
View File

@@ -92,18 +92,24 @@ private:
};
/** Callback function type for the AST walk.
/** Callback function type for preorder traversial visiting function for
the AST walk.
*/
typedef bool (* ASTCallBackFunc)(ASTNode *node, void *data);
typedef bool (* ASTPreCallBackFunc)(ASTNode *node, void *data);
/** Callback function type for postorder traversial visiting function for
the AST walk.
*/
typedef ASTNode * (* ASTPostCallBackFunc)(ASTNode *node, void *data);
/** Walk (some portion of) an AST, starting from the given root node. At
each node, if preFunc is non-NULL, call it, passing the given void
*data pointer; if the call to preFunc function returns false, then the
children of the node aren't visited. This then makes recursive calls
to WalkAST() to process the node's children; after doing so, calls
postFunc, at the node. The return value from the postFunc call is
ignored. */
extern void WalkAST(ASTNode *root, ASTCallBackFunc preFunc,
ASTCallBackFunc postFunc, void *data);
children of the node aren't visited. This function then makes
recursive calls to WalkAST() to process the node's children; after
doing so, calls postFunc, at the node. The return value from the
postFunc call is ignored. */
extern ASTNode *WalkAST(ASTNode *root, ASTPreCallBackFunc preFunc,
ASTPostCallBackFunc postFunc, void *data);
#endif // ISPC_AST_H