void Func::getFuncInfo(ClassInfo::MethodInfo* mi) const { assert(mi); if (info() != nullptr) { // Very large operator=() invocation. *mi = *info(); // Deep copy the vectors of mi-owned pointers. cloneMembers(mi->parameters); cloneMembers(mi->staticVariables); } else { // hphpc sets the ClassInfo::VariableArguments attribute if the method // contains a call to func_get_arg, func_get_args, or func_num_args. We // don't do this in the VM currently and hopefully we never will need to. int attr = 0; if (m_attrs & AttrReference) attr |= ClassInfo::IsReference; if (m_attrs & AttrAbstract) attr |= ClassInfo::IsAbstract; if (m_attrs & AttrFinal) attr |= ClassInfo::IsFinal; if (m_attrs & AttrProtected) attr |= ClassInfo::IsProtected; if (m_attrs & AttrPrivate) attr |= ClassInfo::IsPrivate; if (m_attrs & AttrStatic) attr |= ClassInfo::IsStatic; if (!(attr & ClassInfo::IsProtected || attr & ClassInfo::IsPrivate)) { attr |= ClassInfo::IsPublic; } if (preClass() && (!strcasecmp(m_name->data(), "__construct") || (!(preClass()->attrs() & AttrTrait) && !strcasecmp(m_name->data(), preClass()->name()->data()) && !preClass()->hasMethod(String("__construct").get())))) { attr |= ClassInfo::IsConstructor; } if (attr == 0) attr = ClassInfo::IsNothing; mi->attribute = (ClassInfo::Attribute)attr; mi->name = m_name->data(); mi->file = m_unit->filepath()->data(); mi->line1 = line1(); mi->line2 = line2(); if (docComment() && !docComment()->empty()) { mi->docComment = docComment()->data(); } // Get the parameter info for (unsigned i = 0; i < unsigned(m_numParams); ++i) { ClassInfo::ParameterInfo* pi = new ClassInfo::ParameterInfo; attr = 0; if (byRef(i)) { attr |= ClassInfo::IsReference; } if (attr == 0) { attr = ClassInfo::IsNothing; } const ParamInfoVec& params = shared()->m_params; const ParamInfo& fpi = params[i]; pi->attribute = (ClassInfo::Attribute)attr; pi->name = shared()->m_localNames[i]->data(); if (params.size() <= i || !fpi.hasDefaultValue()) { pi->value = nullptr; pi->valueText = ""; } else { if (fpi.hasScalarDefaultValue()) { // Most of the time the default value is scalar, so we can // avoid evaling in the common case pi->value = strdup(f_serialize( tvAsVariant((TypedValue*)&fpi.defaultValue())).get()->data()); } else { // Eval PHP code to get default value, and serialize the result. Note // that access of undefined class constants can cause the eval() to // fatal. Zend lets such fatals propagate, so don't bother catching // exceptions here. CVarRef v = g_vmContext->getEvaledArg( fpi.phpCode(), cls() ? cls()->nameRef() : nameRef() ); pi->value = strdup(f_serialize(v).get()->data()); } // This is a raw char*, but its lifetime should be at least as long // as the the Func*. At this writing, it's a merged anon string // owned by ParamInfo. pi->valueText = fpi.phpCode()->data(); } pi->type = fpi.typeConstraint().hasConstraint() ? fpi.typeConstraint().typeName()->data() : ""; for (UserAttributeMap::const_iterator it = fpi.userAttributes().begin(); it != fpi.userAttributes().end(); ++it) { // convert the typedvalue to a cvarref and push into pi. auto userAttr = new ClassInfo::UserAttributeInfo; assert(it->first->isStatic()); userAttr->name = const_cast<StringData*>(it->first); userAttr->setStaticValue(tvAsCVarRef(&it->second)); pi->userAttrs.push_back(userAttr); } mi->parameters.push_back(pi); } // XXX ConstantInfo is abused to store static variable metadata, and // although ConstantInfo::callbacks provides a mechanism for registering // callbacks, it does not pass enough information through for the callback // functions to know the function context whence the callbacks came. // Furthermore, the callback mechanism isn't employed in a fashion that // would allow repeated introspection to reflect updated values. // Supporting introspection of static variable values will require // different plumbing than currently exists in ConstantInfo. const SVInfoVec& staticVars = shared()->m_staticVars; for (SVInfoVec::const_iterator it = staticVars.begin(); it != staticVars.end(); ++it) { ClassInfo::ConstantInfo* ci = new ClassInfo::ConstantInfo; ci->name = *(String*)(&(*it).name); if ((*it).phpCode != nullptr) { ci->valueLen = (*it).phpCode->size(); ci->valueText = (*it).phpCode->data(); } else { ci->valueLen = 0; ci->valueText = ""; } mi->staticVariables.push_back(ci); } } }
void JClass::setStaticValue(const char* name, JSignature sig, QVariant value) { QByteArray ba = sig.str().toLatin1(); setStaticValue(name, ba.data(), value); }