1#ifndef ROSE_BinaryAnalysis_SymbolicExpressionParser_H 
    2#define ROSE_BinaryAnalysis_SymbolicExpressionParser_H 
    3#include <featureTests.h> 
    4#ifdef ROSE_ENABLE_BINARY_ANALYSIS 
    6#include <Rose/BinaryAnalysis/BasicTypes.h> 
    7#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h> 
    8#include <Rose/BinaryAnalysis/SymbolicExpression.h> 
    9#include <Rose/Exception.h> 
   10#include <Sawyer/BiMap.h> 
   11#include <Sawyer/CommandLine.h> 
   12#include <Sawyer/Message.h> 
   13#include <Sawyer/SharedPointer.h> 
   16namespace BinaryAnalysis {
 
   42        void print(std::ostream&) 
const;                
 
 
   51        void print(std::ostream&) 
const;
 
 
   73        unsigned lineNumber_, columnNumber_;            
 
   78            : tokenType_(
NONE), lineNumber_(0), columnNumber_(0) {}
 
 
  105        const std::string &
lexeme()
 const { 
return lexeme_; }
 
 
  126        std::istream &input_;
 
  128        unsigned lineNumber_, columnNumber_;
 
  129        const Token endToken_;
 
  130        std::vector<Token> tokens_;
 
  145        const std::string& 
name()
 const { 
return name_; }
 
  201        void fillTokenList(
size_t idx);
 
 
  208        std::string docString_;
 
  218        const std::string& 
title()
 const { 
return title_; }
 
  219        void title(
const std::string &s) { title_ = s; }
 
  227        const std::string& 
docString()
 const { 
return docString_; }
 
  228        void docString(
const std::string &s) { docString_ = s; }
 
 
  338            : regdict_(regdict) {}
 
 
  453        static Ptr instance() {
 
  461        static std::string docString();
 
 
  493    static void initDiagnostics();
 
  505                                  unsigned lineNumber=1, 
unsigned columnNumber=0);
 
 
SmtSolverPtr Ptr
Reference counting pointer for SMT solvers.
 
Virtual base class for expanding atoms.
 
Sawyer::SharedPointer< AtomExpansion > Ptr
Shared-ownership pointer to an AtomExpansion.
 
virtual SymbolicExpression::Ptr immediateExpansion(const Token &name)=0
Expand a parsed atom into some other expression.
 
Virtual base class for atom and operator expansion.
 
void title(const std::string &s)
Property: Title to use for documentation.
 
virtual SymbolicExpression::Ptr delayedExpansion(const SymbolicExpression::Ptr &src, const SymbolicExpressionParser *)
Substitute one expression with another.
 
const std::string & docString() const
Property: Documentation string.
 
Sawyer::SharedPointer< Expansion > Ptr
Shared-ownership pointer to an Expansion.
 
const std::string & title() const
Property: Title to use for documentation.
 
void docString(const std::string &s)
Property: Documentation string.
 
Expand "memory" function to placeholder.
 
void riscOperators(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &ops)
Property: Semantic state used during delayed expansion.
 
virtual SymbolicExpression::Ptr delayedExpansion(const SymbolicExpression::Ptr &, const SymbolicExpressionParser *) override
Substitute one expression with another.
 
Sawyer::SharedPointer< MemorySubstituter > Ptr
Shared-ownership pointer.
 
virtual SymbolicExpression::Ptr immediateExpansion(const Token &name, const SymbolicExpression::Nodes &operands) override
Operator to expand a list into an expression tree.
 
static Ptr instance(const SmtSolver::Ptr &solver)
Allocating constructor.
 
InstructionSemantics::BaseSemantics::RiscOperatorsPtr riscOperators() const
Property: Semantic state used during delayed expansion.
 
Virtual base class for expanding operators.
 
Sawyer::SharedPointer< OperatorExpansion > Ptr
Shared-ownership pointer.
 
virtual SymbolicExpression::Ptr immediateExpansion(const Token &name, const SymbolicExpression::Nodes &operands)=0
Operator to expand a list into an expression tree.
 
Expand register name to placeholder variables.
 
SymbolicExpression::Ptr delayedExpansion(const SymbolicExpression::Ptr &, const SymbolicExpressionParser *) override
Substitute one expression with another.
 
Sawyer::SharedPointer< RegisterSubstituter > Ptr
Shared-ownership pointer.
 
void riscOperators(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &ops)
Property: Semantic state used during delayed expansion.
 
SymbolicExpression::Ptr immediateExpansion(const SymbolicExpressionParser::Token &) override
Expand a parsed atom into some other expression.
 
static Ptr instance(const RegisterDictionaryPtr &)
Allocating constructor.
 
InstructionSemantics::BaseSemantics::RiscOperatorsPtr riscOperators() const
Property: Semantic state used during delayed expansion.
 
Expand register names to register values.
 
Sawyer::SharedPointer< RegisterToValue > Ptr
Shared-ownership pointer.
 
static Ptr instance(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &)
Allocating constructor.
 
SymbolicExpression::Ptr immediateExpansion(const SymbolicExpressionParser::Token &) override
Expand a parsed atom into some other expression.
 
Substitution error during expansion.
 
Parse a symbolic expression from the command-line.
 
Sawyer::SharedPointer< SymbolicExprCmdlineParser > Ptr
Shared-ownership pointer.
 
Syntax errors that are thrown.
 
unsigned columnNumber
Column number (0-origin).
 
unsigned lineNumber
Line number (1-origin).
 
std::string inputName
Name of input, usually a file name.
 
void print(std::ostream &) const
Print error message to stream.
 
Expand unrecognized terms to placholder variables.
 
const NameToVarMap & map() const
Mapping between terms and variables.
 
Sawyer::Container::BiMap< std::string, SymbolicExpression::Ptr > NameToVarMap
Mapping between term names and placeholder variables.
 
SymbolicExpression::Ptr immediateExpansion(const SymbolicExpressionParser::Token &) override
Expand a parsed atom into some other expression.
 
Sawyer::SharedPointer< TermPlaceholders > Ptr
Shared-ownership pointer.
 
static Ptr instance()
Allocating constructor.
 
void consumeInlineComment()
Skip over angle-bracket comments.
 
void consumeWhiteSpaceAndComments()
Skip over white space and/or inline comments.
 
int consumeCharacter()
Consume the next character.
 
unsigned lineNumber() const
Current line number.
 
std::string consumeTerm()
Parse and consume a term.
 
int nextCharacter()
Returns the next character.
 
SymbolicExpression::Type consumeType()
Parse and consume a type specification.
 
int consumeEscapeSequence()
Skip over an escape sequence and return the escaped character.
 
void shift(size_t n=1)
Consume the specified number of tokens.
 
Token scan()
Parse and consume the next token.
 
TokenStream(std::istream &input, const std::string &name="input", unsigned lineNumber=1, unsigned columnNumber=0)
Scan tokens from a character stream.
 
unsigned columnNumber() const
Current column number.
 
const std::string & name() const
Name of this input stream.
 
const Token & operator[](size_t idx)
Returns the specified token without consuming it.
 
void consumeWhiteSpace()
Skip over characters until a non-white-space character is encountered.
 
Tokens generated by the lexical analysis.
 
const std::string & lexeme() const
Lexeme from which token was parsed.
 
unsigned lineNumber() const
Line number for start of token.
 
Token(const Sawyer::Container::BitVector &bv, const SymbolicExpression::Type &exprType, const std::string &lexeme, unsigned lineNumber, unsigned columnNumber)
Construct a token for a numeric constant.
 
const Sawyer::Container::BitVector & bits() const
Bit vector for numeric constants.
 
Token(Type tokenType, const SymbolicExpression::Type &exprType, const std::string &lexeme, unsigned lineNumber, unsigned columnNumber)
Constructs a specific token from a string.
 
Type tokenType() const
Token type.
 
@ BITVECTOR
Numeric constant.
 
@ LTPAREN
Left parenthesis.
 
@ RTPAREN
Right parenthesis.
 
SymbolicExpression::Type exprType() const
Type of expression.
 
SymbolicExpressionParser::SyntaxError syntaxError(const std::string &mesg, const std::string &name="input") const
Creates a syntax error from a token plus message.
 
unsigned columnNumber() const
Column number for start of token.
 
Token()
Constructs an end-of-input token with no position information.
 
Parses symbolic expressions from text.
 
void appendOperatorExpansion(const OperatorExpansion::Ptr &)
Append a new functor for expanding operators into symbolic expressions.
 
RegisterSubstituter::Ptr defineRegisters(const RegisterDictionaryPtr &)
Add definitions for registers.
 
SymbolicExpression::Ptr parse(TokenStream &)
Create a symbolic expression by parsing a token stream.
 
const OperatorTable & operatorTable() const
Return all operator expansion functors.
 
SymbolicExpressionParser()
Default constructor.
 
void appendAtomExpansion(const AtomExpansion::Ptr &)
Append a new functor for expanding atoms into symbolic expressions.
 
SymbolicExpression::Ptr parse(std::istream &input, const std::string &filename, unsigned lineNumber=1, unsigned columnNumber=0)
Create a symbolic expression by parsing a file.
 
void defineRegisters(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &)
Add definitions for registers.
 
OperatorTable & operatorTable()
Return all operator expansion functors.
 
SymbolicExpression::Ptr delayedExpansion(const SymbolicExpression::Ptr &) const
Perform delayed expansion.
 
SymbolicExpressionParser(const SmtSolverPtr &solver)
Parser using a specific SMT solver for simplifications.
 
std::string docString() const
Documentation string.
 
SymbolicExpression::Ptr parse(const std::string &, const std::string &inputName="string")
Create a symbolic expression by parsing a string.
 
const AtomTable & atomTable() const
Return all atom expansion functors.
 
AtomTable & atomTable()
Return all atom expansion functors.
 
std::vector< OperatorExpansion::Ptr > OperatorTable
Ordered operator table.
 
std::vector< AtomExpansion::Ptr > AtomTable
Ordered atom table.
 
Type of symbolic expression.
 
size_t nBits() const
Property: Total width of values.
 
Base class for all ROSE exceptions.
 
Information about a parsed switch value.
 
Base class parsing a value from input.
 
const ValueSaver::Ptr valueSaver() const
Property: functor responsible for saving a parsed value in user storage.
 
One-to-one mapping between source and target values.
 
size_t size() const
Size of vector in bits.
 
Container associating values with keys.
 
Base class for reference counted objects.
 
Reference-counting intrusive smart pointer.
 
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
 
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
 
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.
 
Position within a command-line.