4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
7 #if !defined(_EvalContext_h_)
8 #define _EvalContext_h_
14 #include "SourceFile.h"
20 * \brief Context for evaluating AST tree and expressions.
22 * Keeps a map of variable names to integer values. Each integer value has a
23 * size attribute in addition to the actual value. Variables can be locked, which
24 * simply means that they cannot be assigned a new value.
26 * \todo Switch to using Value instances to keep track of variable values. This
27 * will enable variables to have string values, for one.
33 * \brief Abstract interface for a manager of source files.
35 class SourceFileManager
38 //! \brief Returns true if a source file with the name \a name exists.
39 virtual bool hasSourceFile(const std::string & name)=0;
41 //! \brief Gets the requested source file.
42 virtual SourceFile * getSourceFile(const std::string & name)=0;
44 //! \brief Returns the default source file, or NULL if none is set.
45 virtual SourceFile * getDefaultSourceFile()=0;
49 //! \brief Constructor.
52 //! \brief Destructor.
53 virtual ~EvalContext();
55 //! \name Source file manager
58 void setSourceFileManager(SourceFileManager * manager) { m_sourcesManager = manager; }
61 SourceFileManager * getSourceFileManager() { return m_sourcesManager; }
66 bool isVariableDefined(const std::string & name);
67 uint32_t getVariableValue(const std::string & name);
68 int_size_t getVariableSize(const std::string & name);
69 void setVariable(const std::string & name, uint32_t value, int_size_t size=kWordSize);
74 bool isVariableLocked(const std::string & name);
75 void lockVariable(const std::string & name);
76 void unlockVariable(const std::string & name);
82 //! Information about a variable's value.
83 struct variable_info_t
85 uint32_t m_value; //!< Variable value.
86 int_size_t m_size; //!< Number of bytes
87 bool m_isLocked; //!< Can this variable's value be changed?
90 //! Type to maps between the variable name and its info.
91 typedef std::map<std::string, variable_info_t> variable_map_t;
93 SourceFileManager * m_sourcesManager; //!< Interface to source file manager.
94 variable_map_t m_variables; //!< Map of variables to their final values.
97 }; // namespace elftosb
99 #endif // _EvalContext_h_