本文整理汇总了C++中Argument::name方法的典型用法代码示例。如果您正苦于以下问题:C++ Argument::name方法的具体用法?C++ Argument::name怎么用?C++ Argument::name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Argument
的用法示例。
在下文中一共展示了Argument::name方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BaseName
std::string tesla::BaseName(const Argument& A) {
switch (A.type()) {
case Argument::Any:
case Argument::Constant:
assert(false && "called BaseName() on a non-variable Argument");
case Argument::Variable:
return A.name();
case Argument::Indirect:
return BaseName(A.indirection());
case Argument::Field:
return BaseName(A.field().base());
}
}
示例2: checkFunctionArguments
void CheckDeclaration::checkFunctionArguments(Function *fun)
{
if (! _checkAnonymousArguments)
return;
if (_scope->isClassScope() && fun->isPublic()) {
for (unsigned argc = 0; argc < fun->argumentCount(); ++argc) {
Argument *arg = fun->argumentAt(argc)->asArgument();
assert(arg != 0);
if (! arg->name()) {
translationUnit()->warning(arg->sourceLocation(),
"anonymous argument");
}
}
}
}
示例3: iface_impl_scoping
void tst_Lookup::iface_impl_scoping()
{
const QByteArray source = "\n"
"@interface Scooping{}-(int)method1:(int)arg;-(void)method2;@end\n"
"@implementation Scooping-(int)method1:(int)arg{return arg;}@end\n";
Document::Ptr doc = Document::create("class_with_protocol_with_protocol");
doc->setUtf8Source(source);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->globalSymbolCount(), 2U);
Snapshot snapshot;
snapshot.insert(doc);
ObjCClass *iface = doc->globalSymbolAt(0)->asObjCClass();
QVERIFY(iface);
QVERIFY(iface->isInterface());
ObjCClass *impl = doc->globalSymbolAt(1)->asObjCClass();
QVERIFY(impl);
QVERIFY(!impl->isInterface());
QCOMPARE(iface->memberCount(), 2U);
QCOMPARE(impl->memberCount(), 1U);
ObjCMethod *method1Impl = impl->memberAt(0)->asObjCMethod();
QVERIFY(method1Impl);
QCOMPARE(method1Impl->identifier()->chars(), "method1");
// get the body of method1
QCOMPARE(method1Impl->memberCount(), 2U);
Argument *method1Arg = method1Impl->memberAt(0)->asArgument();
QVERIFY(method1Arg);
QCOMPARE(method1Arg->identifier()->chars(), "arg");
QVERIFY(method1Arg->type()->isIntegerType());
Block *method1Body = method1Impl->memberAt(1)->asBlock();
QVERIFY(method1Body);
const LookupContext context(doc, snapshot);
{ // verify if we can resolve "arg" in the body
QCOMPARE(method1Impl->argumentCount(), 1U);
Argument *arg = method1Impl->argumentAt(0)->asArgument();
QVERIFY(arg);
QVERIFY(arg->name());
QVERIFY(arg->name()->identifier());
QCOMPARE(arg->name()->identifier()->chars(), "arg");
QVERIFY(arg->type()->isIntegerType());
const QList<LookupItem> candidates = context.lookup(arg->name(), method1Body->enclosingScope());
QCOMPARE(candidates.size(), 1);
QVERIFY(candidates.at(0).declaration()->type()->asIntegerType());
}
Declaration *method2 = iface->memberAt(1)->asDeclaration();
QVERIFY(method2);
QCOMPARE(method2->identifier()->chars(), "method2");
{ // verify if we can resolve "method2" in the body
const QList<LookupItem> candidates = context.lookup(method2->name(), method1Body->enclosingScope());
QCOMPARE(candidates.size(), 1);
QCOMPARE(candidates.at(0).declaration(), method2);
}
}
示例4: fetchInformation
void QalculateSyntaxHelpObject::fetchInformation()
{
std::string cmd = command().remove(QLatin1String("help")).simplified().toLatin1().data();
qDebug() << "HELP CALLED FOR:" << QLatin1String(cmd.c_str());
if (cmd == "plot") {
setPlotInformation();
return;
}
if (cmd == "saveVariables") {
setSaveVariablesInformation();
return;
}
if (cmd == "loadVariables") {
setLoadVariablesInformation();
return;
}
ExpressionItem *item = CALCULATOR->getActiveExpressionItem(cmd);
if (!item) {
m_answer = i18n("No function, variable or unit with specified name exist.");
return;
}
switch(item->type()) {
case TYPE_FUNCTION:
MathFunction *f = (MathFunction*) item;
QString title = i18n("Function: %1", QLatin1String(item->title().c_str()));
const ExpressionName *ename = &f->preferredName(false);
int iargs = f->maxargs();
if(iargs < 0) {
iargs = f->minargs() + 1;
}
QString str,str2,syntax;
str += QLatin1String(ename->name.c_str());
str += QLatin1String("(");
if(iargs != 0) {
Argument *arg;
Argument default_arg;
for(int i2 = 1; i2 <= iargs; i2++) {
if(i2 > f->minargs()) {
str += QLatin1String("[");
}
if(i2 > 1) {
str += QLatin1String(CALCULATOR->getComma().c_str());
str += QLatin1String(" ");
}
arg = f->getArgumentDefinition(i2);
if(arg && !arg->name().empty()) {
str2 = QLatin1String(arg->name().c_str());
} else {
str2 = QLatin1String("argument");
str2 += QLatin1String(" ");
str2 += QString::number(i2);
}
str += str2;
if(i2 > f->minargs()) {
str += QLatin1String("]");
}
}
if(f->maxargs() < 0) {
str += QLatin1String(CALCULATOR->getComma().c_str());
str += QLatin1String(" ...");
}
}
str += QLatin1String(")");
syntax = QString::fromLatin1("<p>%1</p>").arg(str);
QString arguments = QLatin1String("");
if(iargs != 0) {
Argument *arg;
Argument default_arg;
for(int i2 = 1; i2 <= iargs; i2++) {
arg = f->getArgumentDefinition(i2);
if(arg && !arg->name().empty()) {
str = QLatin1String(arg->name().c_str());
} else {
str = QString::number(i2);
}
str += QLatin1String(": ");
if(arg) {
str2 = QLatin1String(arg->printlong().c_str());
} else {
str2 = QLatin1String(default_arg.printlong().c_str());
}
if(i2 > f->minargs()) {
str2 += QLatin1String(" (");
//optional argument, in description
str2 += QLatin1String("optional");
if(!f->getDefaultValue(i2).empty()) {
str2 += QLatin1String(", ");
//argument default, in description
str2 += QLatin1String("default: ");
str2 += QLatin1String(f->getDefaultValue(i2).c_str());
}
str2 += QLatin1String(")");
}
str += str2;
arguments += QString::fromLatin1("<p>%1</p>").arg(str);
//.........这里部分代码省略.........
示例5: bind
void bind(std::string type, std::string name, Parameters* ps, Arguments* as, Context* ctx, Env* env, Eval* eval)
{
std::string callee(type + " " + name);
Listize listize(ctx->mem);
std::map<std::string, Parameter*> param_map;
for (size_t i = 0, L = as->length(); i < L; ++i) {
if (auto str = dynamic_cast<String_Quoted*>((*as)[i]->value())) {
// force optional quotes (only if needed)
if (str->quote_mark()) {
str->quote_mark('*');
str->is_delayed(true);
}
}
}
// Set up a map to ensure named arguments refer to actual parameters. Also
// eval each default value left-to-right, wrt env, populating env as we go.
for (size_t i = 0, L = ps->length(); i < L; ++i) {
Parameter* p = (*ps)[i];
param_map[p->name()] = p;
// if (p->default_value()) {
// env->local_frame()[p->name()] = p->default_value()->perform(eval->with(env));
// }
}
// plug in all args; if we have leftover params, deal with it later
size_t ip = 0, LP = ps->length();
size_t ia = 0, LA = as->length();
while (ia < LA) {
Argument* a = (*as)[ia];
if (ip >= LP) {
// skip empty rest arguments
if (a->is_rest_argument()) {
if (List* l = dynamic_cast<List*>(a->value())) {
if (l->length() == 0) {
++ ia; continue;
}
}
}
std::stringstream msg;
msg << "wrong number of arguments (" << LA << " for " << LP << ")";
msg << " for `" << name << "'";
return error(msg.str(), as->pstate());
}
Parameter* p = (*ps)[ip];
// If the current parameter is the rest parameter, process and break the loop
if (p->is_rest_parameter()) {
// The next argument by coincidence provides a rest argument
if (a->is_rest_argument()) {
// We should always get a list for rest arguments
if (List* rest = dynamic_cast<List*>(a->value())) {
// create a new list object for wrapped items
List* arglist = SASS_MEMORY_NEW(ctx->mem, List,
p->pstate(),
0,
rest->separator(),
true);
// wrap each item from list as an argument
for (Expression* item : rest->elements()) {
if (Argument* arg = dynamic_cast<Argument*>(item)) {
(*arglist) << SASS_MEMORY_NEW(ctx->mem, Argument, *arg);
} else {
(*arglist) << SASS_MEMORY_NEW(ctx->mem, Argument,
item->pstate(),
item,
"",
false,
false);
}
}
// assign new arglist to environment
env->local_frame()[p->name()] = arglist;
}
// invalid state
else {
throw std::runtime_error("invalid state");
}
} else if (a->is_keyword_argument()) {
// expand keyword arguments into their parameters
List* arglist = SASS_MEMORY_NEW(ctx->mem, List, p->pstate(), 0, SASS_COMMA, true);
env->local_frame()[p->name()] = arglist;
Map* argmap = static_cast<Map*>(a->value());
for (auto key : argmap->keys()) {
std::string name = unquote(static_cast<String_Constant*>(key)->value());
(*arglist) << SASS_MEMORY_NEW(ctx->mem, Argument,
key->pstate(),
argmap->at(key),
"$" + name,
false,
false);
}
} else {
// create a new list object for wrapped items
//.........这里部分代码省略.........
示例6: debug_ast
//.........这里部分代码省略.........
debug_ast(selector->head(), ind + " " /* + "[" + del + "]" */, env);
if (selector->tail()) {
debug_ast(selector->tail(), ind + "{" + del + "}", env);
} else if(del != " ") {
std::cerr << ind << " |" << del << "| {trailing op}" << std::endl;
}
SourcesSet set = selector->sources();
// debug_sources_set(set, ind + " @--> ");
} else if (dynamic_cast<Compound_Selector*>(node)) {
Compound_Selector* selector = dynamic_cast<Compound_Selector*>(node);
std::cerr << ind << "Compound_Selector " << selector;
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << " <" << selector->hash() << ">";
std::cerr << " [weight:" << longToHex(selector->specificity()) << "]";
std::cerr << " [@media:" << selector->media_block() << "]";
std::cerr << (selector->extended() ? " [extended]": " -");
std::cerr << (selector->is_optional() ? " [is_optional]": " -");
std::cerr << (selector->has_parent_ref() ? " [has-parent]": " -");
std::cerr << (selector->has_line_break() ? " [line-break]": " -");
std::cerr << (selector->has_line_feed() ? " [line-feed]": " -");
std::cerr << " <" << prettyprint(selector->pstate().token.ws_before()) << ">" << std::endl;
for(auto i : selector->elements()) { debug_ast(i, ind + " ", env); }
} else if (dynamic_cast<Propset*>(node)) {
Propset* selector = dynamic_cast<Propset*>(node);
std::cerr << ind << "Propset " << selector;
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << " " << selector->tabs() << std::endl;
if (selector->block()) for(auto i : selector->block()->elements()) { debug_ast(i, ind + " ", env); }
} else if (dynamic_cast<Wrapped_Selector*>(node)) {
Wrapped_Selector* selector = dynamic_cast<Wrapped_Selector*>(node);
std::cerr << ind << "Wrapped_Selector " << selector;
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << " <" << selector->hash() << ">";
std::cerr << " <<" << selector->ns_name() << ">>";
std::cerr << (selector->is_optional() ? " [is_optional]": " -");
std::cerr << (selector->has_parent_ref() ? " [has-parent]": " -");
std::cerr << (selector->has_line_break() ? " [line-break]": " -");
std::cerr << (selector->has_line_feed() ? " [line-feed]": " -");
std::cerr << std::endl;
debug_ast(selector->selector(), ind + " () ", env);
} else if (dynamic_cast<Pseudo_Selector*>(node)) {
Pseudo_Selector* selector = dynamic_cast<Pseudo_Selector*>(node);
std::cerr << ind << "Pseudo_Selector " << selector;
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << " <" << selector->hash() << ">";
std::cerr << " <<" << selector->ns_name() << ">>";
std::cerr << (selector->is_optional() ? " [is_optional]": " -");
std::cerr << (selector->has_parent_ref() ? " [has-parent]": " -");
std::cerr << (selector->has_line_break() ? " [line-break]": " -");
std::cerr << (selector->has_line_feed() ? " [line-feed]": " -");
std::cerr << std::endl;
debug_ast(selector->expression(), ind + " <= ", env);
} else if (dynamic_cast<Attribute_Selector*>(node)) {
Attribute_Selector* selector = dynamic_cast<Attribute_Selector*>(node);
std::cerr << ind << "Attribute_Selector " << selector;
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << " <" << selector->hash() << ">";
std::cerr << " <<" << selector->ns_name() << ">>";
std::cerr << (selector->is_optional() ? " [is_optional]": " -");
std::cerr << (selector->has_parent_ref() ? " [has-parent]": " -");
std::cerr << (selector->has_line_break() ? " [line-break]": " -");
std::cerr << (selector->has_line_feed() ? " [line-feed]": " -");
std::cerr << std::endl;
debug_ast(selector->value(), ind + "[" + selector->matcher() + "] ", env);
} else if (dynamic_cast<Selector_Qualifier*>(node)) {
Selector_Qualifier* selector = dynamic_cast<Selector_Qualifier*>(node);
示例7: bind
void bind(string callee, Parameters* ps, Arguments* as, Context& ctx, Env* env, Eval* eval)
{
map<string, Parameter*> param_map;
// Set up a map to ensure named arguments refer to actual parameters. Also
// eval each default value left-to-right, wrt env, populating env as we go.
for (size_t i = 0, L = ps->length(); i < L; ++i) {
Parameter* p = (*ps)[i];
param_map[p->name()] = p;
// if (p->default_value()) {
// env->current_frame()[p->name()] = p->default_value()->perform(eval->with(env));
// }
}
// plug in all args; if we have leftover params, deal with it later
size_t ip = 0, LP = ps->length();
size_t ia = 0, LA = as->length();
while (ia < LA) {
if (ip >= LP) {
stringstream msg;
msg << callee << " only takes " << LP << " arguments; "
<< "given " << LA;
error(msg.str(), as->path(), as->position());
}
Parameter* p = (*ps)[ip];
Argument* a = (*as)[ia];
// If the current parameter is the rest parameter, process and break the loop
if (p->is_rest_parameter()) {
if (a->is_rest_argument()) {
// rest param and rest arg -- just add one to the other
if (env->current_frame_has(p->name())) {
*static_cast<List*>(env->current_frame()[p->name()])
+= static_cast<List*>(a->value());
}
else {
env->current_frame()[p->name()] = a->value();
}
} else {
// copy all remaining arguments into the rest parameter, preserving names
List* arglist = new (ctx.mem) List(p->path(),
p->position(),
0,
List::COMMA,
true);
env->current_frame()[p->name()] = arglist;
while (ia < LA) {
a = (*as)[ia];
(*arglist) << new (ctx.mem) Argument(a->path(),
a->position(),
a->value(),
a->name(),
false);
++ia;
}
}
++ip;
break;
}
// If the current argument is the rest argument, extract a value for processing
else if (a->is_rest_argument()) {
// normal param and rest arg
List* arglist = static_cast<List*>(a->value());
// empty rest arg - treat all args as default values
if (!arglist->length()) {
break;
}
// otherwise move one of the rest args into the param, converting to argument if necessary
if (arglist->is_arglist()) {
a = static_cast<Argument*>((*arglist)[0]);
} else {
Expression* a_to_convert = (*arglist)[0];
a = new (ctx.mem) Argument(a_to_convert->path(), a_to_convert->position(), a_to_convert, "", false);
}
arglist->elements().erase(arglist->elements().begin());
if (!arglist->length() || (!arglist->is_arglist() && ip + 1 == LP)) {
++ia;
}
} else if (a->is_keyword_argument()) {
Map* argmap = static_cast<Map*>(a->value());
for (auto key : argmap->keys()) {
string name = "$" + unquote(static_cast<String_Constant*>(key)->value());
if (!param_map.count(name)) {
stringstream msg;
msg << callee << " has no parameter named " << name;
error(msg.str(), a->path(), a->position());
}
env->current_frame()[name] = argmap->at(key);
}
++ia;
continue;
} else {
++ia;
}
if (a->name().empty()) {
//.........这里部分代码省略.........
示例8: bind
void bind(string callee, Parameters* ps, Arguments* as, Context& ctx, Env* env, Eval* eval)
{
map<string, Parameter*> param_map;
// Set up a map to ensure named arguments refer to actual parameters. Also
// eval each default value left-to-right, wrt env, populating env as we go.
for (size_t i = 0, L = ps->length(); i < L; ++i) {
Parameter* p = (*ps)[i];
param_map[p->name()] = p;
// if (p->default_value()) {
// env->local_frame()[p->name()] = p->default_value()->perform(eval->with(env));
// }
}
// plug in all args; if we have leftover params, deal with it later
size_t ip = 0, LP = ps->length();
size_t ia = 0, LA = as->length();
while (ia < LA) {
Argument* a = (*as)[ia];
if (ip >= LP) {
// skip empty rest arguments
if (a->is_rest_argument()) {
if (List* l = dynamic_cast<List*>(a->value())) {
if (l->length() == 0) {
++ ia; continue;
}
}
}
stringstream msg;
msg << callee << " only takes " << LP << " arguments; "
<< "given " << LA;
error(msg.str(), as->pstate());
}
Parameter* p = (*ps)[ip];
// If the current parameter is the rest parameter, process and break the loop
if (p->is_rest_parameter()) {
// The next argument by coincidence provides a rest argument
if (a->is_rest_argument()) {
// We should always get a list for rest arguments
if (List* rest = dynamic_cast<List*>(a->value())) {
// arg contains a list
List* args = rest;
// make sure it's an arglist
if (rest->is_arglist()) {
// can pass it through as it was
env->local_frame()[p->name()] = args;
}
// create a new list and wrap each item as an argument
// otherwise we will not be able to fetch it again
else {
// create a new list object for wrapped items
List* arglist = new (ctx.mem) List(p->pstate(),
0,
rest->separator(),
true);
// wrap each item from list as an argument
for (Expression* item : rest->elements()) {
(*arglist) << new (ctx.mem) Argument(item->pstate(),
item,
"",
false,
false);
}
// assign new arglist to environment
env->local_frame()[p->name()] = arglist;
}
}
// invalid state
else {
throw runtime_error("invalid state");
}
} else if (a->is_keyword_argument()) {
// expand keyword arguments into their parameters
List* arglist = new (ctx.mem) List(p->pstate(), 0, List::COMMA, true);
env->local_frame()[p->name()] = arglist;
Map* argmap = static_cast<Map*>(a->value());
for (auto key : argmap->keys()) {
string name = unquote(static_cast<String_Constant*>(key)->value());
(*arglist) << new (ctx.mem) Argument(key->pstate(),
argmap->at(key),
name,
false,
false);
}
} else {
// create a new list object for wrapped items
List* arglist = new (ctx.mem) List(p->pstate(),
0,
List::COMMA,
true);
// consume the next args
while (ia < LA) {
// get and post inc
a = (*as)[ia++];
// wrap current argument into new object
(*arglist) << new (ctx.mem) Argument(a->pstate(),
//.........这里部分代码省略.........
示例9: bind
void bind(string callee, Parameters* ps, Arguments* as, Context& ctx, Env* env, Eval* eval)
{
map<string, Parameter*> param_map;
// Set up a map to ensure named arguments refer to actual parameters. Also
// eval each default value left-to-right, wrt env, populating env as we go.
for (size_t i = 0, L = ps->length(); i < L; ++i) {
Parameter* p = (*ps)[i];
param_map[p->name()] = p;
// if (p->default_value()) {
// env->current_frame()[p->name()] = p->default_value()->perform(eval->with(env));
// }
}
// plug in all args; if we have leftover params, deal with it later
size_t ip = 0, LP = ps->length();
size_t ia = 0, LA = as->length();
while (ia < LA) {
if (ip >= LP) {
stringstream msg;
msg << callee << " only takes " << LP << " arguments; "
<< "given " << LA;
error(msg.str(), as->path(), as->line());
}
Parameter* p = (*ps)[ip];
Argument* a = (*as)[ia];
if (a->is_rest_argument() && p->is_rest_parameter()) {
// rest param and rest arg -- just add one to the other
if (env->current_frame_has(p->name())) {
*static_cast<List*>(env->current_frame()[p->name()])
+= static_cast<List*>(a->value());
}
else {
env->current_frame()[p->name()] = a->value();
}
++ia;
++ip;
}
else if (p->is_rest_parameter()) {
List* arglist = 0;
if (!env->current_frame_has(p->name())) {
arglist = new (ctx.mem) List(p->path(),
p->line(),
0,
List::COMMA,
true);
env->current_frame()[p->name()] = arglist;
}
else {
arglist = static_cast<List*>(env->current_frame()[p->name()]);
}
*arglist << a->value(); // TODO: named args going into rest-param?
++ia;
}
else if (a->is_rest_argument()) {
// normal param and rest arg
if (env->current_frame_has(p->name())) {
stringstream msg;
msg << "parameter " << p->name()
<< " provided more than once in call to " << callee;
error(msg.str(), a->path(), a->line());
}
List* arglist = static_cast<List*>(a->value());
// if it's the last param, move the whole arglist into it
if (ip == LP-1) {
env->current_frame()[p->name()] = arglist;
++ia;
}
// otherwise move one of the rest args into the param and loop
else {
env->current_frame()[p->name()] = (*arglist)[0];
arglist->elements().erase(arglist->elements().begin());
}
++ip;
}
else if (a->name().empty()) {
// ordinal arg -- bind it to the next param
env->current_frame()[p->name()] = a->value();
++ip;
++ia;
}
else {
// named arg -- bind it to the appropriately named param
if (!param_map.count(a->name())) {
stringstream msg;
msg << callee << " has no parameter named " << a->name();
error(msg.str(), a->path(), a->line());
}
if (param_map[a->name()]->is_rest_parameter()) {
stringstream msg;
msg << "argument " << a->name() << " of " << callee
<< "cannot be used as named argument";
error(msg.str(), a->path(), a->line());
}
if (env->current_frame_has(a->name())) {
stringstream msg;
msg << "parameter " << p->name()
<< "provided more than once in call to " << callee;
error(msg.str(), a->path(), a->line());
//.........这里部分代码省略.........