4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
7 #if !defined(_ElftosbAST_h_)
13 #include "smart_ptr.h"
14 #include "EvalContext.h"
23 * \brief Token location in the source file.
27 int m_firstLine; //!< Starting line of the token.
28 int m_lastLine; //!< Ending line of the token.
32 * \brief The base class for all AST node classes.
37 //! \brief Default constructor.
38 ASTNode() : m_parent(0) {}
40 //! \brief Constructor taking a parent node.
41 ASTNode(ASTNode * parent) : m_parent(parent) {}
43 //! \brief Copy constructor.
44 ASTNode(const ASTNode & other) : m_parent(other.m_parent) {}
46 //! \brief Destructor.
49 //! \brief Returns an exact duplicate of this object.
50 virtual ASTNode * clone() const = 0;
52 //! \brief Returns the name of the object's class.
53 virtual std::string nodeName() const { return "ASTNode"; }
57 virtual ASTNode * getParent() const { return m_parent; }
58 virtual void setParent(ASTNode * newParent) { m_parent = newParent; }
61 //! \name Tree printing
63 virtual void printTree() const { printTree(0); }
64 virtual void printTree(int indent) const;
69 virtual void setLocation(token_loc_t & loc) { m_location = loc; }
70 virtual void setLocation(token_loc_t & first, token_loc_t & last);
71 virtual void setLocation(ASTNode * loc) { setLocation(loc->getLocation()); }
72 virtual void setLocation(ASTNode * first, ASTNode * last);
74 virtual token_loc_t & getLocation() { return m_location; }
75 virtual const token_loc_t & getLocation() const { return m_location; }
77 virtual int getFirstLine() { return m_location.m_firstLine; }
78 virtual int getLastLine() { return m_location.m_lastLine; }
82 ASTNode * m_parent; //!< Pointer to parent node of this object. May be NULL.
83 token_loc_t m_location; //!< Location of this node in the source file.
85 //! \brief Prints \a indent number of spaces.
86 void printIndent(int indent) const;
90 * \brief AST node that contains other AST nodes.
92 * Unlike other AST nodes, the location of a ListASTNode is computed dynamically
93 * based on the nodes in its list. Or mostly dynamic at least. The updateLocation()
94 * method is used to force the list object to recalculate its beginning and ending
97 * \todo Figure out why it crashes in the destructor when the
98 * ast_list_t type is a list of smart_ptr<ASTNode>.
100 class ListASTNode : public ASTNode
103 typedef std::list< /*smart_ptr<ASTNode>*/ ASTNode * > ast_list_t;
104 typedef ast_list_t::iterator iterator;
105 typedef ast_list_t::const_iterator const_iterator;
110 ListASTNode(const ListASTNode & other);
112 virtual ~ListASTNode();
114 virtual ASTNode * clone() const { return new ListASTNode(*this); }
116 virtual std::string nodeName() const { return "ListASTNode"; }
118 virtual void printTree(int indent) const;
120 //! \name List operations
122 //! \brief Adds \a node to the end of the ordered list of child nodes.
123 virtual void appendNode(ASTNode * node);
125 //! \brief Returns the number of nodes in this list.
126 virtual unsigned nodeCount() const { return static_cast<unsigned>(m_list.size()); }
129 //! \name Node iterators
131 inline iterator begin() { return m_list.begin(); }
132 inline iterator end() { return m_list.end(); }
134 inline const_iterator begin() const { return m_list.begin(); }
135 inline const_iterator end() const { return m_list.end(); }
140 virtual void updateLocation();
144 ast_list_t m_list; //!< Ordered list of child nodes.
150 class OptionsBlockASTNode : public ASTNode
153 OptionsBlockASTNode(ListASTNode * options) : ASTNode(), m_options(options) {}
155 inline ListASTNode * getOptions() { return m_options; }
157 virtual ASTNode * clone() const { return NULL; }
160 smart_ptr<ListASTNode> m_options;
166 class ConstantsBlockASTNode : public ASTNode
169 ConstantsBlockASTNode(ListASTNode * constants) : ASTNode(), m_constants(constants) {}
171 inline ListASTNode * getConstants() { return m_constants; }
173 virtual ASTNode * clone() const { return NULL; }
176 smart_ptr<ListASTNode> m_constants;
182 class SourcesBlockASTNode : public ASTNode
185 SourcesBlockASTNode(ListASTNode * sources) : ASTNode(), m_sources(sources) {}
187 inline ListASTNode * getSources() { return m_sources; }
189 virtual ASTNode * clone() const { return NULL; }
192 smart_ptr<ListASTNode> m_sources;
196 * \brief Root node for the entire file.
198 class CommandFileASTNode : public ASTNode
201 CommandFileASTNode();
202 CommandFileASTNode(const CommandFileASTNode & other);
204 virtual std::string nodeName() const { return "CommandFileASTNode"; }
206 virtual ASTNode * clone() const { return new CommandFileASTNode(*this); }
208 virtual void printTree(int indent) const;
210 inline void setBlocks(ListASTNode * blocks) { m_blocks = blocks; }
211 inline void setOptions(ListASTNode * options) { m_options = options; }
212 inline void setConstants(ListASTNode * constants) { m_constants = constants; }
213 inline void setSources(ListASTNode * sources) { m_sources = sources; }
214 inline void setSections(ListASTNode * sections) { m_sections = sections; }
216 inline ListASTNode * getBlocks() { return m_blocks; }
217 inline ListASTNode * getOptions() { return m_options; }
218 inline ListASTNode * getConstants() { return m_constants; }
219 inline ListASTNode * getSources() { return m_sources; }
220 inline ListASTNode * getSections() { return m_sections; }
223 smart_ptr<ListASTNode> m_blocks;
224 smart_ptr<ListASTNode> m_options;
225 smart_ptr<ListASTNode> m_constants;
226 smart_ptr<ListASTNode> m_sources;
227 smart_ptr<ListASTNode> m_sections;
231 * \brief Abstract base class for all expression AST nodes.
233 class ExprASTNode : public ASTNode
236 ExprASTNode() : ASTNode() {}
237 ExprASTNode(const ExprASTNode & other) : ASTNode(other) {}
239 virtual std::string nodeName() const { return "ExprASTNode"; }
241 //! \brief Evaluate the expression and produce a result node to replace this one.
243 //! The default implementation simply return this node unmodified. This
244 //! method is responsible for deleting any nodes that are no longer needed.
245 //! (?) how to delete this?
246 virtual ExprASTNode * reduce(EvalContext & context) { return this; }
248 int_size_t resultIntSize(int_size_t a, int_size_t b);
254 class IntConstExprASTNode : public ExprASTNode
257 IntConstExprASTNode(uint32_t value, int_size_t size=kWordSize)
258 : ExprASTNode(), m_value(value), m_size(size)
262 IntConstExprASTNode(const IntConstExprASTNode & other);
264 virtual std::string nodeName() const { return "IntConstExprASTNode"; }
266 virtual ASTNode * clone() const { return new IntConstExprASTNode(*this); }
268 virtual void printTree(int indent) const;
270 uint32_t getValue() const { return m_value; }
271 int_size_t getSize() const { return m_size; }
281 class VariableExprASTNode : public ExprASTNode
284 VariableExprASTNode(std::string * name) : ExprASTNode(), m_variable(name) {}
285 VariableExprASTNode(const VariableExprASTNode & other);
287 inline std::string * getVariableName() { return m_variable; }
289 virtual ASTNode * clone() const { return new VariableExprASTNode(*this); }
291 virtual std::string nodeName() const { return "VariableExprASTNode"; }
293 virtual void printTree(int indent) const;
295 virtual ExprASTNode * reduce(EvalContext & context);
298 smart_ptr<std::string> m_variable;
302 * \brief Expression node for a symbol reference.
304 * The symbol evaluates to its address.
306 class SymbolRefExprASTNode : public ExprASTNode
309 SymbolRefExprASTNode(SymbolASTNode * sym) : ExprASTNode(), m_symbol(sym) {}
310 SymbolRefExprASTNode(const SymbolRefExprASTNode & other);
312 virtual ASTNode * clone() const { return new SymbolRefExprASTNode(*this); }
314 virtual std::string nodeName() const { return "SymbolRefExprASTNode"; }
316 virtual void printTree(int indent) const;
318 virtual ExprASTNode * reduce(EvalContext & context);
321 SymbolASTNode * m_symbol;
325 * \brief Negates an expression.
327 class NegativeExprASTNode : public ExprASTNode
330 NegativeExprASTNode(ExprASTNode * expr) : ExprASTNode(), m_expr(expr) {}
331 NegativeExprASTNode(const NegativeExprASTNode & other);
333 virtual ASTNode * clone() const { return new NegativeExprASTNode(*this); }
335 virtual std::string nodeName() const { return "NegativeExprASTNode"; }
337 virtual void printTree(int indent) const;
339 virtual ExprASTNode * reduce(EvalContext & context);
341 ExprASTNode * getExpr() { return m_expr; }
344 smart_ptr<ExprASTNode> m_expr;
348 * \brief Performa a boolean inversion.
350 class BooleanNotExprASTNode : public ExprASTNode
353 BooleanNotExprASTNode(ExprASTNode * expr) : ExprASTNode(), m_expr(expr) {}
354 BooleanNotExprASTNode(const BooleanNotExprASTNode & other);
356 virtual ASTNode * clone() const { return new BooleanNotExprASTNode(*this); }
358 virtual std::string nodeName() const { return "BooleanNotExprASTNode"; }
360 virtual void printTree(int indent) const;
362 virtual ExprASTNode * reduce(EvalContext & context);
364 ExprASTNode * getExpr() { return m_expr; }
367 smart_ptr<ExprASTNode> m_expr;
371 * \brief Calls a built-in function with a source as the parameter.
373 class SourceFileFunctionASTNode : public ExprASTNode
376 SourceFileFunctionASTNode(std::string * functionName, std::string * sourceFileName) : ExprASTNode(), m_functionName(functionName), m_sourceFile(sourceFileName) {}
377 SourceFileFunctionASTNode(const SourceFileFunctionASTNode & other);
379 virtual ASTNode * clone() const { return new SourceFileFunctionASTNode(*this); }
381 virtual std::string nodeName() const { return "SourceFileFunctionASTNode"; }
383 virtual void printTree(int indent) const;
385 virtual ExprASTNode * reduce(EvalContext & context);
387 std::string * getFunctionName() { return m_functionName; }
388 std::string * getSourceFile() { return m_sourceFile; }
391 smart_ptr<std::string> m_functionName;
392 smart_ptr<std::string> m_sourceFile;
396 * \brief Returns true or false depending on whether a constant is defined.
398 class DefinedOperatorASTNode : public ExprASTNode
401 DefinedOperatorASTNode(std::string * constantName) : ExprASTNode(), m_constantName(constantName) {}
402 DefinedOperatorASTNode(const DefinedOperatorASTNode & other);
404 virtual ASTNode * clone() const { return new DefinedOperatorASTNode(*this); }
406 virtual std::string nodeName() const { return "DefinedOperatorASTNode"; }
408 virtual void printTree(int indent) const;
410 virtual ExprASTNode * reduce(EvalContext & context);
412 std::string * getConstantName() { return m_constantName; }
415 smart_ptr<std::string> m_constantName; //!< Name of the constant.
421 * \brief Returns an integer that is the size in bytes of the operand.
423 class SizeofOperatorASTNode : public ExprASTNode
426 SizeofOperatorASTNode(std::string * constantName) : ExprASTNode(), m_constantName(constantName), m_symbol() {}
427 SizeofOperatorASTNode(SymbolASTNode * symbol) : ExprASTNode(), m_constantName(), m_symbol(symbol) {}
428 SizeofOperatorASTNode(const SizeofOperatorASTNode & other);
430 virtual ASTNode * clone() const { return new SizeofOperatorASTNode(*this); }
432 virtual std::string nodeName() const { return "SizeofOperatorASTNode"; }
434 virtual void printTree(int indent) const;
436 virtual ExprASTNode * reduce(EvalContext & context);
438 std::string * getConstantName() { return m_constantName; }
439 SymbolASTNode * getSymbol() { return m_symbol; }
442 smart_ptr<std::string> m_constantName; //!< Name of the constant.
443 smart_ptr<SymbolASTNode> m_symbol; //!< Symbol reference. If this is non-NULL then the constant name is used instead.
449 class BinaryOpExprASTNode : public ExprASTNode
475 BinaryOpExprASTNode(ExprASTNode * left, operator_t op, ExprASTNode * right)
476 : ExprASTNode(), m_left(left), m_op(op), m_right(right)
480 BinaryOpExprASTNode(const BinaryOpExprASTNode & other);
482 virtual ASTNode * clone() const { return new BinaryOpExprASTNode(*this); }
484 virtual std::string nodeName() const { return "BinaryOpExprASTNode"; }
486 virtual void printTree(int indent) const;
488 virtual ExprASTNode * reduce(EvalContext & context);
490 ExprASTNode * getLeftExpr() { return m_left; }
491 ExprASTNode * getRightExpr() { return m_right; }
492 operator_t getOp() const { return m_op; }
495 smart_ptr<ExprASTNode> m_left;
496 smart_ptr<ExprASTNode> m_right;
499 std::string getOperatorName() const;
503 * \brief Negates an expression.
505 class IntSizeExprASTNode : public ExprASTNode
508 IntSizeExprASTNode(ExprASTNode * expr, int_size_t intSize) : ExprASTNode(), m_expr(expr), m_size(intSize) {}
509 IntSizeExprASTNode(const IntSizeExprASTNode & other);
511 virtual ASTNode * clone() const { return new IntSizeExprASTNode(*this); }
513 virtual std::string nodeName() const { return "IntSizeExprASTNode"; }
515 virtual void printTree(int indent) const;
517 virtual ExprASTNode * reduce(EvalContext & context);
519 ExprASTNode * getExpr() { return m_expr; }
520 int_size_t getIntSize() { return m_size; }
523 smart_ptr<ExprASTNode> m_expr;
528 * Base class for const AST nodes.
530 class ConstASTNode : public ASTNode
533 ConstASTNode() : ASTNode() {}
534 ConstASTNode(const ConstASTNode & other) : ASTNode(other) {}
542 class ExprConstASTNode : public ConstASTNode
545 ExprConstASTNode(ExprASTNode * expr) : ConstASTNode(), m_expr(expr) {}
546 ExprConstASTNode(const ExprConstASTNode & other);
548 virtual ASTNode * clone() const { return new ExprConstASTNode(*this); }
550 virtual std::string nodeName() const { return "ExprConstASTNode"; }
552 virtual void printTree(int indent) const;
554 ExprASTNode * getExpr() { return m_expr; }
557 smart_ptr<ExprASTNode> m_expr;
563 class StringConstASTNode : public ConstASTNode
566 StringConstASTNode(std::string * value) : ConstASTNode(), m_value(value) {}
567 StringConstASTNode(const StringConstASTNode & other);
569 virtual ASTNode * clone() const { return new StringConstASTNode(*this); }
571 virtual std::string nodeName() const { return "StringConstASTNode"; }
573 virtual void printTree(int indent) const;
575 std::string * getString() { return m_value; }
578 smart_ptr<std::string> m_value;
584 class BlobConstASTNode : public ConstASTNode
587 BlobConstASTNode(Blob * value) : ConstASTNode(), m_blob(value) {}
588 BlobConstASTNode(const BlobConstASTNode & other);
590 virtual ASTNode * clone() const { return new BlobConstASTNode(*this); }
592 virtual std::string nodeName() const { return "BlobConstASTNode"; }
594 virtual void printTree(int indent) const;
596 Blob * getBlob() { return m_blob; }
599 smart_ptr<Blob> m_blob;
602 // Forward declaration.
606 * \brief Node for a constant IVT structure as used by HAB4.
608 class IVTConstASTNode : public ConstASTNode
611 IVTConstASTNode() : ConstASTNode(), m_fields() {}
612 IVTConstASTNode(const IVTConstASTNode & other);
614 virtual ASTNode * clone() const { return new IVTConstASTNode(*this); }
616 virtual std::string nodeName() const { return "IVTConstASTNode"; }
618 virtual void printTree(int indent) const;
620 void setFieldAssignments(ListASTNode * fields) { m_fields = fields; }
621 ListASTNode * getFieldAssignments() { return m_fields; }
624 //! Fields of the IVT are set through assignment statements.
625 smart_ptr<ListASTNode> m_fields;
631 class AssignmentASTNode : public ASTNode
634 AssignmentASTNode(std::string * ident, ASTNode * value)
635 : ASTNode(), m_ident(ident), m_value(value)
639 AssignmentASTNode(const AssignmentASTNode & other);
641 virtual ASTNode * clone() const { return new AssignmentASTNode(*this); }
643 virtual std::string nodeName() const { return "AssignmentASTNode"; }
645 virtual void printTree(int indent) const;
647 inline std::string * getIdent() { return m_ident; }
648 inline ASTNode * getValue() { return m_value; }
651 smart_ptr<std::string> m_ident;
652 smart_ptr<ASTNode> m_value;
656 * Base class for PathSourceDefASTNode and ExternSourceDefASTNode.
658 class SourceDefASTNode : public ASTNode
661 SourceDefASTNode(std::string * name) : m_name(name) {}
662 SourceDefASTNode(const SourceDefASTNode & other);
664 inline std::string * getName() { return m_name; }
666 inline void setAttributes(ListASTNode * attributes) { m_attributes = attributes; }
667 inline ListASTNode * getAttributes() { return m_attributes; }
670 smart_ptr<std::string> m_name;
671 smart_ptr<ListASTNode> m_attributes;
677 class PathSourceDefASTNode : public SourceDefASTNode
680 PathSourceDefASTNode(std::string * name, std::string * path)
681 : SourceDefASTNode(name), m_path(path)
685 PathSourceDefASTNode(const PathSourceDefASTNode & other);
687 virtual PathSourceDefASTNode * clone() const { return new PathSourceDefASTNode(*this); }
689 virtual std::string nodeName() const { return "PathSourceDefASTNode"; }
691 virtual void printTree(int indent) const;
693 std::string * getPath() { return m_path; }
696 smart_ptr<std::string> m_path;
702 class ExternSourceDefASTNode : public SourceDefASTNode
705 ExternSourceDefASTNode(std::string * name, ExprASTNode * expr)
706 : SourceDefASTNode(name), m_expr(expr)
710 ExternSourceDefASTNode(const ExternSourceDefASTNode & other);
712 virtual ASTNode * clone() const { return new ExternSourceDefASTNode(*this); }
714 virtual std::string nodeName() const { return "ExternSourceDefASTNode"; }
716 virtual void printTree(int indent) const;
718 ExprASTNode * getSourceNumberExpr() { return m_expr; }
721 smart_ptr<ExprASTNode> m_expr;
727 class SectionContentsASTNode : public ASTNode
730 SectionContentsASTNode() : m_sectionExpr() {}
731 SectionContentsASTNode(ExprASTNode * section) : m_sectionExpr(section) {}
732 SectionContentsASTNode(const SectionContentsASTNode & other);
734 virtual ASTNode * clone() const { return new SectionContentsASTNode(*this); }
736 virtual std::string nodeName() const { return "SectionContentsASTNode"; }
738 virtual void printTree(int indent) const;
740 inline void setSectionNumberExpr(ExprASTNode * section)
742 m_sectionExpr = section;
745 inline ExprASTNode * getSectionNumberExpr()
747 return m_sectionExpr;
750 inline void setOptions(ListASTNode * options)
755 inline ListASTNode * getOptions()
761 smart_ptr<ExprASTNode> m_sectionExpr;
762 smart_ptr<ListASTNode> m_options;
766 * @brief Node representing a raw binary section definition.
768 class DataSectionContentsASTNode : public SectionContentsASTNode
771 DataSectionContentsASTNode(ASTNode * contents)
772 : SectionContentsASTNode(), m_contents(contents)
776 DataSectionContentsASTNode(const DataSectionContentsASTNode & other);
778 virtual ASTNode * clone() const { return new DataSectionContentsASTNode(*this); }
780 virtual std::string nodeName() const { return "DataSectionContentsASTNode"; }
782 virtual void printTree(int indent) const;
784 ASTNode * getContents() { return m_contents; }
787 smart_ptr<ASTNode> m_contents;
793 class BootableSectionContentsASTNode : public SectionContentsASTNode
796 BootableSectionContentsASTNode(ListASTNode * statements)
797 : SectionContentsASTNode(), m_statements(statements)
801 BootableSectionContentsASTNode(const BootableSectionContentsASTNode & other);
803 virtual ASTNode * clone() const { return new BootableSectionContentsASTNode(*this); }
805 virtual std::string nodeName() const { return "BootableSectionContentsASTNode"; }
807 virtual void printTree(int indent) const;
809 ListASTNode * getStatements() { return m_statements; }
812 smart_ptr<ListASTNode> m_statements;
818 class StatementASTNode : public ASTNode
821 StatementASTNode() : ASTNode() {}
822 StatementASTNode(const StatementASTNode & other) : ASTNode(other) {}
830 class IfStatementASTNode : public StatementASTNode
833 IfStatementASTNode() : StatementASTNode(), m_ifStatements(), m_nextIf(), m_elseStatements() {}
834 IfStatementASTNode(const IfStatementASTNode & other);
836 virtual ASTNode * clone() const { return new IfStatementASTNode(*this); }
838 void setConditionExpr(ExprASTNode * expr) { m_conditionExpr = expr; }
839 ExprASTNode * getConditionExpr() { return m_conditionExpr; }
841 void setIfStatements(ListASTNode * statements) { m_ifStatements = statements; }
842 ListASTNode * getIfStatements() { return m_ifStatements; }
844 void setNextIf(IfStatementASTNode * nextIf) { m_nextIf = nextIf; }
845 IfStatementASTNode * getNextIf() { return m_nextIf; }
847 void setElseStatements(ListASTNode * statements) { m_elseStatements = statements; }
848 ListASTNode * getElseStatements() { return m_elseStatements; }
851 smart_ptr<ExprASTNode> m_conditionExpr; //!< Boolean expression.
852 smart_ptr<ListASTNode> m_ifStatements; //!< List of "if" section statements.
853 smart_ptr<IfStatementASTNode> m_nextIf; //!< Link to next "else if". If this is non-NULL then #m_elseStatements must be NULL and vice-versa.
854 smart_ptr<ListASTNode> m_elseStatements; //!< Statements for the "else" part of the statements.
858 * \brief Statement to insert a ROM_MODE_CMD command.
860 class ModeStatementASTNode : public StatementASTNode
863 ModeStatementASTNode() : StatementASTNode(), m_modeExpr() {}
864 ModeStatementASTNode(ExprASTNode * modeExpr) : StatementASTNode(), m_modeExpr(modeExpr) {}
865 ModeStatementASTNode(const ModeStatementASTNode & other);
867 virtual ASTNode * clone() const { return new ModeStatementASTNode(*this); }
869 virtual std::string nodeName() const { return "ModeStatementASTNode"; }
871 virtual void printTree(int indent) const;
873 inline void setModeExpr(ExprASTNode * modeExpr) { m_modeExpr = modeExpr; }
874 inline ExprASTNode * getModeExpr() { return m_modeExpr; }
877 smart_ptr<ExprASTNode> m_modeExpr; //!< Expression that evaluates to the new boot mode.
881 * \brief Statement to print a message to the elftosb user.
883 class MessageStatementASTNode : public StatementASTNode
888 kInfo, //!< Prints an informational messag to the user.
889 kWarning, //!< Prints a warning to the user.
890 kError //!< Throws an error exception.
893 typedef enum _message_type message_type_t;
896 MessageStatementASTNode(message_type_t messageType, std::string * message) : StatementASTNode(), m_type(messageType), m_message(message) {}
897 MessageStatementASTNode(const MessageStatementASTNode & other);
899 virtual ASTNode * clone() const { return new MessageStatementASTNode(*this); }
901 virtual std::string nodeName() const { return "MessageStatementASTNode"; }
903 virtual void printTree(int indent) const;
905 inline message_type_t getType() { return m_type; }
906 inline std::string * getMessage() { return m_message; }
908 const char * getTypeName() const;
911 message_type_t m_type;
912 smart_ptr<std::string> m_message; //!< Message to report.
916 * \brief AST node for a load statement.
918 class LoadStatementASTNode : public StatementASTNode
921 LoadStatementASTNode()
922 : StatementASTNode(), m_data(), m_target(), m_isDCDLoad(false)
926 LoadStatementASTNode(ASTNode * data, ASTNode * target)
927 : StatementASTNode(), m_data(data), m_target(), m_isDCDLoad(false)
931 LoadStatementASTNode(const LoadStatementASTNode & other);
933 virtual ASTNode * clone() const { return new LoadStatementASTNode(*this); }
935 virtual std::string nodeName() const { return "LoadStatementASTNode"; }
937 virtual void printTree(int indent) const;
939 inline void setData(ASTNode * data) { m_data = data; }
940 inline ASTNode * getData() { return m_data; }
942 inline void setTarget(ASTNode * target) { m_target = target; }
943 inline ASTNode * getTarget() { return m_target; }
945 inline void setDCDLoad(bool isDCD) { m_isDCDLoad = isDCD; }
946 inline bool isDCDLoad() const { return m_isDCDLoad; }
949 smart_ptr<ASTNode> m_data;
950 smart_ptr<ASTNode> m_target;
955 * \brief AST node for a call statement.
957 class CallStatementASTNode : public StatementASTNode
960 //! Possible sub-types of call statements.
967 CallStatementASTNode(call_type_t callType=kCallType)
968 : StatementASTNode(), m_type(callType), m_target(), m_arg(), m_isHAB(false)
972 CallStatementASTNode(call_type_t callType, ASTNode * target, ASTNode * arg)
973 : StatementASTNode(), m_type(callType), m_target(target), m_arg(arg), m_isHAB(false)
977 CallStatementASTNode(const CallStatementASTNode & other);
979 virtual ASTNode * clone() const { return new CallStatementASTNode(*this); }
981 virtual std::string nodeName() const { return "CallStatementASTNode"; }
983 virtual void printTree(int indent) const;
985 inline void setCallType(call_type_t callType) { m_type = callType; }
986 inline call_type_t getCallType() { return m_type; }
988 inline void setTarget(ASTNode * target) { m_target = target; }
989 inline ASTNode * getTarget() { return m_target; }
991 inline void setArgument(ASTNode * arg) { m_arg = arg; }
992 inline ASTNode * getArgument() { return m_arg; }
994 inline void setIsHAB(bool isHAB) { m_isHAB = isHAB; }
995 inline bool isHAB() const { return m_isHAB; }
999 smart_ptr<ASTNode> m_target; //!< This becomes the IVT address in HAB mode.
1000 smart_ptr<ASTNode> m_arg;
1007 class SourceASTNode : public ASTNode
1010 SourceASTNode(std::string * name) : ASTNode(), m_name(name) {}
1011 SourceASTNode(const SourceASTNode & other);
1013 virtual ASTNode * clone() const { return new SourceASTNode(*this); }
1015 virtual std::string nodeName() const { return "SourceASTNode"; }
1017 virtual void printTree(int indent) const;
1019 inline std::string * getSourceName() { return m_name; }
1022 smart_ptr<std::string> m_name;
1026 * \brief List of section matches for a particular source name.
1028 class SectionMatchListASTNode : public ASTNode
1031 SectionMatchListASTNode(ListASTNode * sections)
1032 : ASTNode(), m_sections(sections), m_source()
1036 SectionMatchListASTNode(ListASTNode * sections, std::string * source)
1037 : ASTNode(), m_sections(sections), m_source(source)
1041 SectionMatchListASTNode(const SectionMatchListASTNode & other);
1043 virtual ASTNode * clone() const { return new SectionMatchListASTNode(*this); }
1045 virtual std::string nodeName() const { return "SectionMatchListASTNode"; }
1047 virtual void printTree(int indent) const;
1049 inline ListASTNode * getSections() { return m_sections; }
1050 inline std::string * getSourceName() { return m_source; }
1053 smart_ptr<ListASTNode> m_sections;
1054 smart_ptr<std::string> m_source;
1058 * \brief AST node for a section glob.
1060 * Can be assigned an include or exclude action for when this node is part of a
1061 * SectionMatchListASTNode.
1063 class SectionASTNode : public ASTNode
1066 //! Possible actions for a section match list.
1069 kInclude, //!< Include sections matched by this node.
1070 kExclude //!< Exclude sections matched by this node.
1074 SectionASTNode(std::string * name)
1075 : ASTNode(), m_action(kInclude), m_name(name), m_source()
1079 SectionASTNode(std::string * name, match_action_t action)
1080 : ASTNode(), m_action(action), m_name(name), m_source()
1084 SectionASTNode(std::string * name, std::string * source)
1085 : ASTNode(), m_action(kInclude), m_name(name), m_source(source)
1089 SectionASTNode(const SectionASTNode & other);
1091 virtual ASTNode * clone() const { return new SectionASTNode(*this); }
1093 virtual std::string nodeName() const { return "SectionASTNode"; }
1095 virtual void printTree(int indent) const;
1097 inline match_action_t getAction() { return m_action; }
1098 inline std::string * getSectionName() { return m_name; }
1099 inline std::string * getSourceName() { return m_source; }
1102 match_action_t m_action;
1103 smart_ptr<std::string> m_name;
1104 smart_ptr<std::string> m_source;
1110 class SymbolASTNode : public ASTNode
1114 : ASTNode(), m_symbol(), m_source()
1118 SymbolASTNode(std::string * symbol, std::string * source=0)
1119 : ASTNode(), m_symbol(symbol), m_source(source)
1123 SymbolASTNode(const SymbolASTNode & other);
1125 virtual ASTNode * clone() const { return new SymbolASTNode(*this); }
1127 virtual std::string nodeName() const { return "SymbolASTNode"; }
1129 virtual void printTree(int indent) const;
1131 inline void setSymbolName(std::string * symbol) { m_symbol = symbol; }
1132 inline std::string * getSymbolName() { return m_symbol; }
1134 inline void setSource(std::string * source) { m_source = source; }
1135 inline std::string * getSource() { return m_source; }
1138 smart_ptr<std::string> m_symbol; //!< Required.
1139 smart_ptr<std::string> m_source; //!< Optional, may be NULL;
1143 * If the end of the range is NULL, then only a single address was specified.
1145 class AddressRangeASTNode : public ASTNode
1148 AddressRangeASTNode()
1149 : ASTNode(), m_begin(), m_end()
1153 AddressRangeASTNode(ASTNode * begin, ASTNode * end)
1154 : ASTNode(), m_begin(begin), m_end(end)
1158 AddressRangeASTNode(const AddressRangeASTNode & other);
1160 virtual ASTNode * clone() const { return new AddressRangeASTNode(*this); }
1162 virtual std::string nodeName() const { return "AddressRangeASTNode"; }
1164 virtual void printTree(int indent) const;
1166 inline void setBegin(ASTNode * begin) { m_begin = begin; }
1167 inline ASTNode * getBegin() { return m_begin; }
1169 inline void setEnd(ASTNode * end) { m_end = end; }
1170 inline ASTNode * getEnd() { return m_end; }
1173 smart_ptr<ASTNode> m_begin;
1174 smart_ptr<ASTNode> m_end;
1180 class NaturalLocationASTNode : public ASTNode
1183 NaturalLocationASTNode()
1188 NaturalLocationASTNode(const NaturalLocationASTNode & other)
1193 virtual ASTNode * clone() const { return new NaturalLocationASTNode(*this); }
1195 virtual std::string nodeName() const { return "NaturalLocationASTNode"; }
1201 class FromStatementASTNode : public StatementASTNode
1204 FromStatementASTNode() : StatementASTNode() {}
1205 FromStatementASTNode(std::string * source, ListASTNode * statements);
1206 FromStatementASTNode(const FromStatementASTNode & other);
1208 virtual ASTNode * clone() const { return new FromStatementASTNode(*this); }
1210 virtual std::string nodeName() const { return "FromStatementASTNode"; }
1212 virtual void printTree(int indent) const;
1214 inline void setSourceName(std::string * source) { m_source = source; }
1215 inline std::string * getSourceName() { return m_source; }
1217 inline void setStatements(ListASTNode * statements) { m_statements = statements; }
1218 inline ListASTNode * getStatements() { return m_statements; }
1221 smart_ptr<std::string> m_source;
1222 smart_ptr<ListASTNode> m_statements;
1225 }; // namespace elftosb
1227 #endif // _ElftosbAST_h_