public override Exp Analy( ) { if (this.IsAnalyed) { return(this); } SubjectExp = AnalySubExp(SubjectExp); ArgExp = AnalySubExp(ArgExp); if (!this.AnalyCorrect) { return(this); } var propertyName = ZLangUtil.ZListItemPropertyName; var subjType = SubjectExp.RetType; if (subjType is ZLClassInfo) { ZLClassInfo zclass = subjType as ZLClassInfo; Type argType = ZTypeUtil.GetTypeOrBuilder(ArgExp.RetType); Property = zclass.SharpType.GetProperty(propertyName, new Type[] { argType }); } if (Property == null) { Errorf(SubjectExp.Position, "不存在索引"); } else { RetType = ZTypeManager.GetBySharpType(Property.PropertyType) as ZType; } IsAnalyed = true; return(this); }
public override Exp Analy( ) { //SubjectExp.SetContext(this.ExpContext); //ArgExp.SetContext(this.ExpContext); SubjectExp = AnalySubExp(SubjectExp); // SubjectExp.Analy(); ArgExp = AnalySubExp(ArgExp); //ArgExp = ArgExp.Analy(); if (!this.AnalyCorrect) { return(this); } var propertyName = CompileConstant.ZListItemPropertyName;// "Item"; var subjType = SubjectExp.RetType; if (subjType is ZClassType) { ZClassType zclass = subjType as ZClassType; Property = zclass.SharpType.GetProperty(propertyName); } if (Property == null) { ErrorE(SubjectExp.Postion, "不存在索引"); } else { RetType = ZTypeManager.GetBySharpType(Property.PropertyType) as ZType; } return(this); }
public override Exp Analy( ) { if (this.IsAnalyed) { return(this); } AnalyCorrect = true; if (LeftExp == null && RightExp != null) { ExpUnary unexp = new ExpUnary(this.ExpContext, OpToken, RightExp); var exp = unexp.Analy(); return(exp); } else if (LeftExp == null && RightExp == null) { Errorf(this.OpToken.Position, "运算符'{0}'两边缺少表达式", OpToken.Text); } OpKind = OpToken.Kind; LeftExp = AnalySubExp(LeftExp); RightExp = AnalySubExp(RightExp); if (RightExp == null) { Errorf(OpToken.Position, "运算符'{0}'右边缺少运算元素", OpToken.Text); } else { this.AnalyCorrect = this.LeftExp.AnalyCorrect && RightExp.AnalyCorrect && this.AnalyCorrect; if (LeftExp.AnalyCorrect && RightExp.AnalyCorrect) { ZType ltype = LeftExp.RetType; ZType rtype = RightExp.RetType; if (ZTypeUtil.IsVoid(ltype) || ZTypeUtil.IsVoid(rtype)) { Errorf(OpToken.Position, "没有结果的表达式无法进行'{0}'运算", OpToken.ToCode()); } else { OpMethod = ExpBinaryUtil.GetCalcMethod(OpKind, ltype, rtype); if (OpMethod != null) { RetType = ZTypeManager.GetBySharpType(OpMethod.ReturnType) as ZType; } else { Errorf(OpToken.Position, "两种类型无法进行'{0}'运算", OpToken.ToCode()); } } } else { this.RetType = ZLangBasicTypes.ZOBJECT; } } //AnalyResultLocal(); IsAnalyed = true; return(this); }
public void EmitGet( ) { MethodInfo getMethod = Property.GetGetMethod(); SubjectExp.Emit(); ArgExp.RequireType = ZTypeManager.GetBySharpType(getMethod.ReturnType) as ZType; ArgExp.Emit(); EmitHelper.CallDynamic(IL, getMethod); }
public override Exp Analy( ) { //var propertyName = "Item"; var subjType = ListSymbol.SymbolZType; ZClassType zclass = subjType as ZClassType; Property = zclass.SharpType.GetProperty(CompileConstant.ZListItemPropertyName);//propertyName); RetType = ZTypeManager.GetBySharpType(Property.PropertyType) as ZType; return(this); }
protected void EmitArgsExp(ParameterInfo[] paramInfos, Exp[] args) { var size = paramInfos.Length; for (int i = 0; i < size; i++) { Exp argExp = args[i]; ParameterInfo parameter = paramInfos[i]; argExp.RequireType = ZTypeManager.GetBySharpType(parameter.ParameterType) as ZType; argExp.Emit(); } }
public void EmitSet(Exp valueExp) { MethodInfo setMethod = Property.GetSetMethod(); SubjectExp.Emit(); ArgExp.RequireType = ZTypeManager.GetBySharpType(setMethod.GetParameters()[0].ParameterType) as ZType; ArgExp.Emit(); //EmitHelper.Box(il, ArgExp.RetType, setMethod.GetParameters()[0].ParameterType); valueExp.RequireType = ZTypeManager.GetBySharpType(setMethod.GetParameters()[1].ParameterType) as ZType; valueExp.Emit(); EmitHelper.CallDynamic(IL, setMethod); }
public override Exp Analy( ) { if (this.IsAnalyed) { return(this); } var subjType = ListSymbol.GetZType(); ZLClassInfo zclass = subjType as ZLClassInfo; Property = zclass.SharpType.GetProperty(ZLangUtil.ZListItemPropertyName); RetType = ZTypeManager.GetBySharpType(Property.PropertyType) as ZType; IsAnalyed = true; return(this); }
public override Exp Analy( ) { if (LeftExp == null && RightExp != null) { ExpUnary unexp = new ExpUnary(OpToken, RightExp, this.ExpContext); //unexp.SetContext(this.ExpContext); var exp = unexp.Analy(); return(exp); } else if (LeftExp == null && RightExp == null) { ErrorE(this.OpToken.Position, "运算符'{0}'两边缺少表达式", OpToken.GetText()); //AnalyResult = false; } OpKind = OpToken.Kind; LeftExp = AnalySubExp(LeftExp); RightExp = AnalySubExp(RightExp); if (RightExp == null) { ErrorE(OpToken.Position, "运算符'{0}'右边缺少运算元素", OpToken.GetText()); //AnalyResult = false; } else { if (LeftExp.AnalyCorrect && RightExp.AnalyCorrect) { ZType ltype = LeftExp.RetType; ZType rtype = RightExp.RetType; OpMethod = ExpBinaryUtil.GetCalcMethod(OpKind, ltype.SharpType, rtype.SharpType); if (OpMethod != null) { RetType = ZTypeManager.GetBySharpType(OpMethod.ReturnType) as ZType; } else { ErrorE(OpToken.Position, "两种类型无法进行'{0}'运算", OpToken.ToCode()); } } } return(this); }
//private void AnalyListExp() //{ // ListExp = AnalyExpRaw(); // if (ListExp == null) // { // Errorf(ForeachToken.Position, "循环每一个语句没有表达式"); // } // else // { // ListExp = ListExp.Analy(); // } //} //private Exp AnalyExpRaw() //{ // ExpRaw rawExp = Raw.ListExp;// (Exp)ListExp; // ContextExp context = new ContextExp(this.ProcContext, this); // //rawExp.SetContext(context); // List<LexToken> tokens = rawExp.Seg(); // ExpParser parser = new ExpParser(); // Exp exp = parser.Parse(tokens, this.ProcContext.ClassContext.FileContext); // //exp.SetContext(rawExp.ExpContext); // return exp; //} protected void CreateEachSymbols() { var procContext = this.ProcContext; int foreachIndex = procContext.CreateRepeatIndex(); var indexName = "@foreach" + foreachIndex + "_index"; var countName = "@foreach" + foreachIndex + "_count"; var listName = "@foreach" + foreachIndex + "_list"; var itemName = this.Raw.ItemToken.Text; indexSymbol = new ZCLocalVar(indexName, ZLangBasicTypes.ZINT, true); //indexSymbol.LoacalVarIndex = procContext.CreateLocalVarIndex(indexName); this.ProcContext.AddLocalVar(indexSymbol); countSymbol = new ZCLocalVar(countName, ZLangBasicTypes.ZINT, true); //countSymbol.LoacalVarIndex = procContext.CreateLocalVarIndex(countName); this.ProcContext.AddLocalVar(countSymbol); listSymbol = new ZCLocalVar(listName, this.ForeachListExp.RetType, true); //listSymbol.LoacalVarIndex = procContext.CreateLocalVarIndex(listName); this.ProcContext.AddLocalVar(listSymbol); var listType = ZTypeUtil.GetTypeOrBuilder(this.ForeachListExp.RetType); Type[] genericTypes = GenericUtil.GetInstanceGenriceType(listType, typeof(列表 <>)); if (genericTypes.Length == 0) { genericTypes = GenericUtil.GetInstanceGenriceType(listType, typeof(IList <>)); } Type ElementType = genericTypes[0]; itemSymbol = new ZCLocalVar(itemName, (ZType)(ZTypeManager.GetBySharpType(ElementType)), true); //itemSymbol.LoacalVarIndex = procContext.CreateLocalVarIndex(itemName); this.ProcContext.AddLocalVar(itemSymbol); }
protected void EmitArgsExp(IEnumerable <Exp> args, IEnumerable <ParameterInfo> paras) { var ztypes = paras.Select(p => (ZTypeManager.GetBySharpType(p.ParameterType) as ZType)).ToArray(); EmitArgsExp(args, ztypes); }