Exemplo n.º 1
0
void PersistEngine::read(PersistObject *&object) throw(PersistException)
{
  uint32_t id = 0;
  read(id);
  // Is the ID a NULL object?
  if (id == NullObject) {
    object = NULL;
    return;
  }

  // Do we already have this object in memory?
  if (id < myArchiveVector.size()) {
    object = myArchiveVector[id];
    return;
  }

  // Okay - read the identifier for the class in...
  std::string className = readClass();

  // is the pointer already initialized? if so then no need to reallocate
  if (object != NULL) {
    readObject(object);
    return;
  }

  // Create the object (of the relevant type)
  object = TypeManager::createInstanceOf(className.c_str());
  if (object) {
    // Okay then - we can make this object
    readObject(object);
  }
  else
    throw(PersistException(std::string("Unable to instantiate object of class ")+className));
}
Exemplo n.º 2
0
Type *BinReader::readType()
{
    int startPosition = bytes->getPosition();

    const char *stype       = readPoolString();
    const char *packageName = readPoolString();
    const char *name        = readPoolString();
    int        typeID       = bytes->readInt();
    const char *source      = readPoolString();
    int        linenumber   = bytes->readInt();

    utString fullname = packageName;

    fullname += ".";
    fullname += name;

    TypeIndex *tindex = *(types.get(utHashedString(fullname)));

    Type *type = tindex->type;

    type->setTypeID((LSTYPEID)typeID);
    type->packageName = packageName;
    type->fullName    = fullname;

    if (!strcmp(stype, "CLASS"))
    {
        type->attr.isClass = true;
    }
    else if (!strcmp(stype, "INTERFACE"))
    {
        type->attr.isInterface = true;
    }
    else if (!strcmp(stype, "STRUCT"))
    {
        type->attr.isStruct = true;
    }
    else if (!strcmp(stype, "DELEGATE"))
    {
        type->attr.isDelegate = true;
    }
    else if (!strcmp(stype, "ENUM"))
    {
        type->attr.isEnum = true;
    }
    else
    {
        lmAssert(0, "Unknown type: %s", stype);
    }

    readClass(type);

    return type;
}
Exemplo n.º 3
0
ClassFile* loadClass(Interpretador* interpretador, char* className) {
    ClassFile* cFile = getClassFileByName(interpretador->initClass, className);
    printf("PEGOU PELO NOME\n");
    if (cFile == NULL) {
        cFile = readClass(className);
        appendClassList(&(interpretador->initClass), *cFile);
        // Inicia <clinit>
        if (getMethod(*cFile, "<clinit>", "()V") != NULL) {
            printf("\n\nVAI INICIAR CLINIT\n");
            methodInit(className, "<clinit>", "()V", interpretador, 0, 0);
            methodExec(interpretador);
        }
    }
    return cFile;
}
Exemplo n.º 4
0
void PersistEngine::read(PersistObject &object) throw(PersistException)
{
  uint32_t id = 0;
  read(id);
  if (id == NullObject)
    throw("Object Id should not be NULL when un-persisting to a reference");

  // Do we already have this object in memory?
  if (id < myArchiveVector.size()) {
    object = *(myArchiveVector[id]);
    return;
  }

  // Okay - read the identifier for the class in...
  // we won't need it later since this object is already allocated
  readClass();

  // Okay then - we can read data straight into this object
  readObject(&object);
}
Exemplo n.º 5
0
//[cf]
//[of]:main
int main(int argc, char *argv[])
{
  if( argc != 2 )
  {
    puts("usage: db2html <docbook_file>");
    return 1;
  }

  ax_initialize((void*)malloc, (void*)free);

  AXClassContext classContext;
  int res = ax_initializeClassParser(&classContext);
  if( res != 0 )
    return 1;

  AXElementClass* docbookClass = readClass(schemaFilename, &classContext);
  if( docbookClass == NULL )
    return 1;

  AXParseContext parseContext;
  res = ax_initializeParser(&parseContext, chunkSize);
  if( res != 0 )
    return 1;

  AXElement* book = readDocument(argv[1], &parseContext, docbookClass);
  if( book == NULL )
  {
    printAsmXmlError(&parseContext);
    return 1;
  }

  DocbookToHTML db;
  db.processBook(book);
  puts(db.toString());

  // Release the document and its class
  ax_releaseParser(&parseContext);
  ax_releaseClassParser(&classContext);
  return 0;
}
///////////////////////////////////////////////////////////////////////////////
// main
///////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
  int             res;
  AXClassContext  classContext;
  AXParseContext  parseContext;
  AXElementClass* friendClass;
  AXElement*      friends;
  AXElement*      friend;

  // Initialize the AsmXml library
  //
  // Pass the malloc() and free() functions
  //
  ax_initialize(malloc, free);

  // Initialize the class context
  //
  // It can store one or more classes. Classes read with this
  // context are kept in memory as long as it is not released.
  //
  res = ax_initializeClassParser(&classContext);
  // An error while initialization means that allocation failed.
  // It should never happen since it allocates only 4K.
  if( res != 0 )
    return 1;

  // Read the schema and compile it
  //
  friendClass = readClass(schemaFilename, &classContext);
  if( friendClass == NULL )
    return 1;

  // Initialize the parser
  //
  // Documents read with this parser will stay in memory as long as
  // the parser is not released.
  //
  // The choice of the chunk size is very important since the
  // performance can be affected by this value. The parser allocates
  // memory by chunks to reduce calls to malloc that can be very slow.
  // The ideal value is around 50% of the source XML to process.
  //
  res = ax_initializeParser(&parseContext, chunkSize);
  // An error while initialization means that initial allocation failed.
  if( res != 0 )
    return 1;

  // Read the file and parse it
  //
  friends = readDocument(xmlFilename, &parseContext, friendClass);
  if( friends == NULL )
  {
    printAsmXmlError(&parseContext);
    return 1;
  }

  // Enumerate child elements
  friend = friends->firstChild;
  while( friend )
  {
    printf("================================\n");
    printf("Friend ID: %s\n", asString(&friend->attributes[0]));
    printf("Name: %s\n", asString(&friend->attributes[1]));
    printf("UserID: %s\n", asString(&friend->attributes[2]));
    friend = friend->nextSibling;
    printf("================================\n");
  }

  // Release the document and its class
  ax_releaseParser(&parseContext);
  ax_releaseClassParser(&classContext);
  return 0;
}
Exemplo n.º 7
0
   
   Notes: I'm not sure this implementation fully satisfies JVM specification.
   The loading is too complex.....
 */

struct Hjava_lang_Class*
java_lang_ClassLoader_defineClass0(struct Hjava_lang_ClassLoader* this, struct Hjava_lang_String* name, HArrayOfByte* data, jint offset, jint length)
{
    Hjava_lang_Class* clazz;
    classFile hand;
    hand.base = &unhand(data)->body[offset];
    hand.buf = hand.base;
    hand.size = length;
	
    clazz = (Hjava_lang_Class*)newObject(ClassClass);
    clazz = readClass(clazz, &hand, this);

    processClass(clazz, CSTATE_PREPARED);
    return clazz;
}


/*
 * Resolve classes reference by this class.
 */
void
java_lang_ClassLoader_resolveClass0(struct Hjava_lang_ClassLoader* this, struct Hjava_lang_Class* class)
{
	processClass(class, CSTATE_LINKED);
}