示例#1
0
int BrowOperands(Tcl_Interp *interp, struct Instance *i)
{
  struct gl_list_t *ol;
  struct Instance *p;
  unsigned long c,len;
  char *name;

  if (i == NULL) {
    return TCL_OK;
  }
  ol = GetInstanceOperands(i);
  if (ol == NULL) {
    return TCL_OK;
  }
  len = gl_length(ol);
  p = FirstModelUpward(i);
  for (c=1;c <= len; c++) {
    i = gl_fetch(ol,c);
    if (i == NULL) {
      continue;
    }
    name = WriteInstanceNameString(i,p);
    if (name == NULL) {
      continue;
    }
    Tcl_AppendElement(interp,name);
    ascfree(name);
  }
  gl_destroy(ol);

  return TCL_OK;
}
示例#2
0
void EmptyTrash(void)
{
  register unsigned c;
  register unsigned long i,len;
  register struct DumpRec *p,*next;
  register struct gl_list_t *l;
  if (g_dump_inst_count==0) return;
  for(c=0;c<DUMPHASHSIZE;c++) {
    p = g_dump_ht[c];
    g_dump_ht[c]=NULL;
    while (p!=NULL) {
      AssertAllocatedMemory(p,sizeof(struct DumpRec));
      next = p->next;
      if ((l=p->instances)!=NULL) {
	len = gl_length(l);
	for(i=1;i<=len;i++)
	  DestroyInstance((struct Instance *)gl_fetch(l,i),NULL);
	gl_destroy(l);
      }
      ascfree((char *)p);
      p = next;
    }
  }
  g_dump_type_count = 0;
  g_dump_inst_count = 0;
}
示例#3
0
static
void DestroyPANList(struct gl_list_t **gl)
{
	gl_iterate(*gl,(IterateFunc)DestroyPANAndName);
	gl_destroy(*gl);
	*gl = NULL;
}
示例#4
0
struct Instance *FindInstance(symchar *str)
{
  register struct DumpRec *p,*prev;
  register int cmp;
  register struct gl_list_t *l;
  register struct Instance *result;
  register unsigned long bucket;
  if (*(SCP(str)) == '\0') return NULL;
  bucket = DUMPHASHINDEX(SCP(str));
  if ((p = g_dump_ht[bucket])==NULL) return NULL;
  if ((cmp=CmpSymchar(p->type,str)) > 0) return NULL;
  else {
    if (cmp==0) {
      l = p->instances;
      result = (struct Instance *)gl_fetch(l,gl_length(l));
      gl_delete(l,gl_length(l),0);
      g_dump_inst_count--;
      if (gl_length(l)==0) {
	gl_destroy(l);
	g_dump_ht[bucket] = p->next;
	g_dump_type_count--;
	ascfree((char *)p);
      }
    }
    else {
      prev = p;
      if ((p = p->next)==NULL) return NULL;
      while((cmp=CmpSymchar(p->type,str))<0) {
	prev = p;
	if ((p=p->next)==NULL) return NULL;
      }
      if (cmp!=0) return NULL;
      /* pick out instance */
      l = p->instances;
      result = (struct Instance *)gl_fetch(l,gl_length(l));
      gl_delete(l,gl_length(l),0);
      g_dump_inst_count--;
      if (gl_length(l)==0) {
	gl_destroy(l);
	prev->next = p->next;
	g_dump_type_count--;
	ascfree((char *)p);
      }
    }
    return result;
  }
}
示例#5
0
void DestroyStatementList(struct StatementList *sl)
{
  register unsigned long c,len;
  if (sl == NULL) return;
  assert(sl->ref_count!=0);
  if (sl->ref_count < MAXREFCOUNT) sl->ref_count--;
  if (sl->ref_count==0) {
    len = gl_length(sl->l);
    for(c=1;c<=len;c++)
      DestroyStatement((struct Statement *)gl_fetch(sl->l,c));
    gl_destroy(sl->l);
    ascfree((char *)sl);
  }
}
示例#6
0
int main()
{
    gl_read();
    gl_write();
    __VERIFIER_plot(NULL);

    gl_sort();
    gl_write();
    __VERIFIER_plot(NULL);

    gl_destroy();
    __VERIFIER_plot(NULL);

    return 0;
}
示例#7
0
void DestroyCase(struct Case *c)
{
  register struct Set *set;
  set = c->ValueList;
  if (c!=NULL){
      if (c->ValueList) {
	if (set->next== NULL) {
	  DestroySetNodeByReference(c->ValueList);
        }
	else {
	  DestroySetListByReference(c->ValueList);
	}
      }
      gl_destroy(c->ref);
      c->active = 0;
      ascfree((char *)c);
  }
}
示例#8
0
void TrashType(symchar *str)
{
  register unsigned long c,len,bucket;
  register struct DumpRec *p,*prev;
  register struct gl_list_t *l;
  register int cmp;
  assert(AscFindSymbol(str)!=NULL);
  if (*(SCP(str)) == '\0') return;
  bucket = DUMPHASHINDEX(SCP(str));
  if ((p = g_dump_ht[bucket])==NULL) return;
  cmp = CmpSymchar(p->type,str);
  if (cmp == 0)
    g_dump_ht[bucket] = p->next;
  else
    if (cmp > 0) return;
    else {
      prev = p;
      if ((p = p->next)==NULL) return;
      while((cmp=CmpSymchar(p->type,str))<0) {
	prev = p;
	if ((p=p->next)==NULL) return;
      }
      if (cmp!=0) return;
      /* remove from linked list */
      prev->next = p->next;
    }
  if ((l=p->instances)!=NULL) {
    len = gl_length(l);
    for(c=1;c<=len;c++)
      DestroyInstance((struct Instance *)gl_fetch(l,c),NULL);
    gl_destroy(l);
    g_dump_inst_count -= len;
  }
  g_dump_type_count--;
  ascfree((char *)p);
}
示例#9
0
/*
 * Write a list of when statements to the Tcl interpreter
 */
