本文整理汇总了C++中ParameterExpressionPtr::rename方法的典型用法代码示例。如果您正苦于以下问题:C++ ParameterExpressionPtr::rename方法的具体用法?C++ ParameterExpressionPtr::rename怎么用?C++ ParameterExpressionPtr::rename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParameterExpressionPtr
的用法示例。
在下文中一共展示了ParameterExpressionPtr::rename方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: onInitialParse
FunctionScopePtr MethodStatement::onInitialParse(AnalysisResultConstPtr ar,
FileScopePtr fs) {
int minParam, maxParam;
ConstructPtr self = shared_from_this();
minParam = maxParam = 0;
bool hasRef = false;
if (m_params) {
std::set<string> names, allDeclNames;
int i = 0;
maxParam = m_params->getCount();
for (i = maxParam; i--; ) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
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 (i = maxParam-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() + lexical_cast<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;
}
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());
FunctionScopePtr funcScope
(new FunctionScope(ar, m_method, m_name, stmt, m_ref, minParam, maxParam,
m_modifiers, m_attribute, m_docComment, fs, attrs));
if (!m_stmt) {
funcScope->setVirtual();
}
setBlockScope(funcScope);
funcScope->setParamCounts(ar, -1, -1);
return funcScope;
}
示例3: onParseImpl
FunctionScopePtr MethodStatement::onParseImpl(AnalysisResultPtr ar) {
int minParam, maxParam;
ConstructPtr self = shared_from_this();
minParam = maxParam = 0;
bool hasRef = false;
if (m_params) {
set<string> names;
int i = 0;
maxParam = m_params->getCount();
for (; i < maxParam; i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
if (param->isRef()) hasRef = true;
if (param->isOptional()) break;
minParam++;
}
for (i++; i < maxParam; i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
if (param->isRef()) hasRef = true;
if (!param->isOptional()) {
ar->getCodeError()->record(self, CodeError::RequiredAfterOptionalParam,
param);
param->defaultToNull(ar);
}
}
if (ar->isFirstPass()) {
for (i = 0; i < maxParam; i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
if (names.find(param->getName()) == names.end()) {
names.insert(param->getName());
} else {
ar->getCodeError()->record(self,
CodeError::RedundantParameter, param);
for (int j = 0; j < 1000; j++) {
string name = param->getName() + lexical_cast<string>(j);
if (names.find(name) == names.end()) {
param->rename(name);
break;
}
}
}
}
}
}
if (hasRef || m_ref) {
m_attribute |= FileScope::ContainsReference;
}
StatementPtr stmt = dynamic_pointer_cast<Statement>(shared_from_this());
FunctionScopePtr funcScope
(new FunctionScope(ar, m_method, m_name, stmt, m_ref, minParam, maxParam,
m_modifiers, m_attribute, m_docComment,
ar->getFileScope()));
if (!m_stmt) {
funcScope->setVirtual();
}
m_funcScope = funcScope;
// TODO: this may have to expand to a concept of "virtual" functions...
if (ar->getClassScope()) {
funcScope->disableInline();
if (m_name.length() > 2 && m_name.substr(0,2) == "__") {
bool magic = true;
int paramCount = 0;
if (m_name == "__destruct") {
funcScope->setOverriding(Type::Variant);
} else if (m_name == "__call") {
funcScope->setOverriding(Type::Variant, Type::String, Type::Array);
paramCount = 2;
} else if (m_name == "__set") {
funcScope->setOverriding(Type::Variant, Type::String, Type::Variant);
paramCount = 2;
} else if (m_name == "__get") {
funcScope->setOverriding(Type::Variant, Type::String);
paramCount = 1;
} else if (m_name == "__isset") {
funcScope->setOverriding(Type::Boolean, Type::String);
paramCount = 1;
} else if (m_name == "__unset") {
funcScope->setOverriding(Type::Variant, Type::String);
paramCount = 1;
} else if (m_name == "__sleep") {
funcScope->setOverriding(Type::Variant);
} else if (m_name == "__wakeup") {
funcScope->setOverriding(Type::Variant);
} else if (m_name == "__set_state") {
funcScope->setOverriding(Type::Variant, Type::Variant);
paramCount = 1;
} else if (m_name == "__tostring") {
funcScope->setOverriding(Type::String);
} else if (m_name == "__clone") {
funcScope->setOverriding(Type::Variant);
} else {
paramCount = -1;
if (m_name != "__construct") {
ar->getCodeError()->record(self, CodeError::UnknownMagicMethod,
//.........这里部分代码省略.........
示例4: onInitialParse
FunctionScopePtr MethodStatement::onInitialParse(AnalysisResultPtr ar,
FileScopePtr fs,
bool method) {
int minParam, maxParam;
ConstructPtr self = shared_from_this();
minParam = maxParam = 0;
bool hasRef = false;
if (m_params) {
set<string> names;
int i = 0;
maxParam = m_params->getCount();
for (; i < maxParam; i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
if (param->isRef()) hasRef = true;
if (param->isOptional()) break;
minParam++;
}
for (i++; i < maxParam; i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
if (param->isRef()) hasRef = true;
if (!param->isOptional()) {
Compiler::Error(Compiler::RequiredAfterOptionalParam, param);
param->defaultToNull(ar);
}
}
for (i = 0; i < maxParam; i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
if (names.find(param->getName()) == names.end()) {
names.insert(param->getName());
} else {
Compiler::Error(Compiler::RedundantParameter, param);
for (int j = 0; j < 1000; j++) {
string name = param->getName() + lexical_cast<string>(j);
if (names.find(name) == names.end()) {
param->rename(name);
break;
}
}
}
}
}
if (hasRef || m_ref) {
m_attribute |= FileScope::ContainsReference;
}
StatementPtr stmt = dynamic_pointer_cast<Statement>(shared_from_this());
FunctionScopePtr funcScope
(new FunctionScope(ar, m_method, m_name, stmt, m_ref, minParam, maxParam,
m_modifiers, m_attribute, m_docComment, fs));
if (!m_stmt) {
funcScope->setVirtual();
}
setBlockScope(funcScope);
return funcScope;
}