void JSCLanguageBase::add(const AdditionalClass& additionalClass) {
  std::vector<JSCPropertyPointer> properties;

  for (const auto& propertyPair : additionalClass.properties) {
    JSCPropertyType type = JSCProperty::propertyStringToType(std::get<0>(propertyPair));
    if (JSCProperty_Unknown == type) {
      SIAWarning("unsupported property type: %s", std::get<0>(propertyPair).c_str());
      continue;
    }

    JSCPropertyPointer property(new JSCProperty(type));
    property->setPath({std::get<1>(propertyPair)});
    property->setRequired(!std::get<2>(propertyPair));
    properties.push_back(property);
  }

  JSCObjectPointer newClass(new JSCObject(properties));
  newClass->setRootName(additionalClass.className);
  newClass->setPath({additionalClass.name});
  newClass->setCodeGenerate(true);
  newClass->setRequired(!additionalClass.optional);

  m_additionalClasses.push_back(newClass);

  for (const auto& out : generateOutput(newClass)) {
    m_outputs.push_back(out);
  }
}
Beispiel #2
0
LispRef content(LispRef stream, LispRef eos_error_p, LispRef eos_value)
{
    WITH_DEBUG(fprintf(stderr, "content\n"));

    char tag;
    read_byte(tag);

    WITH_DEBUG(fprintf(stderr, "  tag: %x\n", tag));

    switch (tag)
    {
        case TC_NULL:
            return nullReference(stream, eos_error_p, eos_value);
        case TC_REFERENCE:
            return prevObject(stream, eos_error_p, eos_value);
        case TC_CLASS:
            return newClass(stream, eos_error_p, eos_value);
        case TC_OBJECT:
            return newObject(stream, eos_error_p, eos_value);
        case TC_STRING:
            return newString(stream, eos_error_p, eos_value);
        case TC_STATE:
            return newState(stream, eos_error_p, eos_value);
        case TC_VECTOR:
            return newVector(stream, eos_error_p, eos_value);
        case TC_STREAM:
            return newStream(stream, eos_error_p, eos_value);
        case TC_RESET:
            return reset(stream, eos_error_p, eos_value);
        case TC_SELF:
            return stream;
        case TC_FUNCTION:
            return newFunction(stream, eos_error_p, eos_value);
        case TC_BYTEVECTOR:
            return newBytevector(stream, eos_error_p, eos_value);
        case TC_INT:
            return newInt(stream, eos_error_p, eos_value);
        case TC_DOUBLE:
            return newDouble(stream, eos_error_p, eos_value);
        case TC_SYMBOL:
            return newSymbol(stream, eos_error_p, eos_value);
        case TC_KEYWORD:
            return newKeyword(stream, eos_error_p, eos_value);
        case TC_CHAR:
            return newChar(stream, eos_error_p, eos_value);
        case TC_CONS:
            return newCons(stream, eos_error_p, eos_value);
        default:
            {
                LispRef str, args;

                eul_allocate_string(str, "unknown tag in ~a");
                eul_allocate_cons(args, stream, eul_nil);
                eul_serial_error(stream, str, args);
                return eul_nil;
            }
    }
}
Beispiel #3
0
/*
 findClass gets a class object,
 either by finding it already or making it
 in addition, it makes sure it has a size, by setting
 the size to zero if it is nil.
 */
static object findClass(char *name)
{
    object newobj;

