Exemplo n.º 1
0
void wrenPrintValue(Value value)
{
  #if WREN_NAN_TAGGING
  if (IS_NUM(value))
  {
    printf("%.14g", AS_NUM(value));
  }
  else if (IS_OBJ(value))
  {
    printObject(AS_OBJ(value));
  }
  else
  {
    switch (GET_TAG(value))
    {
      case TAG_FALSE: printf("false"); break;
      case TAG_NAN: printf("NaN"); break;
      case TAG_NULL: printf("null"); break;
      case TAG_TRUE: printf("true"); break;
    }
  }
  #else
  switch (value.type)
  {
    case VAL_FALSE: printf("false"); break;
    case VAL_NULL: printf("null"); break;
    case VAL_NUM: printf("%.14g", AS_NUM(value)); break;
    case VAL_TRUE: printf("true"); break;
    case VAL_OBJ:
    {
      printObject(AS_OBJ(value));
    }
  }
  #endif
}
Exemplo n.º 2
0
void printAssertedValues(NB_Link *member){
  struct ASSERTION *assertion;
  NB_Object *value;
  outPut("(");
  while(member!=NULL){
    assertion=(struct ASSERTION *)member->object;
    //if(assertion->object->value==nb_Disabled) value=(*assertion->object->type->eval)(assertion->object);
    //else value=assertion->object->value;
    value=assertion->object->value;
    if(value==nb_True){
      printObject(assertion->target);
      }
    else if(value==nb_False){
      outPut("!");
      printObject(assertion->target);
      }
    else if(value==nb_Unknown){
      outPut("?");
      printObject(assertion->target);
      }
    else{
      printObject(assertion->target);
      outPut("=");
      //printObject(value);
      printObject(assertion->object);
      }
    if((member=member->next)!=NULL) outPut(",");
    }
  outPut(")");
  }
Exemplo n.º 3
0
void printKvStruct(const KeyValue *kv) {
  if (kv != NULL) {
    printObject(kv->key);
    putchar(':');
    printObject(kv->value);
  }
}
Exemplo n.º 4
0
/*
*  Print all or selected objects in a hash
*/
void nbHashShow(struct HASH *hash,char *label,NB_Type *type){
  NB_Object *object,**objectP;
  long v;
  int i;
  int32_t level;

  outPut("Hash: Modulo=%8.8x Objects=%8.8x %s\n",hash->mask+1,hash->objects,label);
  objectP=(NB_Object **)&(hash->vect);
  for(v=0;v<=hash->mask;v++){
    i=0;
    for(object=*objectP;object!=NULL;object=object->next){
      if(type==NULL || object->type==type){
        if(object==object->value) level=0;
        else level=((NB_Cell *)object)->level;
        outPut("Slot=%8.8x.%2.2x Code=%8.8x Ref=%8.8x Level=%8.8x = ",v,i,object->hashcode,object->refcnt,level);
        printObject(object->value);
        if(object!=object->value){
          outPut(" == "); 
          printObject(object);
          }
        outPut("\n");
        if(i<INT_MAX) i++;
        }
      }
    objectP++;
    }
  }
Exemplo n.º 5
0
static int printModel(FILE *f, Imod *m)
{
  int    ob;     /* object index. */
  int    ec = 0; /* error code.   */
  Ipoint min, max, mean;
  Zscale = m->zscale;

  /* DNM: comment out item with no format field */
  fprintf(f, "3DMetafile (1 0 Stream Label0> )\n"/*, m->objsize*/);
  fprintf(f, "\n#Created by imod2meta\n\n");
  fprintf(f, "BeginGroup ( DisplayGroup( ) )\n");

  imodel_minpt(m, &min);
  imodel_maxpt(m, &max);
  mean.x = (max.x + min.x) * 0.5f;
  mean.y = (max.y + min.y) * 0.5f;
  mean.z = (max.z + min.z) * 0.5f;
  fprintf(f, "Translate ( %g %g %g )\n",
          -mean.x, -mean.y, -Zscale*mean.z);


  /* put camera, renderer, lights here */
  if (ObjectOnly < 0){
    for(ob = 0; ob < m->objsize; ob++)
      ec = printObject(f, m, ob);
  }else{
    printf("object %d\n", ObjectOnly);
    ec = printObject(f, m, ObjectOnly);
  }

  fprintf(f, "EndGroup ( )\n");
     
  return(ec);
}
Exemplo n.º 6
0
static void nbSentenceShow(NB_Sentence *sentence) {
    if(sentence==NULL) outPut("(?)");
    else {
        if(sentence->term!=addrContext) printObject((NB_Object *)sentence->term);
        if(*sentence->facet->ident->value) outPut("@%s",sentence->facet->ident->value);
        if(sentence->args) printObject((NB_Object *)sentence->args);
    }
}
Exemplo n.º 7
0
/**
 * \brief Prints the VarDictionary.
 *
 * A debugging function which prints the dictionary structure to the stderr file
 */
