static PT_Tree createLayoutTree(int indent, PT_Tree layout) { int i,j,k; int len = PT_getTreeLength(layout); char *str = PT_yieldTree(layout); PT_Tree result = NULL; /* after every new line a amount of 'indent' spaces should be inserted */ for (i=0, j=0; i < len; i++, j++) { assert(j < MAX_LAYOUT_LENGTH && "Maximum length of layout exceeded"); layout_buffer[j] = str[i]; if (str[i] == '\n') { for(k=0; k < indent; k++) { layout_buffer[++j] = DEFAULT_LAYOUT_CHARACTER; } } } layout_buffer[j] = '\0'; result = PT_makeTreeLayoutFromString(layout_buffer); return result; }
ATerm get_module_id(int cid, ATerm atModule) { SDF_Start start = SDF_StartFromTerm(ATBunpack(atModule)); SDF_Module module = SDF_getStartTopModule(start); SDF_ModuleId id = SDF_getModuleName(module); return ATmake("snd-value(module-id(<str>))", PT_yieldTree((PT_Tree) id)); }
static int calcIndentationLevel(int indent, PT_Tree layout) { int i; int len = PT_getTreeLength(layout); char *str = PT_yieldTree(layout); for (i=len; i >= 0 && str[i] != '\n'; i--); return indent + (len - i) - 1; }
ATbool ASF_isTagDefault(ASF_ASFTag tag) { if (ASF_isASFTagNotEmpty(tag)) { ASF_ASFTagId tagId = ASF_getASFTagASFTagId(tag); ATbool result; const char *lex = PT_yieldTree((PT_Tree)tagId); result = streqn(lex, DEFAULT_TAG_PREFIX, strlen(DEFAULT_TAG_PREFIX)) || streq(lex, DEFAULT_TAG); return result; } return ATfalse; }
static PT_Attr SDFAttributeToPtAttr(SDF_Attribute sdfAttribute) { PT_Attr ptAttr = NULL; if (SDF_isAttributeBracket(sdfAttribute)) { ptAttr = PT_makeAttrBracket(); } else if (SDF_isAttributeReject(sdfAttribute)) { ptAttr = PT_makeAttrReject(); } else if (SDF_isAttributePrefer(sdfAttribute)) { ptAttr = PT_makeAttrPrefer(); } else if (SDF_isAttributeAvoid(sdfAttribute)) { ptAttr = PT_makeAttrAvoid(); } else if (SDF_isAttributeId(sdfAttribute)) { SDF_ModuleName sdfModuleName = SDF_getAttributeModuleName(sdfAttribute); SDF_ModuleId sdfModuleId = SDF_getModuleNameModuleId(sdfModuleName); char *str = PT_yieldTree((PT_Tree) sdfModuleId); ptAttr = PT_makeAttrId(str); } else if (SDF_isAttributeAssoc(sdfAttribute)) { SDF_Associativity sdfAssoc = SDF_getAttributeAssociativity(sdfAttribute); PT_Associativity ptAssoc = NULL; if (SDF_isAssociativityLeft(sdfAssoc)) { ptAssoc = PT_makeAssociativityLeft(); } else if (SDF_isAssociativityRight(sdfAssoc)) { ptAssoc = PT_makeAssociativityRight(); } else if (SDF_isAssociativityNonAssoc(sdfAssoc)) { ptAssoc = PT_makeAssociativityNonAssoc(); } else if (SDF_isAssociativityAssoc(sdfAssoc)) { ptAssoc = PT_makeAssociativityAssoc(); } ptAttr = PT_makeAttrAssoc(ptAssoc); } else if (SDF_isAttributeId(sdfAttribute)) { char *moduleName = PT_yieldTreeToString((PT_Tree) sdfAttribute, ATfalse); ptAttr = PT_makeAttrId(moduleName); } else if (SDF_isAttributeTerm(sdfAttribute)) { ATerm term = ATmake(PT_yieldTreeToString((PT_Tree) sdfAttribute, ATfalse)); if (term == NULL) { ATerror("SDFAttributeToPtAttr (term): unable to convert %s\n", PT_yieldTreeToString((PT_Tree) sdfAttribute, ATfalse)); ptAttr = NULL; } else { ptAttr = PT_makeAttrTerm(term); } } else { ATerror("SDFAttributeToPtAttr: unable to convert %s\n", PT_yieldTreeToString((PT_Tree) sdfAttribute, ATfalse)); ptAttr = NULL; } return ptAttr; }