本文整理汇总了C#中clojure.lang.CljCompiler.Ast.ParserContext类的典型用法代码示例。如果您正苦于以下问题:C# ParserContext类的具体用法?C# ParserContext怎么用?C# ParserContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParserContext类属于clojure.lang.CljCompiler.Ast命名空间,在下文中一共展示了ParserContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Parse
public Expr Parse(ParserContext pcon, object form)
{
if (pcon.Rhc == RHC.Eval)
return Compiler.Analyze(pcon, RT.list(RT.list(Compiler.FN, PersistentVector.EMPTY, form)), "throw__" + RT.nextID());
return new ThrowExpr(Compiler.Analyze(pcon.SetRhc(RHC.Expression).SetAssign(false), RT.second(form)));
}
开发者ID:christianblunden,项目名称:clojure-clr,代码行数:7,代码来源:ThrowExpr.cs
示例2: Parse
public static Expr Parse(ParserContext pcon, IPersistentVector form)
{
ParserContext pconToUse = pcon.EvEx();
bool constant = true;
IPersistentVector args = PersistentVector.EMPTY;
for (int i = 0; i < form.count(); i++ )
{
Expr v = Compiler.Analyze(pconToUse, form.nth(i));
args = (IPersistentVector)args.cons(v);
if ( !(v is LiteralExpr) )
constant = false;
}
Expr ret = new VectorExpr(args);
if ( form is IObj && ((IObj)form).meta() != null )
return Compiler.OptionallyGenerateMetaInit(pcon,form, ret);
else if ( constant )
{
IPersistentVector rv = PersistentVector.EMPTY;
for ( int i=0; i<args.count(); i++ )
{
LiteralExpr ve = (LiteralExpr)args.nth(i);
rv = (IPersistentVector)rv.cons(ve.Val);
}
return new ConstantExpr(rv);
}
else
return ret;
}
开发者ID:101v,项目名称:clojure-clr,代码行数:30,代码来源:VectorExpr.cs
示例3: Parse
public Expr Parse(ParserContext pcon, object frm)
{
// frm is: (deftype* tagname classname [fields] :implements [interfaces] :tag tagname methods*)
ISeq rform = (ISeq)frm;
rform = RT.next(rform);
string tagname = ((Symbol)rform.first()).getName();
rform = rform.next();
Symbol classname = (Symbol)rform.first();
rform = rform.next();
IPersistentVector fields = (IPersistentVector)rform.first();
rform = rform.next();
IPersistentMap opts = PersistentHashMap.EMPTY;
while (rform != null && rform.first() is Keyword)
{
opts = opts.assoc(rform.first(), RT.second(rform));
rform = rform.next().next();
}
ObjExpr ret = Build((IPersistentVector)RT.get(opts, Compiler.ImplementsKeyword, PersistentVector.EMPTY), fields, null, tagname, classname,
(Symbol)RT.get(opts, RT.TagKey), rform, frm,opts);
return ret;
}
开发者ID:TerabyteX,项目名称:clojure-clr,代码行数:25,代码来源:NewInstanceExpr.cs
示例4: Parse
public static Expr Parse(ParserContext pcon, IPersistentMap form)
{
ParserContext pconToUse = pcon.EvEx();
bool constant = true;
IPersistentVector keyvals = PersistentVector.EMPTY;
for (ISeq s = RT.seq(form); s != null; s = s.next())
{
IMapEntry e = (IMapEntry)s.first();
Expr k = Compiler.Analyze(pconToUse, e.key());
Expr v = Compiler.Analyze(pconToUse, e.val());
keyvals = (IPersistentVector)keyvals.cons(k);
keyvals = (IPersistentVector)keyvals.cons(v);
if (!(k is LiteralExpr && v is LiteralExpr))
constant = false;
}
Expr ret = new MapExpr(keyvals);
if (form is IObj && ((IObj)form).meta() != null)
return Compiler.OptionallyGenerateMetaInit(pcon, form, ret);
else if (constant)
{
// This 'optimzation' works, mostly, unless you have nested map values.
// The nested map values do not participate in the constants map, so you end up with the code to create the keys.
// Result: huge duplication of keyword creation. 3X increase in init time to the REPL.
//IPersistentMap m = PersistentHashMap.EMPTY;
//for (int i = 0; i < keyvals.length(); i += 2)
// m = m.assoc(((LiteralExpr)keyvals.nth(i)).Val, ((LiteralExpr)keyvals.nth(i + 1)).Val);
//return new ConstantExpr(m);
return ret;
}
else
return ret;
}
开发者ID:davidadsit,项目名称:clojure-clr,代码行数:35,代码来源:MapExpr.cs
示例5: Parse
public Expr Parse(ParserContext pcon, object form)
{
int argCount = RT.count(form) - 1;
if (argCount != 1)
{
IPersistentMap exData = new PersistentArrayMap(new Object[] { FormKey, form });
throw new ExceptionInfo("Wrong number of args (" +
argCount +
") passed to quote",
exData);
}
object v = RT.second(form);
if (v == null)
return Compiler.NilExprInstance;
else if (v is Boolean)
{
if ((bool)v)
return Compiler.TrueExprInstance;
else
return Compiler.FalseExprInstance;
}
else if (Util.IsNumeric(v))
return NumberExpr.Parse(v);
else if (v is string)
return new StringExpr((String)v);
else if (v is IPersistentCollection && ((IPersistentCollection)v).count() == 0)
return new EmptyExpr(v);
else
return new ConstantExpr(v);
}
开发者ID:TerabyteX,项目名称:clojure-clr,代码行数:31,代码来源:ConstantExpr.cs
示例6: Parse
public static Expr Parse(ParserContext pcon, IPersistentMap form)
{
ParserContext pconToUse = pcon.EvEx();
bool constant = true;
IPersistentVector keyvals = PersistentVector.EMPTY;
for (ISeq s = RT.seq(form); s != null; s = s.next())
{
IMapEntry e = (IMapEntry)s.first();
Expr k = Compiler.Analyze(pconToUse, e.key());
Expr v = Compiler.Analyze(pconToUse, e.val());
keyvals = (IPersistentVector)keyvals.cons(k);
keyvals = (IPersistentVector)keyvals.cons(v);
if (!(k is LiteralExpr && v is LiteralExpr))
constant = false;
}
Expr ret = new MapExpr(keyvals);
if (form is IObj && ((IObj)form).meta() != null)
return Compiler.OptionallyGenerateMetaInit(pcon, form, ret);
else if (constant)
{
IPersistentMap m = PersistentHashMap.EMPTY;
for (int i = 0; i < keyvals.length(); i += 2)
m = m.assoc(((LiteralExpr)keyvals.nth(i)).Val, ((LiteralExpr)keyvals.nth(i + 1)).Val);
return new ConstantExpr(m);
}
else
return ret;
}
开发者ID:christianblunden,项目名称:clojure-clr,代码行数:29,代码来源:MapExpr.cs
示例7: Parse
public static Expr Parse(ParserContext pcon, IPersistentSet form)
{
ParserContext pconToUse = pcon.EvEx();
bool constant = true;
IPersistentVector keys = PersistentVector.EMPTY;
for (ISeq s = RT.seq(form); s != null; s = s.next())
{
object e = s.first();
Expr expr = Compiler.Analyze(pconToUse, e);
keys = (IPersistentVector)keys.cons(expr);
if (!(expr is LiteralExpr))
constant = false;
}
Expr ret = new SetExpr(keys);
if (form is IObj && ((IObj)form).meta() != null)
return Compiler.OptionallyGenerateMetaInit(pcon, form, ret);
else if (constant)
{
IPersistentSet set = PersistentHashSet.EMPTY;
for (int i = 0; i < keys.count(); i++)
{
LiteralExpr ve = (LiteralExpr)keys.nth(i);
set = (IPersistentSet)set.cons(ve.Val);
}
return new ConstantExpr(set);
}
else
return ret;
}
开发者ID:christianblunden,项目名称:clojure-clr,代码行数:30,代码来源:SetExpr.cs
示例8: Parse
public Expr Parse(ParserContext pcon, object form)
{
Symbol sym = (Symbol)RT.second(form);
Var v = Compiler.LookupVar(sym, false);
if (v != null)
return new TheVarExpr(v);
throw new ParseException(string.Format("Unable to resolve var: {0} in this context", sym));
}
开发者ID:TerabyteX,项目名称:clojure-clr,代码行数:8,代码来源:TheVarExpr.cs
示例9: Parse
public Expr Parse(ParserContext pcon, object frm)
{
string source = (string)Compiler.SourceVar.deref();
IPersistentMap spanMap = (IPersistentMap)Compiler.SourceSpanVar.deref(); // Compiler.GetSourceSpanMap(form);
ISeq form = (ISeq)frm;
IPersistentVector loopLocals = (IPersistentVector)Compiler.LoopLocalsVar.deref();
if (pcon.Rhc != RHC.Return || loopLocals == null)
throw new ParseException("Can only recur from tail position");
if (Compiler.NoRecurVar.deref() != null)
throw new ParseException("Cannot recur across try");
IPersistentVector args = PersistentVector.EMPTY;
for (ISeq s = RT.seq(form.next()); s != null; s = s.next())
args = args.cons(Compiler.Analyze(pcon.SetRhc(RHC.Expression).SetAssign(false), s.first()));
if (args.count() != loopLocals.count())
throw new ParseException(string.Format("Mismatched argument count to recur, expected: {0} args, got {1}",
loopLocals.count(), args.count()));
for (int i = 0; i < loopLocals.count(); i++)
{
LocalBinding lb = (LocalBinding)loopLocals.nth(i);
Type primt = lb.PrimitiveType;
if (primt != null)
{
bool mismatch = false;
Type pt = Compiler.MaybePrimitiveType((Expr)args.nth(i));
if (primt == typeof(long))
{
if (!(pt == typeof(long) || pt == typeof(int) || pt == typeof(short) || pt == typeof(uint) || pt == typeof(ushort) || pt == typeof(ulong)
|| pt == typeof(char) || pt == typeof(byte) || pt == typeof(sbyte)))
mismatch = true;
}
else if (primt == typeof(double))
{
if (!(pt == typeof(double) || pt == typeof(float)))
mismatch = true;
}
if (mismatch)
{
lb.RecurMismatch = true;
if (RT.booleanCast(RT.WarnOnReflectionVar.deref()))
RT.errPrintWriter().WriteLine("{0}:{1} recur arg for primitive local: {2} is not matching primitive, had: {3}, needed {4}",
source, spanMap != null ? (int)spanMap.valAt(RT.StartLineKey, 0) : 0,
lb.Name, pt != null ? pt.Name : "Object", primt.Name);
}
}
}
return new RecurExpr(source, spanMap, loopLocals, args);
}
开发者ID:TerabyteX,项目名称:clojure-clr,代码行数:57,代码来源:RecurExpr.cs
示例10: Parse
public Expr Parse(ParserContext pcon, object frm)
{
ISeq form = (ISeq)frm;
if (RT.Length(form) != 3)
throw new ArgumentException("Malformed assignment, expecting (set! target val)");
Expr target = Compiler.Analyze(new ParserContext(RHC.Expression, true), RT.second(form));
if (!(target is AssignableExpr))
throw new ArgumentException("Invalid assignment target");
return new AssignExpr((AssignableExpr)target,
Compiler.Analyze(pcon.SetRhc(RHC.Expression),RT.third(form)));
}
开发者ID:christianblunden,项目名称:clojure-clr,代码行数:11,代码来源:AssignExpr.cs
示例11: Parse
public Expr Parse(ParserContext pcon, object form)
{
if (pcon.Rhc == RHC.Eval)
return Compiler.Analyze(pcon, RT.list(RT.list(Compiler.FnOnceSym, PersistentVector.EMPTY, form)), "throw__" + RT.nextID());
if (RT.Length((ISeq)form) == 1)
return new ThrowExpr();
if (RT.count(form) > 2)
throw new InvalidOperationException("Too many arguments to throw, throw expects a single Exception instance");
return new ThrowExpr(Compiler.Analyze(pcon.SetRhc(RHC.Expression).SetAssign(false), RT.second(form)));
}
开发者ID:TerabyteX,项目名称:clojure-clr,代码行数:13,代码来源:ThrowExpr.cs
示例12: Parse
public Expr Parse(ParserContext pcon, object frm)
{
ISeq form = (ISeq)frm;
// (if test then) or (if test then else)
if (form.count() > 4)
throw new ParseException("Too many arguments to if");
if (form.count() < 3)
throw new ParseException("Too few arguments to if");
Expr testExpr = Compiler.Analyze(pcon.EvalOrExpr().SetAssign(false),RT.second(form));
Expr thenExpr = Compiler.Analyze(pcon.SetAssign(false), RT.third(form));
Expr elseExpr = Compiler.Analyze(pcon.SetAssign(false), RT.fourth(form));
return new IfExpr((IPersistentMap)Compiler.SourceSpanVar.deref(), testExpr, thenExpr, elseExpr);
}
开发者ID:TerabyteX,项目名称:clojure-clr,代码行数:19,代码来源:IfExpr.cs
示例13: Parse
public Expr Parse(ParserContext pcon, object frms)
{
ISeq forms = (ISeq)frms;
if (Util.equals(RT.first(forms), Compiler.DoSym))
forms = RT.next(forms);
IPersistentVector exprs = PersistentVector.EMPTY;
for (; forms != null; forms = forms.next())
{
Expr e = (pcon.Rhc != RHC.Eval && (pcon.Rhc == RHC.Statement || forms.next() != null))
? Compiler.Analyze(pcon.SetRhc(RHC.Statement), forms.first())
: Compiler.Analyze(pcon, forms.first());
exprs = exprs.cons(e);
}
if (exprs.count() == 0)
exprs = exprs.cons(Compiler.NilExprInstance);
return new BodyExpr(exprs);
}
开发者ID:TerabyteX,项目名称:clojure-clr,代码行数:21,代码来源:BodyExpr.cs
示例14: Parse
public Expr Parse(ParserContext pcon, object frm)
{
return new ImportExpr((string)RT.second(frm));
}
开发者ID:christianblunden,项目名称:clojure-clr,代码行数:4,代码来源:ImportExpr.cs
示例15: Parse
public static Expr Parse(ParserContext pcon, ISeq form, string name)
{
ISeq origForm = form;
FnExpr fn = new FnExpr(Compiler.TagOf(form));
fn._src = form;
if (((IMeta)form.first()).meta() != null)
{
fn._onceOnly = RT.booleanCast(RT.get(RT.meta(form.first()), KW_ONCE));
}
fn.ComputeNames(form, name);
// Java: fn.objtype = Type.getObjectType(fn.internalName) -- makes no sense for us, this is ASM only.
List<string> prims = new List<string>();
try
{
Var.pushThreadBindings(RT.map(
Compiler.CONSTANTS, PersistentVector.EMPTY,
Compiler.CONSTANT_IDS, new IdentityHashMap(),
Compiler.KEYWORDS, PersistentHashMap.EMPTY,
Compiler.VARS, PersistentHashMap.EMPTY,
Compiler.KEYWORD_CALLSITES,PersistentVector.EMPTY,
Compiler.PROTOCOL_CALLSITES,PersistentVector.EMPTY,
Compiler.VAR_CALLSITES,Compiler.EmptyVarCallSites(),
Compiler.NO_RECUR,null));
//arglist might be preceded by symbol naming this fn
if (RT.second(form) is Symbol)
{
Symbol nm = (Symbol)RT.second(form);
fn._thisName = nm.Name;
fn.IsStatic = false; // RT.booleanCast(RT.get(nm.meta(), Compiler.STATIC_KEY));
form = RT.cons(Compiler.FN, RT.next(RT.next(form)));
}
// Normalize body
//now (fn [args] body...) or (fn ([args] body...) ([args2] body2...) ...)
//turn former into latter
if (RT.second(form) is IPersistentVector)
form = RT.list(Compiler.FN, RT.next(form));
SortedDictionary<int, FnMethod> methods = new SortedDictionary<int, FnMethod>();
FnMethod variadicMethod = null;
for (ISeq s = RT.next(form); s != null; s = RT.next(s))
{
FnMethod f = FnMethod.Parse(fn, (ISeq)RT.first(s),fn.IsStatic);
if (f.IsVariadic)
{
if (variadicMethod == null)
variadicMethod = f;
else
throw new Exception("Can't have more than 1 variadic overload");
}
else if (!methods.ContainsKey(f.RequiredArity))
methods[f.RequiredArity] = f;
else
throw new Exception("Can't have 2 overloads with the same arity.");
if (f.Prim != null)
prims.Add(f.Prim);
}
if (variadicMethod != null && methods.Count > 0 && methods.Keys.Max() >= variadicMethod.NumParams)
throw new Exception("Can't have fixed arity methods with more params than the variadic method.");
if ( fn.IsStatic && fn.Closes.count() > 0 )
throw new ArgumentException("static fns can't be closures");
IPersistentCollection allMethods = null;
foreach (FnMethod method in methods.Values)
allMethods = RT.conj(allMethods, method);
if (variadicMethod != null)
allMethods = RT.conj(allMethods, variadicMethod);
fn._methods = allMethods;
fn._variadicMethod = variadicMethod;
fn.Keywords = (IPersistentMap)Compiler.KEYWORDS.deref();
fn.Vars = (IPersistentMap)Compiler.VARS.deref();
fn.Constants = (PersistentVector)Compiler.CONSTANTS.deref();
fn.KeywordCallsites = (IPersistentVector)Compiler.KEYWORD_CALLSITES.deref();
fn.ProtocolCallsites = (IPersistentVector)Compiler.PROTOCOL_CALLSITES.deref();
fn.VarCallsites = (IPersistentSet)Compiler.VAR_CALLSITES.deref();
fn._constantsID = RT.nextID();
}
finally
{
Var.popThreadBindings();
}
IPersistentMap fmeta = RT.meta(origForm);
if (fmeta != null)
fmeta = fmeta.without(RT.LINE_KEY).without(RT.FILE_KEY);
fn._hasMeta = RT.count(fmeta) > 0;
if (Compiler.IsCompiling || prims.Count > 0)
//.........这里部分代码省略.........
开发者ID:davidadsit,项目名称:clojure-clr,代码行数:101,代码来源:FnExpr.cs
示例16: Parse
public Expr Parse(ParserContext pcon, object form)
{
return new MonitorEnterExpr(Compiler.Analyze(pcon.SetRhc(RHC.Expression), RT.second(form)));
}
开发者ID:telefunkenvf14,项目名称:clojure-clr,代码行数:4,代码来源:MonitorEnterExpr.cs
示例17: Parse
public Expr Parse(ParserContext pcon, object frm)
{
ISeq form = (ISeq)frm;
if (pcon.Rhc != RHC.Return)
return Compiler.Analyze(pcon, RT.list(RT.list(Compiler.FN, PersistentVector.EMPTY, form)), "try__" + RT.nextID());
// (try try-expr* catch-expr* finally-expr?)
// catch-expr: (catch class sym expr*)
// finally-expr: (finally expr*)
IPersistentVector body = PersistentVector.EMPTY;
IPersistentVector catches = PersistentVector.EMPTY;
Expr bodyExpr = null;
Expr finallyExpr = null;
bool caught = false;
int retLocal = Compiler.GetAndIncLocalNum();
int finallyLocal = Compiler.GetAndIncLocalNum();
for (ISeq fs = form.next(); fs != null; fs = fs.next())
{
object f = fs.first();
object op = (f is ISeq) ? ((ISeq)f).first() : null;
if (!Util.equals(op, Compiler.CATCH) && !Util.equals(op, Compiler.FINALLY))
{
if (caught)
throw new Exception("Only catch or finally clause can follow catch in try expression");
body = body.cons(f);
}
else
{
if (bodyExpr == null)
bodyExpr = new BodyExpr.Parser().Parse(pcon.SetAssign(false),RT.seq(body));
if (Util.equals(op, Compiler.CATCH))
{
Type t = HostExpr.MaybeType(RT.second(f), false);
if (t == null)
throw new ArgumentException("Unable to resolve classname: " + RT.second(f));
if (!(RT.third(f) is Symbol))
throw new ArgumentException("Bad binding form, expected symbol, got: " + RT.third(f));
Symbol sym = (Symbol)RT.third(f);
if (sym.Namespace != null)
throw new Exception("Can't bind qualified name: " + sym);
IPersistentMap dynamicBindings = RT.map(
Compiler.LOCAL_ENV, Compiler.LOCAL_ENV.deref(),
Compiler.NEXT_LOCAL_NUM, Compiler.NEXT_LOCAL_NUM.deref(),
Compiler.IN_CATCH_FINALLY, true);
try
{
Var.pushThreadBindings(dynamicBindings);
LocalBinding lb = Compiler.RegisterLocal(sym,
(Symbol)(RT.second(f) is Symbol ? RT.second(f) : null),
null,false);
Expr handler = (new BodyExpr.Parser()).Parse(pcon.SetAssign(false), RT.next(RT.next(RT.next(f))));
catches = catches.cons(new CatchClause(t, lb, handler)); ;
}
finally
{
Var.popThreadBindings();
}
caught = true;
}
else // finally
{
if (fs.next() != null)
throw new Exception("finally clause must be last in try expression");
try
{
//Var.pushThreadBindings(RT.map(Compiler.IN_CATCH_FINALLY, RT.T));
Var.pushThreadBindings(RT.map(Compiler.IN_CATCH_FINALLY, true));
finallyExpr = (new BodyExpr.Parser()).Parse(pcon.SetRhc(RHC.Statement).SetAssign(false), RT.next(f));
}
finally
{
Var.popThreadBindings();
}
}
}
}
if ( bodyExpr == null )
bodyExpr = (new BodyExpr.Parser()).Parse(pcon, RT.seq(body));
return new TryExpr(bodyExpr, catches, finallyExpr, retLocal, finallyLocal);
}
开发者ID:christianblunden,项目名称:clojure-clr,代码行数:87,代码来源:TryExpr.cs
示例18: Parse
public Expr Parse(ParserContext pcon, object form)
{
object v = RT.second(form);
if (v == null)
return Compiler.NIL_EXPR;
else
return new ConstantExpr(v);
}
开发者ID:christianblunden,项目名称:clojure-clr,代码行数:8,代码来源:ConstantExpr.cs
示例19: Parse
public Expr Parse(ParserContext pcon, object frm)
{
ISeq form = (ISeq)frm;
// form => (letfn* [var1 (fn [args] body) ... ] body ... )
IPersistentVector bindings = RT.second(form) as IPersistentVector;
if (bindings == null)
throw new ParseException("Bad binding form, expected vector");
if ((bindings.count() % 2) != 0)
throw new ParseException("Bad binding form, expected matched symbol/expression pairs.");
ISeq body = RT.next(RT.next(form));
if (pcon.Rhc == RHC.Eval)
return Compiler.Analyze(pcon, RT.list(RT.list(Compiler.FnOnceSym, PersistentVector.EMPTY, form)), "letfn__" + RT.nextID());
IPersistentMap dynamicBindings = RT.map(
Compiler.LocalEnvVar, Compiler.LocalEnvVar.deref(),
Compiler.NextLocalNumVar, Compiler.NextLocalNumVar.deref());
try
{
Var.pushThreadBindings(dynamicBindings);
// pre-seed env (like Lisp labels)
IPersistentVector lbs = PersistentVector.EMPTY;
for (int i = 0; i < bindings.count(); i += 2)
{
if (!(bindings.nth(i) is Symbol))
throw new ParseException("Bad binding form, expected symbol, got " + bindings.nth(i));
Symbol sym = (Symbol)bindings.nth(i);
if (sym.Namespace != null)
throw new ParseException("Can't let qualified name: " + sym);
LocalBinding b = Compiler.RegisterLocal(sym, Compiler.TagOf(sym), null, typeof(Object), false);
// b.CanBeCleared = false;
lbs = lbs.cons(b);
}
IPersistentVector bindingInits = PersistentVector.EMPTY;
for (int i = 0; i < bindings.count(); i += 2)
{
Symbol sym = (Symbol)bindings.nth(i);
Expr init = Compiler.Analyze(pcon.SetRhc(RHC.Expression),bindings.nth(i + 1),sym.Name);
LocalBinding b = (LocalBinding)lbs.nth(i / 2);
b.Init = init;
BindingInit bi = new BindingInit(b, init);
bindingInits = bindingInits.cons(bi);
}
return new LetFnExpr(bindingInits,new BodyExpr.Parser().Parse(pcon, body));
}
finally
{
Var.popThreadBindings();
}
}
开发者ID:clojure,项目名称:clojure-clr,代码行数:61,代码来源:LetFnExpr.cs
示例20: Parse
public Expr Parse(ParserContext pcon, object frm)
{
ISeq form = (ISeq)frm;
// form is one of:
// (. x fieldname-sym)
// (. x 0-ary-method)
// (. x propertyname-sym)
// (. x methodname-sym args)+
// (. x (methodname-sym args?))
// (. x (generic-m
if (RT.Length(form) < 3)
throw new ArgumentException("Malformed member expression, expecting (. target member ... )");
string source = (string)Compiler.SOURCE.deref();
IPersistentMap spanMap = (IPersistentMap)Compiler.SOURCE_SPAN.deref(); // Compiler.GetSourceSpanMap(form);
Symbol tag = Compiler.TagOf(form);
// determine static or instance
// static target must be symbol, either fully.qualified.Typename or Typename that has been imported
Type t = HostExpr.MaybeType(RT.second(form), false);
// at this point, t will be non-null if static
Expr instance = null;
if (t == null)
instance = Compiler.Analyze(pcon.EvEx(),RT.second(form));
bool isZeroArityCall = RT.Length(form) == 3 && (RT.third(form) is Symbol || RT.third(form) is Keyword);
if (isZeroArityCall)
{
PropertyInfo pinfo = null;
FieldInfo finfo = null;
MethodInfo minfo = null;
Symbol sym = (RT.third(form) is Keyword) ? ((Keyword)RT.third(form)).Symbol : (Symbol)RT.third(form);
string fieldName = Compiler.munge(sym.Name);
// The JVM version does not have to worry about Properties. It captures 0-arity methods under fields.
// We have to put in special checks here for this.
// Also, when reflection is required, we have to capture 0-arity methods under the calls that
// are generated by StaticFieldExpr and InstanceFieldExpr.
if (t != null)
{
if ((finfo = Reflector.GetField(t, fieldName, true)) != null)
return new StaticFieldExpr(source, spanMap, tag, t, fieldName, finfo);
if ((pinfo = Reflector.GetProperty(t, fieldName, true)) != null)
return new StaticPropertyExpr(source, spanMap, tag, t, fieldName, pinfo);
if ((minfo = Reflector.GetArityZeroMethod(t, fieldName, true)) != null)
return new StaticMethodExpr(source, spanMap, tag, t, fieldName, null, new List<HostArg>());
throw new MissingMemberException(t.Name, fieldName);
}
else if (instance != null && instance.HasClrType && instance.ClrType != null)
{
Type instanceType = instance.ClrType;
if ((finfo = Reflector.GetField(instanceType, fieldName, false)) != null)
return new InstanceFieldExpr(source, spanMap, tag, instance, fieldName, finfo);
if ((pinfo = Reflector.GetProperty(instanceType, fieldName, false)) != null)
return new InstancePropertyExpr(source, spanMap, tag, instance, fieldName, pinfo);
if ((minfo = Reflector.GetArityZeroMethod(instanceType, fieldName, false)) != null)
return new InstanceMethodExpr(source, spanMap, tag, instance, fieldName, null, new List<HostArg>());
if (pcon.IsAssignContext)
return new InstanceFieldExpr(source, spanMap, tag, instance, fieldName, null); // same as InstancePropertyExpr when last arg is null
else
return new InstanceZeroArityCallExpr(source, spanMap, tag, instance, fieldName);
}
else
{
// t is null, so we know this is not a static call
// If instance is null, we are screwed anyway.
// If instance is not null, then we don't have a type.
// So we must be in an instance call to a property, field, or 0-arity method.
// The code generated by InstanceFieldExpr/InstancePropertyExpr with a null FieldInfo/PropertyInfo
// will generate code to do a runtime call to a Reflector method that will check all three.
//return new InstanceFieldExpr(source, spanMap, tag, instance, fieldName, null); // same as InstancePropertyExpr when last arg is null
//return new InstanceZeroArityCallExpr(source, spanMap, tag, instance, fieldName);
if (pcon.IsAssignContext)
return new InstanceFieldExpr(source, spanMap, tag, instance, fieldName, null); // same as InstancePropertyExpr when last arg is null
else
return new InstanceZeroArityCallExpr(source, spanMap, tag, instance, fieldName);
}
}
//ISeq call = RT.third(form) is ISeq ? (ISeq)RT.third(form) : RT.next(RT.next(form));
ISeq call;
List<Type> typeArgs = null;
//object third = RT.third(form);
//if (third is ISeq && RT.first(third) is Symbol && ((Symbol)RT.first(third)).Equals(GENERIC))
//{
// // We have a generic method call
// // (. thing (generic methodname type1 ...) args...)
// typeArgs = ParseGenericMethodTypeArgs(RT.next(RT.next(third)));
// call = RT.listStar(RT.second(third), RT.next(RT.next(RT.next(form))));
//}
//.........这里部分代码省略.........
开发者ID:davidadsit,项目名称:clojure-clr,代码行数:101,代码来源:HostExpr.cs
注:本文中的clojure.lang.CljCompiler.Ast.ParserContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论