static void dsInternalDictionaryPrintInternalWithFunction(const DSInternalDictionary *dictionary, const void *printFunction, const DSUInteger position)
{
        DSUInteger i;
        int (*print)(const char *,...) = DSPrintf;
        int (*printObject)(void *);
        if (dictionary == NULL) {
                goto bail;
        }
        printObject = printFunction;
        if (print == NULL)
                print = printf;
        dsInternalDictionaryPrintInternalWithFunction(dictionary->lower, printFunction, position+1);
        for (i = 1; i < position+1; i++)
                print(".");
        if (dictionary->current == '\0') {
                print("+- ");
                printObject(dsInternalDictionaryValue(dictionary));
                print("\n");
        } else {
                print("+-%c\n", dictionary->current);
        }
        dsInternalDictionaryPrintInternalWithFunction(dictionary->next, printFunction, position+2);
        dsInternalDictionaryPrintInternalWithFunction(dictionary->higher, printFunction, position+1);
bail:
        return;
}
Exemplo n.º 8
0
// Render a value to text.
char*
aJsonClass::printValue(aJsonObject *item)
{
  char *out = NULL;
  if (!item)
    return NULL;
  switch (item->type)
    {
  case aJson_NULL:
    out = strdup("null");
    break;
  case aJson_False:
    out = strdup("false");
    break;
  case aJson_True:
    out = strdup("true");
    break;
  case aJson_Int:
    out = printInt(item);
    break;
  case aJson_Float:
    out = printFloat(item);
    break;
  case aJson_String:
    out = printString(item);
    break;
  case aJson_Array:
    out = printArray(item);
    break;
  case aJson_Object:
    out = printObject(item);
    break;
    }
  return out;
}
Exemplo n.º 9
0
void printObjectList(ObjectNode* objList, int indent) {
	ObjectNode *node = objList;
	while (node != NULL) {
		printObject(node->object, indent);
		printf("\n");
		node = node->next;
	}
}
Exemplo n.º 10
0
/**********************************************************************
* Private Object Methods
**********************************************************************/
void printAssertion(struct ASSERTION *assertion){
  if(assertion==NULL) outPut("(?)");
  else if(assertion->object==nb_True){
    printObject(assertion->target);
    }
  else if(assertion->object==nb_False){
    outPut("!");
    printObject(assertion->target);
    }
  else if(assertion->object==nb_Unknown){
    outPut("?");
    printObject(assertion->target);
    }
  else{
    printObject(assertion->target);
    outPut("%s",assertion->cell.object.type->name);
    printObject(assertion->object);
    }
  }
