本文整理汇总了Java中org.spoofax.interpreter.terms.ITermFactory类的典型用法代码示例。如果您正苦于以下问题:Java ITermFactory类的具体用法?Java ITermFactory怎么用?Java ITermFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ITermFactory类属于org.spoofax.interpreter.terms包,在下文中一共展示了ITermFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
@Override protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars,
ITermFactory factory, IContext context) {
if(!(current instanceof IStrategoString)) {
return null;
}
String path = Tools.asJavaString(current);
IStrategoTerm basePathTerm = tvars[0];
if(!(basePathTerm instanceof IStrategoString)) {
return null;
}
String basePath = Tools.asJavaString(basePathTerm);
final FileObject base = resourceService.resolve(basePath);
final FileObject abs = resourceService.resolve(base, path);
return factory.makeString(abs.getName().getURI());
}
示例2: toAterm
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
@Override public IStrategoTerm toAterm(SetMultimap<IProduction, IAttribute> prod_attrs) {
ITermFactory tf = ParseTableGenerator.getTermfactory();
List<IStrategoTerm> rhs_terms = Lists.newArrayList();
List<IStrategoTerm> attrs_terms = Lists.newArrayList();
for(Symbol s : rhs) {
rhs_terms.add(s.toAterm(tf));
}
for(IAttribute a : prod_attrs.get(this)) {
attrs_terms.add(a.toAterm(tf));
}
if(attrs_terms.isEmpty()) {
return tf.makeAppl(tf.makeConstructor("prod", 3), tf.makeList(rhs_terms), lhs.toAterm(tf),
tf.makeAppl(tf.makeConstructor("no-attrs", 0)));
}
return tf.makeAppl(tf.makeConstructor("prod", 3), tf.makeList(rhs_terms), lhs.toAterm(tf),
tf.makeAppl(tf.makeConstructor("attrs", 1), tf.makeList(attrs_terms)));
}
示例3: toSDF3Aterm
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
@Override public IStrategoTerm toSDF3Aterm(SetMultimap<IProduction, IAttribute> prod_attrs,
Map<Set<Context>, Integer> ctx_vals, Integer ctx_val) {
ITermFactory tf = ParseTableGenerator.getTermfactory();
List<IStrategoTerm> rhs_terms = Lists.newArrayList();
List<IStrategoTerm> attrs_terms = Lists.newArrayList();
for(Symbol s : rhs) {
rhs_terms.add(s.toSDF3Aterm(tf, ctx_vals, ctx_val));
}
for(IAttribute a : prod_attrs.get(getOrigProduction())) {
attrs_terms.add(a.toSDF3Aterm(tf));
}
if(attrs_terms.isEmpty()) {
return tf.makeAppl(tf.makeConstructor("SdfProduction", 3), lhs.toSDF3Aterm(tf, ctx_vals, ctx_val),
tf.makeAppl(tf.makeConstructor("Rhs", 1), tf.makeList(rhs_terms)),
tf.makeAppl(tf.makeConstructor("NoAttrs", 0)));
} else {
// with constructor
}
return tf.makeAppl(tf.makeConstructor("SdfProduction", 3), lhs.toSDF3Aterm(tf, ctx_vals, ctx_val),
tf.makeAppl(tf.makeConstructor("Rhs", 1), tf.makeList(rhs_terms)),
tf.makeAppl(tf.makeConstructor("Attrs", 1), tf.makeList(attrs_terms)));
}
示例4: initializeParseTable
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
private ParseTable initializeParseTable(ITermFactory factory, IStrategoTerm pt) throws InvalidParseTableException {
long start = System.currentTimeMillis();
ParseTable parseTable = new ParseTable(pt, factory);
long elapsed = System.currentTimeMillis() - start;
if (SGLR.isLogging()) {
Tools.logger("Loading parse table took " + elapsed/1000.0f + "s");
Tools.logger("No. of states: ", parseTable.getStateCount());
Tools.logger("No. of productions: ", parseTable.getProductionCount());
Tools.logger("No. of action entries: ", parseTable.getActionCount());
Tools.logger("No. of gotos entries: ", parseTable.getGotoCount());
Tools.logger((parseTable.hasRejects() ? "Includes" : "Excludes"), " rejects");
Tools.logger((parseTable.hasPriorities() ? "Includes" : "Excludes"), " priorities");
Tools.logger((parseTable.hasPrefers() ? "Includes" : "Excludes"), " prefer actions");
Tools.logger((parseTable.hasAvoids() ? "Includes" : "Excludes"), " avoid actions");
}
return parseTable;
}
示例5: toAterm
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
@Override public IStrategoTerm toAterm(ITermFactory tf, ParseTable pt) {
int status = 0;
for(IAttribute attr : pt.normalizedGrammar().getProductionAttributesMapping().get(prod.getProduction())) {
if(attr instanceof GeneralAttribute) {
GeneralAttribute ga = (GeneralAttribute) attr;
if(ga.getName().equals("reject")) {
status = 1;
} else if(ga.getName().equals("prefer")) {
status = 2;
} else if(ga.getName().equals("avoid")) {
status = 4;
}
}
}
return tf.makeAppl(tf.makeConstructor("reduce", 3), tf.makeInt(prod.getProduction().rightHand().size()), tf.makeInt(prod_label),
tf.makeInt(status));
}
示例6: StrategoTermBuilder
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
public StrategoTermBuilder(ITermFactory factory, XMLLibrary library) {
this.factory = factory;
elementCons = factory.makeConstructor("Element", 3);
attributeCons = factory.makeConstructor("Attribute", 2);
textCons = factory.makeConstructor("Text", 1);
nameCons = factory.makeConstructor("Name", 2);
noneCons = factory.makeConstructor("None", 0);
someCons = factory.makeConstructor("Some", 1);
allowMixedContent = library.getAllowMixedContent();
allowTextContent = library.getAllowCharacterContent();
namespaceAware = library.obtainParser().isNamespaceAware();
// This dummy element collects the root element.
stack.push(new Element(null, null, null, null));
}
示例7: call
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
@Override protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars,
ITermFactory factory, IContext context) throws MetaborgException, IOException {
if(!Tools.isTermString(tvars[0])) {
return null;
}
final IProject project = projectService.get(context.location());
if(project == null) {
return factory.makeList();
}
// GTODO: require language identifier instead of language name
final String languageName = Tools.asJavaString(tvars[0]);
final Iterable<FileObject> includeLocations = languagePathService.includePaths(project, languageName);
final List<IStrategoTerm> terms = Lists.newArrayList();
for(FileObject includeLocation : includeLocations) {
terms.add(factory.makeString(includeLocation.getName().getURI()));
}
return factory.makeList(terms);
}
示例8: JFFLibrary
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
public JFFLibrary(ITermFactory termFactory) {
this.termFactory = termFactory;
add(new JFF_close_file_channel_0_0());
add(new JFF_flip_byte_buffer_0_0());
add(new JFF_make_byte_buffer_0_0());
add(new JFF_open_file_channel_0_0());
add(new JFF_read_from_file_channel_0_0());
add(new JFF_write_to_file_channel_0_0());
add(new JFF_find_class());
add(new JFF_find_primitive_type());
add(new JFF_get_constructor());
add(new JFF_get_method());
add(new JFF_invoke_method());
add(new JFF_new_instance());
add(new JFF_chmod_0_0());
init();
}
示例9: toExternalDef
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
public IStrategoAppl toExternalDef(ITermFactory f, StrategoSignature sig) {
final IStrategoTerm[] sArgs = new IStrategoTerm[strategyArgs.length];
final IStrategoTerm[] tArgs = new IStrategoTerm[termArgs.length];
for (int i = 0; i < sArgs.length; ++i) {
final SVar sv = strategyArgs[i];
sArgs[i] = f.makeAppl(sig.CTOR_VarDec, f.makeString(sv.name), sv.type.toTerm(f, sig));
}
for (int i = 0; i < tArgs.length; ++i) {
tArgs[i] = f.makeAppl(sig.CTOR_VarDec, f.makeString(termArgs[i]), ConstType.INSTANCE.toTerm(f, sig));
}
return f.makeAppl(sig.CTOR_ExtSDef, f.makeString(getUncifiedName()), f.makeList(sArgs), f.makeList(tArgs));
}
示例10: buildOp
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
private IStrategoTerm buildOp(String ctr, IContext env, IStrategoAppl t, ITermFactory factory)
throws InterpreterException {
IStrategoList children = (IStrategoList) t.getSubterm(1);
IStrategoConstructor ctor = factory.makeConstructor(ctr, children.size());
IStrategoTerm[] kids = new IStrategoTerm[children.size()];
for (int i = children.size() -1 ; i >= 0; i--) {
IStrategoTerm kid = buildTerm(env, (IStrategoAppl) children.getSubterm(i));
if (kid == null) {
return null;
}
kids[i] = kid;
}
return factory.makeAppl(ctor, kids);
}
示例11: tracingTermsCompletions
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
private Iterable<IStrategoTerm> tracingTermsCompletions(final int position, Object result,
final ISourceRegion region, final HybridInterpreter runtime, final ITermFactory termFactory,
final String languageName, final Map<IStrategoTerm, Boolean> leftRecursiveTerms,
final Map<IStrategoTerm, Boolean> rightRecursiveTerms) {
if(result == null || region == null) {
return Iterables2.empty();
}
final Collection<IStrategoTerm> parsed = Lists.newLinkedList();
final IStrategoTermVisitor visitor = new AStrategoTermVisitor() {
@Override public boolean visit(IStrategoTerm term) {
final ISourceLocation location = fromTokens(term, runtime, termFactory, position, languageName,
leftRecursiveTerms, rightRecursiveTerms);
if(location != null && location.region().contains(region)) {
parsed.add(term);
return false;
}
return true;
}
};
StrategoTermVisitee.bottomup(visitor, (IStrategoTerm) result);
return parsed;
}
示例12: call
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
/**
* Returns times for self and children:
* (utime, stime, cutime, cstime)
*/
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
ITermFactory factory = env.getFactory();
int utime = (int) (getUserTime() * TICKS_PER_SECOND / 1000000000);
int stime = (int) (getSystemTime() * TICKS_PER_SECOND / 1000000000);
IStrategoTerm utimeTerm = factory.makeInt(utime);
IStrategoTerm stimeTerm = factory.makeInt(stime);
IStrategoTerm ctimeTerm = factory.makeInt(0);
env.setCurrent(factory.makeTuple(utimeTerm, stimeTerm, ctimeTerm, ctimeTerm));
return true;
}
示例13: call
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
IStrategoTerm t = tvars[0];
if (!Tools.isTermString(t))
return false;
String s = ((IStrategoString) t).stringValue();
ITermFactory factory = env.getFactory();
IStrategoList result = factory.makeList();
for (int i = s.length() - 1; i >= 0; i--) {
result = factory.makeListCons(factory.makeInt(s.charAt(i)), result);
}
env.setCurrent(result);
return true;
}
示例14: ParseTable
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
public ParseTable(IStrategoTerm pt, ITermFactory factory, FileObject persistedTable,
org.metaborg.sdf2table.parsetable.ParseTable referencePt) throws Exception {
initTransientData(factory);
dynamicPTgeneration = checkDynamicGeneration(pt);
if(dynamicPTgeneration && persistedTable != null) {
pt_generator = new IncrementalParseTableGenerator(persistedTable, referencePt);
} else {
pt_generator = null;
}
parse(pt_generator.generateATerm(pt_generator.getParseTable()));
gotoCache = new HashMap<Goto, Goto>();
shiftCache = new HashMap<Shift, Shift>();
reduceCache = new HashMap<Reduce, Reduce>();
rangesCache = new HashMap<RangeList, RangeList>();
if(dynamicPTgeneration && persistedTable == null) {
throw new InvalidParseTableException(
"Parse table does not contain any state and normalized grammar is null");
}
}
示例15: get
import org.spoofax.interpreter.terms.ITermFactory; //导入依赖的package包/类
@Override public ITermFactory get(ILanguageComponent component, @Nullable IProject project,
boolean supportsTypesmart) {
if(!supportsTypesmart || project == null) {
return genericFactory;
}
ISpoofaxProjectConfig config = configService.get(project);
if(config == null || !config.typesmart()) {
return genericFactory;
}
TypesmartContext context = getTypesmartContext(component);
if(!context.isEmpty()) {
return new TypesmartTermFactory(genericFactory, typesmartLogger, context);
} else {
return genericFactory;
}
}