home *** CD-ROM | disk | FTP | other *** search
- /*
- * @(#)writeAT.c 1.5 7/1/87
- */
- #include "assert.h"
- #include "nodes.h"
- #include "sequence.h"
- #include "system.h"
- #include "builtins.h"
-
- static char *vlbBuffer = NULL;
- static int vlbBufferLength;
- static char *addPoint;
- static Boolean doExpand = FALSE;
- static Boolean doTypesOK = FALSE;
-
- void vlbStart()
- {
- vlbBufferLength = 100;
- vlbBuffer = malloc((unsigned)vlbBufferLength);
- addPoint = vlbBuffer;
- }
-
- void vlbAppend(s)
- char *s;
- {
- register int length = strlen(s);
- if (length + addPoint >= vlbBuffer + vlbBufferLength) {
- char *nb;
- vlbBufferLength *= 2;
- nb = malloc((unsigned)vlbBufferLength);
- strcpy(nb, vlbBuffer);
- addPoint = nb + (addPoint - vlbBuffer);
- free(vlbBuffer);
- vlbBuffer = nb;
- }
- strcpy(addPoint, s);
- addPoint += length;
- }
-
- char *vlbDone()
- {
- return(vlbBuffer);
- }
-
- static NodePtr me = NULL;
-
- Boolean isMe(p)
- NodePtr p;
- {
- return(p == me);
- }
-
- Boolean writeOID(id)
- OID id;
- {
- char buf[12];
- if (id == 0) return(FALSE);
- sprintf(buf, "O%08x", id);
- vlbAppend(buf);
- return(TRUE);
- }
-
- extern OID getID();
- extern NodePtr
- findManifestValue(),
- figureOutAT();
-
- static Boolean writeParams(p, doingResults)
- register NodePtr p;
- Boolean doingResults;
- {
- register NodePtr q, r, t;
- OID id;
- vlbAppend("[");
- Sequence_For(q, p)
- assert(q->tag == P_PARAM);
- r = q->b.param.sym->b.symdef.symbol->value.ATinfo;
- if (r == NN) {
- /*
- * We may not have assigned types yet, so look at the type expression.
- */
- r = findManifestValue(q->b.param.type);
- if (r != NN) {
- r = figureOutAT(r);
- }
- if (r == NN) {
- /*
- * We have something that is not a type here. Just write garbage
- * and return false.
- */
- vlbAppend("JUNK");
- return(FALSE);
- }
- }
- if (! doExpand && isMe(r)) {
- vlbAppend("S");
- } else {
- t = GETVALUE(r);
- assert(t->tag == P_ATLIT);
- if (t->b.atlit.f.dependsOnTypeVariable) {
- if (!doTypesOK) return(FALSE);
- if (doingResults) {
- id = OIDOfBuiltin(B_INSTAT, NILINDEX);
- } else {
- id = OIDOfBuiltin(B_INSTAT, ANYINDEX);
- }
- } else {
- id = t->b.atlit.id;
- }
- if (!writeOID(id)) return(FALSE);
- }
- if (z__z < p->nChildren-1) vlbAppend(",");
- Sequence_Next
- vlbAppend("]");
- return(TRUE);
- }
-
- static Boolean writeOp(p)
- NodePtr p;
- {
- assert(p->tag == P_OPSIG);
- /* assert(p->b.opsig.where == NULL); */
- vlbAppend(p->b.opsig.isFunction ? "F" : "O");
- if (!writeOID(p->b.opsig.name->b.opname.id)) return(FALSE);
- if (!writeParams(p->b.opsig.params, FALSE)) return(FALSE);
- vlbAppend("->");
- if (!writeParams(p->b.opsig.results, TRUE)) return(FALSE);
- return(TRUE);
- }
-
- char *writeAT(p, expand, typesOK)
- register NodePtr p;
- Boolean expand, typesOK;
- {
- register NodePtr q;
- assert(! p->b.atlit.f.isTypeVariable);
- assert(! p->b.atlit.f.dependsOnTypeVariable);
- assert(p->b.atlit.f.isManifest);
- doExpand = expand;
- doTypesOK = typesOK;
- me = p;
- vlbStart();
- vlbAppend(p->b.atlit.f.cannotBeConformedTo ? "Y" : "N");
- vlbAppend(p->b.atlit.f.isVector ? "Y" : "N");
- vlbAppend(p->b.atlit.f.immutable ? "Y" : "N");
- Sequence_For(q, p->b.atlit.ops)
- if (!writeOp(q)) {
- return(NULL);
- }
- Sequence_Next
- vlbAppend("\n");
- return(vlbDone());
- }
-