本文整理汇总了Java中org.spoofax.interpreter.terms.IStrategoTerm.APPL属性的典型用法代码示例。如果您正苦于以下问题:Java IStrategoTerm.APPL属性的具体用法?Java IStrategoTerm.APPL怎么用?Java IStrategoTerm.APPL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.spoofax.interpreter.terms.IStrategoTerm
的用法示例。
在下文中一共展示了IStrategoTerm.APPL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeAnnotations
public static IStrategoTerm removeAnnotations(IStrategoTerm inTerm, final ITermFactory factory) {
TermTransformer trans = new TermTransformer(factory, true) {
@Override public IStrategoTerm preTransform(IStrategoTerm term) {
switch(term.getTermType()) {
case IStrategoTerm.APPL:
return factory.makeAppl(((IStrategoAppl) term).getConstructor(), term.getAllSubterms(), null);
case IStrategoTerm.LIST:
return factory.makeList(term.getAllSubterms(), null);
case IStrategoTerm.STRING:
return factory.makeString(((IStrategoString) term).stringValue());
case IStrategoTerm.TUPLE:
return factory.makeTuple(term.getAllSubterms(), null);
default:
return term;
}
}
};
return trans.transform(inTerm);
}
示例2: getTermArguments
private IStrategoTerm getTermArguments(IContext env, IStrategoTerm t) throws InterpreterException {
switch(t.getTermType()) {
case IStrategoTerm.INT:
case IStrategoTerm.REAL:
return env.getFactory().makeList();
case IStrategoTerm.APPL:
IStrategoAppl a = (IStrategoAppl)t;
if (Tools.isNil(a, env) || Tools.isCons(a, env))
return t;
else
return env.getFactory().makeList(a.getArguments());
case IStrategoTerm.LIST:
return t;
case IStrategoTerm.STRING:
return env.getFactory().makeList();
case IStrategoTerm.TUPLE:
IStrategoTuple tup = (IStrategoTuple) t;
IStrategoTerm[] args = new IStrategoTerm[tup.getSubtermCount()];
for(int i = 0; i < args.length; i++)
args[i] = tup.get(i);
return env.getFactory().makeList(args);
}
throw new InterpreterException("Unknown term '" + t + "'");
}
示例3: dispatch
private static boolean dispatch(IStrategoTermVisitor visitor, IStrategoTerm term) {
switch(term.getTermType()) {
case IStrategoTerm.APPL:
return visitor.visit((IStrategoAppl) term);
case IStrategoTerm.LIST:
return visitor.visit((IStrategoList) term);
case IStrategoTerm.TUPLE:
return visitor.visit((IStrategoTuple) term);
case IStrategoTerm.INT:
visitor.visit((IStrategoInt) term);
return false;
case IStrategoTerm.REAL:
visitor.visit((IStrategoReal) term);
return false;
case IStrategoTerm.STRING:
visitor.visit((IStrategoString) term);
return false;
case IStrategoTerm.REF:
visitor.visit((IStrategoRef) term);
return false;
case IStrategoTerm.PLACEHOLDER:
return visitor.visit((IStrategoPlaceholder) term);
default:
return visitor.visit(term);
}
}
示例4: getTermArguments
private IStrategoTerm getTermArguments(IContext env, IStrategoTerm t) throws InterpreterException {
switch(t.getTermType()) {
case IStrategoTerm.INT:
case IStrategoTerm.REAL:
return env.getFactory().makeList();
case IStrategoTerm.APPL:
IStrategoAppl a = (IStrategoAppl)t;
if (Tools.isNil(a, env) || Tools.isCons(a, env))
return t;
else
return env.getFactory().makeList(a.getAllSubterms());
case IStrategoTerm.LIST:
return t;
case IStrategoTerm.STRING:
return env.getFactory().makeList();
case IStrategoTerm.TUPLE:
IStrategoTuple tup = (IStrategoTuple) t;
IStrategoTerm[] args = new IStrategoTerm[tup.getSubtermCount()];
for(int i = 0; i < args.length; i++)
args[i] = tup.get(i);
return env.getFactory().makeList(args);
}
throw new InterpreterException("Unknown term '" + t + "'");
}
示例5: match
public static <T> T match(IStrategoTerm term, ICases<T> cases) {
switch(term.getTermType()) {
case IStrategoTerm.APPL:
return cases.caseAppl((IStrategoAppl) term);
case IStrategoTerm.LIST:
return cases.caseList((IStrategoList) term);
case IStrategoTerm.TUPLE:
return cases.caseTuple((IStrategoTuple) term);
case IStrategoTerm.INT:
return cases.caseInt((IStrategoInt) term);
case IStrategoTerm.REAL:
return cases.caseReal((IStrategoReal) term);
case IStrategoTerm.STRING:
return cases.caseString((IStrategoString) term);
default:
throw new IllegalArgumentException("Unsupported Stratego term type " + term.getTermType());
}
}
示例6: rebuildIfNecessary
private IStrategoTerm rebuildIfNecessary(IStrategoTerm term) {
if(term.getTermType() == IStrategoTerm.APPL) {
IStrategoAppl appl = (IStrategoAppl) term;
if(context.getConstructorSignatures().containsKey(appl.getConstructor().getName())
&& TypesmartSortAttachment.getSorts(appl) == null)
return makeAppl(appl.getConstructor(), appl.getAllSubterms(), appl.getAnnotations());
else
return appl;
} else {
IStrategoTerm[] kids = new IStrategoTerm[term.getSubtermCount()];
boolean changed = false;
int i = 0;
for(IStrategoTerm kid : term) {
IStrategoTerm newkid = rebuildIfNecessary(kid);
kids[i] = newkid;
changed = changed || kid != newkid;
}
if(changed) {
switch(term.getTermType()) {
case IStrategoTerm.LIST:
return makeList(kids, term.getAnnotations());
case IStrategoTerm.TUPLE:
return makeTuple(kids, term.getAnnotations());
default:
throw new IllegalStateException();
}
} else {
return term;
}
}
}
示例7: matches
@Override public boolean matches(IStrategoTerm t, TypesmartContext context) {
if(t.getTermType() == IStrategoTerm.APPL) {
IStrategoAppl appl = (IStrategoAppl) t;
if("None".equals(appl.getName()) && appl.getSubtermCount() == 0) {
return true;
}
if("Some".equals(appl.getName()) && appl.getSubtermCount() == 1) {
return elemType.matches(appl.getSubterm(0), context);
}
}
return false;
}
示例8: doSlowMatch
@Override
final protected boolean doSlowMatch(IStrategoTerm second, int commonStorageType) {
if(second.getTermType() != IStrategoTerm.APPL)
return false;
final IStrategoAppl o = (IStrategoAppl) second;
if(getConstructor() != o.getConstructor())
return false;
final IStrategoTerm[] kids = getAllSubterms();
final IStrategoTerm[] secondKids = o.getAllSubterms();
if(kids != secondKids) {
for(int i = 0, sz = kids.length; i < sz; i++) {
final IStrategoTerm kid = kids[i];
final IStrategoTerm secondKid = secondKids[i];
if(kid != secondKid && !kid.match(secondKid)) {
if(commonStorageType == SHARABLE && i != 0)
System.arraycopy(secondKids, 0, kids, 0, i);
return false;
}
}
// FIXME should update sharing when possible
// if (commonStorageType == SHARABLE)
// this.kids = secondKids;
}
final IStrategoList annotations = getAnnotations();
final IStrategoList secondAnnotations = second.getAnnotations();
if(annotations == secondAnnotations) {
return true;
} else if(annotations.match(secondAnnotations)) {
if(commonStorageType == SHARABLE)
internalSetAnnotations(secondAnnotations);
return true;
} else {
return false;
}
}
示例9: doSlowMatch
@Override
protected boolean doSlowMatch(IStrategoTerm second, int commonStorageType) {
if (second.getTermType() != IStrategoTerm.APPL)
return false;
IStrategoAppl o = (IStrategoAppl)second;
if (!ctor.equals(o.getConstructor()))
return false;
IStrategoTerm[] kids = getAllSubterms();
IStrategoTerm[] secondKids = o.getAllSubterms();
if (kids != secondKids) {
for (int i = 0, sz = kids.length; i < sz; i++) {
IStrategoTerm kid = kids[i];
IStrategoTerm secondKid = secondKids[i];
if (kid != secondKid && !kid.match(secondKid)) {
if (commonStorageType == SHARABLE && i != 0)
System.arraycopy(secondKids, 0, kids, 0, i);
return false;
}
}
if (commonStorageType == SHARABLE)
this.kids = secondKids;
}
IStrategoList annotations = getAnnotations();
IStrategoList secondAnnotations = second.getAnnotations();
if (annotations == secondAnnotations) {
return true;
} else if (annotations.match(secondAnnotations)) {
if (commonStorageType == SHARABLE) internalSetAnnotations(secondAnnotations);
return true;
} else {
return false;
}
}
示例10: unpackTerm
public Object unpackTerm(IStrategoTerm term) {
switch(term.getTermType()) {
case IStrategoTerm.INT:
return ((IStrategoInt)term).intValue();
case IStrategoTerm.REAL:
return ((IStrategoReal)term).realValue();
case IStrategoTerm.STRING:
return ((IStrategoString)term).stringValue();
case IStrategoTerm.APPL:
return unwrapObject((IStrategoAppl)term);
default:
return null;
}
}
示例11: match
public Results match(IContext env, IStrategoTerm t, IStrategoAppl p)
throws InterpreterException {
if (t == null) {
throw new InterpreterException("Null term while matching: term library or one of the primitives is defective");
}
switch (t.getTermType()) {
case IStrategoTerm.APPL:
return matchAppl(env, (IStrategoAppl) t, p);
case IStrategoTerm.INT:
return matchInt(env, (IStrategoInt) t, p);
case IStrategoTerm.REAL:
return matchReal(env, (IStrategoReal) t, p);
case IStrategoTerm.STRING:
return matchString(env, (IStrategoString) t, p);
case IStrategoTerm.LIST:
return matchList(env, (IStrategoList) t, p);
case IStrategoTerm.TUPLE:
return matchTuple(env, (IStrategoTuple) t, p);
case IStrategoTerm.REF:
return matchRef(env, (IStrategoRef)t, p);
case IStrategoTerm.BLOB:
return matchBlob(env, t, p);
default:
throw new InterpreterException("Unsupported term type : "
+ t.getClass().toString() + " [" + t.getTermType() + "]");
}
}
示例12: isSomeNode
/**
* Says wether the given node is an optional Some(_) sort.
* @param trm
* @return
*/
public static boolean isSomeNode(IStrategoTerm trm) {
if(trm.getTermType() == IStrategoTerm.APPL){
return trm.getSubtermCount() == 1 && ((IStrategoAppl)trm).getConstructor().getName().equals("Some");
}
return false;
}
示例13: call
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
switch(tvars[0].getTermType()) {
case IStrategoTerm.APPL:
IStrategoAppl a = (IStrategoAppl) tvars[0];
env.setCurrent(env.getFactory().makeList(a.getAllSubterms()));
return true;
case IStrategoTerm.INT:
case IStrategoTerm.STRING:
case IStrategoTerm.REAL:
case IStrategoTerm.BLOB:
env.setCurrent(env.getFactory().makeList());
return true;
case IStrategoTerm.LIST:
env.setCurrent(tvars[0]);
return true;
case IStrategoTerm.TUPLE:
IStrategoTuple tuple = (IStrategoTuple) tvars[0];
env.setCurrent(env.getFactory().makeList(tuple.getAllSubterms()));
return true;
case IStrategoTerm.PLACEHOLDER:
IStrategoPlaceholder placeholder = (IStrategoPlaceholder) tvars[0];
env.setCurrent(env.getFactory().makeList(placeholder.getTemplate()));
return true;
default:
throw new IllegalStateException("SSL_get_arguments failed for " + tvars[0]);
}
}
示例14: call
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
final ITermFactory f = env.getFactory();
final LinkedList<IStrategoAppl> as = new LinkedList<IStrategoAppl>();
// see also Context.getStrategyNames()
VarScope v = env.getVarScope();
while (v.getParent() != null)
v = v.getParent();
// FIXME: ugh
if (env instanceof Context) {
final StrategoSignature sign = ((Context) env).getStrategoSignature();
final HashSet<String> names = new HashSet<String>();
final TermVisitor collectSVars = new TermVisitor() {
public void preVisit(IStrategoTerm term) {
if (term.getTermType() == IStrategoTerm.APPL
&& ((IStrategoAppl) term).getConstructor() == sign.CTOR_SVar) {
names.add(Tools.javaStringAt(term, 0));
}
}
};
collectSVars.visit(tvars[0]);
for (SDefT sdef : v.getSVars()) {
if (names.contains(sdef.getUncifiedName())) {
as.addFirst(sdef.toExternalDef(f, sign));
}
}
}
env.setCurrent(f.makeList(as));
return true;
}
示例15: isLayout
public boolean isLayout() {
if (isLayout != null)
return isLayout;
IStrategoTerm t = prod.getSubterm(1);
while (true) {
if (t.getTermType() != IStrategoTerm.APPL) {
isLayout = false;
break;
}
IStrategoAppl app = (IStrategoAppl) t;
if (Term.hasConstructor(app, "layout")) {
isLayout = true;
break;
}
if (app.getSubtermCount() == 1 &&
(Term.hasConstructor(app, "cf") ||
Term.hasConstructor(app, "lex") ||
Term.hasConstructor(app, "opt") ||
Term.hasConstructor(app, "iter")))
t = app.getSubterm(0);
else {
isLayout = false;
break;
}
}
return isLayout;
}