Exemplo n.º 11
0
//
// printHierarchy
//
void wb_print_wbl::printHierarchy(wb_volume& v, wb_object& o)
{
  if (v.object() == o)
    indent(1) << "SObject " << v.name() << ":" << endl;
  else
    indent(1) << "SObject " << o.parent().longName() << endl;
  
  printObject(v, o);
  
  indent(-1) << "EndSObject" << endl;
}
Exemplo n.º 12
0
int script_dump() {
    con_passthrough = 1;

    if (loadObjects(resmgr)) {
        fprintf(stderr, "Unable to load object hierarchy\n");
        return 1;
    }

    printObject(object_root, SCRIPT_PRINT_METHODS | SCRIPT_PRINT_CHILDREN);
    return 0;
}
Exemplo n.º 13
0
int execute(char* code, VM* vm, Contexts* contexts, Method** methods){
	Tree* tree = parse(code);
	printNode(tree->root, 0);

	Vtree* vtree = getVtree(tree, vm);
	//printVnode(vtree->root, 0);

	calc(vtree->root, vm, contexts, methods);
	printVnode(vtree->root, 0);

	printf(">>>>> ");
	printObject(vtree->root->obj, 0);
	printf("\n");

	return 0;
}
Exemplo n.º 14
0
jobjectArray MetaInterface::parsePath() {
  // first element is "get" or, eventually, "set".
  const char* system_string = mElements.get(1);
  DLOG(INFO) << "Looking for system: " << system_string;
  const MetaObject* system_meta = MetaRegistry::getMetaRegistry()->getMetaObject(system_string);
  const System* system = SystemRegistry::getSystemRegistry()->getSystem(system_meta);
  MetaBase const* root = system;

  jobjectArray output = NULL;
  if (system != NULL) {
    DLOG(INFO) << "Found system: " << system->getMetaObject()->getName();
    if (mElements.getCount() > 2) {
      output = parseObject(root, 2);
    } else {
      output = printObject(root);
    }
  }
  
  return output;
}
Exemplo n.º 15
0
int compile(char *fileName) {
  if (openInputStream(fileName) == IO_ERROR)
    return IO_ERROR;

  currentToken = NULL;
  lookAhead = getValidToken();

  initSymTab();

  compileProgram();

  printObject(symtab->program,0);

  cleanSymTab();
  free(currentToken);
  free(lookAhead);
  closeInputStream();
  return IO_SUCCESS;

}
Exemplo n.º 16
0
// Render a value to text.
int
aJsonClass::printValue(aJsonObject *item, FILE* stream)
{
  int result = 0;
  if (item == NULL)
    {
      //nothing to do
      return 0;
    }
  switch (item->type)
    {
  case aJson_NULL:
    result = fprintf(stream, PSTR("null"));
    break;
  case aJson_False:
    result = fprintf_P(stream, PSTR("false"));
    break;
  case aJson_True:
    result = fprintf_P(stream, PSTR("true"));
    break;
  case aJson_Int:
    result = printInt(item, stream);
    break;
  case aJson_Float:
    result = printFloat(item, stream);
    break;
  case aJson_String:
    result = printString(item, stream);
    break;
  case aJson_Array:
    result = printArray(item, stream);
    break;
  case aJson_Object:
    result = printObject(item, stream);
    break;
    }
  //good time to flush the stream
  fflush(stream);
  return result;
}
Exemplo n.º 17
0
void Printer::dispatchType(const Value &val, std::ostringstream &out) {
    switch (val.getType()) {
    case JSON_OBJECT:
        printObject(val, out);
        break;
    case JSON_ARRAY:
        printArray(val, out);
        break;
    case JSON_NUMBER:
        printNumber(val, out);
        break;
    case JSON_BOOL:
        printBoolean(val, out);
        break;
    case JSON_STRING:
        printString(val, out);
        break;
    case JSON_NULL:
        out << typenames[JSON_NULL];
        break;
    }
}
Exemplo n.º 18
0
jobjectArray MetaInterface::parseObject(MetaBase const* root, const int current_index) {
  int next_index = current_index + 1;
  const int path_elements = mElements.getCount();
  jobjectArray result = NULL;
  
  
  const MetaObject* meta = root->getMetaObject();
  
  const char* field_string = mElements.get(current_index);
  const int field_count = meta->getFieldCount();
  for (int y = 0; y < field_count; y++) {
    const MetaField* metaField = meta->getField(y);

    if (strcmp(field_string, metaField->getName()) == 0) {
      DLOG(INFO) << "Found field: " << metaField->getName();
      // found the field!
  
      // test for array access
      int array_index = -1;
      if (current_index + 1 < path_elements) {
        const char* next_element = mElements.get(current_index + 1);
        if (isNumber(next_element)) {
          array_index = atoi(next_element);
          next_index++;
        }
      }

      // pull the object out of the root object
      void* object = NULL;
      bool is_array_terminator = false;
      
      if (array_index >= 0) {
        if (array_index >= 0 && array_index <= metaField->getElementCount(root)) {
          if (metaField->getStorageType() == MetaField::TYPE_pointer) {
            // array of pointers
            object = *((void**)metaField->getElement(root, array_index));
          } else {
            // inline array
            object = metaField->getElement(root, array_index);
          }
        }
      } else if (metaField->getElementCount(root) > 1 && next_index >= path_elements) {
        // This is an array request.
        is_array_terminator = true;
      } else {
        if (metaField->getStorageType() == MetaField::TYPE_pointer) {
          object = *((void**)metaField->get(root));
        } else {
          object = metaField->get(root);
        }
      }


      if (object && MetaBase::authenticatePointer(object)) {
        // safe to cast!
        MetaBase* new_root = static_cast<MetaBase*>(object);
        if (next_index < path_elements) {
          // recurse
          result = parseObject(new_root, next_index);
        } else {
          // leaf
          result = printObject(new_root);
        }
      } else if (is_array_terminator) {
        // This is the leaf, but it's an array.
        result = printArray(root, metaField);
      } else {
        // we found the field but can't go any further.
        DLOG(INFO) << "Field null or unknown type: " << metaField->getTypeName() << " (" << reinterpret_cast<int>(object) << ")";
      }
    }
  }
  return result;
}
Exemplo n.º 19
0
//
// printObject
//
void wb_print_wbl::printObject(wb_volume& v, wb_object& o, bool recursive)
{
  wb_object to = o;
  wb_object templ;
  cdh_uObjid	uid;
  unsigned int idx;
  wb_cdef cdef = v.cdef(o);
  if ( !cdef) {
    m_os << "! %WBDUMP-E-Error Failed to get object class" << endl;
    m_errCnt++;
    // return;
    cdef = v.cdef( pwr_eClass_ClassLost);
  }
  const char* cname = cdef.name();
  char *block;
  int size;

  if ( o.docBlock( &block, &size) && strcmp( block, "") != 0) {
    indent(0) << "!/**" << endl;
    indent(0) << "! ";
    for ( char *s = block; *s; s++) {
      if ( *s == '\n') {
	m_os << *s;
	indent(0) << "! ";
	continue;
      }
      m_os << *s;
    }
    m_os << endl;
    indent(0) << "!*/" << endl;
  }

  indent(1) << "Object " << o.name() << " " << cname;

  if (m_idxFlag) {
    switch (cdef.cid()) {
    case pwr_eClass_ClassDef:
      uid.pwr = o.oid();
      idx = uid.c.cix;
      break;
    case pwr_eClass_TypeDef:
      uid.pwr = o.oid();
      idx = uid.t.tix;
      break;
    case pwr_eClass_ObjBodyDef:
      uid.pwr = o.oid();
      idx = uid.c.bix;
      break;
    case pwr_eClass_Param:
    case pwr_eClass_Input:
    case pwr_eClass_Output:
    case pwr_eClass_Intern:
    case pwr_eClass_Buffer:
    case pwr_eClass_ObjXRef:
      uid.pwr = o.oid();
      idx = uid.c.aix;
      break;
    default:
      idx = (unsigned long) o.oix();
    }
    m_os << " " << idx;
  }
  if ( m_timeFlag) {
    // Get oh time
    char timestr[40];
    pwr_tTime ohtime = o.ohTime();
    time_AtoAscii( &ohtime, time_eFormat_DateAndTime, timestr, sizeof(timestr));

    m_os << " " << timestr;
  }
  m_os << endl;

  wb_object co = v.object(cdh_ClassIdToObjid(cdef.cid()));
  wb_name t("Template");
  
  templ = co.child(t);
  if (!templ) {
    m_errCnt++;
    m_os << "Template not found for class " << cdef.name() << endl;
    return;
  }

  if ( v.cid() == pwr_eClass_ClassVolume &&
       strcmp( o.name(), "Template") == 0)
    m_isTemplateObject = true;
  else
    m_isTemplateObject = false;
  
 
  printBody(v, o, templ, cdef, pwr_eBix_rt);
  printBody(v, o, templ, cdef, pwr_eBix_dev);

  if (recursive) {
    if ( !(m_noFoCodeFlag && isFoCodeObject( v, o))) {
      for (to = o.first(); to; to = to.after())
	printObject(v, to);
    }
  }    

  indent(-1) << "EndObject" << endl;
}
Exemplo n.º 20
0
void PExport::exportStore(void)
{
    unsigned i;
    time_t now;
    time(&now);

    // Calculate a first guess for the map size based on the space size
    totalBytes = 0;
    void *startAddr = 0;
    for (i = 0; i < memTableEntries; i++)
    {
        if (i != ioMemEntry)
        {
            totalBytes += (unsigned long)memTable[i].mtLength;
            // Get the lowest address.
            if (startAddr == 0 || memTable[i].mtAddr < startAddr)
                startAddr = memTable[i].mtAddr;
        }
    }
    // Create a map entry for each entry.  Allow five words per object.
    nMapSize = totalBytes/(sizeof(PolyWord)*5);
    pMap = (PolyObject **)malloc(sizeof(PolyObject*)*nMapSize);

    if (pMap == 0)
        throw MemoryException();

    // We want the entries in pMap to be in ascending
    // order of address to make searching easy so we need to process the areas
    // in order of increasing address, which may not be the order in memTable.
    indexOrder = (unsigned*)calloc(sizeof(unsigned), memTableEntries-1);
    if (indexOrder == 0)
        throw MemoryException();

    unsigned items = 0;
    for (i = 0; i < memTableEntries; i++)
    {
        if (i != ioMemEntry)
        {
            unsigned j = items;
            while (j > 0 && memTable[i].mtAddr < memTable[indexOrder[j-1]].mtAddr)
            {
                indexOrder[j] = indexOrder[j-1];
                j--;
            }
            indexOrder[j] = i;
            items++;
        }
    }
    ASSERT(items == memTableEntries-1);

    // Process the area in order of ascending address.
    for (i = 0; i < items; i++)
    {
        unsigned index = indexOrder[i];
        char *start = (char*)memTable[index].mtAddr;
        char *end = start + memTable[index].mtLength;
        for (PolyWord *p = (PolyWord*)start; p < (PolyWord*)end; )
        {
            p++;
            PolyObject *obj = (PolyObject*)p;
            if (nObjects == nMapSize)
            {
                // Need to expand the array.
                PolyObject **newMap =
                    (PolyObject **)realloc(pMap, (nMapSize + nMapSize/2)*sizeof(PolyObject*));
                if (newMap == 0)
                    throw MemoryException();
                pMap = newMap;

            }
            POLYUNSIGNED length = obj->Length();
            pMap[nObjects++] = obj;
            p += length;
        }
    }

    /* Start writing the information. */
    fprintf(exportFile, "Objects\t%lu\n", nObjects);
    fprintf(exportFile, "Root\t%lu\n", getIndex(rootFunction));


    // Generate each of the areas apart from the IO area.
    for (i = 0; i < memTableEntries; i++)
    {
        if (i != ioMemEntry) // Don't relocate the IO area
        {
            char *start = (char*)memTable[i].mtAddr;
            char *end = start + memTable[i].mtLength;
            for (PolyWord *p = (PolyWord*)start; p < (PolyWord*)end; )
            {
                p++;
                PolyObject *obj = (PolyObject*)p;
                POLYUNSIGNED length = obj->Length();
                printObject(obj);
                p += length;
            }
        }
    }

    fclose(exportFile); exportFile = NULL;
}
Exemplo n.º 21
0
int main() {
	Object* obj;

	initSymTab();

	obj = createProgramObject("PRG");
	enterBlock(obj->progAttrs->scope);

	obj = createConstantObject("c1");
	obj->constAttrs->value = makeIntConstant(10);
	declareObject(obj);

	obj = createConstantObject("c2");
	obj->constAttrs->value = makeCharConstant('a');
	declareObject(obj);

	obj = createTypeObject("t1");
	obj->typeAttrs->actualType = makeArrayType(10, makeIntType());
	declareObject(obj);

	obj = createVariableObject("v1");
	obj->varAttrs->type = makeIntType();
	declareObject(obj);

	obj = createVariableObject("v2");
	obj->varAttrs->type = makeArrayType(10, makeArrayType(10, makeIntType()));
	declareObject(obj);

	obj = createFunctionObject("f");
	obj->funcAttrs->returnType = makeIntType();
	declareObject(obj);

	enterBlock(obj->funcAttrs->scope);

	obj = createParameterObject("p1", PARAM_VALUE, symtab->currentScope->owner);
	obj->paramAttrs->type = makeIntType();
	declareObject(obj);

	obj = createParameterObject("p2", PARAM_REFERENCE, symtab->currentScope->owner);
	obj->paramAttrs->type = makeCharType();
	declareObject(obj);

	exitBlock();

	obj = createProcedureObject("p");
	declareObject(obj);

	enterBlock(obj->procAttrs->scope);

	obj = createParameterObject("v1", PARAM_VALUE, symtab->currentScope->owner);
	obj->paramAttrs->type = makeIntType();
	declareObject(obj);

	obj = createConstantObject("c1");
	obj->constAttrs->value = makeCharConstant('a');
	declareObject(obj);

	obj = createConstantObject("c3");
	obj->constAttrs->value = makeIntConstant(10);
	declareObject(obj);

	obj = createTypeObject("t1");
	obj->typeAttrs->actualType = makeIntType();
	declareObject(obj);

	obj = createTypeObject("t2");
	obj->typeAttrs->actualType = makeArrayType(10, makeIntType());
	declareObject(obj);

	obj = createVariableObject("v2");
	obj->varAttrs->type = makeArrayType(10, makeIntType());
	declareObject(obj);

	obj = createVariableObject("v3");
	obj->varAttrs->type = makeCharType();
	declareObject(obj);

	exitBlock();


	exitBlock();
	printObject(symtab->program, 0);
	cleanSymTab();

	return 0;
}
Exemplo n.º 22
0
REPC SEXP RsetField(SEXP ref, SEXP name, SEXP value) {
  jobject o = 0, otr;
  SEXP obj = ref;
  const char *fnam;
  sig_buffer_t sig;
  char *clnam = 0;
  jfieldID fid;
  jclass cls;
  jvalue jval;
  JNIEnv *env=getJNIEnv();

  if (TYPEOF(name)!=STRSXP && LENGTH(name)!=1)
    error("invalid field name");
  fnam = CHAR(STRING_ELT(name, 0));
  if (obj == R_NilValue) error("cannot set a field of a NULL object");
  if (IS_JOBJREF(obj))
    obj = GET_SLOT(obj, install("jobj"));
  if (TYPEOF(obj)==EXTPTRSXP) {
    jverify(obj);
    o=(jobject)EXTPTR_PTR(obj);
  } else if (TYPEOF(obj)==STRSXP && LENGTH(obj)==1)
    clnam = strdup(CHAR(STRING_ELT(obj, 0)));
  else
    error("invalid object parameter");
  if (!o && !clnam)
    error("cannot set a field of a NULL object");
#ifdef RJ_DEBUG
  if (o) {
    rjprintf("RsetField.object: "); printObject(env, o);
  } else {
    rjprintf("RsetField.class: %s\n", clnam);
  }
#endif
  if (o)
    cls = objectClass(env, o);
  else {
    char *c = clnam;
    while(*c) { if (*c=='/') *c='.'; c++; }
    cls = findClass(env, clnam);
    if (!cls) {
      error("cannot find class %s", CHAR(STRING_ELT(obj, 0)));
    }
  }
  if (!cls)
    error("cannot determine object class");
#ifdef RJ_DEBUG
  rjprintf("RsetField.class: "); printObject(env, cls);
#endif
  init_sigbuf(&sig);
  jval = R1par2jvalue(env, value, &sig, &otr);
  
  if (o) {
    fid = (*env)->GetFieldID(env, cls, fnam, sig.sig);
    if (!fid) {
      checkExceptionsX(env, 1);
      o = 0;
      fid = (*env)->GetStaticFieldID(env, cls, fnam, sig.sig);
    }
  } else
    fid = (*env)->GetStaticFieldID(env, cls, fnam, sig.sig);
  if (!fid) {
    checkExceptionsX(env, 1);
    releaseObject(env, cls);
    if (otr) releaseObject(env, otr);
    done_sigbuf(&sig);
    error("cannot find field %s with signature %s", fnam, sig.sigbuf);
  }
  switch(sig.sig[0]) {
  case 'Z':
    o?(*env)->SetBooleanField(env, o, fid, jval.z):
      (*env)->SetStaticBooleanField(env, cls, fid, jval.z);
    break;
  case 'C':
    o?(*env)->SetCharField(env, o, fid, jval.c):
      (*env)->SetStaticCharField(env, cls, fid, jval.c);
    break;
  case 'B':
    o?(*env)->SetByteField(env, o, fid, jval.b):
      (*env)->SetStaticByteField(env, cls, fid, jval.b);
    break;
  case 'I':
    o?(*env)->SetIntField(env, o, fid, jval.i):
      (*env)->SetStaticIntField(env, cls, fid, jval.i);
    break;
  case 'D':
    o?(*env)->SetDoubleField(env, o, fid, jval.d):
      (*env)->SetStaticDoubleField(env, cls, fid, jval.d);
    break;
  case 'F':
    o?(*env)->SetFloatField(env, o, fid, jval.f):
      (*env)->SetStaticFloatField(env, cls, fid, jval.f);
    break;
  case 'J':
    o?(*env)->SetLongField(env, o, fid, jval.j):
      (*env)->SetStaticLongField(env, cls, fid, jval.j);
    break;
  case 'S':
    o?(*env)->SetShortField(env, o, fid, jval.s):
      (*env)->SetStaticShortField(env, cls, fid, jval.s);
    break;
  case '[':
  case 'L':
    o?(*env)->SetObjectField(env, o, fid, jval.l):
      (*env)->SetStaticObjectField(env, cls, fid, jval.l);
    break;
  default:
    releaseObject(env, cls);
    if (otr) releaseObject(env, otr);
    done_sigbuf(&sig);
    error("unknown field sighanture %s", sig.sigbuf);
  }
  done_sigbuf(&sig);
  releaseObject(env, cls);
  if (otr) releaseObject(env, otr);
  return ref;
}
Exemplo n.º 23
0
/** get value of a field of an object or class
    object (int), return signature (string), field name (string)
    arrays and objects are returned as IDs (hence not evaluated)
    class name can be in either form / or .
*/
REPC SEXP RgetField(SEXP obj, SEXP sig, SEXP name, SEXP trueclass) {
  jobject o = 0;
  SEXP e;
  const char *retsig, *fnam;
  char *clnam = 0, *detsig = 0;
  jfieldID fid;
  jclass cls;
  int tc = asInteger(trueclass);
  JNIEnv *env=getJNIEnv();

  if (obj == R_NilValue) return R_NilValue;
  if ( IS_JOBJREF(obj) )
    obj = GET_SLOT(obj, install("jobj"));
  if (TYPEOF(obj)==EXTPTRSXP) {
    jverify(obj);
    o=(jobject)EXTPTR_PTR(obj);
  } else if (TYPEOF(obj)==STRSXP && LENGTH(obj)==1)
    clnam = strdup(CHAR(STRING_ELT(obj, 0)));
  else
    error("invalid object parameter");
  if (!o && !clnam)
    error("cannot access a field of a NULL object");
#ifdef RJ_DEBUG
  if (o) {
    rjprintf("RgetField.object: "); printObject(env, o);
  } else {
    rjprintf("RgetField.class: %s\n", clnam);
  }
#endif
  if (o)
    cls = objectClass(env, o);
  else {
    char *c = clnam;
    while(*c) { if (*c=='/') *c='.'; c++; }
    cls = findClass(env, clnam);
    free(clnam);
    if (!cls) {
      error("cannot find class %s", CHAR(STRING_ELT(obj, 0)));
    }
  }
  if (!cls)
    error("cannot determine object class");
#ifdef RJ_DEBUG
  rjprintf("RgetField.class: "); printObject(env, cls);
#endif
  if (TYPEOF(name)!=STRSXP || LENGTH(name)!=1) {
    releaseObject(env, cls);
    error("invalid field name");
  }
  fnam = CHAR(STRING_ELT(name,0));
  if (sig == R_NilValue) {
    retsig = detsig = findFieldSignature(env, cls, fnam);
    if (!retsig) {
      releaseObject(env, cls);
      error("unable to detect signature for field '%s'", fnam);
    }
  } else {
    if (TYPEOF(sig)!=STRSXP || LENGTH(sig)!=1) {
      releaseObject(env, cls);
      error("invalid signature parameter");
    }
    retsig = CHAR(STRING_ELT(sig,0));
  }
  _dbg(rjprintf("field %s signature is %s\n",fnam,retsig));
  
  if (o) { /* first try non-static fields */
    fid = (*env)->GetFieldID(env, cls, fnam, retsig);
    checkExceptionsX(env, 1);
    if (!fid) { /* if that fails, try static ones */
      o = 0;
      fid = (*env)->GetStaticFieldID(env, cls, fnam, retsig);
    }
  } else /* no choice if the object was a string */
    fid = (*env)->GetStaticFieldID(env, cls, fnam, retsig);

  if (!fid) {
    checkExceptionsX(env, 1);
    releaseObject(env, cls);
    if (detsig) free(detsig);
    error("RgetField: field %s not found", fnam);
  }
  switch (*retsig) {
  case 'I': {
    int r=o?
      (*env)->GetIntField(env, o, fid):
      (*env)->GetStaticIntField(env, cls, fid);
    e = allocVector(INTSXP, 1);
    INTEGER(e)[0] = r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'S': {
    jshort r=o?
      (*env)->GetShortField(env, o, fid):
      (*env)->GetStaticShortField(env, cls, fid);
    e = allocVector(INTSXP, 1);
    INTEGER(e)[0] = r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'C': {
    int r=(int) (o?
		 (*env)->GetCharField(env, o, fid):
		 (*env)->GetStaticCharField(env, cls, fid));
    e = allocVector(INTSXP, 1);
    INTEGER(e)[0] = r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'B': {
    int r=(int) (o?
		 (*env)->GetByteField(env, o, fid):
		 (*env)->GetStaticByteField(env, cls, fid));
    e = allocVector(INTSXP, 1);
    INTEGER(e)[0] = r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'J': {
    jlong r=o?
      (*env)->GetLongField(env, o, fid):
      (*env)->GetStaticLongField(env, cls, fid);
    e = allocVector(REALSXP, 1);
    REAL(e)[0] = (double)r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'Z': {
    jboolean r=o?
      (*env)->GetBooleanField(env, o, fid):
      (*env)->GetStaticBooleanField(env, cls, fid);
    e = allocVector(LGLSXP, 1);
    LOGICAL(e)[0] = r?1:0;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'D': {
    double r=o?
      (*env)->GetDoubleField(env, o, fid):
      (*env)->GetStaticDoubleField(env, cls, fid);
    e = allocVector(REALSXP, 1);
    REAL(e)[0] = r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'F': {
    double r = (double) (o?
      (*env)->GetFloatField(env, o, fid):
      (*env)->GetStaticFloatField(env, cls, fid));
    e = allocVector(REALSXP, 1);
    REAL(e)[0] = r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'L':
  case '[': {
    SEXP rv;
    jobject r = o?
      (*env)->GetObjectField(env, o, fid):
      (*env)->GetStaticObjectField(env, cls, fid);
    _mp(MEM_PROF_OUT("  %08x LNEW field value\n", (int) r))
    releaseObject(env, cls);
    if (tc) {
      if (detsig) free(detsig);
      return new_jobjRef(env, r, 0);
    }
    if (*retsig=='L') { /* need to fix the class name */      
      char *d = strdup(retsig), *c = d;
      while (*c) { if (*c==';') { *c=0; break; }; c++; }
      rv = new_jobjRef(env, r, d+1);
      free(d);
    } else
      rv = new_jobjRef(env, r, retsig);
    if (detsig) free(detsig);
    return rv;
  }
  } /* switch */
  releaseObject(env, cls);
  if (detsig) {
    free(detsig);
    error("unknown field signature");
  }
  error("unknown field signature '%s'", retsig);
  return R_NilValue;
}
Exemplo n.º 24
0
int
main(int argc, char **argv)
{
    CONDITION				cond;								/* Return value from DUL and ACR routines */
    DCM_OBJECT				* object;							/* Handle to the information object */
    DCM_ELEMENT				element;							/* Handle to the DCM_ELEMENT */
    IE_OBJECT				* ieObject;							/* Handle to the IE_OBJECT object */
    IE_INFORMATIONENTITY	* ieIE, *ie_node;					/* Handle to IE_INFORMATIONENTITY */
    LST_HEAD				* ie_head, *mod_head, *attr_head;	/* Handle to the LST_HEAD */
    IE_MODULE				* ieModule, *mod_node;				/* Handle to IE_MODULE */
    IE_ATTRIBUTE			* attr_node;						/* Handle to IE_ATTRIBUTE */
    CTNBOOLEAN				verbose = FALSE;					/* For debugging purpose */
    CTNBOOLEAN				flag;								/* Return value from findElement routine */
    unsigned long			options = DCM_ORDERLITTLEENDIAN;	/* Byte order in data streams */
    char					*file;								/* The image file name */
    char					UID[90];							/* The SOP Class UID of the image file */
    U32						length;								/* Length of the data field of DCM_ELEMENT */
    int						ie_loop, mod_loop, attr_loop, j, k, i;/* Iteration variables */


    while (--argc > 0 && (*++argv)[0] == '-') {
    	switch (*(argv[0] + 1)) {
			case 'v':
						verbose = TRUE;
						break;
			case 'b':
						options &= ~DCM_ORDERMASK;
						options |= DCM_ORDERBIGENDIAN;
						break;
			case 't':
						options &= ~DCM_FILEFORMATMASK;
						options |= DCM_PART10FILE;
						break;
			default:
						break;
    	}
    }

    if (argc < 1) usageerror();

    file = *argv;
    THR_Init();
    DCM_Debug(verbose);

    /* Open a DICOM object file and put the contents into the memory represented by the information object. */
    cond = DCM_OpenFile(file, options, &object);


    if (cond != DCM_NORMAL && ((options & DCM_PART10FILE) == 0)) {
    	COND_DumpConditions();
    	(void) DCM_CloseObject(&object);
    	(void) COND_PopCondition(TRUE);
    	fprintf(stderr, "Could not open %s as expected.  Trying Part 10 format.\n", file);
    	cond = DCM_OpenFile(file, options | DCM_PART10FILE, &object);
    }

    if (cond != DCM_NORMAL) {
     	COND_DumpConditions();
     	THR_Shutdown();
     	return 1;
    }else{
    	printf("file is successfully opened!\n");
    	/* Call IE_ExamineObject to examine this DCM object. */
    	cond = IE_ExamineObject(&object, &ieObject);
    	if (cond == IE_ILLEGALDCMOBJECT || cond == IE_LISTFAILURE || cond == IE_MALLOCFAILURE){
    		COND_DumpConditions();
    	}else{
    		/* Print the IE_OBJECT object.  */
    		strcpy(UID, ieObject->classUID);
    		printObject(ieObject);

    		/* Examine each IE on the list.  */
    		ie_head = ieObject->ieList;
    		ie_loop = LST_Count(&ie_head);

    		for (i = 0; i < ie_loop; i++) {
    			ie_node = LST_Pop(&ie_head);
    			cond = IE_ExamineInformationEntity(&object, ie_node->ieType, &ieIE);

    			/* Print each IE_IE. */
    			printIE(ieIE);

    			/* Examine each module on the list. */
    			mod_head = ieIE->moduleList;
    			mod_loop = LST_Count(&mod_head);

    			for (k = 0; k < mod_loop; k++) {
    				mod_node = LST_Pop(&mod_head);
    				cond = IE_ExamineModule(&object, ieIE->ieType, mod_node->moduleType, &ieModule);
    				printModule(ieModule);

    				/* Print each IE_ATTRIBUTE.  */
    				attr_head = ieModule->attributeList;
    				attr_loop = LST_Count(&attr_head);

    				for (j = 0; j < attr_loop; j++) {
    					attr_node = LST_Pop(&attr_head);
    					printIEAttribute(attr_node);
    					free(attr_node);
    				}
    				free(mod_node);

    				cond = IE_Free((void **) &ieModule);
    			}
    			free(ie_node);

    			cond = IE_Free((void **) &ieIE);
    		}
    		cond = IE_Free((void **) &ieObject);

	    /* Check to see the status of the Information Entities. */
	    cond = IE_ExamineObject(&object, &ieObject);
	    printf("\n%s requirements:\n", ieObject->objectDescription);
	    ie_head = ieObject->ieList;
	    ie_loop = LST_Count(&ie_head);

	    for (i = 0; i < ie_loop; i++) {
	    	ie_node = LST_Pop(&ie_head);
	    	if (ie_node->requirement == IE_K_REQUIRED) printIE(ie_node);
	    	free(ie_node);
	    }

	    cond = IE_Free((void **) &ieObject);

	    /* Check to see the status of the Information Entity and status of the Modules within them. */
	    cond = IE_ExamineObject(&object, &ieObject);
	    printf("\n%s requirements:\n", ieObject->objectDescription);
	    ie_head = ieObject->ieList;
	    ie_loop = LST_Count(&ie_head);

	    for (i = 0; i < ie_loop; i++) {
	    	ie_node = LST_Pop(&ie_head);
	    	cond = IE_ExamineInformationEntity(&object, ie_node->ieType, &ieIE);
	    	if (ie_node->requirement == IE_K_REQUIRED) {
	    		printf("\n");
	    		printIE(ieIE);
	    		mod_head = ieIE->moduleList;
	    		mod_loop = LST_Count(&mod_head);

	    		for (k = 0; k < mod_loop; k++) {
	    			mod_node = LST_Pop(&mod_head);
	    			if (mod_node->requirement == IE_K_REQUIRED) printModule(mod_node);
	    			free(mod_node);
	    		}
	    	}
	    	free(ie_node);
	    	cond = IE_Free((void **) &ieIE);
	    }
	    cond = IE_Free((void **) &ieObject);

	    /* Check to see the missing attributes if there is any. */
	    cond = IE_ObjectRequirements(UID, &ieObject);
	    printf("\n  Missing required(type1 and type2) attributes: \n");
	    ie_head = ieObject->ieList;
	    ie_loop = LST_Count(&ie_head);

	    for (i = 0; i < ie_loop; i++) {
	    	ie_node = LST_Pop(&ie_head);
	    	cond = IE_IERequirements(UID, ie_node->ieType, &ieIE);
	    	mod_head = ieIE->moduleList;
	    	mod_loop = LST_Count(&mod_head);

	    	for (k = 0; k < mod_loop; k++) {
	    		mod_node = LST_Pop(&mod_head);
	    		cond = IE_ModuleRequirements(UID, ie_node->ieType, mod_node->moduleType, &ieModule);
	    		printf("  %s\n", ieModule->moduleDescription);
	    		attr_head = ieModule->attributeList;
	    		attr_loop = LST_Count(&attr_head);

	    		for (j = 0; j < attr_loop; j++) {
	    			attr_node = LST_Pop(&attr_head);
	    			flag = findElement(object, attr_node->element.tag, &element);
	    			cond = DCM_LookupElement(&element);
	    			if (cond != DCM_NORMAL) cond = COND_PopCondition(FALSE);

	    			if (!flag) {
	    				if (attr_node->requirement == IE_K_TYPE1){
	    					printf("    %08x, %s\n", element.tag, element.description);
	    				}else if (attr_node->requirement == IE_K_TYPE2){
	    					cond = DCM_GetElementSize(&object, attr_node->element.tag, &length);
	    					if (cond != DCM_NORMAL){
	    						cond = COND_PopCondition(FALSE);
	    						printf("    %08x, %s\n", element.tag, element.description);
	    					}
	    				}
	    			}
	    		}		/* finish one module */
	    		free(mod_node);
	    		cond = IE_Free((void **) &ieModule);
	    	}
	    	free(ie_node);
	    	cond = IE_Free((void **) &ieIE);
	    }
	    cond = IE_Free((void **) &ieObject);
    	}
    }

    /* Free the memory and remove the object handle. */
    cond = DCM_CloseObject(&object);
    if (cond != DCM_NORMAL){
    	COND_DumpConditions();
    }else{
    	printf("The object  is closed successfully.\n");
    }
    THR_Shutdown();
    return 0;
}
Exemplo n.º 25
0
/**********************************************************************
* Public Methods
**********************************************************************/
void printAssertions(NB_Link *link){
  while(link!=NULL){
    printObject(link->object);
    if((link=link->next)!=NULL) outPut(",");
    }
  }