use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class ErlParser method create.
/**
* create an IErlMember from a tuple from noparse
*
* @param el
* the tuple, either function or attribute
* @return
*/
private IErlMember create(final IErlModule module, final OtpErlangTuple el) {
final OtpErlangAtom type = (OtpErlangAtom) el.elementAt(0);
final String typeS = type.atomValue();
if ("error".equals(typeS)) {
final OtpErlangTuple er = (OtpErlangTuple) el.elementAt(1);
final String msg = helper.formatError(er);
final ErlParserProblem e = ErlParserProblem.newError(module, msg);
setPos(e, er.elementAt(0));
return e;
} else if ("tree".equals(typeS)) {
final OtpErlangTuple atr = (OtpErlangTuple) el.elementAt(3);
final OtpErlangObject pos = ((OtpErlangTuple) el.elementAt(2)).elementAt(1);
final OtpErlangTuple name = (OtpErlangTuple) atr.elementAt(1);
final OtpErlangAtom n = (OtpErlangAtom) concreteTerm(name);
final OtpErlangObject val = atr.elementAt(2);
final OtpErlangObject extra = el.arity() > 4 ? el.elementAt(4) : null;
return addAttribute(module, pos, n, val, extra, null);
} else if ("attribute".equals(typeS)) {
final OtpErlangObject pos = el.elementAt(1);
final OtpErlangAtom name = (OtpErlangAtom) el.elementAt(2);
final OtpErlangObject val = el.elementAt(3);
final OtpErlangObject extra = el.arity() > 4 ? el.elementAt(4) : null;
final OtpErlangObject arity = el.arity() > 5 ? el.elementAt(5) : null;
return addAttribute(module, pos, name, val, extra, arity);
} else if ("function".equals(typeS)) {
final ErlFunction f = makeErlFunction(module, el);
final OtpErlangList clauses = (OtpErlangList) el.elementAt(6);
final List<ErlFunctionClause> cls = Lists.newArrayListWithCapacity(clauses.arity());
for (int i = 0; i < clauses.arity(); i++) {
final OtpErlangTuple clause = (OtpErlangTuple) clauses.elementAt(i);
final ErlFunctionClause cl = makeErlFunctionClause(f, i, clause);
cls.add(cl);
}
f.setChildren(cls);
return f;
} else {
ErlLogger.debug("unknown: " + typeS);
}
return null;
}
use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class ErlParser method addMacroDef.
private IErlMember addMacroDef(final IErlModule module, final OtpErlangObject pos, final OtpErlangObject val, final OtpErlangObject extra, final String nameS) {
if (val instanceof OtpErlangAtom) {
final String s = Util.stringValue(extra);
final ErlMember r = new ErlMacroDef(module, ((OtpErlangAtom) val).atomValue(), s);
setPos(r, pos);
// r.setParseTree(val);
return r;
} else if (val instanceof OtpErlangList) {
final OtpErlangList macroList = (OtpErlangList) val;
if (macroList.elementAt(0) instanceof OtpErlangTuple) {
final OtpErlangTuple macroNameTuple = (OtpErlangTuple) macroList.elementAt(0);
OtpErlangObject o = macroNameTuple.elementAt(2);
if (o instanceof OtpErlangTuple) {
o = ((OtpErlangTuple) o).elementAt(2);
}
ErlMember r;
if (o instanceof OtpErlangAtom) {
final String macroName = ((OtpErlangAtom) o).atomValue();
r = new ErlMacroDef(module, macroName, null);
} else {
// what do we do here? the define isn't correct
// Erlang...
ErlLogger.warn("Strange macro definition in %s: %s", module.getName(), o.toString());
r = new ErlMacroDef(module, o.toString(), null);
}
setPos(r, pos);
// r.setParseTree(val);
return r;
}
}
return addOtherAttribute(module, pos, val, extra, nameS);
}
use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class ErlParser method addImportAttribute.
private IErlImport addImportAttribute(final IErlModule module, final OtpErlangObject pos, final OtpErlangObject val) {
final OtpErlangTuple t = (OtpErlangTuple) val;
if (t.elementAt(0) instanceof OtpErlangAtom && t.elementAt(1) instanceof OtpErlangList) {
final OtpErlangAtom importModule = (OtpErlangAtom) t.elementAt(0);
final OtpErlangList functionList = (OtpErlangList) t.elementAt(1);
final ErlImport imp = new ErlImport(module, importModule.atomValue(), functionList);
setPos(imp, pos);
return imp;
}
return null;
}
use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class OtpRpc method async_call_result.
@Override
public void async_call_result(final IRpcResultCallback cb, final String m, final String f, final String signature, final Object... args) throws RpcException {
final OtpErlangAtom gleader = OtpRpc.USER_ATOM;
try {
final Object[] args1 = new Object[args.length + 1];
System.arraycopy(args, 0, args1, 1, args.length);
final OtpMbox mbox = localNode.createMbox();
args1[0] = mbox.self();
new RpcResultReceiver(mbox, cb);
rpcCast(localNode, nodeName, false, gleader, m, f, signature, args1);
} catch (final SignatureException e) {
throw new RpcException(e);
}
}
use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class RpcResultReceiver method run.
@Override
public void run() {
boolean done = false;
do {
OtpErlangObject msg;
try {
msg = mbox.receive(3000);
if (msg != null) {
if (msg instanceof OtpErlangTuple) {
final OtpErlangTuple tuple = (OtpErlangTuple) msg;
final String tag = ((OtpErlangAtom) tuple.elementAt(0)).atomValue();
if ("start".equals(tag)) {
callback.start(tuple.elementAt(1));
} else if ("stop".equals(tag)) {
done = true;
callback.stop(tuple.elementAt(1));
} else if ("progress".equals(tag)) {
callback.progress(tuple.elementAt(1));
}
}
}
} catch (final Exception e) {
ErlLogger.error(e);
}
} while (!done || Thread.interrupted());
}
Aggregations