本文整理汇总了C++中RvalScalarValue函数的典型用法代码示例。如果您正苦于以下问题:C++ RvalScalarValue函数的具体用法?C++ RvalScalarValue怎么用?C++ RvalScalarValue使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RvalScalarValue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Epimenides
static bool Epimenides(EvalContext *ctx, const char *ns, const char *scope, const char *var, Rval rval, int level)
{
switch (rval.type)
{
case RVAL_TYPE_SCALAR:
if (StringContainsVar(RvalScalarValue(rval), var))
{
Log(LOG_LEVEL_ERR, "Scalar variable '%s' contains itself (non-convergent) '%s'", var, RvalScalarValue(rval));
return true;
}
if (IsCf3VarString(RvalScalarValue(rval)))
{
Buffer *exp = BufferNew();
ExpandScalar(ctx, ns, scope, RvalScalarValue(rval), exp);
if (strcmp(BufferData(exp), RvalScalarValue(rval)) == 0)
{
BufferDestroy(exp);
return false;
}
if (level > 3)
{
BufferDestroy(exp);
return false;
}
if (Epimenides(ctx, ns, scope, var, (Rval) { BufferGet(exp), RVAL_TYPE_SCALAR}, level + 1))
{
BufferDestroy(exp);
return true;
}
BufferDestroy(exp);
}
break;
case RVAL_TYPE_LIST:
for (const Rlist *rp = RvalRlistValue(rval); rp != NULL; rp = rp->next)
{
if (Epimenides(ctx, ns, scope, var, rp->val, level))
{
return true;
}
}
break;
case RVAL_TYPE_CONTAINER:
case RVAL_TYPE_FNCALL:
case RVAL_TYPE_NOPROMISEE:
return false;
}
return false;
}
示例2: ResolvePackageManagerBody
static void ResolvePackageManagerBody(EvalContext *ctx, const Body *pm_body)
{
PackageModuleBody *new_manager = xcalloc(1, sizeof(PackageModuleBody));
new_manager->name = SafeStringDuplicate(pm_body->name);
for (size_t i = 0; i < SeqLength(pm_body->conlist); i++)
{
Constraint *cp = SeqAt(pm_body->conlist, i);
Rval returnval = {0};
if (IsDefinedClass(ctx, cp->classes))
{
returnval = ExpandPrivateRval(ctx, NULL, "body",
cp->rval.item, cp->rval.type);
}
if (returnval.item == NULL || returnval.type == RVAL_TYPE_NOPROMISEE)
{
Log(LOG_LEVEL_VERBOSE, "have invalid constraint while resolving"
"package promise body: %s", cp->lval);
RvalDestroy(returnval);
continue;
}
if (strcmp(cp->lval, "query_installed_ifelapsed") == 0)
{
new_manager->installed_ifelapsed =
(int)IntFromString(RvalScalarValue(returnval));
}
else if (strcmp(cp->lval, "query_updates_ifelapsed") == 0)
{
new_manager->updates_ifelapsed =
(int)IntFromString(RvalScalarValue(returnval));
}
else if (strcmp(cp->lval, "default_options") == 0)
{
new_manager->options = RlistCopy(RvalRlistValue(returnval));
}
else
{
/* This should be handled by the parser. */
assert(0);
}
RvalDestroy(returnval);
}
AddPackageModuleToContext(ctx, new_manager);
}
示例3: ExpandBundleReference
Rval ExpandBundleReference(EvalContext *ctx,
const char *ns, const char *scope,
Rval rval)
{
// Allocates new memory for the copy
switch (rval.type)
{
case RVAL_TYPE_SCALAR:
return (Rval) {
ExpandScalar(ctx, ns, scope, RvalScalarValue(rval), NULL),
RVAL_TYPE_SCALAR
};
case RVAL_TYPE_FNCALL:
return (Rval) {
ExpandFnCall(ctx, ns, scope, RvalFnCallValue(rval)),
RVAL_TYPE_FNCALL
};
case RVAL_TYPE_CONTAINER:
case RVAL_TYPE_LIST:
case RVAL_TYPE_NOPROMISEE:
return RvalNew(NULL, RVAL_TYPE_NOPROMISEE);
}
assert(false);
return RvalNew(NULL, RVAL_TYPE_NOPROMISEE);
}
示例4: ExpandDanglers
Rval ExpandDanglers(EvalContext *ctx, const char *ns, const char *scope, Rval rval, const Promise *pp)
{
assert(ctx);
assert(pp);
switch (rval.type)
{
case RVAL_TYPE_SCALAR:
if (IsCf3VarString(RvalScalarValue(rval)))
{
return EvaluateFinalRval(ctx, PromiseGetPolicy(pp), ns, scope, rval, false, pp);
}
else
{
return RvalCopy(rval);
}
break;
case RVAL_TYPE_LIST:
{
Rlist *result_list = RlistCopy(RvalRlistValue(rval));
RlistFlatten(ctx, &result_list);
return RvalNew(result_list, RVAL_TYPE_LIST);
}
break;
case RVAL_TYPE_CONTAINER:
case RVAL_TYPE_FNCALL:
case RVAL_TYPE_NOPROMISEE:
return RvalCopy(rval);
}
ProgrammingError("Unhandled Rval type");
}
示例5: RvalWrite
void RvalWrite(Writer *writer, Rval rval)
{
if (rval.item == NULL)
{
return;
}
switch (rval.type)
{
case RVAL_TYPE_SCALAR:
ScalarWrite(writer, RvalScalarValue(rval));
break;
case RVAL_TYPE_LIST:
RlistWrite(writer, RvalRlistValue(rval));
break;
case RVAL_TYPE_FNCALL:
FnCallPrint(writer, RvalFnCallValue(rval));
break;
case RVAL_TYPE_NOPROMISEE:
WriterWrite(writer, "(no-one)");
break;
default:
ProgrammingError("Unknown rval type %c", rval.type);
}
}
示例6: RvalWrite
void RvalWrite(Writer *writer, Rval rval)
{
if (rval.item == NULL)
{
return;
}
switch (rval.type)
{
case RVAL_TYPE_SCALAR:
ScalarWrite(writer, RvalScalarValue(rval));
break;
case RVAL_TYPE_LIST:
RlistWrite(writer, RvalRlistValue(rval));
break;
case RVAL_TYPE_FNCALL:
FnCallWrite(writer, RvalFnCallValue(rval));
break;
case RVAL_TYPE_NOPROMISEE:
WriterWrite(writer, "(no-one)");
break;
case RVAL_TYPE_CONTAINER:
JsonWrite(writer, RvalContainerValue(rval), 0);
break;
}
}
示例7: RvalDestroy
void RvalDestroy(Rval rval)
{
if (rval.item == NULL)
{
return;
}
switch (rval.type)
{
case RVAL_TYPE_SCALAR:
ThreadLock(cft_lock);
free(RvalScalarValue(rval));
ThreadUnlock(cft_lock);
return;
case RVAL_TYPE_LIST:
RlistDestroy(RvalRlistValue(rval));
return;
case RVAL_TYPE_FNCALL:
FnCallDestroy(RvalFnCallValue(rval));
break;
case RVAL_TYPE_CONTAINER:
JsonDestroy(RvalContainerValue(rval));
break;
case RVAL_TYPE_NOPROMISEE:
return;
}
}
示例8: PolicyNew
static Policy *LoadPolicyInputFiles(EvalContext *ctx, GenericAgentConfig *config, const Rlist *inputs, StringSet *parsed_files_and_checksums, StringSet *failed_files)
{
Policy *policy = PolicyNew();
for (const Rlist *rp = inputs; rp; rp = rp->next)
{
if (rp->val.type != RVAL_TYPE_SCALAR)
{
Log(LOG_LEVEL_ERR, "Non-file object in inputs list");
continue;
}
const char *unresolved_input = RlistScalarValue(rp);
if (strcmp(CF_NULL_VALUE, unresolved_input) == 0)
{
continue;
}
if (IsExpandable(unresolved_input))
{
PolicyResolve(ctx, policy, config);
}
Rval resolved_input = EvaluateFinalRval(ctx, policy, NULL, "sys", rp->val, true, NULL);
Policy *aux_policy = NULL;
switch (resolved_input.type)
{
case RVAL_TYPE_SCALAR:
if (IsCf3VarString(RvalScalarValue(resolved_input)))
{
Log(LOG_LEVEL_ERR, "Unresolved variable '%s' in input list, cannot parse", RvalScalarValue(resolved_input));
break;
}
aux_policy = LoadPolicyFile(ctx, config, GenericAgentResolveInputPath(config, RvalScalarValue(resolved_input)), parsed_files_and_checksums, failed_files);
break;
case RVAL_TYPE_LIST:
aux_policy = LoadPolicyInputFiles(ctx, config, RvalRlistValue(resolved_input), parsed_files_and_checksums, failed_files);
break;
default:
ProgrammingError("Unknown type in input list for parsing: %d", resolved_input.type);
break;
}
if (aux_policy)
{
policy = PolicyMerge(policy, aux_policy);
}
RvalDestroy(resolved_input);
}
return policy;
}
示例9: LogPromiseContext
static void LogPromiseContext(const EvalContext *ctx, const Promise *pp)
{
Writer *w = StringWriter();
WriterWrite(w, "Additional promise info:");
if (PromiseGetHandle(pp))
{
WriterWriteF(w, " handle '%s'", PromiseGetHandle(pp));
}
{
Rval retval;
if (EvalContextVariableControlCommonGet(ctx, COMMON_CONTROL_VERSION, &retval))
{
WriterWriteF(w, " version '%s'", RvalScalarValue(retval));
}
}
if (PromiseGetBundle(pp)->source_path)
{
WriterWriteF(w, " source path '%s' at line %zu", PromiseGetBundle(pp)->source_path, pp->offset.line);
}
switch (pp->promisee.type)
{
case RVAL_TYPE_SCALAR:
WriterWriteF(w, " promisee '%s'", RvalScalarValue(pp->promisee));
break;
case RVAL_TYPE_LIST:
WriterWrite(w, " promisee ");
RlistWrite(w, pp->promisee.item);
break;
default:
break;
}
if (pp->comment)
{
WriterWriteF(w, " comment '%s'", pp->comment);
}
Log(LOG_LEVEL_VERBOSE, "%s", StringWriterData(w));
WriterClose(w);
}
示例10: TestGet
static void TestGet(VariableTable *t, const char *ref_str)
{
VarRef *ref = VarRefParse(ref_str);
Variable *v = VariableTableGet(t, ref);
assert_true(v != NULL);
assert_int_equal(0, VarRefCompare(ref, v->ref));
assert_string_equal(ref_str, RvalScalarValue(v->rval));
VarRefDestroy(ref);
}
示例11: MapIteratorsFromRval
/**
* Recursively go down the #rval and run PromiseIteratorPrepare() to take note
* of all iterables and mangle all rvals than need to be mangled before
* iterating.
*/
static void MapIteratorsFromRval(EvalContext *ctx,
PromiseIterator *iterctx,
Rval rval)
{
switch (rval.type)
{
case RVAL_TYPE_SCALAR:
PromiseIteratorPrepare(iterctx, ctx, RvalScalarValue(rval));
break;
case RVAL_TYPE_LIST:
for (const Rlist *rp = RvalRlistValue(rval);
rp != NULL; rp = rp->next)
{
MapIteratorsFromRval(ctx, iterctx, rp->val);
}
break;
case RVAL_TYPE_FNCALL:
{
char *fn_name = RvalFnCallValue(rval)->name;
/* Check function name. */
PromiseIteratorPrepare(iterctx, ctx, fn_name);
/* Check each of the function arguments. */
/* EXCEPT on functions that use special variables: the mangled
* variables would never be resolved if they contain inner special
* variables (for example "$(bundle.A[$(this.k)])" and the returned
* slist would contained mangled vars like "bundle#A[1]" which would
* never resolve in future iterations. By skipping the iteration
* engine for now, the function returns an slist with unmangled
* entries, and the iteration engine works correctly on the next
* pass! */
if (strcmp(fn_name, "maplist") != 0 &&
strcmp(fn_name, "mapdata") != 0 &&
strcmp(fn_name, "maparray")!= 0)
{
for (Rlist *rp = RvalFnCallValue(rval)->args;
rp != NULL; rp = rp->next)
{
MapIteratorsFromRval(ctx, iterctx, rp->val);
}
}
break;
}
case RVAL_TYPE_CONTAINER:
case RVAL_TYPE_NOPROMISEE:
break;
}
}
示例12: xcalloc
Promise *ExpandDeRefPromise(EvalContext *ctx, const Promise *pp)
{
Promise *pcopy;
Rval returnval, final;
pcopy = xcalloc(1, sizeof(Promise));
returnval = ExpandPrivateRval(ctx, NULL, "this", pp->promiser, RVAL_TYPE_SCALAR);
pcopy->promiser = RvalScalarValue(returnval);
if (pp->promisee.item)
{
pcopy->promisee = EvaluateFinalRval(ctx, NULL, "this", pp->promisee, true, pp);
}
else
{
pcopy->promisee = (Rval) {NULL, RVAL_TYPE_NOPROMISEE };
}
if (pp->classes)
{
pcopy->classes = xstrdup(pp->classes);
}
else
{
pcopy->classes = xstrdup("any");
}
if (pcopy->promiser == NULL)
{
ProgrammingError("ExpandPromise returned NULL");
}
pcopy->parent_promise_type = pp->parent_promise_type;
pcopy->offset.line = pp->offset.line;
pcopy->comment = pp->comment ? xstrdup(pp->comment) : NULL;
pcopy->conlist = SeqNew(10, ConstraintDestroy);
pcopy->org_pp = pp->org_pp;
/* No further type checking should be necessary here, already done by CheckConstraintTypeMatch */
for (size_t i = 0; i < SeqLength(pp->conlist); i++)
{
Constraint *cp = SeqAt(pp->conlist, i);
Rval returnval;
if (ExpectedDataType(cp->lval) == DATA_TYPE_BUNDLE)
{
final = ExpandBundleReference(ctx, NULL, "this", cp->rval);
}
else
{
示例13: RvalHash
unsigned RvalHash(Rval rval, unsigned seed, unsigned max)
{
switch (rval.type)
{
case RVAL_TYPE_SCALAR:
return StringHash(RvalScalarValue(rval), seed, max);
case RVAL_TYPE_FNCALL:
return FnCallHash(RvalFnCallValue(rval), seed, max);
case RVAL_TYPE_LIST:
return RlistHash(RvalRlistValue(rval), seed, max);
case RVAL_TYPE_NOPROMISEE:
return (seed + 1) % max;
default:
ProgrammingError("Unhandled case in switch: %d", rval.type);
}
}
示例14: assert
JsonElement *RvalToJson(Rval rval)
{
assert(rval.item);
switch (rval.type)
{
case RVAL_TYPE_SCALAR:
return JsonStringCreate(RvalScalarValue(rval));
case RVAL_TYPE_LIST:
return RlistToJson(RvalRlistValue(rval));
case RVAL_TYPE_FNCALL:
return FnCallToJson(RvalFnCallValue(rval));
default:
assert(false && "Invalid rval type");
return JsonStringCreate("");
}
}
示例15: RvalHash
unsigned RvalHash(Rval rval, unsigned seed)
{
switch (rval.type)
{
case RVAL_TYPE_SCALAR:
return StringHash(RvalScalarValue(rval), seed);
case RVAL_TYPE_FNCALL:
return FnCallHash(RvalFnCallValue(rval), seed);
case RVAL_TYPE_LIST:
return RlistHash(RvalRlistValue(rval), seed);
case RVAL_TYPE_NOPROMISEE:
/* TODO modulus operation is biasing results. */
return (seed + 1);
default:
ProgrammingError("Unhandled case in switch: %d", rval.type);
}
}