FunctionType FunctionType::substitute(const TemplateVarMap& templateVarMap, const Predicate& selfconst) const { if (templateVarMap.empty() && selfconst.isSelfConst()) { return *this; } const auto substitutedReturnType = returnType()->substitute(templateVarMap, selfconst); bool changed = (substitutedReturnType != returnType()); TypeArray substitutedParameterTypes; for (const auto parameterType: parameterTypes()) { const auto substitutedParameterType = parameterType->substitute(templateVarMap, selfconst); changed |= (substitutedParameterType != parameterType); substitutedParameterTypes.push_back(substitutedParameterType); } auto noExceptPredicate = attributes().noExceptPredicate().substitute(templateVarMap, selfconst); changed |= (noExceptPredicate != attributes().noExceptPredicate()); if (changed) { FunctionAttributes newAttributes(attributes().isVarArg(), attributes().isMethod(), attributes().isTemplated(), std::move(noExceptPredicate)); return FunctionType(std::move(newAttributes), substitutedReturnType, std::move(substitutedParameterTypes)); } else { return *this; } }
AST::Value CallValue(Context& context, AST::Value rawValue, HeapArray<AST::Value> args, const Debug::SourceLocation& location) { auto value = derefValue(std::move(rawValue)); if (getDerefType(value.type())->isTypename()) { return CallValue(context, GetStaticMethod(context, std::move(value), context.getCString("create"), location), std::move(args), location); } if (!value.type()->isCallable()) { // Try to use 'call' method. if (TypeCapabilities(context).hasCallMethod(getDerefType(value.type()))) { return CallValue(context, GetMethod(context, std::move(value), context.getCString("call"), location), std::move(args), location); } else { context.issueDiag(TypeNotCallableDiag(getDerefType(value.type())), location); return AST::Value::Constant(Constant::Integer(0), context.typeBuilder().getIntType()); } } const auto functionType = value.type()->asFunctionType(); const auto& typeList = functionType.parameterTypes(); if (functionType.attributes().isVarArg()) { if (args.size() < typeList.size()) { context.issueDiag(VarArgTooFewArgsDiag(value.toDiagString(), args.size(), typeList.size()), location); } } else { if (args.size() != typeList.size()) { context.issueDiag(CallIncorrectArgCountDiag(value.toDiagString(), args.size(), typeList.size()), location); } } if (!TypeCapabilities(context).isSized(functionType.returnType())) { // TODO: also check that the type is not abstract. context.issueDiag(CallReturnTypeIsUnsizedDiag(functionType.returnType()), location); } if (functionType.returnType()->hasConst()) { context.issueDiag(CallReturnTypeIsConstDiag(functionType.returnType()), location); } return addDebugInfo(AST::Value::Call(std::move(value), CastFunctionArguments(context, std::move(args), typeList, location), functionType.returnType()->stripConst()), location); }
std::string Function::toString() const { if (isDeclaration()) { return makeString("FunctionDecl(name = %s, returnType = %s, ... (TODO))", name()->toString().c_str(), returnType().toString().c_str()); } else { if (isDefaultDefinition()) { return makeString("DefaultFunctionDef(name = %s)", name()->toString().c_str()); } else { return makeString("FunctionDef(name = %s, returnType = %s, ... (TODO))", name()->toString().c_str(), returnType().toString().c_str()); } } }
std::size_t FunctionTypeData::hash() const { Hasher hasher; hasher.add(attributes()); hasher.add(returnType()); hasher.add(parameterTypes()); return hasher.get(); }
void UmlOperation::write_return_type(FileOut & out, QCString decl) { const UmlTypeSpec & t = returnType(); static int return_rank = 0; if ((t.type != 0) || !t.explicit_type.isEmpty()) { out.indent(); out << "<UML:Parameter name=\"return\" xmi.id=\"BOUML_return_" << ++return_rank << "\" kind=\"return\">\n"; out.indent(); out << "\t<UML:Parameter.type>\n"; out.indent(); out << "\t\t<UML:DataType"; switch (_lang) { case Uml: if (t.type != 0) out.idref(t.type); else out.idref_datatype(t.explicit_type); break; case Cpp: write_cpp_returntype(out, decl); break; default: // java write_java_returntype(out, decl); } out << "/>\n"; out.indent(); out << "\t</UML:Parameter.type>\n"; out.indent(); out << "</UML:Parameter>\n"; } }
string InterfaceGenerator::generateMethod(Method & m) { string tmp = TEMPLATE_INTERFACE_METHOD; //set methodname replaceAll(tmp, "<methodName>", m.name); replaceAll(tmp, "<methodComment>", "[method] " + m.name + ": " + m.comment); std::stringstream aliases; std::stringstream pcom; for (Argument::List::iterator a = m.inArguments.begin(); a != m.inArguments.end(); a++) { pcom << tab << tab << " * [in] " << argType(*a) << " " << a->name << ": " << a->comment << endl; if (!a->alias.empty()){ aliases << tab << tab << "typedef " << argType(*a) << " " << a->alias << ";" << endl; } } for (Argument::List::iterator a = m.outArguments.begin(); a != m.outArguments.end(); a++) { pcom << tab << tab << " * [out] " << argType(*a) << " " << a->name << ": " << a->comment << endl; if (!a->alias.empty()){ aliases << tab << tab << "typedef " << argType(*a) << " " << a->alias << ";" << endl; } } replaceAll(tmp, "<paramsComments>", pcom.str()); replaceAll(tmp, "<aliases>", aliases.str()); replaceAll(tmp, "<returnType>", returnType(m, true)); replaceAll(tmp, "<parameters>", methodArgDefinition(m, true)); return tmp; }
void SemanticAnalysisVisitor::visit(ast::FunctionCall& functionCall) { functionCall.visitOperand(*this); functionCall.visitArguments(*this); // FIXME: try/catch for undefined functions auto functionSymbol = symbolTable.findFunction(functionCall.operandSymbol()->getName()); functionCall.setSymbol(functionSymbol); auto& arguments = functionCall.getArgumentList(); if (arguments.size() == functionSymbol.argumentCount()) { auto& declaredArguments = functionSymbol.arguments(); for (std::size_t i { 0 }; i < arguments.size(); ++i) { const auto& declaredArgument = declaredArguments.at(i); const auto& actualArgument = arguments.at(i)->getResultSymbol(); typeCheck(actualArgument->getType(), *declaredArgument, functionCall.getContext()); } auto& returnType = functionSymbol.returnType(); if (!returnType.isVoid()) { functionCall.setResultSymbol(symbolTable.createTemporarySymbol(std::unique_ptr<ast::FundamentalType> { returnType.clone() })); } } else { semanticError("no match for function " + functionSymbol.getType().toString(), functionCall.getContext()); } }
ExprType ExprPrototypeNode::prep(bool wantScalar, ExprVarEnvBuilder& envBuilder) { // TODO: implement prototype bool error=false; checkCondition(false, "Prototypes are currently not supported",error); return ExprType().Error(); #if 0 bool error = false; if (_retTypeSet) checkCondition(returnType().isValid(), "Function has bad return type", error); _argTypes.clear(); for (int c = 0; c < numChildren(); c++) { ExprType type = child(c)->type(); checkCondition(type.isValid(), "Function has a parameter with a bad type", error); _argTypes.push_back(type); ExprLocalVar* localVar = new ExprLocalVar(type); envBuilder.current()->add(((ExprVarNode*)child(c))->name(), localVar); std::cerr << "after create localvar phi " << localVar->getPhi() << std::endl; child(c)->prep(wantScalar, envBuilder); } if (error) setType(ExprType().Error()); else setType(ExprType().None().Varying()); return _type; #endif }
void UmlOperation::write_cpp_returntype(FileOut & out, QCString decl) { // doesn't manage function pointer // manage keywords int index; if ((index = decl.find("${static}")) != -1) decl.remove(index, 9); if ((index = decl.find("${friend}")) != -1) decl.remove(index, 9); if ((index = decl.find("${virtual}")) != -1) decl.remove(index, 10); if ((index = decl.find("${inline}")) != -1) decl.remove(index, 9); if ((index = decl.find("${(}")) == -1) decl = "${type} ${name}"; else decl.truncate(index); UmlTypeSpec t = returnType(); if ((t.type != 0) || !(t.explicit_type = CppSettings::type(t.explicit_type)).isEmpty()) write_type(out, t, decl, "${name}", "${type}"); }
void UmlOperation::write_java_returntype(FileOut & out, QCString decl) { // manage keywords int index; if ((index = decl.find("${visibility}")) != -1) decl.remove(index, 13); if ((index = decl.find("${final}")) != -1) decl.remove(index, 8); if ((index = decl.find("${static}")) != -1) decl.remove(index, 9); if ((index = decl.find("${abstract}")) != -1) decl.remove(index, 11); if ((index = decl.find("${synchronized}")) != -1) decl.remove(index, 15); if ((index = decl.find("${@}")) != -1) decl.remove(index, 4); if ((index = decl.find("${(}")) == -1) decl = "${type} ${name}"; else decl.truncate(index); UmlTypeSpec t = returnType(); if ((t.type != 0) || !(t.explicit_type = JavaSettings::type(t.explicit_type)).isEmpty()) write_type(out, t, decl, "${name}", "${type}"); }
std::string MethodSetElement::toString() const { return makeString("MethodSetElement(constPredicate: %s, noexceptPredicate: %s, requirePredicate: %s, returnType: %s, ...)", constPredicate().toString().c_str(), noexceptPredicate().toString().c_str(), requirePredicate().toString().c_str(), returnType()->toString().c_str()); }
std::string JsonServerGenerator::generateAbstractDefinitions(Class &c) { stringstream result; //methods for (Method::List::iterator m = c.methods.begin(); m != c.methods.end(); m++) { string tmp = TEMPLATE_SERVER_ABSTRACTDEFINITION; //set methodname replaceAll(tmp, "<methodName>", m->name); replaceAll(tmp, "<returnType>", returnType(*m)); replaceAll(tmp, "<parameters>", methodArgDefinition(*m)); replaceAll(tmp, "<parameterValues>", methodArgValues(*m)); /*if (m->outArguments.size() > 1) { throw Poco::Exception("cannot convert more then one out param to json client"); }*/ if (m->isReturn()) { replaceAll(tmp, "<returnStatement>", "return"); } else { replaceAll(tmp, "<returnStatement>", ""); } result << tmp << endl; } return result.str(); }
std::string JsonServerGenerator::generateProcedureDefinitions(Class &c) { stringstream result; string tmp; //methods for (Method::List::iterator m = c.methods.begin(); m != c.methods.end(); m++) { if (m->isVoid()) { tmp = TEMPLATE_SERVER_EMPTYMETHODDEFINITION; } else if (m->isReturn()) { tmp = TEMPLATE_SERVER_METHODDEFINITION; replaceAll(tmp, "<returnType>", returnType(*m)); } else { tmp = TEMPLATE_SERVER_OUTMETHODDEFINITION; std::stringstream outParams; std::stringstream outParamsAssignment; for (Argument::List::iterator a = m->outArguments.begin(); a != m->outArguments.end(); a++) { outParams << this->argType(*a) << " tmpvar_" << a->name << ";" <<std::endl; outParamsAssignment << "response[\"" + a->name + "\"] = jsonrpc::Convertor::cpp2Json<" + this->argType(*a) + " >(tmpvar_" << a->name << ");" <<std::endl; } replaceAll(tmp, "<outputParams>", outParams.str()); replaceAll(tmp, "<responseAssign>",outParamsAssignment.str()); } replaceAll(tmp, "<procedureName>", m->name); replaceAll(tmp, "<parameterMapping>", this->generateParameterMapping(*m)); result << tmp << endl; } return result.str(); return ""; }
std::string FunctionTypeData::nameToString() const { return makeString("FunctionType(" "attributes: %s, " "returnType: %s, " "parameterTypes: %s)", attributes().toString().c_str(), returnType()->nameToString().c_str(), makeNameArrayString(parameterTypes()).c_str()); }
bool ContainedInvocableType::canStandAlone() const { if (!returnType()->canStandAlone()) return false; foreach (TypeConcept* e, cardinalChildrenAs<TypeConcept>()) if (!e->asKind<TypeConcept>()->canStandAlone()) return false; return true; }
datatypes::ReturnType HaierCommonSDK::GetInfo(const datatypes::RealDevice &device, const datatypes::Attribute &attr_names, void *extra) { if (attr_names.GetAttributeName().compare(GET_ALARM) == 0) { if (device_alarm_cache.find(device) != device_alarm_cache.end()) { datatypes::Value value = datatypes::Value(); if (device_alarm_cache.find(device) != device_alarm_cache.end()) { for (int i = 0; i < device_alarm_cache[device].size(); i++) { value.InsertValue( datatypes::ValueTypePair( device_alarm_cache[device][i], datatypes::ValType::STRING ) ); } } datatypes::AttributeValuePair pair = datatypes::AttributeValuePair( datatypes::Attribute(GET_ALARM), value); datatypes::ReturnType returnType = datatypes::ReturnType(device, pair, "", datatypes::ReturnType::SDK_OK, ""); return returnType; } else { datatypes::AttributeValuePair pair = datatypes::AttributeValuePair(datatypes::Attribute(GET_ALARM), datatypes::Value()); return datatypes::ReturnType(device, pair, "", datatypes::ReturnType::SDK_OK, ""); } } char *attr_name = (char *) attr_names.GetAttributeName().c_str(); context_t *context = ugw_new_context(); //while (!device_set_attr_lock); int ret = ugw_get_attr(handle, context, (char *) device.GetDeviceId().c_str(), attr_name); std::vector<datatypes::ValueTypePair> vector;// = std::vector<datatypes::ValueTypePair>(); if (ret == 0) { datatypes::ValueTypePair pair(new int(atoi(context->value)), datatypes::ValType::INT); vector.push_back(pair); } datatypes::AttributeValuePair attributeValuePair(attr_names, datatypes::Value(vector)); datatypes::ReturnType returnType(device, attributeValuePair, "", ConvertErrorCode(ret), ""); ugw_free_context(context); return returnType; }
bool MethodSetElement::operator==(const MethodSetElement& methodSetElement) const { return templateVariables() == methodSetElement.templateVariables() && constPredicate() == methodSetElement.constPredicate() && noexceptPredicate() == methodSetElement.noexceptPredicate() && requirePredicate() == methodSetElement.requirePredicate() && returnType() == methodSetElement.returnType() && parameterTypes() == methodSetElement.parameterTypes() && isStatic() == methodSetElement.isStatic(); }
std::string Prototype::getMangledName() const { std::ostringstream Scratch; auto FTy = cast<FunctionType>(VTy); Scratch << "std_" << *FTy->returnType() << "_" << Name << "__"; auto ATys = FTy->getATys(); Scratch << *ATys.front(); ATys.erase(ATys.begin()); for (auto ATy : ATys) Scratch << "_" << *ATy; return Scratch.str(); }
Ellipse::Ellipse() { type="Ellipse"; returnType(); radius = ((int)ofRandom(8)+3)*2.5; speed = (0.00229) * ((int)ofRandom(16)+1)/16.; size = ofVec2f(radius, radius); originalSize = size; ofSetCircleResolution(360); angle = ofRandom(360); originalAlpha = ofRandom(100)+20; }
FunctionType FunctionType::makeTemplated() const { if (attributes().isTemplated()) { return *this; } const bool newIsTemplated = true; FunctionAttributes newAttributes(attributes().isVarArg(), attributes().isMethod(), newIsTemplated, attributes().noExceptPredicate().copy()); return FunctionType(std::move(newAttributes), returnType(), parameterTypes().copy()); }
String Signature::toString() const { String result(makeString(returnType())); result.append(" ("); for (SignatureArgCount arg = 0; arg < argumentCount(); ++arg) { if (arg) result.append(", "); result.append(makeString(argument(arg))); } result.append(')'); return result; }
Image::Image(string filename, ofVec3f loc){ this->loc = loc; type = "Image"; returnType(); image.load(filename); // image.mirror(true, false); cout << image.getImageType() << endl; // image.setImageType(OF_IMAGE_COLOR_ALPHA); size = ofVec2f(image.getWidth(), image.getHeight()); loc = ofVec2f(0,0); meshSetup(); // createFullScreenCopy(); }
String FunctorType::code(String const& _middle) const { String ret = L"(("; foreach (Concept* e, cardinalChildren()) { if (ret.right(2) != L"((") ret += L", "; ret += e->asKind<TypeConcept>()->code(); } ret += L")->" + returnType()->code() + L")" + _middle; return ret; }
QString Method::signature(bool withReturnType) const { QString sig; if(withReturnType) sig += returnType() + " "; sig += name; sig += "("; QStringList paramSigs; foreach (const Parameter ¶m, params) paramSigs << param.signature(); sig += paramSigs.join(", "); sig += ")"; return sig; }
String FunctionType::code(String const& _middle) const { String ret = returnType()->code() + "(" + _middle + ")("; foreach (Concept* e, cardinalChildren()) { if (ret.right(1) != "(") ret += ", "; ret += e->asKind<TypeConcept>()->code(); } if (m_ellipsis) ret += (cardinalChildCount()) ? ", ..." : "..."; ret += ")"; return ret; }
std::size_t MethodSetElement::hash() const { std::size_t seed = 0; boost::hash_combine(seed, templateVariables().hash()); boost::hash_combine(seed, constPredicate().hash()); boost::hash_combine(seed, noexceptPredicate().hash()); boost::hash_combine(seed, requirePredicate().hash()); boost::hash_combine(seed, isStatic()); boost::hash_combine(seed, returnType()); for (const auto& parameterType: parameterTypes()) { boost::hash_combine(seed, parameterType); } return seed; }
bool FunctionType::dependsOnOnly(const TemplateVarArray& array) const { if (!returnType()->dependsOnOnly(array)) { return false; } if (!attributes().noExceptPredicate().dependsOnOnly(array)) { return false; } for (const auto& paramType: parameterTypes()) { if (!paramType->dependsOnOnly(array)) { return false; } } return true; }
datatypes::ReturnType HaierCommonSDK::GetDevList(void *extra) { context_t *context = ugw_new_context(); int ret = ugw_get_devs(handle, context); datatypes::Value value = datatypes::Value(); for (int i = 0; i < context->dev_count; i++) { datatypes::RealDevice *rd = new datatypes::RealDevice(context->devs[i].device_id, HAIER_VENDOR_ID); datatypes::ValueTypePair pair(rd, datatypes::ValType::REAL_DEVICE); value.InsertValue(pair); } datatypes::Attribute attr = datatypes::Attribute(REAL_DEVICE_LIST); datatypes::AttributeValuePair attributeValuePair = datatypes::AttributeValuePair(attr, value); datatypes::ReturnType returnType(datatypes::RealDevice("", HAIER_VENDOR_ID), attributeValuePair, "", ConvertErrorCode(ret), ""); ugw_free_context(context); return returnType; }
bool mitk::IGTLDevice::SendRTSMessage(const char* type) { //construct the device type for the return message, it starts with RTS_ and //continues with the requested type std::string returnType("RTS_"); returnType.append(type); //create a return message igtl::MessageBase::Pointer rtsMsg = this->m_MessageFactory->CreateInstance(returnType); //if retMsg is NULL there is no return message defined and thus it is not //necessary to send one back if ( rtsMsg.IsNotNull() ) { this->SendMessage(rtsMsg); return true; } else { return false; } }
void UmlOperation::generate_imports(QTextStream & f, WrapperStr & made) { WrapperStr s = pythonDecl(); if (!s.isEmpty()) { UmlArtifact * art = ((UmlClass *) parent())->assocArtifact(); returnType().generate_import(f, art, FALSE, made); int index1 = s.find("${(}"); if (index1 == -1) return; index1 += 4; int index2 = s.find("${)}", index1); if (index2 == -1) return; s = s.mid((unsigned) index1, (unsigned)(index2 - index1)); const QList<UmlParameter> & params = this->params(); QList<UmlParameter>::ConstIterator it; unsigned rank; char ti[16]; strcpy(ti, "${p"); for (it = params.begin(), rank = 0; it != params.end(); ++it, rank += 1) { sprintf(ti + 3, "%u}", rank); if (s.find(ti) != -1) (*it).type.generate_import(f, art, FALSE, made); } } }