private void buildListOfAllPatterns(Domain domain, String prefix, int level) throws TermWareException { SortedSet directSystemNames = domain.getNamesOfSystems(); Iterator systemsIterator = directSystemNames.iterator(); while (systemsIterator.hasNext()) { String name = (String) systemsIterator.next(); TermSystem system = domain.resolveSystem(name); SortedSet<String> names = system.getPatternNames(); Iterator namesIterator = names.iterator(); while (namesIterator.hasNext()) { String patternName = (String) namesIterator.next(); if (!allPatterns_.containsKey(patternName)) { HashSet indexEntries = new HashSet(); allPatterns_.put(patternName, indexEntries); } HashSet systemsSet = (HashSet) allPatterns_.get(patternName); systemsSet.add(new APIGen.PatternIndexEntry(prefix, domain, name, level)); } } SortedSet domainsSet = domain.getNamesOfDirectSubdomains(); Iterator domainsIterator = domainsSet.iterator(); while (domainsIterator.hasNext()) { String subdomainName = (String) domainsIterator.next(); Domain subdomain = domain.getDirectSubdomain(subdomainName); buildListOfAllPatterns(subdomain, prefix + subdomainName + "/", level + 1); } }
public boolean runTest(IEnv env) { try { TermSystem general = TermWare.getInstance().getRoot().resolveSystem("general"); Term t = TermWare.getInstance().getTermFactory().createParsedTerm("neq(p(x),p(x))"); Term r = general.reduce(t); if (!(r.isBoolean() && r.getBoolean() == false)) { System.out.println("r1=" + TermHelper.termToString(r)); return false; } t = TermWare.getInstance().getTermFactory().createParsedTerm("neq(p(\"x\"),p(\"x\"))"); r = general.reduce(t); if (r.isBoolean()) { if (r.getBoolean() == false) { return true; } else { return false; } } else { System.out.println("r2=" + TermHelper.termToString(r)); return false; } } catch (TermWareException ex) { ex.printStackTrace(); return false; } }
private void generateSystemPages(Domain domain, String prefix, int level) throws IOException, TermWareException { SortedSet directSystemNames = domain.getNamesOfSystems(); Iterator systemsIterator = directSystemNames.iterator(); while (systemsIterator.hasNext()) { String name = (String) systemsIterator.next(); PrintStream out = openPrintStream(prefix + name, "all-patterns.html"); printHeader(out, "patterns for " + name); out.println("<BODY BGCOLOR=\"white\">"); out.println("<TABLE BORDER=\"0\" WIDTH=\"100%\">"); out.println("<TR>"); out.println("<TD NOWRAP><FONT size=\"+1\">"); out.println("Patterns"); out.println("</FONT></TD>"); out.println("</TR></TABLE>"); out.println("<TABLE BORDER=\"0\" WIDTH=\"100%\">"); out.println("<TR><TD NOWRAP><P>"); out.println("<FONT>"); TermSystem system = domain.resolveSystem(name); SortedSet names = system.getPatternNames(); Iterator namesIterator = names.iterator(); while (namesIterator.hasNext()) { String patternName = (String) namesIterator.next(); String uri = prefix + name + "/index.html#" + patternName; out.print("<A href=\"../"); for (int i = 0; i < level; ++i) { out.print("../"); } out.print(uri + "\" TARGET=\"transformerFrame\" >"); out.print(patternName); out.println("</A>"); out.println("<BR>"); } out.println("</FONT>"); out.println("</TD>"); out.println("</TR>"); out.println("</TABLE>"); out.println("<P> </BODY></HTML>"); out.close(); out = openPrintStream(prefix + name, "index.html"); TermSystem ts = domain.resolveSystem(name); printSystemIndexPage(out, prefix + name, ts); out.close(); } SortedSet domainsSet = domain.getNamesOfDirectSubdomains(); Iterator domainsIterator = domainsSet.iterator(); while (domainsIterator.hasNext()) { String subdomainName = (String) domainsIterator.next(); Domain subdomain = domain.getDirectSubdomain(subdomainName); generateSystemPages(subdomain, prefix + subdomainName + "/", level + 1); } }
public static Term static_transform(Term t, TermSystem sys, TransformationContext ctx) throws TermWareException { if (!t.getName().equals("javaStrategy")) return t; if (t.getArity() != 2) { return t; } sys.getInstance().addJavaStrategy(t.getSubtermAt(0).getName(), t.getSubtermAt(1).getName()); ctx.setChanged(true); return TermFactory.createBoolean(true); }
private void printSystemIndexPage(PrintStream out, String systemName, TermSystem ts) throws IOException, TermWareException { printHeader(out, systemName); out.println("<BODY BGCOLOR=\"white\">"); SortedSet patternNames = ts.getPatternNames(); Iterator patternsIterator = patternNames.iterator(); while (patternsIterator.hasNext()) { String patternName = (String) patternsIterator.next(); out.println("<HR><A NAME=\"" + patternName + "\"><!-- --></A>"); out.println("<FONT +1>" + patternName + "</FONT><BR>"); out.println("<ul>"); Iterator it = ts.getStrategy().getStar().iterator(patternName); HashSet sourceOnlyRules = new HashSet(); while (it.hasNext()) { ITermTransformer tr = (ITermTransformer) it.next(); String description = tr.getDescription(); if (description.length() == 0) { sourceOnlyRules.add(tr); } else { out.println("<li>"); out.print(description); out.println("</li>"); } } if (!sourceOnlyRules.isEmpty()) { Iterator sourceOnlyIterator = sourceOnlyRules.iterator(); while (sourceOnlyIterator.hasNext()) { ITermTransformer tr = (ITermTransformer) sourceOnlyIterator.next(); out.println("<li><code>"); out.println(tr.getSource()); out.println("</code></li>"); } } out.println("</ul>"); } out.println("</BODY></HTML>"); }
public static Term static_transform(Term t, TermSystem system, TransformationContext ctx) throws TermWareException { if (t.getArity() != 2) { throw new AssertException("logical_and must have arity 2"); } LogHelper.log(system, LogicalAndTransformer.class, "LogicalAnd, t=", t); Term frs = t.getSubtermAt(0); Term snd = t.getSubtermAt(1); Term retval = t; if (frs.isBoolean() && snd.isBoolean()) { ctx.setChanged(true); retval = system.getInstance().getTermFactory().createBoolean(frs.getBoolean() && snd.getBoolean()); } else if (frs.isBoolean()) { if (frs.getBoolean()) { // true && y -> y ctx.setChanged(true); retval = snd; } else { // false && y -> false ctx.setChanged(true); retval = frs; } } else if (snd.isBoolean()) { if (snd.getBoolean()) { // x && true -> x ctx.setChanged(true); retval = frs; } else { // x && false -> x ctx.setChanged(true); retval = snd; } } LogHelper.log(system, LogicalAndTransformer.class, "return ", retval); return retval; }
public static Term static_transform(Term t, TermSystem sys, TransformationContext ctx) throws TermWareException { if (!t.getName().equals("printTerm")) return t; if (sys.isLoggingMode()) { sys.getEnv().getLog().print("native:"); t.print(sys.getEnv().getLog()); sys.getEnv().getLog().println(); } Term retval = t; if (t.getArity() == 1) { t.getSubtermAt(0).print(sys.getEnv().getOutput()); retval = t.getSubtermAt(0); } else if (t.getArity() == 2 || t.getArity() == 3) { // TODO: // 1. check that name and language is string // 2. outTag can be parameter. String printerName = t.getSubtermAt(1).getName(); IPrinterFactory printerFactory = sys.getInstance().getPrinterFactory(printerName); IPrinter printer; Term arg = ((t.getArity() == 2) ? TermFactory.createNIL() : t.getSubtermAt(2)); printer = printerFactory.createPrinter(sys.getEnv().getOutput(), "unknown", sys, arg); printer.writeTerm(t.getSubtermAt(0)); retval = t.getSubtermAt(0); } else { if (sys.isLoggingMode()) { sys.getEnv().getLog().print("native:"); t.print(sys.getEnv().getLog()); sys.getEnv().getLog().println("- not changed."); } return t; } ctx.setChanged(true); if (sys.isLoggingMode()) { sys.getEnv().getLog().print("native:"); t.print(sys.getEnv().getLog()); sys.getEnv().getLog().println("- printed."); } return retval; }