本文整理汇总了C++中ParameterExpressionPtr::isVariadic方法的典型用法代码示例。如果您正苦于以下问题:C++ ParameterExpressionPtr::isVariadic方法的具体用法?C++ ParameterExpressionPtr::isVariadic怎么用?C++ ParameterExpressionPtr::isVariadic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParameterExpressionPtr
的用法示例。
在下文中一共展示了ParameterExpressionPtr::isVariadic方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onInitialParse
FunctionScopePtr MethodStatement::onInitialParse(AnalysisResultConstPtr ar,
FileScopePtr fs) {
ConstructPtr self = shared_from_this();
int minParam = 0, numDeclParam = 0;
bool hasRef = false;
bool hasVariadicParam = false;
if (m_params) {
std::set<string> names, allDeclNames;
int i = 0;
numDeclParam = m_params->getCount();
ParameterExpressionPtr lastParam =
dynamic_pointer_cast<ParameterExpression>(
(*m_params)[numDeclParam - 1]);
hasVariadicParam = lastParam->isVariadic();
if (hasVariadicParam) {
allDeclNames.insert(lastParam->getName());
// prevent the next loop from visiting the variadic param and testing
// its optionality. parsing ensures that the variadic capture param
// can *only* be the last param.
i = numDeclParam - 2;
} else {
i = numDeclParam - 1;
}
for (; i >= 0; --i) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
assert(!param->isVariadic());
if (param->isRef()) { hasRef = true; }
if (!param->isOptional()) {
if (!minParam) minParam = i + 1;
} else if (minParam && !param->hasTypeHint()) {
Compiler::Error(Compiler::RequiredAfterOptionalParam, param);
}
allDeclNames.insert(param->getName());
}
// For the purpose of naming (having entered the the function body), a
// variadic capture param acts as any other variable.
for (i = (numDeclParam - 1); i >= 0; --i) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
if (names.find(param->getName()) != names.end()) {
Compiler::Error(Compiler::RedundantParameter, param);
for (int j = 0; j < 1000; j++) {
string name = param->getName() + folly::to<string>(j);
if (names.find(name) == names.end() &&
allDeclNames.find(name) == allDeclNames.end()) {
param->rename(name);
break;
}
}
}
names.insert(param->getName());
}
}
if (hasRef || m_ref) {
m_attribute |= FileScope::ContainsReference;
}
if (hasVariadicParam) {
m_attribute |= FileScope::VariadicArgumentParam;
}
vector<UserAttributePtr> attrs;
if (m_attrList) {
for (int i = 0; i < m_attrList->getCount(); ++i) {
UserAttributePtr a =
dynamic_pointer_cast<UserAttribute>((*m_attrList)[i]);
attrs.push_back(a);
}
}
StatementPtr stmt = dynamic_pointer_cast<Statement>(shared_from_this());
auto funcScope =
std::make_shared<FunctionScope>(ar, m_method, m_originalName,
stmt, m_ref, minParam, numDeclParam,
m_modifiers, m_attribute, m_docComment,
fs, attrs);
if (!m_stmt) {
funcScope->setVirtual();
}
setBlockScope(funcScope);
funcScope->setParamCounts(ar, -1, -1);
return funcScope;
}
示例2: onParseRecur
//.........这里部分代码省略.........
getOriginalName().c_str(),
m_modifiers->isPrivate() ? "private" :
(m_modifiers->isFinal() ? "final" : "native"));
}
if (!classScope->isInterface() && !classScope->isAbstract()) {
/* note that classScope->isAbstract() returns true for traits */
m_modifiers->parseTimeFatal(fileScope,
Compiler::InvalidAttribute,
"Class %s contains abstract method %s and "
"must therefore be declared abstract",
classScope->getOriginalName().c_str(),
getOriginalName().c_str());
}
if (getStmts()) {
parseTimeFatal(fileScope,
Compiler::InvalidAttribute,
"Abstract method %s::%s() cannot contain body",
classScope->getOriginalName().c_str(),
getOriginalName().c_str());
}
if (m_modifiers->isAsync()) {
m_modifiers->parseTimeFatal(
fileScope,
Compiler::InvalidAttribute,
Strings::ASYNC_WITHOUT_BODY,
"abstract", classScope->getOriginalName().c_str(),
getOriginalName().c_str()
);
}
}
if (!m_modifiers->isStatic() && classScope->isStaticUtil()) {
m_modifiers->parseTimeFatal(
fileScope,
Compiler::InvalidAttribute,
"Class %s contains non-static method %s and "
"therefore cannot be declared 'abstract final'",
classScope->getOriginalName().c_str(),
getOriginalName().c_str()
);
}
if (isNative) {
if (getStmts()) {
parseTimeFatal(fileScope,
Compiler::InvalidAttribute,
"Native method %s::%s() cannot contain body",
classScope->getOriginalName().c_str(),
getOriginalName().c_str());
}
auto is_ctordtor = isNamed("__construct") || isNamed("__destruct");
if (!m_retTypeAnnotation && !is_ctordtor) {
parseTimeFatal(fileScope,
Compiler::InvalidAttribute,
"Native method %s::%s() must have a return type hint",
classScope->getOriginalName().c_str(),
getOriginalName().c_str());
} else if (m_retTypeAnnotation &&
is_ctordtor &&
(m_retTypeAnnotation->dataType() != KindOfNull)) {
parseTimeFatal(fileScope,
Compiler::InvalidAttribute,
"Native method %s::%s() must return void",
classScope->getOriginalName().c_str(),
getOriginalName().c_str());
}
}
}
if ((!m_modifiers || !m_modifiers->isAbstract()) &&
!getStmts() && !classScope->isInterface() && !isNative) {
parseTimeFatal(fileScope,
Compiler::InvalidAttribute,
"Non-abstract method %s::%s() must contain body",
classScope->getOriginalName().c_str(),
getOriginalName().c_str());
}
classScope->addFunction(ar, fileScope, funcScope);
setSpecialMethod(fileScope, classScope);
if (Option::DynamicInvokeFunctions.count(getOriginalFullName())) {
funcScope->setDynamicInvoke();
}
if (m_params) {
auto nParams = m_params->getCount();
for (int i = 0; i < nParams; i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
param->parseHandler(fileScope, classScope);
// Variadic capture params don't need types because they'll
// be treated as Arrays as far as HNI is concerned.
if (isNative && !param->hasUserType() && !param->isVariadic()) {
parseTimeFatal(fileScope,
Compiler::InvalidAttribute,
"Native method calls must have type hints on all args");
}
}
}
FunctionScope::RecordFunctionInfo(m_originalName, funcScope);
}
示例3: onParseRecur
//.........这里部分代码省略.........
}
if (m_modifiers->isAsync()) {
m_modifiers->parseTimeFatal(
Compiler::InvalidAttribute,
Strings::ASYNC_WITHOUT_BODY,
"interface", classScope->getOriginalName().c_str(),
getOriginalName().c_str()
);
}
if (getStmts()) {
getStmts()->parseTimeFatal(
Compiler::InvalidMethodDefinition,
"Interface method %s::%s() cannot contain body",
classScope->getOriginalName().c_str(),
getOriginalName().c_str());
}
}
if (m_modifiers->isAbstract()) {
if (m_modifiers->isPrivate() || m_modifiers->isFinal() || isNative) {
m_modifiers->parseTimeFatal(
Compiler::InvalidAttribute,
"Cannot declare abstract method %s::%s() %s",
classScope->getOriginalName().c_str(),
getOriginalName().c_str(),
m_modifiers->isPrivate() ? "private" :
(m_modifiers->isFinal() ? "final" : "native"));
}
if (!classScope->isInterface() && !classScope->isAbstract()) {
/* note that classScope->isAbstract() returns true for traits */
m_modifiers->parseTimeFatal(Compiler::InvalidAttribute,
"Class %s contains abstract method %s and "
"must therefore be declared abstract",
classScope->getOriginalName().c_str(),
getOriginalName().c_str());
}
if (getStmts()) {
parseTimeFatal(Compiler::InvalidAttribute,
"Abstract method %s::%s() cannot contain body",
classScope->getOriginalName().c_str(),
getOriginalName().c_str());
}
if (m_modifiers->isAsync()) {
m_modifiers->parseTimeFatal(
Compiler::InvalidAttribute,
Strings::ASYNC_WITHOUT_BODY,
"abstract", classScope->getOriginalName().c_str(),
getOriginalName().c_str()
);
}
}
if (isNative) {
if (getStmts()) {
parseTimeFatal(Compiler::InvalidAttribute,
"Native method %s::%s() cannot contain body",
classScope->getOriginalName().c_str(),
getOriginalName().c_str());
}
if (!m_retTypeAnnotation) {
parseTimeFatal(Compiler::InvalidAttribute,
"Native method %s::%s() must have a return type hint",
classScope->getOriginalName().c_str(),
getOriginalName().c_str());
}
}
}
if ((!m_modifiers || !m_modifiers->isAbstract()) &&
!getStmts() && !classScope->isInterface() && !isNative) {
parseTimeFatal(Compiler::InvalidAttribute,
"Non-abstract method %s::%s() must contain body",
classScope->getOriginalName().c_str(),
getOriginalName().c_str());
}
classScope->addFunction(ar, fs);
m_className = classScope->getName();
m_originalClassName = classScope->getOriginalName();
setSpecialMethod(classScope);
if (Option::DynamicInvokeFunctions.find(getFullName()) !=
Option::DynamicInvokeFunctions.end()) {
fs->setDynamicInvoke();
}
if (m_params) {
auto nParams = m_params->getCount();
for (int i = 0; i < nParams; i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
param->parseHandler(classScope);
// Variadic capture params don't need types because they'll
// be treated as Arrays as far as HNI is concerned.
if (isNative && !param->hasUserType() && !param->isVariadic()) {
parseTimeFatal(Compiler::InvalidAttribute,
"Native method calls must have type hints on all args");
}
}
}
FunctionScope::RecordFunctionInfo(m_name, fs);
}