void DataStatement::validate() { unsigned int baseSize = dataType == WORD ? 2 : 1; unsigned int size = 0; ListNode<DataItem*>::ListType& list = items->getList(); for(size_t i = 0; i < list.size(); i++) { DataItem* item = list[i]; item->check(); switch(item->getItemType()) { case DataItem::STRING_LITERAL: size += baseSize * item->getStringLiteral()->getValue().length(); break; case DataItem::EXPRESSION: size += baseSize; break; } } // Reserve the bytes needed for this data. // (Previous errors shouldn't wreck the size calculation). RomBank* bank = romGenerator->getActiveBank(); if(!bank) { error("data statement found, but a rom bank hasn't been selected yet", getSourcePosition(), true); } else { bank->expand(size, getSourcePosition()); } }
void BlockStatement::aggregate() { // Create scope. scope = new SymbolTable(SymbolTable::getActiveScope()); // If this scope has a name, register that as // a member of the containing scope. if(name) { // Assumes this code will never get executed by the outermost block (before there is an active scope). SymbolTable* outer = SymbolTable::getActiveScope(); PackageDefinition* package = new PackageDefinition(name->getValue(), scope); // Shove the this package into the containing outer scope. outer->put(package, getSourcePosition()); // Create a back-reference, so the scope knows it defines a new package, // rather than just sharing a private subset of the outer scope's package. scope->setPackage(package); } // Enter the created scope. SymbolTable::enterScope(scope); ListNode<Statement*>::ListType& list = statements->getList(); // First gather all constant definitions in this scope. for(size_t i = 0; i < list.size(); i++) { Statement* statement = list[i]; if(statement->getStatementType() == Statement::CONSTANT_DECLARATION) { statement->aggregate(); } } // Next, if this is the main block, calculate the header. if(handleHeader(list)) { // Now, check out all the other statements. for(size_t i = 0; i < list.size(); i++) { Statement* statement = list[i]; switch(statement->getStatementType()) { // Skip already handled cases. case Statement::CONSTANT_DECLARATION: case Statement::HEADER: break; // Aggregate the rest. default: statement->aggregate(); break; } } } SymbolTable::exitScope(); }
bool HeaderSetting::checkValue(unsigned int min, unsigned int max) { if(!expression->fold(true, false)) { std::ostringstream os; os << "ines header has `" << name->getValue() << "` setting with a value which could not be resolved."; error(os.str(), getSourcePosition()); return false; } else if(expression->getFoldedValue() < min || expression->getFoldedValue() > max) { std::ostringstream os; os << "ines header's `" << name->getValue() << "` setting must be between " << min << ".." << max << ", but got " << expression->getFoldedValue() << " instead."; error(os.str(), getSourcePosition()); return false; } return true; }
// Find and handle the header for the main block. bool BlockStatement::handleHeader(ListNode<Statement*>::ListType& list) { Statement* header = 0; for(size_t i = 0; i < list.size(); i++) { Statement* statement = list[i]; if(statement->getStatementType() == Statement::HEADER) { if(blockType == MAIN) { if(!header) { header = list[i]; } else { std::ostringstream os; os << "multiple ines headers found. (previous header at "; header->getSourcePosition()->print(os); os << ")."; error(os.str(), statement->getSourcePosition(), true); return false; } } else { std::ostringstream os; os << "ines header cannot appear inside a begin/end block."; error(os.str(), statement->getSourcePosition(), true); return false; } } else if(blockType == MAIN && !header) { if(statement->getStatementType() != Statement::CONSTANT_DECLARATION) { error("statement that is not a constant declaration found before the ines header.", statement->getSourcePosition(), true); return false; } } } if(blockType == MAIN) { if(!header) { error("no ines header found.", getSourcePosition(), true); return false; } header->aggregate(); } return true; }
void DataStatement::generate() { // Get the bank to use for writing. RomBank* bank = romGenerator->getActiveBank(); if(!bank) { error("data statement found, but a rom bank hasn't been selected yet", getSourcePosition(), true); return; } ListNode<DataItem*>::ListType list = items->getList(); for(size_t i = 0; i < list.size(); i++) { DataItem* item = list[i]; switch(item->getItemType()) { case DataItem::STRING_LITERAL: { const std::string& str = item->getStringLiteral()->getValue(); const char* data = str.data(); if(dataType == WORD) { for(size_t j = 0; j < str.length(); j++) { bank->writeWord(data[i], getSourcePosition()); } } else { for(size_t j = 0; j < str.length(); j++) { bank->writeByte(data[i], getSourcePosition()); } } break; } case DataItem::EXPRESSION: if(item->getExpression()->fold(true, true)) { if(dataType == WORD) { bank->writeWord(item->getExpression()->getFoldedValue(), getSourcePosition()); } else { bank->writeByte(item->getExpression()->getFoldedValue(), getSourcePosition()); } } else { error("data item has indeterminate value", getSourcePosition()); } break; } } }
std::string JPetTreeHeader::stringify() const { std::ostringstream tmp; tmp<<"-----------------------------------------------------------------\n"; tmp<<"------------------------- General Info --------------------------\n"; tmp<<"-----------------------------------------------------------------\n"; tmp<< "Run number : " << JPetCommonTools::Itoa(fRunNo) <<"\n"; tmp<< "Base file name : "<<getBaseFileName()<<"\n"; tmp<< "Source (if any) position: "<< Form("%lf",getSourcePosition())<<"\n"; tmp<< "Created with:" << "\n"; tmp<< " framework version : "<< getFrameworkVersion() <<"\n"; tmp<< " git revision : "<< getFrameworkRevision() <<"\n"; tmp << stringifyHistory(); tmp << stringifyDictionary(); return tmp.str(); }
static Graph::Face *splitFace(Graph &graph, Graph::Face &face, FRandomStream &random) { auto edgePair = getRandomOpposingEdges(face, random); auto dir = getDirection(*edgePair.first); // Assumes both edges are opposing faces on a rectangle. auto otherDir = getDirection(*edgePair.second); check((dir.x == -1 * otherDir.x) && (dir.y == -1 * otherDir.y)); // If the rectangle is not big enough do not split it. if ((std::abs(dir.x) < 2*MARGIN+1) && (std::abs(dir.y) < 2*MARGIN+1)) return nullptr; // Get a random point along the edges. auto randX = (dir.x != 0 ? signOf(dir.x) * random.RandRange(MARGIN, std::abs(dir.x) - MARGIN) : 0); auto randY = (dir.y != 0 ? signOf(dir.y) * random.RandRange(MARGIN, std::abs(dir.y) - MARGIN) : 0); auto position0 = getSourcePosition(*edgePair.first) + Graph::Position{randX, randY}; auto position1 = getTargetPosition(*edgePair.second) + Graph::Position{randX, randY}; // Split the edges and connect. Graph::Node &node0 = graph.SplitEdge(position0, *edgePair.first); Graph::Node &node1 = graph.SplitEdge(position1, *edgePair.second); return &graph.ConnectNodes(node0, node1); }
static Graph::Position getDirection(const Graph::HalfEdge &edge) { return getTargetPosition(edge) - getSourcePosition(edge); }