void InstCall::dump(const Cfg *Func) const { Ostream &Str = Func->getContext()->getStrDump(); if (getDest()) { dumpDest(Func); Str << " = "; } Str << "call "; if (getDest()) Str << getDest()->getType(); else Str << "void"; Str << " "; getCallTarget()->dump(Func); Str << "("; for (SizeT I = 0; I < getNumArgs(); ++I) { if (I > 0) Str << ", "; Str << getArg(I)->getType() << " "; getArg(I)->dump(Func); } Str << ")"; }
Sequence FunctionSubstring::createSequence(DynamicContext* context, int flags) const { XPath2MemoryManager* memMgr = context->getMemoryManager(); Sequence string=getParamNumber(1, context)->toSequence(context); if(string.isEmpty()) return Sequence(context->getItemFactory()->createString(XERCES_CPP_NAMESPACE_QUALIFIER XMLUni::fgZeroLenString, context), memMgr); ATStringOrDerived::Ptr str = (const ATStringOrDerived::Ptr )string.first(); Sequence startingLoc=getParamNumber(2,context)->toSequence(context); ATDoubleOrDerived::Ptr index = (const ATDoubleOrDerived::Ptr )startingLoc.first(); ATDoubleOrDerived::Ptr subStrLength; if(getNumArgs()>2) { Sequence length=getParamNumber(3,context)->toSequence(context); subStrLength=(const ATDoubleOrDerived::Ptr )length.first(); } else { subStrLength=(const ATDoubleOrDerived::Ptr )context->getItemFactory()->createDouble((long)((const ATStringOrDerived*)str)->getLength(), context); } return Sequence(((const ATStringOrDerived*)str)->substring(index, subStrLength, context), memMgr); }
void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, keyword_begin(), getNumArgs()); }
IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const { assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index"); return keyword_begin()[i]; }
keyword_iterator keyword_end() const { return keyword_begin()+getNumArgs(); }
Sequence FunctionReplace::createSequence(DynamicContext* context, int flags) const { XPath2MemoryManager* memMgr = context->getMemoryManager(); const XMLCh* input = XMLUni::fgZeroLenString; Item::Ptr inputString = getParamNumber(1,context)->next(context); if(inputString.notNull()) input = inputString->asString(context); const XMLCh *pattern = getParamNumber(2,context)->next(context)->asString(context); const XMLCh *replacement = getParamNumber(3,context)->next(context)->asString(context); const XMLCh *ptr; for(ptr = replacement; *ptr != chNull; ++ptr) { if(*ptr == chDollarSign) { ++ptr; //check that after the '$' is a digit if(!XMLString::isDigit(*ptr)) XQThrow(FunctionException, X("FunctionReplace::createSequence"), X("Invalid replacement pattern - '$' without following digit [err:FORX0004]")); } else if(*ptr == chBackSlash) { ++ptr; //check that after the '\' is a '$' or '\' if(*ptr != chDollarSign && *ptr != chBackSlash) { XQThrow(FunctionException, X("FunctionReplace::createSequence"), X("Invalid replacement pattern - '\\' without following '$' or '\\' [err:FORX0004]")); } } } const XMLCh *options = XMLUni::fgZeroLenString; if(getNumArgs()>3) options=getParamNumber(4,context)->next(context)->asString(context); //Check that the options are valid - throw an exception if not (can have s,m,i and x) //Note: Are allowed to duplicate the letters. const XMLCh* cursor=options; for(; *cursor != 0; ++cursor){ switch(*cursor) { case chLatin_s: case chLatin_m: case chLatin_i: case chLatin_x: break; default: XQThrow(FunctionException, X("FunctionReplace::createSequence"),X("Invalid regular expression flags [err:FORX0001].")); } } // Now attempt to replace try { AutoDeallocate<const XMLCh> result(replace(input, pattern, replacement, options, memMgr), memMgr); return Sequence(context->getItemFactory()->createString(result.get(), context), memMgr); } catch (ParseException &e){ XMLBuffer buf(1023, memMgr); buf.set(X("Invalid regular expression: ")); buf.append(e.getMessage()); buf.append(X(" [err:FORX0002]")); XQThrow(FunctionException, X("FunctionReplace::createSequence"), buf.getRawBuffer()); } catch (RuntimeException &e){ if(e.getCode()==XMLExcepts::Regex_RepPatMatchesZeroString) XQThrow(FunctionException, X("FunctionReplace::createSequence"), X("The pattern matches the zero-length string [err:FORX0003]")); else if(e.getCode()==XMLExcepts::Regex_InvalidRepPattern) XQThrow(FunctionException, X("FunctionReplace::createSequence"), X("Invalid replacement pattern [err:FORX0004]")); else XQThrow(FunctionException, X("FunctionReplace::createSequence"), e.getMessage()); } // Never happens }
Sequence FunctionNormalizeUnicode::createSequence(DynamicContext* context, int flags) const { XPath2MemoryManager* memMgr = context->getMemoryManager(); Sequence strParm=getParamNumber(1,context)->toSequence(context); if(strParm.isEmpty()) { return Sequence(context->getItemFactory()->createString(XMLUni::fgZeroLenString, context), memMgr); } const XMLCh *str = strParm.first()->asString(context); static const XMLCh fg_NFC[] = { chLatin_N, chLatin_F, chLatin_C, chNull }; static const XMLCh fg_NFD[] = { chLatin_N, chLatin_F, chLatin_D, chNull }; static const XMLCh fg_NFKC[] = { chLatin_N, chLatin_F, chLatin_K, chLatin_C, chNull }; static const XMLCh fg_NFKD[] = { chLatin_N, chLatin_F, chLatin_K, chLatin_D, chNull }; static const XMLCh fg_fully[] = { chLatin_F, chLatin_U, chLatin_L, chLatin_L, chLatin_Y, chDash, chLatin_N, chLatin_O, chLatin_R, chLatin_M, chLatin_A, chLatin_L, chLatin_I, chLatin_Z, chLatin_E, chLatin_D, chNull }; const XMLCh* normalization = fg_NFC; if(getNumArgs()==2) { Sequence normParam=getParamNumber(2,context)->toSequence(context); const XMLCh *src = normParam.first()->asString(context); normalization = XPath2Utils::toUpper(src, memMgr); if (XMLString::stringLen(normalization) > 0) { unsigned int i; // remove leading spaces for(i = 0; i < XMLString::stringLen(normalization); i++) { XMLCh ch = normalization[i]; if((ch != 0x9) && (ch != 0xA) && (ch != 0xD) && (ch != 0x20)) break; } const XMLCh *frontChop = XPath2Utils::subString(normalization, i, XPath2Utils::uintStrlen(normalization)-i, memMgr); // remove trailing spaces for(i = XPath2Utils::uintStrlen(frontChop)-1; i !=0 ; i--) { XMLCh ch = frontChop[i]; if((ch != 0x9) && (ch != 0xA) && (ch != 0xD) && (ch != 0x20)) break; } normalization = XPath2Utils::subString(frontChop, 0, i+1, memMgr); } } if(XMLString::stringLen(normalization) == 0) { return Sequence(context->getItemFactory()->createString(str, context), memMgr); } else { AutoDeallocate<XMLCh> buf(0, memMgr); if(XPath2Utils::equals(normalization, fg_NFC)) { buf.set(UnicodeTransformer::normalizeC(str, memMgr)); } else if(XPath2Utils::equals(normalization, fg_NFD)) { buf.set(UnicodeTransformer::normalizeD(str, memMgr)); } else if(XPath2Utils::equals(normalization, fg_NFKC)) { buf.set(UnicodeTransformer::normalizeKC(str, memMgr)); } else if(XPath2Utils::equals(normalization, fg_NFKD)) { buf.set(UnicodeTransformer::normalizeKD(str, memMgr)); } else if(XPath2Utils::equals(normalization, fg_fully)) { XQThrow(FunctionException, X("FunctionNormalizeUnicode::createSequence"), X("Unsupported normalization form [err:FOCH0003].")); } else { XQThrow(FunctionException, X("FunctionNormalizeUnicode::createSequence"), X("Invalid normalization form [err:FOCH0003].")); } return Sequence(context->getItemFactory()->createString(buf.get(), context), memMgr); } // Never reached return Sequence(memMgr); }
int XC::ElementRecorder::initialize(void) { const int numEle= eleID.Size(); if(numEle == 0 || theDomain == 0) { if(!theDomain) std::cerr << getClassName() << "::" << __FUNCTION__ << "; undefined domain." << std::endl; if(numEle == 0) std::cerr << getClassName() << "::" << __FUNCTION__ << "; there is no elements." << std::endl; return -1; } // Set the response objects: // 1. create an array of pointers for them // 2. iterate over the elements invoking setResponse() to get the new objects & determine size of data // int numDbColumns = 0; if(echoTimeFlag == true) numDbColumns = 1; // 1 for the pseudo-time theResponses= std::vector<Response *>(numEle,static_cast<Response *>(nullptr)); Information eleInfo(1.0); int i; for(i=0; i<numEle; i++) { Element *theEle = theDomain->getElement(eleID(i)); if(theEle == 0) { theResponses[i]= 0; } else { theResponses[i] = theEle->setResponse(responseArgs, eleInfo); if(theResponses[i] != 0) { // from the response type determine no of cols for each Information &eleInfo = theResponses[i]->getInformation(); const Vector &eleData = eleInfo.getData(); numDbColumns += eleData.Size(); } } } // // now create the columns strings for the data description // for each element do a getResponse() // std::vector<std::string> dbColumns(numDbColumns); static std::string aColumn; int counter = 0; if(echoTimeFlag == true) { dbColumns[0] = "time"; counter = 1; } std::string dataToStore= ""; const size_t numArgs= getNumArgs(); for(size_t j=0; j<numArgs; j++) { dataToStore+= responseArgs[j]; if(j<(numArgs-1)) dataToStore+= " "; } for(i=0; i<eleID.Size(); i++) { int eleTag = eleID(i); int numVariables = 0; if(theResponses[i]!=nullptr) { const XC::Information &eleInfo = theResponses[i]->getInformation(); if(eleInfo.theType == IntType || eleInfo.theType == DoubleType) { // create column heading for single data item for element numVariables = 0; //sprintf(aColumn, "Element%d_%s", eleTag, dataToStore); aColumn= "Element" + boost::lexical_cast<std::string>(eleTag) + "_" + dataToStore; dbColumns[counter] = aColumn; counter++; } else if(eleInfo.theType == VectorType) numVariables = eleInfo.theVector->Size(); else if(eleInfo.theType == IdType) numVariables = eleInfo.theID->Size(); else if(eleInfo.theType == MatrixType) numVariables = eleInfo.theMatrix->noRows()* eleInfo.theMatrix->noCols(); // create the column headings for multiple data for the element for(int j=1; j<=numVariables; j++) { //sprintf(aColumn, "Element%d_%s_%d",eleTag, dataToStore, j); aColumn= "Element" + boost::lexical_cast<std::string>(eleTag) + "_" + dataToStore + "_" + boost::lexical_cast<std::string>(j); dbColumns[counter] = aColumn; counter++; } } } // replace spaces with undescore for tables for(int kk=0; kk<numDbColumns; kk++) replace(dbColumns[kk],' ','_'); // // call open in the handler with the data description // theHandler->open(dbColumns); // create the vector to hold the data data= Vector(numDbColumns); initializationDone = true; return 0; }
Result FunctionSubsequence::createResult(DynamicContext* context, int flags) const { if(getNumArgs() == 2) return new SingleArgSubsequenceResult(this); return new SubsequenceResult(this); }