local void testSymeAddCondition() { String B_imp = "import from Boolean"; String C_txt = "C: Category == with"; String D1_txt = "D1: with == add"; String D2_txt = "D2: with == add"; StringList lines = listList(String)(4, B_imp, C_txt, D1_txt, D2_txt); AbSynList code = listCons(AbSyn)(stdtypes(), abqParseLines(lines)); AbSyn absyn = abNewSequenceL(sposNone, code); initFile(); Stab stab = stabFile(); abPutUse(absyn, AB_Use_NoValue); scopeBind(stab, absyn); typeInfer(stab, absyn); AbSyn D1 = abFrSyme(uniqueMeaning(stabFile(), "D1")); AbSyn D2 = abFrSyme(uniqueMeaning(stabFile(), "D2")); AbSyn C = abFrSyme(uniqueMeaning(stabFile(), "C")); Syme syme1 = symeNewExport(symInternConst("syme2"), tfNewAbSyn(TF_General, id("D")), car(stab)); symeAddCondition(syme1, sefo(has(D1, C)), true); testIntEqual("test1", 1, listLength(Sefo)(symeCondition(syme1))); Syme syme2 = symeNewExport(symInternConst("syme1"),tfNewAbSyn(TF_General, id("D")), car(stab)); symeAddCondition(syme2, sefo(and(has(D1, C), has(D2, C))), true); testIntEqual("test2", 2, listLength(Sefo)(symeCondition(syme2))); finiFile(); }
Syme symeAddCondition(Syme syme, Sefo cond, Bool pos) { SefoList l = symeCondition(syme); assert(tiTopFns()->tiCanSefo(cond)); if (abTag(cond) == AB_Test) cond = cond->abTest.cond; if (abTag(cond) == AB_And) { Length i = abArgc(cond); while (i > 0) { symeAddCondition(syme, abArgv(cond)[--i], pos); } } else { l = listCons(Sefo)(cond, l); symeSetCondition(syme, l); } return syme; }
/* * Usage: showexports libName type-expression * Example: showexports libaldor.al 'List(Integer)' */ int main(int argc, char *argv[]) { osInit(); sxiInit(); keyInit(); ssymInit(); dbInit(); stabInitGlobal(); tfInit(); foamInit(); optInit(); tinferInit(); pathInit(); sposInit(); ablogInit(); comsgInit(); macexInitFile(); comsgInit(); scobindInitFile(); stabInitFile(); fileAddLibraryDirectory("."); String archive = argv[1]; String expression = argv[2]; scmdHandleLibrary("LIB", archive); AbSyn ab = shexpParse(expression); Stab stab = stabFile(); Syme syme = stabGetArchive(symInternConst("LIB")); AbSyn arAbSyn = abNewId(sposNone, symInternConst("LIB")); AbSyn boolean = abNewId(sposNone, symInternConst("Boolean")); stabImportTForm(stab, tiGetTForm(stab, arAbSyn)); stabImportTForm(stab, tiGetTForm(stab, boolean)); abPutUse(ab, AB_Use_Value); scopeBind(stab, ab); typeInfer(stab, ab); TForm tf = tiGetTForm(stab, ab); aprintf("Type: %s Cat: %d\n", tfPretty(tf), tfSatCat(tf)); if (tfSatDom(tf)) { SymeList list = tfGetCatExports(tf); aprintf("Category\n"); for (; list != listNil(Syme); list = cdr(list)) { Syme syme = car(list); aprintf("%5s %3d %s %pAbSynList\n", symeString(syme), symeHasDefault(syme), tfPretty(symeType(syme)), symeCondition(syme)); } } else { aprintf(">>> Exports\n"); SymeList list = tfStabGetDomImports(stab, tf); for (; list != listNil(Syme); list = cdr(list)) { Syme syme = car(list); aprintf("%s %d %d %s\n", symeString(syme), symeDefnNum(syme), symeConstNum(syme), tfPretty(symeType(syme))); } TQualList tqList; aprintf(">>> Cascades\n"); tqList = tfGetDomCascades(tf); for (; tqList != listNil(TQual); tqList = cdr(tqList)) { TQual tq = car(tqList); aprintf("--> %s\n", tfPretty(tqBase(tq))); } } scobindFiniFile(); stabFiniFile(); comsgFini(); macexFiniFile(); }