Exemplo n.º 1
0
Arquivo: sl.c Projeto: bitemyapp/j
A jtstcreate(J jt,C k,I p,I n,C*u){A g,*pv,x,y;C s[20];I m,*nv;L*v;
 GA(g,SYMB,ptab[p],1,0); 
 RZ(v=symnew(AV(g))); v->flag|=LINFO; v->sn=jt->symindex++;
 switch(k){
  case 0:  /* named    locale */
   RZ(x=nfs(n,u));
   LOCNAME(g)=x; LOCPATH(g)=ra(1==n&&'z'==*u?vec(BOX,0L,0L):zpath);
   symbis(x,g,jt->stloc);
   break;
  case 1:  /* numbered locale */
   ASSERT(0<=jt->stmax,EVLOCALE);
   sprintf(s,FMTI,n); RZ(x=nfs(strlen(s),s));
   LOCNAME(g)=x; LOCPATH(g)=ra(zpath);
   ++jt->stused;
   m=AN(jt->stnum);
   if(m<jt->stused){
    x=ext(1,jt->stnum); y=ext(1,jt->stptr); RZ(x&&y); jt->stnum=x; jt->stptr=y;
    nv=m+AV(jt->stnum); pv=m+AAV(jt->stptr); DO(AN(x)-m, *nv++=-1; *pv++=0;); 
   }
Exemplo n.º 2
0
struct sym *
symadd(struct idl *idl,
		const char *idl_type,
		const char *out_type,
		const char *ndr_type,
		size_t ndr_size)
{
	struct sym *sym;

	if (idl == NULL || idl_type == NULL || *idl_type == '\0') {
		PMNO(EINVAL);
		return NULL;
	}

	if ((sym = symnew(idl->al)) == NULL) {
		AMSG("");
		return NULL;
	}

	sym->idl_type = dupstr(idl_type, idl->al);

	if (out_type) {
		sym->out_type = dupstr(out_type, idl->al);
	}
	if (ndr_type) {
		sym->ndr_type = dupstr(ndr_type, idl->al);
	}
	sym->ndr_size = ndr_size;

	if (hashmap_put(idl->syms, (void *)sym->idl_type, sym) == -1) {
		AMSG("");
		return NULL;
	}

	return sym;
}
Exemplo n.º 3
0
int
symexpand(struct idl *idl, struct sym *sym)
{
	char *key;
	struct sym *mem;
	iter_t iter;

	if (IS_EXPANDED(sym)) {
		return 0;
	}
	sym->flags |= FLAGS_EXPANDED;
	sym->orig = sym;

	if (IS_INTERFACE(sym)) {
		const char *pd = hashmap_get(&sym->attrs, "pointer_default");
		idl->ptr_default = PTR_TYPE_UNIQUE;
		if (pd) {
			if (strcmp(pd, "ptr") == 0) {
				idl->ptr_default = PTR_TYPE_PTR;
			} else if (strcmp(pd, "ref") == 0) {
				idl->ptr_default = PTR_TYPE_REF;
			}
		}
	} else if (IS_ENUM(sym)) {
		char buf[16];
		int val = 0;

		linkedlist_iterate(&sym->mems, &iter);
		while ((mem = linkedlist_next(&sym->mems, &iter))) {
			mem->flags = FLAGS_CONST | FLAGS_PRIMATIVE;
			if (mem->value) {
				val = strtoul(mem->value, NULL, 0);
			}
			sprintf(buf, "%d", val++);
			mem->value = dupstr(buf, idl->al);
		}
	} else if (sym->ptr) {
		if (hashmap_get(&sym->attrs, "unique")) {
			sym->ptr_type = PTR_TYPE_UNIQUE;
		} else if (hashmap_get(&sym->attrs, "ptr")) {
			sym->ptr_type = PTR_TYPE_PTR;
		} else if (hashmap_get(&sym->attrs, "ref")) {
			sym->ptr_type = PTR_TYPE_REF;
		} else if (IS_PARAMETER(sym) || IS_OPERATION(sym)) {
			sym->ptr_type = PTR_TYPE_REF;
		} else {
			sym->ptr_type = idl->ptr_default;
		}
	}

	/* If the symbol is typedef'd add it to the table using the
	 * typedef'd name too
	 */
	if (IS_TYPEDEFD(sym) && sym->name) {
		if (IS_ENUM(sym) && (mem = hashmap_get(idl->syms, sym->idl_type))) {
			mem->noemit = 1; /* supress redundant enum */
		}
		key = sym->name;
	} else {
		key = sym->idl_type;
	}
	if (hashmap_get(idl->syms, key) == NULL) {
		if (hashmap_put(idl->syms, key, sym) == -1) {
			AMSG("");
		}
	}

	/* If the symbol has members it is already expanded
	 */
	if (linkedlist_size(&sym->mems) == 0) {
		struct sym *s = symlook(idl, sym->idl_type);
		if (s) {
			sym->interface = s->interface;
			linkedlist_iterate(&s->mems, &iter);
			while ((mem = linkedlist_next(&s->mems, &iter))) {
				struct sym *cpy = symnew(idl->al);
				symcopy(mem, cpy, idl->al);
				linkedlist_add(&sym->mems, cpy);
			}
		} else {
			AMSG("");
			return -1;
		}
	}

	sym->id = idl->symid++;

	/* Perform expansion recursively on all symbols
	 */
	linkedlist_iterate(&sym->mems, &iter);
	while ((mem = linkedlist_next(&sym->mems, &iter))) {
		symexpand(idl, mem);
		mem->parent = sym;
	}

	return 0;
}