From 89e07bf2c75e3a91abddde3219e1108c75059985 Mon Sep 17 00:00:00 2001 From: jimblandy Date: Fri, 5 Feb 2010 17:51:35 +0000 Subject: 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 --- src/processor/postfix_evaluator.h | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/processor/postfix_evaluator.h') 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. -- cgit v1.2.1