int Asc_BrowWriteWhenListCmd(ClientData cdata, Tcl_Interp *interp,
                          int argc, CONST84 char *argv[])
{
  struct Instance *i, *when_inst;
  unsigned long len, c;
  int save=0;
  unsigned long nwhens;

  UNUSED_PARAMETER(cdata);

  if (( argc < 2 )||( argc > 3 )) {
    Tcl_AppendResult(interp,"wrong # args : ",
                     "Usage \"bgetwhens\" ?cur?search? save",(char *)NULL);
    return TCL_ERROR;
  }

  if (strncmp(argv[1],"current",3)==0) {
    i = g_curinst;
  } else {
    if (strncmp(argv[1],"search",3)==0) {
      i = g_search_inst;
    } else {
      Tcl_SetResult(interp, "invalid args to \"bgetwhens\"", TCL_STATIC);
      return TCL_ERROR;
    }
  }

  if ( argc == 3 ) {
    if (strncmp(argv[2],"save",4)==0) {
      save = 1;
    }
  }

  if (!i) {
    return TCL_ERROR;
  }

  if (!g_brow_whenlist) {
    g_brow_whenlist = gl_create(40L);
  }

  VisitInstanceTree(i,BrowGetWhens,0,0);
  len = gl_length(g_brow_whenlist);

  /* Writing the WHENs in the model, array or WHEN itself */
  if (len) {
    Tcl_AppendResult(interp,
                     "{WHENs in this Instance: } ",
                     (char *)NULL);
  }
  for (c=1;c<=len;c++) {
    char *tmp;
    when_inst = (struct Instance *)gl_fetch(g_brow_whenlist,c);
    Tcl_AppendResult(interp,"{",(char *)NULL);
    tmp = WriteWhenString(when_inst,NULL);
    Tcl_AppendResult(interp,tmp,(char *)NULL);
    ascfree(tmp);
    Tcl_AppendResult(interp,"} ",(char *)NULL);
  }

  /* Writing the WHEN which include such MODEL or WHEN(nesting) */

  switch (InstanceKind(i)) {
    case MODEL_INST:
    case WHEN_INST:
      nwhens = WhensCount(i);
      if (nwhens) {
        Tcl_AppendResult(interp,
                         "{This Instance is used in CASEs OF: } ",
                         (char *)NULL);
        for (c=1;c<=nwhens;c++) {
          char *tmp;
          when_inst = WhensForInstance(i,c);
          Tcl_AppendResult(interp,"{",(char *)NULL);
          tmp = WriteWhenString(when_inst,NULL);
          Tcl_AppendResult(interp,tmp,(char *)NULL);
          ascfree(tmp);
          Tcl_AppendResult(interp,"} ",(char *)NULL);
        }
      }
      break;
    case ARRAY_INT_INST:
    case ARRAY_ENUM_INST:
      break;
    default:
      Tcl_AppendResult(interp,"Inappropriate instance called",
                              "in BrowWriteWhenList",(char *)NULL);
      return TCL_ERROR;
  }

  if (!save) {
    gl_destroy(g_brow_whenlist);
    g_brow_whenlist=NULL;
  }

  return TCL_OK;
}