本文整理汇总了C++中ParameterExpressionPtr::defaultValue方法的典型用法代码示例。如果您正苦于以下问题:C++ ParameterExpressionPtr::defaultValue方法的具体用法?C++ ParameterExpressionPtr::defaultValue怎么用?C++ ParameterExpressionPtr::defaultValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParameterExpressionPtr
的用法示例。
在下文中一共展示了ParameterExpressionPtr::defaultValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onParse
void FunctionStatement::onParse(AnalysisResultConstPtr ar, FileScopePtr scope) {
// Correctness checks are normally done before adding function to scope.
if (m_params) {
for (int i = 0; i < m_params->getCount(); i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
if (param->hasTypeHint() && param->defaultValue()) {
param->compatibleDefault();
}
}
}
// note it's important to add to scope, not a pushed FunctionContainer,
// as a function may be declared inside a class's method, yet this function
// is a global function, not a class method.
FunctionScopePtr fs = onInitialParse(ar, scope);
FunctionScope::RecordFunctionInfo(m_name, fs);
if (!scope->addFunction(ar, fs)) {
m_ignored = true;
return;
}
if (Option::PersistenceHook) {
fs->setPersistent(Option::PersistenceHook(fs, scope));
}
}
示例2: setParamCounts
void FunctionScope::setParamCounts(AnalysisResultPtr ar, int minParam,
int maxParam) {
m_minParam = minParam;
m_maxParam = maxParam;
ASSERT(m_minParam >= 0 && m_maxParam >= m_minParam);
if (m_maxParam > 0) {
m_paramNames.resize(m_maxParam);
m_paramTypes.resize(m_maxParam);
m_paramTypeSpecs.resize(m_maxParam);
m_paramDefaults.resize(m_maxParam);
m_paramDefaultTexts.resize(m_maxParam);
m_refs.resize(m_maxParam);
if (m_stmt) {
MethodStatementPtr stmt = dynamic_pointer_cast<MethodStatement>(m_stmt);
ExpressionListPtr params = stmt->getParams();
for (int i = 0; i < m_maxParam; i++) {
if (stmt->isRef(i)) m_refs[i] = true;
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*params)[i]);
m_paramNames[i] = param->getName();
m_paramTypeSpecs[i] = param->getTypeSpec(ar);
ExpressionPtr exp = param->defaultValue();
if (exp) {
m_paramDefaults[i] = exp->getText(false, false, ar);
}
}
}
}
}
示例3: onParse
void FunctionStatement::onParse(AnalysisResultConstPtr ar, FileScopePtr scope) {
// Correctness checks are normally done before adding function to scope.
if (m_params) {
for (int i = 0; i < m_params->getCount(); i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
if (param->hasTypeHint() && param->defaultValue()) {
param->compatibleDefault();
}
}
}
// note it's important to add to scope, not a pushed FunctionContainer,
// as a function may be declared inside a class's method, yet this function
// is a global function, not a class method.
FunctionScopePtr fs = onInitialParse(ar, scope);
FunctionScope::RecordFunctionInfo(m_name, fs);
if (!scope->addFunction(ar, fs)) {
m_ignored = true;
return;
}
if (Option::PersistenceHook) {
fs->setPersistent(Option::PersistenceHook(fs, scope));
}
if (fs->isNative()) {
if (getStmts()) {
parseTimeFatal(Compiler::InvalidAttribute,
"Native functions must not have an implementation body");
}
if (m_params) {
int nParams = m_params->getCount();
for (int i = 0; i < nParams; ++i) {
auto param = dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
if (!param->hasUserType()) {
parseTimeFatal(Compiler::InvalidAttribute,
"Native function calls must have type hints "
"on all args");
}
}
}
if (getReturnTypeConstraint().empty()) {
parseTimeFatal(Compiler::InvalidAttribute,
"Native function %s() must have a return type hint",
getOriginalName().c_str());
}
} else if (!getStmts()) {
parseTimeFatal(Compiler::InvalidAttribute,
"Global function %s() must contain a body",
getOriginalName().c_str());
}
}
示例4: setParamSpecs
void FunctionScope::setParamSpecs(AnalysisResultPtr ar) {
if (m_maxParam > 0 && m_stmt) {
MethodStatementPtr stmt = dynamic_pointer_cast<MethodStatement>(m_stmt);
ExpressionListPtr params = stmt->getParams();
for (int i = 0; i < m_maxParam; i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*params)[i]);
TypePtr specType = param->getTypeSpec(ar, false);
if (specType &&
!specType->is(Type::KindOfSome) &&
!specType->is(Type::KindOfVariant)) {
m_paramTypeSpecs[i] = specType;
}
ExpressionPtr exp = param->defaultValue();
if (exp) {
m_paramDefaults[i] = exp->getText(false, false, ar);
}
}
}
}
示例5: inliner
ExpressionPtr FunctionCall::inliner(AnalysisResultConstPtr ar,
ExpressionPtr obj, std::string localThis) {
FunctionScopePtr fs = getFunctionScope();
if (m_noInline || !fs || fs == m_funcScope || !m_funcScope->getStmt()) {
return ExpressionPtr();
}
BlockScope::s_jobStateMutex.lock();
if (m_funcScope->getMark() == BlockScope::MarkProcessing) {
fs->setForceRerun(true);
BlockScope::s_jobStateMutex.unlock();
return ExpressionPtr();
}
ReadLock lock(m_funcScope->getInlineMutex());
BlockScope::s_jobStateMutex.unlock();
if (!m_funcScope->getInlineAsExpr()) {
return ExpressionPtr();
}
if (m_funcScope->getInlineSameContext() &&
m_funcScope->getContainingClass() &&
m_funcScope->getContainingClass() != getClassScope()) {
/*
The function contains a context sensitive construct such as
call_user_func (context sensitive because it could call
array('parent', 'foo')) so its not safe to inline it
into a different context.
*/
return ExpressionPtr();
}
MethodStatementPtr m
(dynamic_pointer_cast<MethodStatement>(m_funcScope->getStmt()));
VariableTablePtr vt = fs->getVariables();
int nAct = m_params ? m_params->getCount() : 0;
int nMax = m_funcScope->getMaxParamCount();
if (nAct < m_funcScope->getMinParamCount() || !m->getStmts()) {
return ExpressionPtr();
}
InlineCloneInfo info(m_funcScope);
info.elist = ExpressionListPtr(new ExpressionList(
getScope(), getLocation(),
ExpressionList::ListKindWrapped));
std::ostringstream oss;
oss << fs->nextInlineIndex() << "_" << m_name << "_";
std::string prefix = oss.str();
if (obj) {
info.callWithThis = true;
if (!obj->isThis()) {
SimpleVariablePtr var
(new SimpleVariable(getScope(),
obj->getLocation(),
prefix + "this"));
var->updateSymbol(SimpleVariablePtr());
var->getSymbol()->setHidden();
var->getSymbol()->setUsed();
var->getSymbol()->setReferenced();
AssignmentExpressionPtr ae
(new AssignmentExpression(getScope(),
obj->getLocation(),
var, obj, false));
info.elist->addElement(ae);
info.sepm[var->getName()] = var;
info.localThis = var->getName();
}
} else {
if (m_classScope) {
if (!m_funcScope->isStatic()) {
ClassScopeRawPtr oCls = getOriginalClass();
FunctionScopeRawPtr oFunc = getOriginalFunction();
if (oCls && !oFunc->isStatic() &&
(oCls == m_classScope ||
oCls->derivesFrom(ar, m_className, true, false))) {
info.callWithThis = true;
info.localThis = localThis;
}
}
if (!isSelf() && !isParent() && !isStatic()) {
info.staticClass = m_className;
}
}
}
ExpressionListPtr plist = m->getParams();
int i;
for (i = 0; i < nMax || i < nAct; i++) {
ParameterExpressionPtr param
(i < nMax ?
dynamic_pointer_cast<ParameterExpression>((*plist)[i]) :
ParameterExpressionPtr());
ExpressionPtr arg = i < nAct ? (*m_params)[i] :
Clone(param->defaultValue(), getScope());
SimpleVariablePtr var
(new SimpleVariable(getScope(),
//.........这里部分代码省略.........
示例6: onParse
void FunctionStatement::onParse(AnalysisResultConstPtr ar, FileScopePtr scope) {
checkParameters(scope);
// Correctness checks are normally done before adding function to scope.
if (m_params) {
for (int i = 0; i < m_params->getCount(); i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
if (param->hasTypeHint() && param->defaultValue()) {
param->compatibleDefault(scope);
}
}
}
// note it's important to add to scope, not a pushed FunctionContainer,
// as a function may be declared inside a class's method, yet this function
// is a global function, not a class method.
FunctionScopePtr fs = onInitialParse(ar, scope);
FunctionScope::RecordFunctionInfo(m_originalName, fs);
if (!scope->addFunction(ar, fs)) {
m_ignored = true;
return;
}
fs->setPersistent(false);
if (isNamed("__autoload")) {
if (m_params && m_params->getCount() != 1) {
parseTimeFatal(scope,
Compiler::InvalidMagicMethod,
"__autoload() must take exactly 1 argument");
}
}
if (fs->isNative()) {
if (getStmts()) {
parseTimeFatal(scope,
Compiler::InvalidAttribute,
"Native functions must not have an implementation body");
}
if (m_params) {
int nParams = m_params->getCount();
for (int i = 0; i < nParams; ++i) {
// Variadic capture params don't need types
// since they'll be Arrays as far as HNI is concerned.
auto param = dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
if (!param->hasUserType() && !param->isVariadic()) {
parseTimeFatal(scope,
Compiler::InvalidAttribute,
"Native function calls must have type hints "
"on all args");
}
}
}
if (getReturnTypeConstraint().empty()) {
parseTimeFatal(scope,
Compiler::InvalidAttribute,
"Native function %s() must have a return type hint",
getOriginalName().c_str());
}
} else if (!getStmts()) {
parseTimeFatal(scope,
Compiler::InvalidAttribute,
"Global function %s() must contain a body",
getOriginalName().c_str());
}
}
示例7: outputCPPClassMap
void FunctionScope::outputCPPClassMap(CodeGenerator &cg, AnalysisResultPtr ar) {
int attribute = ClassInfo::IsNothing;
if (!isUserFunction()) attribute |= ClassInfo::IsSystem;
if (isRedeclaring()) attribute |= ClassInfo::IsRedeclared;
if (isVolatile()) attribute |= ClassInfo::IsVolatile;
if (isRefReturn()) attribute |= ClassInfo::IsReference;
if (isProtected()) {
attribute |= ClassInfo::IsProtected;
} else if (isPrivate()) {
attribute |= ClassInfo::IsPrivate;
} else {
attribute |= ClassInfo::IsPublic;
}
if (isAbstract()) attribute |= ClassInfo::IsAbstract;
if (isStatic() && !isStaticMethodAutoFixed()) {
attribute |= ClassInfo::IsStatic;
}
if (isFinal()) attribute |= ClassInfo::IsFinal;
if (!m_docComment.empty()) attribute |= ClassInfo::HasDocComment;
// Use the original cased name, for reflection to work correctly.
cg.printf("(const char *)0x%04X, \"%s\", NULL, NULL,\n", attribute,
getOriginalName().c_str());
if (!m_docComment.empty()) {
char *dc = string_cplus_escape(m_docComment.c_str());
cg.printf("\"%s\",\n", dc);
free(dc);
}
Variant defArg;
for (int i = 0; i < m_maxParam; i++) {
int attr = ClassInfo::IsNothing;
if (i >= m_minParam) attr |= ClassInfo::IsOptional;
if (isRefParam(i)) attr |= ClassInfo::IsReference;
cg.printf("(const char *)0x%04X, \"%s\", \"%s\", ",
attr, m_paramNames[i].c_str(),
Util::toLower(m_paramTypes[i]->getPHPName()).c_str());
if (i >= m_minParam) {
MethodStatementPtr m =
dynamic_pointer_cast<MethodStatement>(getStmt());
if (m) {
ExpressionListPtr params = m->getParams();
assert(i < params->getCount());
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*params)[i]);
assert(param);
ExpressionPtr def = param->defaultValue();
if (!def->isScalar() || !def->getScalarValue(defArg)) {
defArg = "1";
}
} else {
defArg = "1";
}
char *s = string_cplus_escape(f_serialize(defArg).data());
cg.printf("\"%s\",\n", s);
free(s);
} else {
cg.printf("\"\",\n");
}
}
cg.printf("NULL,\n");
m_variables->outputCPPStaticVariables(cg, ar);
}
示例8: outputCPPClassMap
void FunctionScope::outputCPPClassMap(CodeGenerator &cg, AnalysisResultPtr ar) {
int attribute = ClassInfo::IsNothing;
if (!isUserFunction()) attribute |= ClassInfo::IsSystem;
if (isRedeclaring()) attribute |= ClassInfo::IsRedeclared;
if (isVolatile()) attribute |= ClassInfo::IsVolatile;
if (isRefReturn()) attribute |= ClassInfo::IsReference;
if (isProtected()) {
attribute |= ClassInfo::IsProtected;
} else if (isPrivate()) {
attribute |= ClassInfo::IsPrivate;
} else {
attribute |= ClassInfo::IsPublic;
}
if (isAbstract()) attribute |= ClassInfo::IsAbstract;
if (isStatic()) {
attribute |= ClassInfo::IsStatic;
}
if (isFinal()) attribute |= ClassInfo::IsFinal;
if (isVariableArgument()) {
attribute |= ClassInfo::VariableArguments;
}
if (isReferenceVariableArgument()) {
attribute |= ClassInfo::RefVariableArguments;
}
if (isMixedVariableArgument()) {
attribute |= ClassInfo::MixedVariableArguments;
}
attribute |= m_attributeClassInfo;
if (!m_docComment.empty() && Option::GenerateDocComments) {
attribute |= ClassInfo::HasDocComment;
} else {
attribute &= ~ClassInfo::HasDocComment;
}
// Use the original cased name, for reflection to work correctly.
cg_printf("(const char *)0x%04X, \"%s\", \"%s\", (const char *)%d, "
"(const char *)%d, NULL, NULL,\n", attribute,
getOriginalName().c_str(),
m_stmt ? m_stmt->getLocation()->file : "",
m_stmt ? m_stmt->getLocation()->line0 : 0,
m_stmt ? m_stmt->getLocation()->line1 : 0);
if (!m_docComment.empty() && Option::GenerateDocComments) {
char *dc = string_cplus_escape(m_docComment.c_str(), m_docComment.size());
cg_printf("\"%s\",\n", dc);
free(dc);
}
Variant defArg;
for (int i = 0; i < m_maxParam; i++) {
int attr = ClassInfo::IsNothing;
if (i >= m_minParam) attr |= ClassInfo::IsOptional;
if (isRefParam(i)) attr |= ClassInfo::IsReference;
const std::string &tname = m_paramTypeSpecs[i] ?
m_paramTypeSpecs[i]->getPHPName() : "";
cg_printf("(const char *)0x%04X, \"%s\", \"%s\", ",
attr, m_paramNames[i].c_str(),
Util::toLower(tname).c_str());
if (i >= m_minParam) {
MethodStatementPtr m =
dynamic_pointer_cast<MethodStatement>(getStmt());
if (m) {
ExpressionListPtr params = m->getParams();
assert(i < params->getCount());
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*params)[i]);
assert(param);
ExpressionPtr def = param->defaultValue();
string sdef = def->getText();
char *esdef = string_cplus_escape(sdef.data(), sdef.size());
if (!def->isScalar() || !def->getScalarValue(defArg)) {
/**
* Special value runtime/ext/ext_reflection.cpp can check and throw.
* If we want to avoid seeing this so to make getDefaultValue()
* work better for reflections, we will have to implement
* getScalarValue() to greater extent under compiler/expressions.
*/
cg_printf("\"\x01\", \"%s\",\n", esdef);
} else {
String str = f_serialize(defArg);
char *s = string_cplus_escape(str.data(), str.size());
cg_printf("\"%s\", \"%s\",\n", s, esdef);
free(s);
}
free(esdef);
} else {
char *def = string_cplus_escape(m_paramDefaults[i].data(),
m_paramDefaults[i].size());
char *defText = string_cplus_escape(m_paramDefaultTexts[i].data(),
m_paramDefaultTexts[i].size());
cg_printf("\"%s\", \"%s\",\n", def, defText);
free(def);
free(defText);
}
} else {
//.........这里部分代码省略.........