Esempio n. 1
0
        public void AddField(string typeName, ASTDeclarationField n)
        {
            TypeBuilderInfo info = TypeBuilderMap[typeName];

            //define the field in the type builder, and save the FieldBuiler in a map, keyed off the name of the field
            FieldBuilder fieldBuilder = info.Builder.DefineField(n.Name, LookupCilType(n.Type), FieldAttributes.Public);

            info.FieldMap.Add(n.Name, fieldBuilder);
        }
Esempio n. 2
0
        public void AddCtor(string typeName, ASTDeclarationCtor n)
        {
            TypeBuilderInfo info     = TypeBuilderMap[typeName];
            TypeFunction    function = n.Type as TypeFunction;

            ConstructorBuilder builderObj = info.Builder.DefineConstructor(MethodAttributes.Public,
                                                                           CallingConventions.Standard,
                                                                           ArgumentTypes(function));

            info.ConstructorBuilder = new ConstructorBuilderInfo(builderObj, BuildFormalMap(n.Descriptor.Formals));
        }
Esempio n. 3
0
        public void AddMethod(string typeName, ASTDeclarationMethod n)
        {
            TypeBuilderInfo info = TypeBuilderMap[typeName];

            //we need to know the CIL type for the return type and arguments
            Type         returnType = LookupCilType(n.ReturnType);
            TypeFunction function   = n.Type as TypeFunction;

            MethodBuilder methodBuilder = info.Builder.DefineMethod(n.Name,
                                                                    MethodAccessibility(n),
                                                                    returnType,
                                                                    ArgumentTypes(function));

            //store this MethodBuilder, keyed off its name
            info.MethodMap.Add(n.Name, new MethodBuilderInfo(methodBuilder, BuildFormalMap(n.Descriptor.Formals)));
        }
Esempio n. 4
0
        public override void VisitDerefField(ASTDereferenceField n)
        {
            //visit the identifier
            n.Object.Visit(this);
            TypeBuilderInfo info  = _typeManager.GetBuilderInfo(_lastWalkedType.Name);
            FieldBuilder    field = info.FieldMap[n.Field];

            //store the type that we're dereferencing
            _lastWalkedType = field.FieldType;

            //see what we need to do after visiting the identifier
            if (!n.IsLeftHandSide)
            {
                _gen.Emit(OpCodes.Ldfld, field);
            }
            else
            {
                _assignmentCallback = gen => gen.Emit(OpCodes.Stfld, field); //set what needs to happen at the end of the assignment
            }
        }
Esempio n. 5
0
 public override void VisitClassDefinition(ASTClassDefinition n)
 {
     _currentTypeBuilder = _typeManager.GetBuilderInfo(n.Name);
     n.Declarations.Visit(this);
 }
Esempio n. 6
0
 public TypeBuilderInfo(ASTSubClassDefinition n, ModuleBuilder module, TypeBuilderInfo parent)
 {
     Builder = module.DefineType(n.Name, TypeAttributes.Public, parent.Builder);
     Init();
 }