Terminal* Grammar::getNamedNode ( Terminal & node, const string & name ) { // This function only operates on the parent chain. // We only want to output non-source-position dependent constructors for SgLocatedNodes. Test for this. Terminal* parentNode = node.getBaseClass(); #if 0 string parentNodeName; if (parentNode != NULL) { parentNodeName = parentNode->getName(); // printf ("parentNodeName = %s \n",parentNodeName.c_str()); } // printf ("In Grammar::getNamedNode(): name = %s \n",name.c_str()); #endif while ( parentNode != NULL && string(parentNode->getName()) != name ) // while ( (parentNode != NULL) && (parentNodeName != name) ) { // printf ("node %s parent node: %s \n",name.c_str(),parentNode->getName().c_str()); parentNode = parentNode->getBaseClass(); } if (parentNode != NULL) { // printf ("Found node %s parent node: %s \n",name.c_str(),parentNode->getName().c_str()); } return parentNode; }
void Grammar::buildConstructorWithoutSourcePositionInformationSupport( Terminal & node, StringUtility::FileWithLineNumbers & outputFile ) { StringUtility::FileWithLineNumbers editString = buildConstructorWithoutSourcePositionInformation(node); editString = StringUtility::copyEdit (editString,"$CLASSNAME",node.getName()); editString = StringUtility::copyEdit (editString,"$GRAMMAR_NAME",getGrammarName()); // grammarName string defined in Grammar class // Set these to NULL strings if they are still present within the string editString = StringUtility::copyEdit (editString,"$CLASSTAG",node.getTagName()); #if 1 // Also output strings to single file outputFile += editString; #endif // printf ("node.name = %s (# of subtrees/leaves = %" PRIuPTR ") \n",node.getName(),node.nodeList.size()); #if 1 // Call this function recursively on the children of this node in the tree vector<Terminal *>::const_iterator treeNodeIterator; for( treeNodeIterator = node.subclasses.begin(); treeNodeIterator != node.subclasses.end(); treeNodeIterator++ ) { ROSE_ASSERT ((*treeNodeIterator) != NULL); ROSE_ASSERT ((*treeNodeIterator)->getBaseClass() != NULL); buildConstructorWithoutSourcePositionInformationSupport(**treeNodeIterator,outputFile); } #endif }
/* * Player opened a mission terminal or pressed refresh */ void MissionManager::listRequest(PlayerObject* player, uint64 terminal_id,uint8 refresh_count) { Terminal* terminal = dynamic_cast<Terminal*> (gWorldManager->getObjectById(terminal_id)); //uint32 terminal_type = terminal->getTerminalType(); int8 terminal_name[255]; strcpy(terminal_name,terminal->getName().getAnsi()); gLogger->logMsgF("Terminal id %"PRIu64" is type '%s'", MSG_NORMAL, terminal_id, terminal_name); int count = 0; int len = strlen(terminal_name); MissionBag* mission_bag = dynamic_cast<MissionBag*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_MissionBag)); MissionList::iterator it = mission_bag->getMissions()->begin(); while(it != mission_bag->getMissions()->end()) { MissionObject* mission = dynamic_cast<MissionObject*>(*it); mission->clear(); mission->setIssuingTerminal(terminal); mission->setRefreshCount(refresh_count); switch(len) { case 16: //terminal_mission count < 5 ? generateDestroyMission(mission,terminal_id) : generateDeliverMission(mission); break; case 22: //terminal_mission_scout if (count < 5) { mission->setRefreshCount(0); } else { generateReconMission(mission); } break; case 24: //terminal_mission_artisan count < 5 ? generateCraftingMission(mission) : generateSurveyMission(mission); break; case 28: //terminal_mission_entertainer generateEntertainerMission(mission,count); break; default: gLogger->logMsgF("Terminal id %"PRIu64" is type '%s'", MSG_NORMAL, terminal_id, terminal_name); mission->setRefreshCount(0); } gMessageLib->sendMISO_Delta(mission, player); count++; ++it; } }
string // Grammar::outputClassesAndFields ( GrammarTreeNode & node, fstream & outputFile ) Grammar::outputClassesAndFields ( Terminal & node ) { string className = node.getName(); string dataFields = node.outputClassesAndFields(); string returnString = className + "\n" + dataFields; // printf ("returnString = \n%s\n",returnString.c_str()); #if 1 // Call this function recursively on the children of this node in the tree vector<Terminal *>::iterator treeNodeIterator; for( treeNodeIterator = node.subclasses.begin(); treeNodeIterator != node.subclasses.end(); treeNodeIterator++ ) { ROSE_ASSERT ((*treeNodeIterator) != NULL); ROSE_ASSERT ((*treeNodeIterator)->getBaseClass() != NULL); // outputClassesAndFields(**treeNodeIterator,outputFile); returnString += outputClassesAndFields(**treeNodeIterator); } #endif // returnString = GrammarString::copyEdit(returnString.c_str(),"$CLASSNAME",node.getName()); const string target = "$CLASSNAME"; const string name = node.getName(); // returnString = GrammarString::copyEdit(returnString,target,name); // returnString = GrammarString::copyEdit(string(returnString),"$CLASSNAME",string(node.getName())); // returnString = GrammarString::copyEdit(string(returnString),target,name); // returnString = GrammarString::copyEdit(returnString,target,name); string copy = returnString; returnString = GrammarString::copyEdit(copy,target,name); return returnString; }
StringUtility::FileWithLineNumbers Grammar::buildConstructorWithoutSourcePositionInformation ( Terminal & node ) { // DQ (11/6/2006): This function generates the code for a newer form of the constructor // that has not source position information in it's parameter list. This new form of the constructor // is easier to work with and separates the details of maintaining the source position information from // the construction of the IR node within the AST. // Build the constructors for each class // Example: // /* this is the generated constructor */ // ClassDeclaration::ClassDeclaration // ( Name name, int class_type, ClassType* type, ClassDefinition* definition) // : DeclarationStatement(NULL) // { // p_name = name; // p_class_type = class_type; // p_type = type; // p_definition = definition; // /* now a call to the user defined intialization function */ // post_construction_initialization(); // } string className = node.getName(); StringUtility::FileWithLineNumbers returnString; // We only want to output non-source-position dependent constructors for SgLocatedNodes. Test for this. Terminal* parentNode = getNamedNode ( node, "SgLocatedNode" ); // We only want to output non-source-position dependent constructors for SgLocatedNodes. if (parentNode != NULL && node.generateConstructor() == true) { string constructorTemplateFileName = "../Grammar/grammarConstructorDefinitionMacros.macro"; StringUtility::FileWithLineNumbers constructorSourceCodeTemplate = Grammar::readFileWithPos (constructorTemplateFileName); bool complete = false; ConstructParamEnum config = CONSTRUCTOR_PARAMETER; if (node.getBuildDefaultConstructor()) { config = NO_CONSTRUCTOR_PARAMETER; } StringUtility::FileWithLineNumbers constructorSource = constructorSourceCodeTemplate; if (node.getBaseClass() != NULL) { string parentClassName = node.getBaseClass()->getName(); // printf ("In Grammar::buildConstructor(): parentClassName = %s \n",parentClassName); // printf ("Calling base class default constructor (should call paramtererized version) \n"); string baseClassParameterString = ""; bool withInitializers = false; bool withTypes = false; baseClassParameterString = buildConstructorParameterListString (*node.getBaseClass(),withInitializers,withTypes, config); string preInitializationString = ": " + parentClassName + "($BASECLASS_PARAMETERS)"; preInitializationString = StringUtility::copyEdit (preInitializationString,"$BASECLASS_PARAMETERS",baseClassParameterString); constructorSource = StringUtility::copyEdit (constructorSource,"$PRE_INITIALIZATION_LIST",preInitializationString); } else { constructorSource = StringUtility::copyEdit (constructorSource,"$PRE_INITIALIZATION_LIST",""); } bool withInitializers = false; bool withTypes = true; string constructorParameterString = buildConstructorParameterListString (node,withInitializers,withTypes,config,&complete); constructorSource = StringUtility::copyEdit (constructorSource,"$CONSTRUCTOR_PARAMETER_LIST",constructorParameterString); constructorSource = StringUtility::copyEdit (constructorSource,"$CLASSNAME",className); if (config == NO_CONSTRUCTOR_PARAMETER) { constructorSource = StringUtility::copyEdit (constructorSource,"$CONSTRUCTOR_BODY",""); } else { string constructorFunctionBody = node.buildConstructorBody(withInitializers, config); constructorSource = StringUtility::copyEdit (constructorSource,"$CONSTRUCTOR_BODY",constructorFunctionBody); } returnString.insert(returnString.end(), constructorSource.begin(), constructorSource.end()); } returnString = StringUtility::copyEdit(returnString,"$GRAMMAR_PREFIX_","Sg"); return returnString; }