    newobj = globalSymbol(name);
    if (newobj == nilobj)
        newobj = newClass(name);
    if (basicAt(newobj, sizeInClass) == nilobj)
    {
        basicAtPut(newobj, sizeInClass, newInteger(0));
    }
    return newobj;
}
//-------------------------------------------------------------------------------------------------
Class& ClassManager::addClass(const std::string& name, const std::string& id)
{
    const IdIndex&   ids   = m_classes.get<Id>();
    const NameIndex& names = m_classes.get<Name>();

    // First make sure that the class doesn't already exist
    if ((ids.find(id) != ids.end()) || (names.find(name) != names.end()))
        CAMP_ERROR(ClassAlreadyCreated(name, id));

    // Create the new class
    std::shared_ptr<Class> newClass(new Class(name));

    // Insert it into the table
    ClassInfo info;
    info.id = id;
    info.name = name;
    info.classPtr = newClass;
    m_classes.insert(info);

    // Notify observers
    notifyClassAdded(*newClass);

    return *newClass;
}
Beispiel #5
0
Class* Unit::defClass(PreClass* preClass,
                      bool failIsFatal /* = true */) {
  Class* const* clsList = preClass->namedEntity()->clsList();
  Class* top = *clsList;
  if (top) {
    Class *cls = top->getCached();
    if (cls) {
      // Raise a fatal unless the existing class definition is identical to the
      // one this invocation would create.
      if (cls->preClass() != preClass) {
        if (failIsFatal) {
          raise_error("Class already declared: %s", preClass->name()->data());
        }
        return NULL;
      }
      return cls;
    }
  }
  // Get a compatible Class, and add it to the list of defined classes.

  Class* parent = NULL;
  for (;;) {
    // Search for a compatible extant class.  Searching from most to least
    // recently created may have better locality than alternative search orders.
    // In addition, its the only simple way to make this work lock free...
    for (Class* class_ = top; class_ != NULL; class_ = class_->m_nextClass) {
      if (class_->preClass() != preClass) continue;

      Class::Avail avail = class_->avail(parent, failIsFatal /*tryAutoload*/);
      if (LIKELY(avail == Class::AvailTrue)) {
        class_->setCached();
        DEBUGGER_ATTACHED_ONLY(phpDefClassHook(class_));
        return class_;
      }
      if (avail == Class::AvailFail) {
        if (failIsFatal) {
          raise_error("unknown class %s", parent->name()->data());
        }
        return NULL;
      }
      ASSERT(avail == Class::AvailFalse);
    }

    // Create a new class.
    if (!parent && preClass->parent()->size() != 0) {
      parent = Unit::getClass(preClass->parent(), failIsFatal);
      if (parent == NULL) {
        if (failIsFatal) {
          raise_error("unknown class %s", preClass->parent()->data());
        }
        return NULL;
      }
    }

    VMExecutionContext* ec = g_vmContext;
    ActRec* fp = ec->getFP();
    PC pc = ec->getPC();

    bool needsFrame = ec->m_stack.top() &&
      (!fp || fp->m_func->unit() != preClass->unit());

    if (needsFrame) {
      /*
        we can be called from Unit::merge, which hasnt yet setup
        the frame (because often it doesnt need to).
        Set up a fake frame here, in case of errors.
        But note that mergeUnit is called for systemlib etc before the
        stack has been setup. So dont do anything if m_stack.top()
        is NULL
      */
      ActRec &tmp = *ec->m_stack.allocA();
      tmp.m_savedRbp = (uint64_t)fp;
      tmp.m_savedRip = 0;
      tmp.m_func = preClass->unit()->getMain();
      tmp.m_soff = preClass->getOffset() - tmp.m_func->base();
      tmp.setThis(NULL);
      tmp.m_varEnv = 0;
      tmp.initNumArgs(0);
      ec->m_fp = &tmp;
      ec->m_pc = preClass->unit()->at(preClass->getOffset());
      ec->pushLocalsAndIterators(tmp.m_func);
    }
    ClassPtr newClass(Class::newClass(preClass, parent));
    if (needsFrame) {
      ec->m_stack.top() = (Cell*)(ec->m_fp+1);
      ec->m_fp = fp;
      ec->m_pc = pc;
    }
    Lock l(Unit::s_classesMutex);
    /*
      We could re-enter via Unit::getClass() or class_->avail(), so
      no need for *clsList to be volatile
    */
    if (UNLIKELY(top != *clsList)) {
      top = *clsList;
      continue;
    }
    if (top) {
      newClass->m_cachedOffset = top->m_cachedOffset;
    } else {
      newClass->m_cachedOffset =
        Transl::TargetCache::allocKnownClass(preClass->name());
    }
    newClass->m_nextClass = top;
    Util::compiler_membar();
    *const_cast<Class**>(clsList) = newClass.get();
    newClass.get()->incAtomicCount();
    newClass.get()->setCached();
    DEBUGGER_ATTACHED_ONLY(phpDefClassHook(newClass.get()));
    return newClass.get();
  }
}
Beispiel #6
0
static int cls(int cn) {
  if(cn<0) return newExcept(any,newClass(-cn));
  if(cn==0) return notAllowed;
  return newClass(cn);
}
Beispiel #7
0
Hjava_lang_Class* floatClass; 
Hjava_lang_Class* doubleClass;
Hjava_lang_Class* byteClass; 
Hjava_lang_Class* shortClass;     
Hjava_lang_Class* voidClass;

Hjava_lang_Class* types[MAXTYPES];

static
void
initPrimClass(Hjava_lang_Class** class, const char* name, char sig, int len)
{
	errorInfo info;
	classEntry* centry;
	char entryName[10];
	Hjava_lang_Class* clazz = newClass();
	Utf8Const *uname;

	if (clazz == 0) {
		goto bad;
	}
	(*class) = clazz;
	if (!gc_add_ref(clazz)) {
		goto bad;
	}

	clazz->vtable = _PRIMITIVE_DTABLE;
	clazz->name = utf8ConstFromString(name);
	clazz->accflags = ACC_PUBLIC | ACC_FINAL;
	CLASS_PRIM_SIG(clazz) = sig;
        CLASS_PRIM_NAME(clazz) = utf8ConstNew(&sig, 1);