private void HandleInternalType(string name, DeclarationClass n) { SetupInternalClass(n, name); if(n.Statements != null) n.Statements.Visit(this); _gen.Emit(OpCodes.Ret); }
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); } }
//this is a special case since it will be the entry point.. private MethodBuilderInfo CreateEntryPointMethod(DeclarationClass n, string name) { _currentType = name; _currentTypeBuilder = _typeManager.GetBuilderInfo(n.Name); var method = new DeclarationMethod(name, n.Statements) { Type = new TypeFunction(true), Descriptor = new MethodDescriptor(n.Type, name, n.Descriptor) }; _typeManager.AddMethod(name, method); return _typeManager.GetMethodBuilderInfo(_currentType, n.Name); }
private ConstructorBuilderInfo CreateInternalClassCtor(DeclarationClass n, string name) { _currentType = name; _currentTypeBuilder = _typeManager.GetBuilderInfo(n.Name); var method = new DeclarationMethod(name, n.Statements) { Type = new TypeFunction(true), Descriptor = new MethodDescriptor(n.Type, name, n.Descriptor) }; _typeManager.AddCtor(name, method); return _currentTypeBuilder.ConstructorBuilder; }
public override void VisitDeclarationClass(DeclarationClass n) { _itemIncrementer = 0; _currentClass = new TypeClass(n.Name); var classScope = _mgr.PushScope(string.Format("class {0}", _currentClass.ClassName)); _currentClass.Descriptor = (ClassDescriptor)_mgr.Find(n.Name, p => p is ClassDescriptor); if(n.Statements != null) CheckSubTree(n.Statements); n.Type = _currentClass; _currentClass.Descriptor.Scope = _currentClass.Scope = classScope; AddCtorIfNone(classScope, n.Name); _mgr.PopScope(); }
public void AddClass(DeclarationClass n) { TypeBuilderMap.Add(n.Name, new TypeBuilderInfo(n, Module)); }
private void AddInternalClass(string name) { var decl = new DeclarationClass(name, new StatementList()); TypeBuilderMap.Add(name, new TypeBuilderInfo(decl, Module)); var entry = TypeBuilderMap[name]; var builderObj = entry.Builder.DefineDefaultConstructor(MethodAttributes.Public); entry.ConstructorBuilder = new ConstructorBuilderInfo(builderObj); }
public override void VisitDeclarationClass(DeclarationClass n) { var cls = new TypeClass(n.Name); _currentClass = cls; n.Descriptor = _scopeMgr.AddClass(cls.ClassName, cls); n.Type = cls; }
public TypeBuilderInfo(DeclarationClass n, ModuleBuilder module) { Builder = module.DefineType(n.Name, TypeAttributes.Public); Init(); }