Esempio n. 1
0
void QoreValueList::insert(QoreValue val) {
   assert(reference_count() == 1);
   priv->resize(priv->length + 1);
   if (priv->length - 1)
      memmove(priv->entry + 1, priv->entry, sizeof(QoreValue) * (priv->length - 1));
   priv->entry[0] = val;
   if (val.hasNode() && get_container_obj(val.getInternalNode()))
      priv->incObjectCount(1);
}
Esempio n. 2
0
QoreValueList* QoreValueList::reverse() const {
   QoreValueList* l = new QoreValueList;
   l->priv->resize(priv->length);
   for (size_t i = 0; i < priv->length; ++i) {
      QoreValue n = priv->entry[priv->length - i - 1];
      l->priv->entry[i] = n.refSelf();
   }
   return l;
}
Esempio n. 3
0
QoreListNode* QoreValueList::getOldList(size_t start) const {
   if (start >= priv->length)
      return 0;

   QoreListNode* rv = new QoreListNode;
   for (size_t i = start; i < priv->length; ++i) {
      QoreValue v = priv->entry[i];
      rv->push(v.getReferencedValue());
   }
   return rv;
}
Esempio n. 4
0
void QoreValueList::merge(const QoreValueList* list) {
   assert(reference_count() == 1);
   int start = priv->length;
   priv->resize(priv->length + list->priv->length);
   for (size_t i = 0; i < list->priv->length; i++) {
      QoreValue p = list->priv->entry[i];
      priv->entry[start + i] = p.refSelf();
      if (p.hasNode() && get_container_obj(p.getInternalNode()))
	 priv->incObjectCount(1);
   }
}
Esempio n. 5
0
int QoreValueList::getAsString(QoreString &str, int foff, ExceptionSink* xsink) const {
   QoreContainerHelper cch(this);
   if (!cch) {
      str.sprintf("[ERROR: recursive reference to list %p]", this);
      return 0;
   }

   if (foff == FMT_YAML_SHORT) {
      str.concat('[');
      ConstValueListIterator li(this);
      while (li.next()) {
	 QoreValue n = li.getValue();
	 if (n.getAsString(str, foff, xsink))
	    return -1;
	 if (!li.last())
	    str.concat(", ");
      }
      str.concat(']');
      return 0;
   }

   if (!size()) {
      str.concat(&EmptyListString);
      return 0;
   }
   str.concat("list: (");

   if (foff != FMT_NONE)
      str.sprintf("%d element%s)\n", priv->length, priv->length == 1 ? "" : "s");

   for (size_t i = 0; i < priv->length; ++i) {
      if (foff != FMT_NONE) {
	 str.addch(' ', foff + 2);
	 str.sprintf("[%d]=", i);
      }

      QoreValue n = priv->entry[i];
      if (n.getAsString(str, foff != FMT_NONE ? foff + 2 : foff, xsink))
	 return -1;

      if (i != (priv->length - 1)) {
	 if (foff != FMT_NONE)
	    str.concat('\n');
	 else
	    str.concat(", ");
      }
   }
   if (foff == FMT_NONE)
      str.concat(')');

   return 0;
}
Esempio n. 6
0
QoreValue QoreValueList::minValue(ExceptionSink* xsink) const {
   if (!priv->length)
      return QoreValue();
   QoreValue rv = priv->entry[0];

   for (size_t i = 1; i < priv->length; ++i) {
      QoreValue v = priv->entry[i];
      if (QoreLogicalLessThanOperatorNode::doLessThan(v, rv, xsink))
	 rv = v;
      if (*xsink)
	 return QoreValue();
   }
   return rv.refSelf();
}
Esempio n. 7
0
bool QoreValue::isEqualHard(const QoreValue n) const {
   qore_type_t t = getType();
   if (t != n.getType())
      return false;
   switch (t) {
      case NT_INT: return getAsBigInt() == n.getAsBigInt();
      case NT_BOOLEAN: return getAsBool() == n.getAsBool();
      case NT_FLOAT: return getAsFloat() == n.getAsFloat();
      case NT_NOTHING:
      case NT_NULL:
	 return true;
   }
   return !compareHard(v.n, n.v.n, 0);
}
Esempio n. 8
0
QoreValue QoreValueList::maxValue(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const {
   if (!priv->length)
      return QoreValue();
   QoreValue rv = priv->entry[0];

   for (size_t i = 1; i < priv->length; ++i) {
      QoreValue v = priv->entry[i];

      safe_qorelist_t args(do_args(v, rv), xsink);
      ValueHolder result(fr->execValue(*args, xsink), xsink);
      if (*xsink)
	 return QoreValue();
      if (result->getAsBigInt() > 0)
	 rv = v;
   }
   return rv.refSelf();
}
Esempio n. 9
0
bool OrNothingTypeInfo::acceptInputImpl(QoreValue& n, ExceptionSink *xsink) const {
   qore_type_t t = n.getType();
   if (t == NT_NOTHING)
      return true;
   if (t == NT_NULL) {
      discard(n.assign((AbstractQoreNode*)0), xsink);
      return true;
   }

   if (qc) {
      if (t != NT_OBJECT)
	 return false;
      const QoreClass* n_qc = reinterpret_cast<const QoreObject*>(n.getInternalNode())->getClass();
      return qore_class_private::runtimeCheckCompatibleClass(*qc, *n_qc);
   }

   return t == qt;
}
Esempio n. 10
0
QoreValue VarRefNode::evalValueImpl(bool& needs_deref, ExceptionSink* xsink) const {
   QoreValue v;
   if (type == VT_LOCAL) {
      printd(5, "VarRefNode::evalImpl() this: %p lvar %p (%s)\n", this, ref.id, ref.id->getName());
      v = ref.id->evalValue(needs_deref, xsink);
   }
   else if (type == VT_CLOSURE) {
      printd(5, "VarRefNode::evalImpl() this: %p closure var %p (%s)\n", this, ref.id, ref.id->getName());
      ClosureVarValue *val = thread_get_runtime_closure_var(ref.id);
      v = val->evalValue(needs_deref, xsink);
   }
   else if (type == VT_LOCAL_TS) {
      printd(5, "VarRefNode::evalImpl() this: %p local thread-safe var %p (%s)\n", this, ref.id, ref.id->getName());
      ClosureVarValue *val = thread_find_closure_var(ref.id->getName());
      v = val->evalValue(needs_deref, xsink);
   }
   else if (type == VT_IMMEDIATE)
      v = ref.cvv->evalValue(needs_deref, xsink);
   else {
      assert(needs_deref);
      printd(5, "VarRefNode::evalImpl() this: %p global var: %p (%s)\n", this, ref.var, ref.var->getName());
      v = ref.var->eval();
   }

   AbstractQoreNode* n = v.getInternalNode();
   if (n && n->getType() == NT_REFERENCE) {
      ReferenceNode* r = reinterpret_cast<ReferenceNode*>(n);
      bool nd;
      QoreValue nv = r->evalValue(nd, xsink);
      if (needs_deref)
	 discard(v.getInternalNode(), xsink);
      needs_deref = nd;
      return v = nv;
   }

   return v;
}
Esempio n. 11
0
int QoreTypeInfo::runtimeAcceptInputIntern(bool &priv_error, QoreValue& n) const {
   qore_type_t nt = n.getType();

   if (qt != nt)
      return -1;

   if (qt != NT_OBJECT || !qc)
      return 0;

   bool priv;
   if (reinterpret_cast<const QoreObject*>(n.getInternalNode())->getClass()->getClass(*qc, priv)) {
      if (!priv)
	 return 0;

      // check private access if required class is privately
      // inherited in the input argument's class
      if (qore_class_private::runtimeCheckPrivateClassAccess(*qc))
	 return 0;

      priv_error = true;
   }

   return -1;
}
Esempio n. 12
0
void QoreValueListEvalOptionalRefHolder::evalIntern(const QoreListNode* exp) {
   if (!exp || exp->empty()) {
      val = 0;
      needs_deref = false;
      return;
   }
   val = new QoreValueList;
   needs_deref = true;

   ConstListIterator li(exp);
   while (li.next()) {
      const AbstractQoreNode* v = li.getValue();
      if (!v || v->is_value() || v->getType() == NT_REFERENCE) {
	 QoreValue qv;
	 qv.assignAndSanitize(v);
	 val->push(qv.refSelf());
	 continue;
      }
      val->push(v->evalValue(xsink));
      if (*xsink)
	 return;
   }
   assert(val->size() == exp->size());
}
Esempio n. 13
0
DateTimeValueHelper::DateTimeValueHelper(const QoreValue& n) {
   if (!n.isNullOrNothing()) {
      switch (n.type) {
	 case QV_Node: {
	    dt = n.v.n->getDateTimeRepresentation(del);
	    return;
	 }
	 case QV_Bool: {
	    dt = n.v.b ? OneDate : ZeroDate;
	    del = false;
	    return;
	 }
	 case QV_Int: {
	    if (n.v.i == 1) {
	       dt = OneDate;
	       del = false;
	       return;
	    }
	    dt = DateTime::makeRelativeFromSeconds(n.v.i);
	    del = true;
	    return;
	 }
	 case QV_Float: {
	    if (!n.v.f) {
	       dt = ZeroDate;
	       del = false;
	       return;
	    }
	    if (n.v.f == 1.0) {
	       dt = OneDate;
	       del = false;
	       return;
	    }
	    dt = DateTime::makeRelativeFromSeconds((int64)n.v.f, (int)((n.v.f - (float)((int)n.v.f)) * 1000000));
	    del = true;
	    return;
	 }
	 default:
	    assert(false);
	    // no break
      }
   }
   dt = ZeroDate;
   del = false;
}
Esempio n. 14
0
QoreValue copy_value_and_resolve_lvar_refs(QoreValue& n, ExceptionSink* xsink) {
   if (!n.hasNode())
      return n;
   return copy_and_resolve_lvar_refs(n.getInternalNode(), xsink);
}
Esempio n. 15
0
QoreValue pseudo_classes_eval(const QoreValue n, const char *name, const QoreListNode *args, ExceptionSink *xsink) {
   return qore_class_private::evalPseudoMethod(pseudo_get_class(n.getType()), n, name, args, xsink);
}