Index: trunk/src/libcschem/abstract.c =================================================================== --- trunk/src/libcschem/abstract.c (revision 3332) +++ trunk/src/libcschem/abstract.c (revision 3333) @@ -155,14 +155,23 @@ { csch_aport_t *port; - port = htsp_get(&comp->ports, name); - if ((port != NULL) || (!alloc)) - return port; + if (comp != NULL) { + port = htsp_get(&comp->ports, name); + if ((port != NULL) || (!alloc)) + return port; + } + else { + TODO("hierarchic: we probably need a per sheet hash of terminals"); + } port = calloc(sizeof(csch_aport_t), 1); csch_aobj_init(abs, &port->hdr, CSCH_ATYPE_PORT); port->name = rnd_strdup(name); - htsp_set(&comp->ports, port->name, port); + + if (comp != NULL) + htsp_set(&comp->ports, port->name, port); + else + TODO("hierarchic: we probably need a per sheet hash of terminals"); return port; } Index: trunk/src/libcschem/compile.c =================================================================== --- trunk/src/libcschem/compile.c (revision 3332) +++ trunk/src/libcschem/compile.c (revision 3333) @@ -96,50 +96,15 @@ return compile_attributes(&net->hdr, &src->hdr.attr); } -static int compile_symbol(csch_abstract_t *dst, const csch_sheet_t *sheet, csch_cgrp_t *src) +static csch_aport_t *compile_port(csch_abstract_t *dst, const csch_sheet_t *sheet, csch_acomp_t *comp, csch_cgrp_t *t) { char tmpname[128]; - htip_entry_t *e; - const char *name, *pname_tmp; - const csch_attrib_t *aname = NULL; - csch_acomp_t *comp; - int res = 0; - - if (src->hdr.type == CSCH_CTYPE_GRP_REF) - aname = csch_cgrp_ref_get_attr(src, "name"); - else - aname = csch_attrib_get(&src->hdr.attr, "name"); - - dst->ucnt.comp++; - if ((aname == NULL) || (aname->key == NULL) || (*aname->key == '\0')) { - sprintf(tmpname, "anon_comp_%ld", dst->ucnt.comp); - name = tmpname; - } - else - name = aname->val; - - comp = csch_acomp_get(dst, name, 1); - if (comp == NULL) - return -1; - - compile_add_source(src, &comp->hdr); - - res |= compile_attributes(&comp->hdr, &src->hdr.attr); - if ((src->hdr.type == CSCH_CTYPE_GRP_REF) && (src->data.ref.grp != NULL)) - res |= compile_attributes(&comp->hdr, &src->data.ref.grp->hdr.attr); - - csch_eng_call(sheet->parent, CSCH_ENGHK_SYMBOL_JOINED_COMPONENT, - FGW_COBJ, src, FGW_AOBJ, comp, FGW_INVALID); - - /* compile ports */ - for(e = htip_first(&src->id2obj); e != NULL; e = htip_next(&src->id2obj, e)) { - csch_cgrp_t *t = e->value; const csch_attrib_t *trole, *tname; - const char *pname; - csch_aport_t *port; + const char *pname, *pname_tmp; + csch_aport_t *port = NULL; if ((t->hdr.type != CSCH_CTYPE_GRP) && (t->hdr.type != CSCH_CTYPE_GRP_REF)) - continue; + return NULL; if (t->hdr.type == CSCH_CTYPE_GRP_REF) trole = csch_cgrp_ref_get_attr(t, "role"); @@ -146,7 +111,7 @@ else trole = csch_attrib_get(&t->hdr.attr, "role"); if ((trole == NULL) || (trole->val == NULL) || (strcmp(trole->val, "terminal") != 0)) - continue; + return NULL; if (t->hdr.type == CSCH_CTYPE_GRP_REF) tname = csch_cgrp_ref_get_attr(t, "name"); @@ -173,7 +138,48 @@ compile_add_source(t, &port->hdr); csch_eng_free_strmod(&pname_tmp, pname); + + return port; +} + +static int compile_symbol(csch_abstract_t *dst, const csch_sheet_t *sheet, csch_cgrp_t *src) +{ + char tmpname[128]; + htip_entry_t *e; + const char *name; + const csch_attrib_t *aname = NULL; + csch_acomp_t *comp; + int res = 0; + + if (src->hdr.type == CSCH_CTYPE_GRP_REF) + aname = csch_cgrp_ref_get_attr(src, "name"); + else + aname = csch_attrib_get(&src->hdr.attr, "name"); + + dst->ucnt.comp++; + if ((aname == NULL) || (aname->key == NULL) || (*aname->key == '\0')) { + sprintf(tmpname, "anon_comp_%ld", dst->ucnt.comp); + name = tmpname; } + else + name = aname->val; + + comp = csch_acomp_get(dst, name, 1); + if (comp == NULL) + return -1; + + compile_add_source(src, &comp->hdr); + + res |= compile_attributes(&comp->hdr, &src->hdr.attr); + if ((src->hdr.type == CSCH_CTYPE_GRP_REF) && (src->data.ref.grp != NULL)) + res |= compile_attributes(&comp->hdr, &src->data.ref.grp->hdr.attr); + + csch_eng_call(sheet->parent, CSCH_ENGHK_SYMBOL_JOINED_COMPONENT, + FGW_COBJ, src, FGW_AOBJ, comp, FGW_INVALID); + + /* compile ports */ + for(e = htip_first(&src->id2obj); e != NULL; e = htip_next(&src->id2obj, e)) + compile_port(dst, sheet, comp, e->value); return res; } @@ -327,12 +333,19 @@ case CSCH_ROLE_WIRE_NET: res |= compile_wire_net(dst, src, grp); break; case CSCH_ROLE_SYMBOL: res |= compile_symbol(dst, src, grp); break; + case CSCH_ROLE_TERMINAL: + { + csch_aport_t *aport = compile_port(dst, src, NULL, grp); + TODO("hierarchic: this probably won't connect sheet port to nets; maybe we should remember sheet ports in a hash separately?"); + csch_eng_call(src->parent, CSCH_ENGHK_COMPILE_PORT, FGW_AOBJ, aport, FGW_INVALID); + } + break; + case CSCH_ROLE_invalid: case CSCH_ROLE_empty: case CSCH_ROLE_BUS_NET: case CSCH_ROLE_BUS_TERMINAL: case CSCH_ROLE_HUB_POINT: - case CSCH_ROLE_TERMINAL: case CSCH_ROLE_JUNCTION: break; }