public void AddField(string typeName, Assign n) { var info = TypeBuilderMap[typeName]; if (info.FieldMap.ContainsKey(n.Name)) return; var flags = FieldAttributes.Public; if (Enum.GetNames(typeof(InternalTrancheTypes)).Contains(n.Name) || typeName == "Simulation") flags |= FieldAttributes.Static; var type = n.Qualifier == null ? LookupCilType(n.InternalType) : LookupCilType(n.Qualifier.InternalType); var fieldBuilder = info.Builder.DefineField(n.Name, type, flags); info.FieldMap.Add(n.Name, fieldBuilder); }
public override void VisitAssign(Assign n) { InternalType declFieldType; if(n.Expr != null) declFieldType = CheckSubTree(n.Expr); else if(n.Statement != null) declFieldType = CheckSubTree(n.Expr); else declFieldType = CheckSubTree(n.Qualifier); n.InternalType = declFieldType; var desc = _mgr.AddMember(n.LValue.Id, declFieldType, _currentClass); n.Descriptor = desc; }
public override void VisitAssign(Assign n) { _typeManager.AddField(_currentType, n); //we're treating everything like a field (for now) n.LValue.Visit(this); if(n.Expr != null) n.Expr.Visit(this); else if (n.Statement != null) n.Statement.Visit(this); else n.Qualifier.Visit(this); ApplyAssignmentCallback(); }
private void SetupInternalClass(DeclarationClass n, string name) { _typeManager.AddClass(n); if (name.Equals(ENTRY_POINT, StringComparison.OrdinalIgnoreCase)) { var methodInfo = CreateEntryPointMethod(n, name); _gen = methodInfo.Builder.GetILGenerator(); foreach (var item in Enum.GetNames(typeof(InternalTrancheTypes))) { var ident = new Identifier(n.Location, item); var instantiate = new InstantiateClass(item, new ExpressionList()); var assign = new Assign(ident, instantiate) {InternalType = new TypeClass(item)}; VisitAssign(assign); } _assemblyBuilder.SetEntryPoint(methodInfo.Builder); } else { var ctorInfo = CreateInternalClassCtor(n, name); _gen = ctorInfo.Builder.GetILGenerator(); var baseCtor = typeof(object).GetConstructor(Type.EmptyTypes); _gen.Emit(OpCodes.Ldarg_0); //this. if (baseCtor != null) _gen.Emit(OpCodes.Call, baseCtor); } }