void ScopeInferrer::visitEFuncDeclWithType(EFuncDeclWithType *p) { string varName(p->ident_); p->type_->accept(this); auto retType = typeStack.top(); typeStack.pop(); auto s = current->makeChildScope(p); current = s.get(); int i = typeStack.size(); p->listargument_->accept(this); vector < shared_ptr < shimmr::type::Type >> argList; int end = typeStack.size(); for (; i < end; i++) { argList.push_back(typeStack.top()); typeStack.pop(); } reverse(argList.begin(), argList.end()); auto type = current->typeSystem->makeFunction(retType, argList); auto elem = make_shared<ScopeElement>(current, type, p, false); p->statementblock_->accept(this); current = current->parent; current->assign(elem, varName); }
void ScopeInferrer::visitSimpleDeclWith(SimpleDeclWith *p) { string varName(p->ident_); auto elem = make_shared<ScopeElement>(current, nullptr, p, false); current->assign(elem, varName); p->exp_1->accept(this); p->exp_2->accept(this); }
void VarUnit::removeVariable(TVar * var){ // TVar * parent = var->getParent(); // parent->removeChild(var); // if (var->getValueType() == 5) // pointers.remove(var->pointer); varList.remove(varName(var).join(".")); }
size_t VarContainer::varIndex(std::string var_name) { for (int i = 0; i < numVars(); ++i) { if (varName(i) == var_name) return i; } return numVars(); }
const Foam::scalarField& Foam::equationReader::getScalarFieldSrcDictSourceDScalar ( const equationReader * eqnReader, const label equationIndex, const label equationOperationIndex, const label maxStoreIndex, const label storageOffset ) const { dimensionedScalar ds("noSource", dimless, 0.0); const equation& eqn(operator[](equationIndex)); const equationOperation& eqOp(eqn[equationOperationIndex]); label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; word varName(dictLookups_[eqOp.dictLookupIndex()]); ITstream srcStrm ( dictSources_[zeroSourceIndex].lookup(varName) ); srcStrm >> ds; tempSrcField_ = ds.value() * sign(eqOp.sourceIndex()); return tempSrcField_; }
// *** // 获取Javascript数组中指定位置的整数元素值 // *** HRESULT GetArrayNumberOfIndex(IDispatch* pDisp, int index, int * pValue) { CComVariant varName(index, VT_I4); // 数组下标 DISPPARAMS noArgs = {NULL, NULL, 0, 0}; DISPID dispId; VARIANT varValue; HRESULT hr = 0; VariantInit(&varValue); varName.ChangeType(VT_BSTR); // 将数组下标转为数字型,以进行GetIDsOfNames // // 获取通过下标访问数组的过程,将过程名保存在dispId中 // hr = pDisp->GetIDsOfNames(IID_NULL, &varName.bstrVal, 1, LOCALE_USER_DEFAULT, &dispId); if (FAILED(hr)) return hr; // // 调用COM过程,访问指定下标数组元素,根据dispId 将元素值保存在varValue中 // hr = pDisp->Invoke(dispId, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, &noArgs, &varValue, NULL, NULL); if (SUCCEEDED(hr)) { *pValue = varValue.intVal; // 将数组元素按int类型取出 return hr; } else { return hr; } }
HRESULT GetElementById(const CString& cszId, CComPtr<IHTMLElement>& spElement) { CComPtr<IHTMLDocument2> spIHTMLDocument2; HRESULT hr = GetHtmlDocument(spIHTMLDocument2); if (FAILED(hr)) return hr; CComPtr<IHTMLElementCollection> spIHTMLElementCollection; hr = spIHTMLDocument2->get_all(&spIHTMLElementCollection); if (FAILED(hr)) return hr; CComBSTR bstrName(cszId); CComVariant varName(bstrName); CComVariant varIndex(static_cast<int>(0)); CComPtr<IDispatch> spIDispatchIHTMLElement; hr = spIHTMLElementCollection->item(varName, varIndex, &spIDispatchIHTMLElement); if (FAILED(hr)) return hr; if (spIDispatchIHTMLElement == NULL) return E_FAIL; return spIDispatchIHTMLElement.QueryInterface<IHTMLElement>(&spElement); }
void ScopeInferrer::visitBareDecl(BareDecl *p) { string varName(p->ident_); p->type_->accept(this); auto type = typeStack.top(); typeStack.pop(); auto elem = make_shared<ScopeElement>(current, type, p, false); current->assign(elem, varName); }
void ScopeInferrer::visitArgumentDef(ArgumentDef *p) { string varName(p->ident_); p->type_->accept(this); auto type = typeStack.top(); auto elem = make_shared<ScopeElement>(current, type, p, true); current->assign(elem, varName); current->addFunctionArg(current->resolveName(p->ident_)); }
void VarUnit::addVariable(TVar * var){ QString n = varName(var).join("."); // pointers.insert(var->pointer); varList.insert(n); if ( var->hidden ){ hidden.insert(shortVarName(var).join(".")); } }
bool SiftDetectorConfig::fromJSON(std::string &file) { Json::Value root = readJSON(file); if(root.empty()) { return false; } else { const Json::Value params = root[identifier()]; mBestFeatures = params.get(varName(mBestFeatures), 0).asInt(); mOctaves = params.get(varName(mOctaves), 3).asInt(); mContrastThresh = params.get(varName(mContrastThresh), 0.04).asDouble(); mEdgeThresh = params.get(varName(mEdgeThresh), 10.0).asDouble(); mSigma = params.get(varName(mSigma), 1.6).asDouble(); return true; } }
// ParseImportDirective //------------------------------------------------------------------------------ bool BFFParser::ParseImportDirective( const BFFIterator & directiveStart, BFFIterator & iter ) { iter.SkipWhiteSpace(); // make sure we haven't hit the end of the file if ( iter.IsAtEnd() ) { Error::Error_1012_UnexpectedEndOfFile( directiveStart ); return false; } // make sure this is a variable name if ( iter.IsAtValidVariableNameCharacter() == false ) { Error::Error_1013_UnexpectedCharInVariableName( iter, nullptr ); return false; } // find the end of the variable name const BFFIterator varNameStart( iter ); iter.SkipVariableName(); if ( iter.IsAtEnd() ) { Error::Error_1012_UnexpectedEndOfFile( iter ); return false; } const BFFIterator varNameEnd( iter ); // sanity check it is a sensible length size_t varNameLen = varNameStart.GetDistTo( varNameEnd ); if ( varNameLen > MAX_VARIABLE_NAME_LENGTH ) { Error::Error_1014_VariableNameIsTooLong( iter, (uint32_t)varNameLen, (uint32_t)MAX_VARIABLE_NAME_LENGTH ); return false; } AStackString<> varName( varNameStart.GetCurrent(), varNameEnd.GetCurrent() ); // look for varName in system environment AStackString<> varValue; uint32_t varHash = 0; if ( FBuild::Get().ImportEnvironmentVar( varName.Get(), varValue, varHash ) == false ) { Error::Error_1009_UnknownVariable( varNameStart, nullptr ); return false; } // add the dot to variable name varName = "."; varName.Append( varNameStart.GetCurrent(), varNameLen ); // import variable in current scope BFFStackFrame::SetVarString( varName, varValue, nullptr ); FLOG_INFO( "Imported <string> variable '%s' with value '%s' from system environment", varName.Get(), varValue.Get() ); return true; }
void testSimpleItkMultiComponentImageTransfer() { std::string varName("m_ImageMultiComponent"); CPPUNIT_ASSERT_MESSAGE( "Valid image copied to python import should return true.", m_PythonService->CopyToPythonAsSimpleItkImage( m_Image, varName) == true ); mitk::Image::Pointer pythonImage = m_PythonService->CopySimpleItkImageFromPython(varName); CPPUNIT_ASSERT_MESSAGE( "Compare if images are equal after transfer.", mitk::Equal(*pythonImage.GetPointer(),*m_Image.GetPointer(), mitk::eps,true) ); }
_String ProcessStringArgument (_String* data) { if (data->sLength>2) { if (data->sData[data->sLength-1]=='_' && data->sData[data->sLength-2]=='_') { _String varName (*data,0,data->sLength-3); _FString* theVar = (_FString*)FetchObjectFromVariableByType(&varName,STRING); if (theVar) { return *theVar->theString; } } } return empty; }
void ScopeInferrer::visitSomeStatement(SomeStatement *p) { p->exp_->accept(this); auto s = current->makeChildScope(p); current = s.get(); auto elem = make_shared<ScopeElement>(current, nullptr, p, false); string varName(p->ident_); current->assign(elem, varName); p->statementblock_->accept(this); current = current->parent; }
VisitResult EvaluatorVisitor::Visit(VariableNode * node) { std::string varName(node->mName.mText, node->mName.mLength); auto& currentSymbols = symbol_stack_.back(); Variable* newVar; auto varSymbol = currentSymbols.find(varName); if(varSymbol != currentSymbols.end())//alright so we found something of the same name { node->mSymbol = static_cast<Variable*>(varSymbol->second); ErrorSameName(varName); } else { newVar = library_->CreateVariable(std::string(node->mName.mText, node->mName.mLength), !parent_type_ && !parent_function_); currentSymbols.insert(std::make_pair(varName, newVar)); } //search for type from dependencies and globals? auto& name = node->mType->mName; std::string typeName(name.mText, name.mLength); //find type newVar->mType = static_cast<Type*>(find_symbol_by_name(typeName, dependencies_, library_)); newVar->mType = library_->GetPointerType(newVar->mType, node->mType->mPointerCount); newVar->mParentFunction = parent_function_; newVar->mParentType = parent_type_; node->mSymbol = newVar; if(parent_type_) { if(parent_function_) { //same as function parent_function_->mLocals.push_back(newVar); } else { parent_type_->mMembers.push_back(newVar); parent_type_->mMembersByName.insert(std::make_pair(newVar->mName, newVar)); //just class } } else if(parent_function_) { parent_function_->mLocals.push_back(newVar); } node->Walk(this, false); return VisitResult::Stop; }
void ScopeInferrer::visitEFuncDecl(EFuncDecl *p) { string varName(p->ident_); auto elem = make_shared<ScopeElement>(current, nullptr, p, false); current->assign(elem, varName); auto s = current->makeChildScope(p); current = s.get(); p->listargument_->accept(this); p->statementblock_->accept(this); current = current->parent; }
void ScopeInferrer::visitForStatement(ForStatement *p) { p->exp_->accept(this); auto s = current->makeChildScope(p); current = s.get(); auto elem = make_shared<ScopeElement>(current, nullptr, p, false); string varName(p->ident_); current->assign(elem, varName); auto fullName = current->resolveName(varName); current->addIteratorArg(fullName); p->statementblock_->accept(this); current = current->parent; }
void testCVImageTransfer() { std::string varName("mitkImage"); CPPUNIT_ASSERT_MESSAGE ( "Is OpenCV Python Wrapping available?", m_PythonService->IsOpenCvPythonWrappingAvailable() == true ); CPPUNIT_ASSERT_MESSAGE( "Valid image copied to python import should return true.", m_PythonService->CopyToPythonAsCvImage( m_Image2D, varName) == true ); mitk::Image::Pointer pythonImage = m_PythonService->CopyCvImageFromPython(varName); // todo pixeltypes do not match, cv is changing it //CPPUNIT_ASSERT_MESSAGE( "Compare if images are equal after transfer.", // mitk::Equal(pythonImage,m_Image2D) ); }
HRESULT GetArrayStrOfIndex(IDispatch* pDisp, int index, char * pValue, int * pLen) { CComVariant varName(index, VT_I4); // 数组下标 DISPPARAMS noArgs = {NULL, NULL, 0, 0}; DISPID dispId; VARIANT varValue; HRESULT hr = 0; VariantInit(&varValue); varName.ChangeType(VT_BSTR); // 将数组下标转为数字型,以进行GetIDsOfNames // // 获取通过下标访问数组的过程,将过程名保存在dispId中 // hr = pDisp->GetIDsOfNames(IID_NULL, &varName.bstrVal, 1, LOCALE_USER_DEFAULT, &dispId); if (FAILED(hr)) return hr; // // 调用COM过程,访问指定下标数组元素,根据dispId 将元素值保存在varValue中 // hr = pDisp->Invoke(dispId, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, &noArgs, &varValue, NULL, NULL); if (SUCCEEDED(hr)) { if(NULL == varValue.bstrVal) { * pLen = 0; } else { // 将数组元素按string类型取出 int data_len = 1024 * 1024; char * data_value = new char[data_len]; WideCharToMultiByte( CP_ACP, 0, varValue.bstrVal,wcslen(varValue.bstrVal), data_value, data_len, NULL, NULL); * pLen = strlen(data_value); memcpy(pValue,data_value,* pLen); } return hr; } else { return hr; } }
void PrintLeaves(TChain *theChain, std::ofstream &theFile){ for(int i(0); i<theChain->GetListOfLeaves()->GetSize(); ++i){ std::string typeName(static_cast<TLeafObject*>((theChain->GetListOfLeaves()->At(i)))->GetTypeName()); std::string varName(static_cast<TLeaf*>((theChain->GetListOfLeaves()->At(i)))->GetBranch()->GetName()); bool nonSimp(false); for(unsigned long j(typeName.find("vector")); j!=std::string::npos; j=typeName.find("vector",j+6)){ typeName.replace(j,6,"std::vector"); nonSimp=true; } for(unsigned long j(typeName.find("string")); j!=std::string::npos; j=typeName.find("string",j+6)){ typeName.replace(j,6,"std::string"); nonSimp=true; } if(nonSimp){ theFile << " " << typeName << " *" << varName << ";\n"; }else{ theFile << " " << typeName << " " << varName << ";\n"; } } }
void RvctToolChain::addToEnvironment(Utils::Environment &env) const { if (m_compilerPath.isEmpty()) return; if (m_version.isNull()) setVersion(version(m_compilerPath)); if (m_version.isNull()) return; env.modify(m_environmentChanges); env.set(QLatin1String("QT_RVCT_VERSION"), QString::fromLatin1("%1.%2") .arg(m_version.majorVersion).arg(m_version.minorVersion)); env.set(varName(QLatin1String("BIN")), QDir::toNativeSeparators(QFileInfo(m_compilerPath).absolutePath())); // Add rvct to path and set locale to 'C' if (!m_compilerPath.isEmpty()) env.prependOrSetPath(QFileInfo(m_compilerPath).absolutePath()); env.set(QLatin1String("LANG"), QString(QLatin1Char('C'))); }
Foam::scalar Foam::equationReader::getScalarSrcDictSourceScalar ( const equationReader * eqnReader, const label equationIndex, const label equationOperationIndex, const label maxStoreIndex, const label storageOffset ) const { const equation& eqn(operator[](equationIndex)); const equationOperation& eqOp(eqn[equationOperationIndex]); label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; word varName(dictLookups_[eqOp.dictLookupIndex()]); scalar returnMe ( readScalar(dictSources_[zeroSourceIndex].lookup(varName)) ); returnMe *= sign(eqOp.sourceIndex()); return returnMe; }
/** * @brief Returns a string representation of the given value @a v (it's name). */ std::string VarsHandler::getValueName(const llvm::Value *v) { PRECONDITION_NON_NULL(v); std::string varName(v->getName()); // If the variable does not have its original name, assign a new, unique // name to it. if (varName.empty()) { if (hasItem(anonVarNames, v)) { // This variable already has an assigned name, so use it. varName = anonVarNames[v]; } else { // Generate a new name for this variable. // varNameGen->getNextVarName() automatically resets itself when // there are no available names left (this should not happen in // practice, though). anonVarNames[v] = varName = varNameGen->getNextVarName(); } } return varName; }
Foam::dimensionSet Foam::equationReader::getDimsSrcDictSourceDScalar ( const equationReader * eqnReader, const label equationIndex, const label equationOperationIndex, const label maxStoreIndex, const label storageOffset ) const { dimensionedScalar ds("noSource", dimless, 0); const equation& eqn(operator[](equationIndex)); const equationOperation& eqOp(eqn[equationOperationIndex]); label zeroSourceIndex = mag(eqOp.sourceIndex()) - 1; word varName(dictLookups_[eqOp.dictLookupIndex()]); ITstream srcStrm ( dictSources_[zeroSourceIndex].lookup(varName) ); srcStrm >> ds; return ds.dimensions(); }
vtkDataSet * Streaker::GetMesh(const std::string &mesh, const PDBFileObjectVector &pdb) { #ifdef MDSERVER return 0; #else if(mesh.size() <= 5) return 0; std::string varName(mesh.substr(0, mesh.size()-5)); std::map<std::string, StreakInfo>::iterator pos = streaks.find(varName); if(pos == streaks.end()) return 0; // Create the dataset if needed. if(pos->second.dataset == 0) pos->second.dataset = ConstructDataset(varName, pos->second, pdb); // Increment the reference count. pos->second.dataset->Register(NULL); return pos->second.dataset; #endif }
bool Logger::boolean(LogItem item) { bool rtn = false; BasicName varName(item.value(0).toString()); bool expected = item.value(1).toBool(); QVariant actual = item.value(2); if ( ! actual.canConvert(QVariant::nameToType("bool"))) { item.setValue(3, actual.typeName()); item.setMessage("Can't convert %1 (a %4) to bool; expected %2; is %3"); } else if (expected == actual.toBool()) { rtn = true; item.setLevelToPass(); item.setMessage("%1 IS %2 %3!"); } else { item.setMessage("%1 is NOT %2 %3!"); } enqueue(item); return rtn; }
// *** // 设置Javascript数组中指定位置的整数元素值 // *** HRESULT SetArrayNumberOfIndex(IDispatch* pDisp, int index, int value) { CComVariant varName(index, VT_I4); DISPID dispId; CComVariant varValue; HRESULT hr = 0; varName.ChangeType(VT_BSTR); // 将数组下标转为数字型,以进行GetIDsOfNames hr = pDisp->GetIDsOfNames (IID_NULL, &varName.bstrVal, 1, LOCALE_USER_DEFAULT, &dispId); if (FAILED(hr)) return hr; DISPID dispidPut = DISPID_PROPERTYPUT; // put操作 DISPPARAMS dispparams; dispparams.rgvarg = new VARIANTARG[1]; // 初始化rgvarg dispparams.rgvarg[0].vt = VT_I4; // 数据类型 dispparams.rgvarg[0].intVal = value; // 更新值 dispparams.cArgs = 1; // 参数数量 dispparams.cNamedArgs = 1; // 参数名称 dispparams.rgdispidNamedArgs = &dispidPut; // 操作DispId,表明本参数适用于put操作 hr = pDisp->Invoke(dispId, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL); return hr; }
bool VesselMask::fromJSON(const std::string &file) { Json::Value root = readJSON(file); if(root.empty()) { return false; } else { const Json::Value params = root[identifier()]; mOctaves = params.get(varName(mOctaves), 3).asInt(); mStages = params.get(varName(mStages), 3).asInt(); mSigma = params.get(varName(mSigma), 1).asDouble(); mBeta = params.get(varName(mBeta), 0.5).asDouble(); mC = params.get(varName(mC), 12).asDouble(); mThreshold = params.get(varName(mThreshold), 0.5).asDouble(); return true; } }
// -------------------------------------------------------- // Loads the specified shader and builds the variable table using shader // reflection. This must be a separate step from the constructor since // we can't invoke derived class overrides in the base class constructor. // // shaderFile - A "wide string" specifying the compiled shader to load // // Returns true if shader is loaded properly, false otherwise // -------------------------------------------------------- bool ISimpleShader::LoadShaderFile(LPCWSTR shaderFile) { // Load the shader to a blob and ensure it worked ID3DBlob* shaderBlob = 0; HRESULT hr = D3DReadFileToBlob(shaderFile, &shaderBlob); if (hr != S_OK) { return false; } // Create the shader - Calls an overloaded version of this abstract // method in the appropriate child class shaderValid = CreateShader(shaderBlob); if (!shaderValid) { shaderBlob->Release(); return false; } // Set up shader reflection to get information about // this shader and its variables, buffers, etc. ID3D11ShaderReflection* refl; D3DReflect( shaderBlob->GetBufferPointer(), shaderBlob->GetBufferSize(), IID_ID3D11ShaderReflection, (void**)&refl); // Get the description of the shader D3D11_SHADER_DESC shaderDesc; refl->GetDesc(&shaderDesc); // Create an array of constant buffers constantBufferCount = shaderDesc.ConstantBuffers; constantBuffers = new SimpleConstantBuffer[constantBufferCount]; // Handle bound resources (like shaders and samplers) unsigned int resourceCount = shaderDesc.BoundResources; for (unsigned int r = 0; r < resourceCount; r++) { // Get this resource's description D3D11_SHADER_INPUT_BIND_DESC resourceDesc; refl->GetResourceBindingDesc(r, &resourceDesc); // Check the type switch (resourceDesc.Type) { case D3D_SIT_TEXTURE: // A texture resource textureTable.insert(std::pair<std::string, unsigned int>(resourceDesc.Name, resourceDesc.BindPoint)); break; case D3D_SIT_SAMPLER: // A sampler resource samplerTable.insert(std::pair<std::string, unsigned int>(resourceDesc.Name, resourceDesc.BindPoint)); break; } } // Loop through all constant buffers for (unsigned int b = 0; b < constantBufferCount; b++) { // Get this buffer ID3D11ShaderReflectionConstantBuffer* cb = refl->GetConstantBufferByIndex(b); // Get the description of this buffer D3D11_SHADER_BUFFER_DESC bufferDesc; cb->GetDesc(&bufferDesc); // Get the description of the resource binding, so // we know exactly how it's bound in the shader D3D11_SHADER_INPUT_BIND_DESC bindDesc; refl->GetResourceBindingDescByName(bufferDesc.Name, &bindDesc); // Set up the buffer and put its pointer in the table constantBuffers[b].BindIndex = bindDesc.BindPoint; cbTable.insert(std::pair<std::string, SimpleConstantBuffer*>(bufferDesc.Name, &constantBuffers[b])); // Create this constant buffer D3D11_BUFFER_DESC newBuffDesc; newBuffDesc.Usage = D3D11_USAGE_DEFAULT; newBuffDesc.ByteWidth = bufferDesc.Size; newBuffDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; newBuffDesc.CPUAccessFlags = 0; newBuffDesc.MiscFlags = 0; newBuffDesc.StructureByteStride = 0; device->CreateBuffer(&newBuffDesc, 0, &constantBuffers[b].ConstantBuffer); // Set up the data buffer for this constant buffer constantBuffers[b].LocalDataBuffer = new unsigned char[bufferDesc.Size]; ZeroMemory(constantBuffers[b].LocalDataBuffer, bufferDesc.Size); // Loop through all variables in this buffer for (unsigned int v = 0; v < bufferDesc.Variables; v++) { // Get this variable ID3D11ShaderReflectionVariable* var = cb->GetVariableByIndex(v); // Get the description of the variable D3D11_SHADER_VARIABLE_DESC varDesc; var->GetDesc(&varDesc); // Create the variable struct SimpleShaderVariable varStruct; varStruct.ConstantBufferIndex = b; varStruct.ByteOffset = varDesc.StartOffset; varStruct.Size = varDesc.Size; // Get a string version std::string varName(varDesc.Name); // Add this variable to the table varTable.insert(std::pair<std::string, SimpleShaderVariable>(varName, varStruct)); } } // All set refl->Release(); shaderBlob->Release(); return true; }