4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
8 #include "ElftosbAST.h"
12 #include "ElftosbErrors.h"
13 #include "format_string.h"
15 using namespace elftosb;
17 #pragma mark = ASTNode =
19 void ASTNode::printTree(int indent) const
22 printf("%s\n", nodeName().c_str());
25 void ASTNode::printIndent(int indent) const
28 for (i=0; i<indent; ++i)
34 void ASTNode::setLocation(token_loc_t & first, token_loc_t & last)
36 m_location.m_firstLine = first.m_firstLine;
37 m_location.m_lastLine = last.m_lastLine;
40 void ASTNode::setLocation(ASTNode * first, ASTNode * last)
42 m_location.m_firstLine = first->getLocation().m_firstLine;
43 m_location.m_lastLine = last->getLocation().m_lastLine;
46 #pragma mark = ListASTNode =
48 ListASTNode::ListASTNode(const ListASTNode & other)
49 : ASTNode(other), m_list()
51 // deep copy each item of the original's list
52 const_iterator it = other.begin();
53 for (; it != other.end(); ++it)
55 m_list.push_back((*it)->clone());
59 //! Deletes child node in the list.
61 ListASTNode::~ListASTNode()
63 iterator it = begin();
64 for (; it != end(); it++)
70 //! If \a node is NULL then the list is left unmodified.
72 //! The list node's location is automatically updated after the node is added by a call
73 //! to updateLocation().
74 void ListASTNode::appendNode(ASTNode * node)
78 m_list.push_back(node);
83 void ListASTNode::printTree(int indent) const
85 ASTNode::printTree(indent);
88 const_iterator it = begin();
89 for (; it != end(); it++, n++)
91 printIndent(indent + 1);
93 (*it)->printTree(indent + 2);
97 void ListASTNode::updateLocation()
99 token_loc_t current = { 0 };
100 const_iterator it = begin();
101 for (; it != end(); it++)
103 const ASTNode * node = *it;
104 const token_loc_t & loc = node->getLocation();
107 if (current.m_firstLine == 0)
113 if (loc.m_firstLine < current.m_firstLine)
115 current.m_firstLine = loc.m_firstLine;
118 if (loc.m_lastLine > current.m_lastLine)
120 current.m_lastLine = loc.m_lastLine;
124 setLocation(current);
127 #pragma mark = CommandFileASTNode =
129 CommandFileASTNode::CommandFileASTNode()
130 : ASTNode(), m_options(), m_constants(), m_sources(), m_sections()
134 CommandFileASTNode::CommandFileASTNode(const CommandFileASTNode & other)
135 : ASTNode(other), m_options(), m_constants(), m_sources(), m_sections()
137 m_options = dynamic_cast<ListASTNode*>(other.m_options->clone());
138 m_constants = dynamic_cast<ListASTNode*>(other.m_constants->clone());
139 m_sources = dynamic_cast<ListASTNode*>(other.m_sources->clone());
140 m_sections = dynamic_cast<ListASTNode*>(other.m_sections->clone());
143 void CommandFileASTNode::printTree(int indent) const
145 ASTNode::printTree(indent);
147 printIndent(indent + 1);
148 printf("options:\n");
149 if (m_options) m_options->printTree(indent + 2);
151 printIndent(indent + 1);
152 printf("constants:\n");
153 if (m_constants) m_constants->printTree(indent + 2);
155 printIndent(indent + 1);
156 printf("sources:\n");
157 if (m_sources) m_sources->printTree(indent + 2);
159 printIndent(indent + 1);
160 printf("sections:\n");
161 if (m_sections) m_sections->printTree(indent + 2);
164 #pragma mark = ExprASTNode =
166 int_size_t ExprASTNode::resultIntSize(int_size_t a, int_size_t b)
181 result = kHalfWordSize;
189 else if (b == kHalfWordSize)
191 result = kHalfWordSize;
203 #pragma mark = IntConstExprASTNode =
205 IntConstExprASTNode::IntConstExprASTNode(const IntConstExprASTNode & other)
206 : ExprASTNode(other), m_value(other.m_value), m_size(other.m_size)
210 void IntConstExprASTNode::printTree(int indent) const
226 printf("%s(%d:%c)\n", nodeName().c_str(), m_value, sizeChar);
229 #pragma mark = VariableExprASTNode =
231 VariableExprASTNode::VariableExprASTNode(const VariableExprASTNode & other)
232 : ExprASTNode(other), m_variable()
234 m_variable = new std::string(*other.m_variable);
237 void VariableExprASTNode::printTree(int indent) const
240 printf("%s(%s)\n", nodeName().c_str(), m_variable->c_str());
243 ExprASTNode * VariableExprASTNode::reduce(EvalContext & context)
245 if (!context.isVariableDefined(*m_variable))
247 throw std::runtime_error(format_string("line %d: undefined variable '%s'", getFirstLine(), m_variable->c_str()));
250 uint32_t value = context.getVariableValue(*m_variable);
251 int_size_t size = context.getVariableSize(*m_variable);
252 return new IntConstExprASTNode(value, size);
255 #pragma mark = SymbolRefExprASTNode =
257 SymbolRefExprASTNode::SymbolRefExprASTNode(const SymbolRefExprASTNode & other)
258 : ExprASTNode(other), m_symbol(NULL)
262 m_symbol = dynamic_cast<SymbolASTNode*>(other.m_symbol->clone());
266 void SymbolRefExprASTNode::printTree(int indent) const
270 ExprASTNode * SymbolRefExprASTNode::reduce(EvalContext & context)
272 EvalContext::SourceFileManager * manager = context.getSourceFileManager();
275 throw std::runtime_error("no source manager available");
280 throw semantic_error("no symbol provided");
283 // Get the name of the symbol
284 std::string * symbolName = m_symbol->getSymbolName();
287 // throw semantic_error(format_string("line %d: no symbol name provided", getFirstLine()));
290 // Get the source file.
291 std::string * sourceName = m_symbol->getSource();
292 SourceFile * sourceFile;
296 sourceFile = manager->getSourceFile(*sourceName);
299 throw semantic_error(format_string("line %d: no source file named %s", getFirstLine(), sourceName->c_str()));
304 sourceFile = manager->getDefaultSourceFile();
307 throw semantic_error(format_string("line %d: no default source file is set", getFirstLine()));
311 // open the file if it hasn't already been
312 if (!sourceFile->isOpen())
317 // Make sure the source file supports symbols before going any further
318 if (symbolName && !sourceFile->supportsNamedSymbols())
320 throw semantic_error(format_string("line %d: source file %s does not support symbols", getFirstLine(), sourceFile->getPath().c_str()));
323 if (!symbolName && !sourceFile->hasEntryPoint())
325 throw semantic_error(format_string("line %d: source file %s does not have an entry point", getFirstLine(), sourceFile->getPath().c_str()));
328 // Returns a const expr node with the symbol's value.
332 value = sourceFile->getSymbolValue(*symbolName);
336 value = sourceFile->getEntryPointAddress();
338 return new IntConstExprASTNode(value);
341 #pragma mark = NegativeExprASTNode =
343 NegativeExprASTNode::NegativeExprASTNode(const NegativeExprASTNode & other)
344 : ExprASTNode(other), m_expr()
346 m_expr = dynamic_cast<ExprASTNode*>(other.m_expr->clone());
349 void NegativeExprASTNode::printTree(int indent) const
351 ExprASTNode::printTree(indent);
352 if (m_expr) m_expr->printTree(indent + 1);
355 ExprASTNode * NegativeExprASTNode::reduce(EvalContext & context)
362 m_expr = m_expr->reduce(context);
363 IntConstExprASTNode * intConst = dynamic_cast<IntConstExprASTNode*>(m_expr.get());
366 int32_t value = -(int32_t)intConst->getValue();
367 return new IntConstExprASTNode((uint32_t)value, intConst->getSize());
375 #pragma mark = BooleanNotExprASTNode =
377 BooleanNotExprASTNode::BooleanNotExprASTNode(const BooleanNotExprASTNode & other)
378 : ExprASTNode(other), m_expr()
380 m_expr = dynamic_cast<ExprASTNode*>(other.m_expr->clone());
383 void BooleanNotExprASTNode::printTree(int indent) const
385 ExprASTNode::printTree(indent);
386 if (m_expr) m_expr->printTree(indent + 1);
389 ExprASTNode * BooleanNotExprASTNode::reduce(EvalContext & context)
396 m_expr = m_expr->reduce(context);
397 IntConstExprASTNode * intConst = dynamic_cast<IntConstExprASTNode*>(m_expr.get());
400 int32_t value = !((int32_t)intConst->getValue());
401 return new IntConstExprASTNode((uint32_t)value, intConst->getSize());
405 throw semantic_error(format_string("line %d: expression did not evaluate to an integer", m_expr->getFirstLine()));
409 #pragma mark = SourceFileFunctionASTNode =
411 SourceFileFunctionASTNode::SourceFileFunctionASTNode(const SourceFileFunctionASTNode & other)
412 : ExprASTNode(other), m_functionName(), m_sourceFile()
414 m_functionName = new std::string(*other.m_functionName);
415 m_sourceFile = new std::string(*other.m_sourceFile);
418 void SourceFileFunctionASTNode::printTree(int indent) const
420 ExprASTNode::printTree(indent);
421 printIndent(indent+1);
423 // for some stupid reason the msft C++ compiler barfs on the following line if the ".get()" parts are remove,
424 // even though the first line of reduce() below has the same expression, just in parentheses. stupid compiler.
425 if (m_functionName.get() && m_sourceFile.get())
427 printf("%s ( %s )\n", m_functionName->c_str(), m_sourceFile->c_str());
431 ExprASTNode * SourceFileFunctionASTNode::reduce(EvalContext & context)
433 if (!(m_functionName && m_sourceFile))
435 throw std::runtime_error("unset function name or source file");
438 // Get source file manager from evaluation context. This will be the
439 // conversion controller itself.
440 EvalContext::SourceFileManager * mgr = context.getSourceFileManager();
443 throw std::runtime_error("source file manager is not set");
447 uint32_t functionResult = 0;
448 if (*m_functionName == "exists")
450 functionResult = static_cast<uint32_t>(mgr->hasSourceFile(*m_sourceFile));
453 // Return function result as an expression node
454 return new IntConstExprASTNode(functionResult);
457 #pragma mark = DefinedOperatorASTNode =
459 DefinedOperatorASTNode::DefinedOperatorASTNode(const DefinedOperatorASTNode & other)
460 : ExprASTNode(other), m_constantName()
462 m_constantName = new std::string(*other.m_constantName);
465 void DefinedOperatorASTNode::printTree(int indent) const
467 ExprASTNode::printTree(indent);
468 printIndent(indent+1);
472 printf("defined ( %s )\n", m_constantName->c_str());
476 ExprASTNode * DefinedOperatorASTNode::reduce(EvalContext & context)
478 assert(m_constantName);
480 // Return function result as an expression node
481 return new IntConstExprASTNode(context.isVariableDefined(m_constantName) ? 1 : 0);
484 #pragma mark = SizeofOperatorASTNode =
486 SizeofOperatorASTNode::SizeofOperatorASTNode(const SizeofOperatorASTNode & other)
487 : ExprASTNode(other), m_constantName(), m_symbol()
489 m_constantName = new std::string(*other.m_constantName);
490 m_symbol = dynamic_cast<SymbolASTNode*>(other.m_symbol->clone());
493 void SizeofOperatorASTNode::printTree(int indent) const
495 ExprASTNode::printTree(indent);
497 printIndent(indent+1);
501 printf("sizeof: %s\n", m_constantName->c_str());
506 m_symbol->printTree(indent + 2);
510 ExprASTNode * SizeofOperatorASTNode::reduce(EvalContext & context)
512 // One or the other must be defined.
513 assert(m_constantName || m_symbol);
515 EvalContext::SourceFileManager * manager = context.getSourceFileManager();
518 unsigned sizeInBytes = 0;
519 SourceFile * sourceFile;
523 // Get the symbol name.
524 std::string * symbolName = m_symbol->getSymbolName();
527 // Get the source file, using the default if one is not specified.
528 std::string * sourceName = m_symbol->getSource();
531 sourceFile = manager->getSourceFile(*sourceName);
534 throw semantic_error(format_string("line %d: invalid source file: %s", getFirstLine(), sourceName->c_str()));
539 sourceFile = manager->getDefaultSourceFile();
542 throw semantic_error(format_string("line %d: no default source file is set", getFirstLine()));
546 // Get the size of the symbol.
547 if (sourceFile->hasSymbol(*symbolName))
549 sizeInBytes = sourceFile->getSymbolSize(*symbolName);
552 else if (m_constantName)
554 // See if the "constant" is really a constant or if it's a source name.
555 if (manager->hasSourceFile(m_constantName))
557 sourceFile = manager->getSourceFile(m_constantName);
560 sizeInBytes = sourceFile->getSize();
566 if (!context.isVariableDefined(*m_constantName))
568 throw semantic_error(format_string("line %d: cannot get size of undefined constant %s", getFirstLine(), m_constantName->c_str()));
571 int_size_t intSize = context.getVariableSize(*m_constantName);
575 sizeInBytes = sizeof(uint32_t);
578 sizeInBytes = sizeof(uint16_t);
581 sizeInBytes = sizeof(uint8_t);
587 // Return function result as an expression node
588 return new IntConstExprASTNode(sizeInBytes);
591 #pragma mark = BinaryOpExprASTNode =
593 BinaryOpExprASTNode::BinaryOpExprASTNode(const BinaryOpExprASTNode & other)
594 : ExprASTNode(other), m_left(), m_op(other.m_op), m_right()
596 m_left = dynamic_cast<ExprASTNode*>(other.m_left->clone());
597 m_right = dynamic_cast<ExprASTNode*>(other.m_right->clone());
600 void BinaryOpExprASTNode::printTree(int indent) const
602 ExprASTNode::printTree(indent);
604 printIndent(indent + 1);
606 if (m_left) m_left->printTree(indent + 2);
608 printIndent(indent + 1);
609 printf("op: %s\n", getOperatorName().c_str());
611 printIndent(indent + 1);
613 if (m_right) m_right->printTree(indent + 2);
616 std::string BinaryOpExprASTNode::getOperatorName() const
648 case kGreaterThanEqual:
663 //! \todo Fix power operator under windows!!!
665 ExprASTNode * BinaryOpExprASTNode::reduce(EvalContext & context)
667 if (!m_left || !m_right)
672 IntConstExprASTNode * leftIntConst = NULL;
673 IntConstExprASTNode * rightIntConst = NULL;
678 // Always reduce the left hand side.
679 m_left = m_left->reduce(context);
680 leftIntConst = dynamic_cast<IntConstExprASTNode*>(m_left.get());
683 throw semantic_error(format_string("left hand side of %s operator failed to evaluate to an integer", getOperatorName().c_str()));
685 leftValue = leftIntConst->getValue();
687 // Boolean && and || operators are handled separately so that we can perform
688 // short-circuit evaluation.
689 if (m_op == kBooleanAnd || m_op == kBooleanOr)
691 // Reduce right hand side only if required to evaluate the boolean operator.
692 if ((m_op == kBooleanAnd && leftValue != 0) || (m_op == kBooleanOr && leftValue == 0))
694 m_right = m_right->reduce(context);
695 rightIntConst = dynamic_cast<IntConstExprASTNode*>(m_right.get());
698 throw semantic_error(format_string("right hand side of %s operator failed to evaluate to an integer", getOperatorName().c_str()));
700 rightValue = rightIntConst->getValue();
702 // Perform the boolean operation.
706 result = leftValue && rightValue;
710 result = leftValue && rightValue;
714 else if (m_op == kBooleanAnd)
716 // The left hand side is false, so the && operator's result must be false
717 // without regard to the right hand side.
720 else if (m_op == kBooleanOr)
722 // The left hand value is true so the || result is automatically true.
728 // Reduce right hand side always for most operators.
729 m_right = m_right->reduce(context);
730 rightIntConst = dynamic_cast<IntConstExprASTNode*>(m_right.get());
733 throw semantic_error(format_string("right hand side of %s operator failed to evaluate to an integer", getOperatorName().c_str()));
735 rightValue = rightIntConst->getValue();
740 result = leftValue + rightValue;
743 result = leftValue - rightValue;
746 result = leftValue * rightValue;
749 result = leftValue / rightValue;
752 result = leftValue % rightValue;
758 result = lroundf(powf(float(leftValue), float(rightValue)));
762 result = leftValue & rightValue;
765 result = leftValue | rightValue;
768 result = leftValue ^ rightValue;
771 result = leftValue << rightValue;
774 result = leftValue >> rightValue;
777 result = leftValue < rightValue;
780 result = leftValue > rightValue;
783 result = leftValue <= rightValue;
785 case kGreaterThanEqual:
786 result = leftValue >= rightValue;
789 result = leftValue == rightValue;
792 result = leftValue != rightValue;
797 // Create the result value.
798 int_size_t resultSize;
799 if (leftIntConst && rightIntConst)
801 resultSize = resultIntSize(leftIntConst->getSize(), rightIntConst->getSize());
803 else if (leftIntConst)
805 resultSize = leftIntConst->getSize();
809 // This shouldn't really be possible, but just in case.
810 resultSize = kWordSize;
812 return new IntConstExprASTNode(result, resultSize);
815 #pragma mark = IntSizeExprASTNode =
817 IntSizeExprASTNode::IntSizeExprASTNode(const IntSizeExprASTNode & other)
818 : ExprASTNode(other), m_expr(), m_size(other.m_size)
820 m_expr = dynamic_cast<ExprASTNode*>(other.m_expr->clone());
823 void IntSizeExprASTNode::printTree(int indent) const
825 ExprASTNode::printTree(indent);
840 printIndent(indent + 1);
841 printf("size: %c\n", sizeChar);
843 printIndent(indent + 1);
845 if (m_expr) m_expr->printTree(indent + 2);
848 ExprASTNode * IntSizeExprASTNode::reduce(EvalContext & context)
855 m_expr = m_expr->reduce(context);
856 IntConstExprASTNode * intConst = dynamic_cast<IntConstExprASTNode*>(m_expr.get());
862 return new IntConstExprASTNode(intConst->getValue(), m_size);
865 #pragma mark = ExprConstASTNode =
867 ExprConstASTNode::ExprConstASTNode(const ExprConstASTNode & other)
868 : ConstASTNode(other), m_expr()
870 m_expr = dynamic_cast<ExprASTNode*>(other.m_expr->clone());
873 void ExprConstASTNode::printTree(int indent) const
875 ConstASTNode::printTree(indent);
876 if (m_expr) m_expr->printTree(indent + 1);
879 #pragma mark = StringConstASTNode =
881 StringConstASTNode::StringConstASTNode(const StringConstASTNode & other)
882 : ConstASTNode(other), m_value()
884 m_value = new std::string(other.m_value);
887 void StringConstASTNode::printTree(int indent) const
890 printf("%s(%s)\n", nodeName().c_str(), m_value->c_str());
893 #pragma mark = BlobConstASTNode =
895 BlobConstASTNode::BlobConstASTNode(const BlobConstASTNode & other)
896 : ConstASTNode(other), m_blob()
898 m_blob = new Blob(*other.m_blob);
901 void BlobConstASTNode::printTree(int indent) const
905 const uint8_t * dataPtr = m_blob->getData();
906 unsigned dataLen = m_blob->getLength();
907 printf("%s(%p:%d)\n", nodeName().c_str(), dataPtr, dataLen);
910 #pragma mark = IVTConstASTNode =
912 IVTConstASTNode::IVTConstASTNode(const IVTConstASTNode & other)
913 : ConstASTNode(other), m_fields()
915 m_fields = dynamic_cast<ListASTNode*>(other.m_fields->clone());
918 void IVTConstASTNode::printTree(int indent) const
921 printf("%s:\n", nodeName().c_str());
924 m_fields->printTree(indent + 1);
928 #pragma mark = AssignmentASTNode =
930 AssignmentASTNode::AssignmentASTNode(const AssignmentASTNode & other)
931 : ASTNode(other), m_ident(), m_value()
933 m_ident = new std::string(*other.m_ident);
934 m_value = dynamic_cast<ConstASTNode*>(other.m_value->clone());
937 void AssignmentASTNode::printTree(int indent) const
940 printf("%s(%s)\n", nodeName().c_str(), m_ident->c_str());
942 if (m_value) m_value->printTree(indent + 1);
945 #pragma mark = SourceDefASTNode =
947 SourceDefASTNode::SourceDefASTNode(const SourceDefASTNode & other)
948 : ASTNode(other), m_name()
950 m_name = new std::string(*other.m_name);
953 #pragma mark = PathSourceDefASTNode =
955 PathSourceDefASTNode::PathSourceDefASTNode(const PathSourceDefASTNode & other)
956 : SourceDefASTNode(other), m_path()
958 m_path = new std::string(*other.m_path);
961 void PathSourceDefASTNode::printTree(int indent) const
963 SourceDefASTNode::printTree(indent);
965 printIndent(indent+1);
966 printf("path: %s\n", m_path->c_str());
968 printIndent(indent+1);
969 printf("attributes:\n");
972 m_attributes->printTree(indent+2);
976 #pragma mark = ExternSourceDefASTNode =
978 ExternSourceDefASTNode::ExternSourceDefASTNode(const ExternSourceDefASTNode & other)
979 : SourceDefASTNode(other), m_expr()
981 m_expr = dynamic_cast<ExprASTNode*>(other.m_expr->clone());
984 void ExternSourceDefASTNode::printTree(int indent) const
986 SourceDefASTNode::printTree(indent);
988 printIndent(indent+1);
990 if (m_expr) m_expr->printTree(indent + 2);
992 printIndent(indent+1);
993 printf("attributes:\n");
996 m_attributes->printTree(indent+2);
1000 #pragma mark = SectionContentsASTNode =
1002 SectionContentsASTNode::SectionContentsASTNode(const SectionContentsASTNode & other)
1003 : ASTNode(other), m_sectionExpr()
1005 m_sectionExpr = dynamic_cast<ExprASTNode*>(other.m_sectionExpr->clone());
1008 void SectionContentsASTNode::printTree(int indent) const
1010 ASTNode::printTree(indent);
1012 printIndent(indent + 1);
1013 printf("section#:\n");
1014 if (m_sectionExpr) m_sectionExpr->printTree(indent + 2);
1017 #pragma mark = DataSectionContentsASTNode =
1019 DataSectionContentsASTNode::DataSectionContentsASTNode(const DataSectionContentsASTNode & other)
1020 : SectionContentsASTNode(other), m_contents()
1022 m_contents = dynamic_cast<ASTNode*>(other.m_contents->clone());
1025 void DataSectionContentsASTNode::printTree(int indent) const
1027 SectionContentsASTNode::printTree(indent);
1031 m_contents->printTree(indent + 1);
1035 #pragma mark = BootableSectionContentsASTNode =
1037 BootableSectionContentsASTNode::BootableSectionContentsASTNode(const BootableSectionContentsASTNode & other)
1038 : SectionContentsASTNode(other), m_statements()
1040 m_statements = dynamic_cast<ListASTNode*>(other.m_statements->clone());
1043 void BootableSectionContentsASTNode::printTree(int indent) const
1045 SectionContentsASTNode::printTree(indent);
1047 printIndent(indent + 1);
1048 printf("statements:\n");
1049 if (m_statements) m_statements->printTree(indent + 2);
1052 #pragma mark = IfStatementASTNode =
1054 //! \warning Be careful; this method could enter an infinite loop if m_nextIf feeds
1055 //! back onto itself. m_nextIf must be NULL at some point down the next if list.
1056 IfStatementASTNode::IfStatementASTNode(const IfStatementASTNode & other)
1057 : StatementASTNode(),
1063 m_conditionExpr = dynamic_cast<ExprASTNode*>(other.m_conditionExpr->clone());
1064 m_ifStatements = dynamic_cast<ListASTNode*>(other.m_ifStatements->clone());
1065 m_nextIf = dynamic_cast<IfStatementASTNode*>(other.m_nextIf->clone());
1066 m_elseStatements = dynamic_cast<ListASTNode*>(other.m_elseStatements->clone());
1069 #pragma mark = ModeStatementASTNode =
1071 ModeStatementASTNode::ModeStatementASTNode(const ModeStatementASTNode & other)
1072 : StatementASTNode(other), m_modeExpr()
1074 m_modeExpr = dynamic_cast<ExprASTNode*>(other.m_modeExpr->clone());
1077 void ModeStatementASTNode::printTree(int indent) const
1079 StatementASTNode::printTree(indent);
1080 printIndent(indent + 1);
1082 if (m_modeExpr) m_modeExpr->printTree(indent + 2);
1085 #pragma mark = MessageStatementASTNode =
1087 MessageStatementASTNode::MessageStatementASTNode(const MessageStatementASTNode & other)
1088 : StatementASTNode(other), m_type(other.m_type), m_message()
1090 m_message = new std::string(*other.m_message);
1093 void MessageStatementASTNode::printTree(int indent) const
1095 StatementASTNode::printTree(indent);
1096 printIndent(indent + 1);
1097 printf("%s: %s\n", getTypeName(), m_message->c_str());
1100 const char * MessageStatementASTNode::getTypeName() const
1117 #pragma mark = LoadStatementASTNode =
1119 LoadStatementASTNode::LoadStatementASTNode(const LoadStatementASTNode & other)
1120 : StatementASTNode(other), m_data(), m_target(), m_isDCDLoad(other.m_isDCDLoad)
1122 m_data = other.m_data->clone();
1123 m_target = other.m_target->clone();
1126 void LoadStatementASTNode::printTree(int indent) const
1128 StatementASTNode::printTree(indent);
1130 printIndent(indent + 1);
1132 if (m_data) m_data->printTree(indent + 2);
1134 printIndent(indent + 1);
1135 printf("target:\n");
1136 if (m_target) m_target->printTree(indent + 2);
1139 #pragma mark = CallStatementASTNode =
1141 CallStatementASTNode::CallStatementASTNode(const CallStatementASTNode & other)
1142 : StatementASTNode(other), m_type(other.m_type), m_target(), m_arg()
1144 m_target = other.m_target->clone();
1145 m_arg = other.m_arg->clone();
1148 void CallStatementASTNode::printTree(int indent) const
1150 printIndent(indent);
1151 printf("%s(%s)%s\n", nodeName().c_str(), (m_type == kCallType ? "call" : "jump"), (m_isHAB ? "/HAB" : ""));
1153 printIndent(indent + 1);
1154 printf("target:\n");
1155 if (m_target) m_target->printTree(indent + 2);
1157 printIndent(indent + 1);
1159 if (m_arg) m_arg->printTree(indent + 2);
1162 #pragma mark = SourceASTNode =
1164 SourceASTNode::SourceASTNode(const SourceASTNode & other)
1165 : ASTNode(other), m_name()
1167 m_name = new std::string(*other.m_name);
1170 void SourceASTNode::printTree(int indent) const
1172 printIndent(indent);
1173 printf("%s(%s)\n", nodeName().c_str(), m_name->c_str());
1176 #pragma mark = SectionMatchListASTNode =
1178 SectionMatchListASTNode::SectionMatchListASTNode(const SectionMatchListASTNode & other)
1179 : ASTNode(other), m_sections(), m_source()
1181 if (other.m_sections)
1183 m_sections = dynamic_cast<ListASTNode *>(other.m_sections->clone());
1188 m_source = new std::string(*other.m_source);
1192 void SectionMatchListASTNode::printTree(int indent) const
1194 ASTNode::printTree(indent);
1196 printIndent(indent+1);
1197 printf("sections:\n");
1200 m_sections->printTree(indent+2);
1203 printIndent(indent+1);
1204 printf("source: ", m_source->c_str());
1207 printf("%s\n", m_source->c_str());
1215 #pragma mark = SectionASTNode =
1217 SectionASTNode::SectionASTNode(const SectionASTNode & other)
1218 : ASTNode(other), m_name(), m_source()
1220 m_action = other.m_action;
1224 m_name = new std::string(*other.m_name);
1229 m_source = new std::string(*other.m_source);
1233 void SectionASTNode::printTree(int indent) const
1235 printIndent(indent);
1237 const char * actionName;
1241 actionName = "include";
1244 actionName = "exclude";
1250 printf("%s(%s:%s:%s)\n", nodeName().c_str(), actionName, m_name->c_str(), m_source->c_str());
1254 printf("%s(%s:%s)\n", nodeName().c_str(), actionName, m_name->c_str());
1258 #pragma mark = SymbolASTNode =
1260 SymbolASTNode::SymbolASTNode(const SymbolASTNode & other)
1261 : ASTNode(other), m_symbol(), m_source()
1263 m_symbol = new std::string(*other.m_symbol);
1264 m_source = new std::string(*other.m_source);
1267 void SymbolASTNode::printTree(int indent) const
1269 printIndent(indent);
1271 const char * symbol = NULL;
1274 symbol = m_symbol->c_str();
1277 const char * source = NULL;
1280 source = m_source->c_str();
1283 printf("%s(", nodeName().c_str());
1304 #pragma mark = AddressRangeASTNode =
1306 AddressRangeASTNode::AddressRangeASTNode(const AddressRangeASTNode & other)
1307 : ASTNode(other), m_begin(), m_end()
1309 m_begin = other.m_begin->clone();
1310 m_end = other.m_end->clone();
1313 void AddressRangeASTNode::printTree(int indent) const
1315 ASTNode::printTree(indent);
1317 printIndent(indent + 1);
1319 if (m_begin) m_begin->printTree(indent + 2);
1321 printIndent(indent + 1);
1323 if (m_end) m_end->printTree(indent + 2);
1326 #pragma mark = FromStatementASTNode =
1328 FromStatementASTNode::FromStatementASTNode(std::string * source, ListASTNode * statements)
1329 : StatementASTNode(), m_source(source), m_statements(statements)
1333 FromStatementASTNode::FromStatementASTNode(const FromStatementASTNode & other)
1334 : StatementASTNode(), m_source(), m_statements()
1336 m_source = new std::string(*other.m_source);
1337 m_statements = dynamic_cast<ListASTNode*>(other.m_statements->clone());
1340 void FromStatementASTNode::printTree(int indent) const
1342 ASTNode::printTree(indent);
1344 printIndent(indent + 1);
1346 if (m_source) printf("%s\n", m_source->c_str());
1348 printIndent(indent + 1);
1349 printf("statements:\n");
1350 if (m_statements) m_statements->printTree(indent + 2);