void extractPlotData() { if(!rawData_.getLength()) return; plotData_->clear(); uint8_t* currentPos_ = rawData_.getData().get(); int32_t skipLength_ = *reinterpret_cast<int32_t*>(currentPos_); currentPos_ += sizeof(int32_t); currentPos_ += skipLength_; uint32_t numberOfItems_ = *reinterpret_cast<uint32_t*>(currentPos_); currentPos_ += sizeof(uint32_t); for (uint32_t i = 0; i < numberOfItems_; ++i) { extractOneItem(currentPos_); } }
//! Takes an AST node that is one of the following subclasses and creates the corresponding //! type of DataSource object from it. //! - StringConstASTNode //! - ExprASTNode //! - SourceASTNode //! - SectionASTNode //! - SectionMatchListASTNode //! - BlobConstASTNode //! - IVTConstASTNode //! //! \exception elftosb::semantic_error Thrown if a semantic problem is found with //! the data node. //! \exception std::runtime_error Thrown if an error occurs that shouldn't be possible //! based on the grammar. DataSource * ConversionController::createSourceFromNode(ASTNode * dataNode) { assert(dataNode); DataSource * source = NULL; StringConstASTNode * stringNode; BlobConstASTNode * blobNode; ExprASTNode * exprNode; SourceASTNode * sourceNode; SectionASTNode * sectionNode; SectionMatchListASTNode * matchListNode; IVTConstASTNode * ivtNode; if (stringNode = dynamic_cast<StringConstASTNode*>(dataNode)) { // create a data source with the string contents std::string * stringData = stringNode->getString(); const uint8_t * stringContents = reinterpret_cast<const uint8_t *>(stringData->c_str()); source = new UnmappedDataSource(stringContents, static_cast<unsigned>(stringData->size())); } else if (blobNode = dynamic_cast<BlobConstASTNode*>(dataNode)) { // create a data source with the raw binary data Blob * blob = blobNode->getBlob(); source = new UnmappedDataSource(blob->getData(), blob->getLength()); } else if (exprNode = dynamic_cast<ExprASTNode*>(dataNode)) { // reduce the expression first exprNode = exprNode->reduce(m_context); IntConstExprASTNode * intNode = dynamic_cast<IntConstExprASTNode*>(exprNode); if (!intNode) { throw semantic_error("load pattern expression did not evaluate to an integer"); } SizedIntegerValue intValue(intNode->getValue(), intNode->getSize()); source = new PatternSource(intValue); } else if (sourceNode = dynamic_cast<SourceASTNode*>(dataNode)) { // load the entire source contents SourceFile * sourceFile = getSourceFromName(sourceNode->getSourceName(), sourceNode->getFirstLine()); source = sourceFile->createDataSource(); } else if (sectionNode = dynamic_cast<SectionASTNode*>(dataNode)) { // load some subset of the source SourceFile * sourceFile = getSourceFromName(sectionNode->getSourceName(), sectionNode->getFirstLine()); if (!sourceFile->supportsNamedSections()) { throw semantic_error(format_string("line %d: source does not support sections", sectionNode->getFirstLine())); } // create data source from the section name std::string * sectionName = sectionNode->getSectionName(); GlobMatcher globber(*sectionName); source = sourceFile->createDataSource(globber); if (!source) { throw semantic_error(format_string("line %d: no sections match the pattern", sectionNode->getFirstLine())); } } else if (matchListNode = dynamic_cast<SectionMatchListASTNode*>(dataNode)) { SourceFile * sourceFile = getSourceFromName(matchListNode->getSourceName(), matchListNode->getFirstLine()); if (!sourceFile->supportsNamedSections()) { throw semantic_error(format_string("line %d: source type does not support sections", matchListNode->getFirstLine())); } // create string matcher ExcludesListMatcher matcher; // add each pattern to the matcher ListASTNode * matchList = matchListNode->getSections(); ListASTNode::iterator it = matchList->begin(); for (; it != matchList->end(); ++it) { ASTNode * node = *it; sectionNode = dynamic_cast<SectionASTNode*>(node); if (!sectionNode) { throw std::runtime_error(format_string("line %d: unexpected node type in section pattern list", (*it)->getFirstLine())); } bool isInclude = sectionNode->getAction() == SectionASTNode::kInclude; matcher.addPattern(isInclude, *(sectionNode->getSectionName())); } // create data source from the section match list source = sourceFile->createDataSource(matcher); if (!source) { throw semantic_error(format_string("line %d: no sections match the section pattern list", matchListNode->getFirstLine())); } } else if (ivtNode = dynamic_cast<IVTConstASTNode*>(dataNode)) { source = createIVTDataSource(ivtNode); } else { throw semantic_error(format_string("line %d: unexpected load data node type", dataNode->getFirstLine())); } return source; }