本文整理汇总了Java中org.spoofax.interpreter.terms.IStrategoTerm.LIST属性的典型用法代码示例。如果您正苦于以下问题:Java IStrategoTerm.LIST属性的具体用法?Java IStrategoTerm.LIST怎么用?Java IStrategoTerm.LIST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.spoofax.interpreter.terms.IStrategoTerm
的用法示例。
在下文中一共展示了IStrategoTerm.LIST属性的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: 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);
}
}
示例3: 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 + "'");
}
示例4: call
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
switch (tvars[0].getTermType()) {
case IStrategoTerm.STRING:
IStrategoString string = (IStrategoString) tvars[0];
return makeString(env, string) || makeAppl(env, string, tvars[1]);
case IStrategoTerm.INT:
case IStrategoTerm.REAL:
env.setCurrent(tvars[0]);
return true;
case IStrategoTerm.LIST:
if (tvars[1].getTermType() != IStrategoTerm.LIST)
return false;
env.setCurrent(tvars[1]);
return true;
default:
return false;
}
}
示例5: makeAppl
private boolean makeAppl(IContext env, IStrategoString nameTerm, IStrategoTerm argsTerm) {
if (argsTerm.getTermType() != IStrategoTerm.LIST)
return false;
String name = nameTerm.stringValue();
for (int i = 0; i < name.length(); i++) {
char c = name.charAt(i);
if (!(Character.isLetterOrDigit(c) || c == '_' || c == '-'
|| c == '+' || c == '*' || c == '$')) {
name = name.substring(0, i);
break;
}
}
IStrategoList args = (IStrategoList) argsTerm;
if (name.length() == 0) { // tuple
env.setCurrent(env.getFactory().makeTuple(args.getAllSubterms()));
} else {
IStrategoConstructor cons = env.getFactory().makeConstructor(name, args.size());
env.setCurrent(env.getFactory().makeAppl(cons, args.getAllSubterms()));
}
return true;
}
示例6: 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());
}
}
示例7: 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;
}
}
}
示例8: matches
@Override public boolean matches(IStrategoTerm t, TypesmartContext context) {
if(t.getTermType() == IStrategoTerm.LIST) {
for(IStrategoTerm sub : t)
if(!elemType.matches(sub, context))
return false;
return true;
}
return false;
}
示例9: serialize
/**
* Serializes the term from the position where it left of the last time this
* method was called. Note that the buffer will be flipped before returned.
*
* @param buffer
* The buffer that will be filled with data.
*/
public void serialize(ByteBuffer buffer) {
currentBuffer = buffer;
while (currentTerm != null) {
if (buffer.remaining() < MINIMUMFREESPACE)
break;
Integer id = sharedTerms.get(currentTerm);
if (id != null) {
buffer.put((byte) ISSHAREDFLAG);
writeInt(id.intValue());
stackPosition--; // Pop the term from the stack, since it's
// subtree is shared.
} else {
visit(currentTerm);
if (currentTerm.getTermType() == IStrategoTerm.LIST)
stack[stackPosition].nextPartOfList = (IStrategoList) currentTerm; // <-
// for
// ATermList->next
// optimizaton.
// Don't add the term to the shared list until we are completely
// done with it.
if (indexInTerm == 0)
sharedTerms.put(currentTerm, new Integer(currentKey++));
else
break;
}
currentTerm = getNextTerm();
}
buffer.flip();
}
示例10: match
public Results match(IContext env, IStrategoTerm t, IStrategoAppl p)
throws InterpreterException {
if (t == null) {
throw new InterpreterException("Null term while matching: term library 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() + "]");
}
}
示例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: call
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
ITermFactory factory = env.getFactory();
switch(tvars[0].getTermType()) {
case IStrategoTerm.APPL:
IStrategoAppl a = (IStrategoAppl) tvars[0];
env.setCurrent(factory.makeString(a.getConstructor().getName()));
return true;
case IStrategoTerm.INT:
env.setCurrent(factory.makeInt(((IStrategoInt) tvars[0]).intValue()));
return true;
case IStrategoTerm.REAL:
env.setCurrent(factory.makeReal(((IStrategoReal) tvars[0]).realValue()));
return true;
case IStrategoTerm.BLOB:
env.setCurrent(factory.makeString("BLOB_" + tvars[0].toString()));
return true;
case IStrategoTerm.LIST:
env.setCurrent(factory.makeList());
return true;
case IStrategoTerm.STRING:
IStrategoString current = (IStrategoString) factory.annotateTerm(tvars[0], factory.makeList());
env.setCurrent(factory.makeString(current.toString()));
return true;
case IStrategoTerm.TUPLE:
env.setCurrent(factory.makeString(""));
return true;
case IStrategoTerm.PLACEHOLDER:
env.setCurrent(factory.makePlaceholder(factory.makeList()));
return true;
default:
throw new IllegalStateException("SSL_get_constructor failed for " + tvars[0]);
}
}
示例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: getTermType
@Override public int getTermType() {
return IStrategoTerm.LIST;
}
示例15: getTermType
public final int getTermType() {
return IStrategoTerm.LIST;
}