aboutsummaryrefslogtreecommitdiff
path: root/src/processor/postfix_evaluator.h
diff options
context:
space:
mode:
authorjimblandy <jimblandy@4c0a9323-5329-0410-9bdc-e9ce6186880e>2010-02-05 17:51:35 +0000
committerjimblandy <jimblandy@4c0a9323-5329-0410-9bdc-e9ce6186880e>2010-02-05 17:51:35 +0000
commit89e07bf2c75e3a91abddde3219e1108c75059985 (patch)
tree36a2476332a7439ed3e5d52fe64a220e0fc901c4 /src/processor/postfix_evaluator.h
parentBreakpad x86 Stack Walker: Pass "out" parameters by address, not reference. (diff)
downloadbreakpad-89e07bf2c75e3a91abddde3219e1108c75059985.tar.xz
Breakpad processor: Support evaluating a postfix expression to produce a value.
This adds an EvaluateForValue member function to PostfixEvaluator, and along with appropriate unit tests. a=jimblandy, r=nealsid git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@511 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/processor/postfix_evaluator.h')
-rw-r--r--src/processor/postfix_evaluator.h28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/processor/postfix_evaluator.h b/src/processor/postfix_evaluator.h
index d70bcaa0..a8979051 100644
--- a/src/processor/postfix_evaluator.h
+++ b/src/processor/postfix_evaluator.h
@@ -1,3 +1,5 @@
+// -*- mode: C++ -*-
+
// Copyright (c) 2010, Google Inc.
// All rights reserved.
//
@@ -93,15 +95,21 @@ class PostfixEvaluator {
PostfixEvaluator(DictionaryType *dictionary, const MemoryRegion *memory)
: dictionary_(dictionary), memory_(memory), stack_() {}
- // Evaluate the expression. The results of execution will be stored
- // in one (or more) variables in the dictionary. Returns false if any
- // failures occure during execution, leaving variables in the dictionary
- // in an indeterminate state. If assigned is non-NULL, any keys set in
- // the dictionary as a result of evaluation will also be set to true in
- // assigned, providing a way to determine if an expression modifies any
- // of its input variables.
+ // Evaluate the expression, starting with an empty stack. The results of
+ // execution will be stored in one (or more) variables in the dictionary.
+ // Returns false if any failures occur during execution, leaving
+ // variables in the dictionary in an indeterminate state. If assigned is
+ // non-NULL, any keys set in the dictionary as a result of evaluation
+ // will also be set to true in assigned, providing a way to determine if
+ // an expression modifies any of its input variables.
bool Evaluate(const string &expression, DictionaryValidityType *assigned);
+ // Like Evaluate, but provides the value left on the stack to the
+ // caller. If evaluation succeeds and leaves exactly one value on
+ // the stack, pop that value, store it in *result, and return true.
+ // Otherwise, return false.
+ bool EvaluateForValue(const string &expression, ValueType *result);
+
DictionaryType* dictionary() const { return dictionary_; }
// Reset the dictionary. PostfixEvaluator does not take ownership.
@@ -137,6 +145,12 @@ class PostfixEvaluator {
// Pushes a new value onto the stack.
void PushValue(const ValueType &value);
+ // Evaluate expression, updating *assigned if it is non-zero. Return
+ // true if evaluation completes successfully. Do not clear the stack
+ // upon successful evaluation.
+ bool EvaluateInternal(const string &expression,
+ DictionaryValidityType *assigned);
+
// The dictionary mapping constant and variable identifiers (strings) to
// values. Keys beginning with '$' are treated as variable names, and
// PostfixEvaluator is free to create and modify these keys. Weak pointer.