Ejemplo n.º 1
0
        void CreateSharedLocalsClass()
        {
            _shared.Clear();

            CollectSharedLocalEntities(_currentMethod.Locals);
            CollectSharedLocalEntities(_currentMethod.Parameters);

            if (_shared.Count > 0)
            {
                BooClassBuilder builder = CodeBuilder.CreateClass(
                    string.Format("___locals{0}", _context.AllocIndex()));
                builder.AddBaseType(TypeSystemServices.ObjectType);

                int i = 0;
                foreach (ILocalEntity local in _shared)
                {
                    Field field = builder.AddField(
                        string.Format("___{0}_{1}", local.Name, i),
                        local.Type);
                    field.Modifiers = TypeMemberModifiers.Internal;
                    ++i;

                    _mappings[local] = field.Entity;
                }

                builder.AddConstructor().Body.Add(
                    CodeBuilder.CreateSuperConstructorInvocation(TypeSystemServices.ObjectType));

                _sharedLocalsClass = builder.ClassDefinition;
            }
        }
Ejemplo n.º 2
0
        BooMethodBuilder CreateConstructor(BooClassBuilder builder)
        {
            BooMethodBuilder constructor = builder.AddConstructor();

            constructor.Body.Add(CodeBuilder.CreateSuperConstructorInvocation(builder.Entity.BaseType));
            return(constructor);
        }
Ejemplo n.º 3
0
        public void DeclareFieldsAndConstructor(BooClassBuilder builder)
        {
            var keys = _referencedEntities.Keys.Cast <ITypedEntity>().ToArray();

            foreach (var entity in keys)
            {
                _collector.Visit(entity.Type);
            }
            if (_collector.Matches.Any())
            {
                BuildTypeMap(builder.ClassDefinition);
            }

            // referenced entities turn into fields
            foreach (var entity in keys)
            {
                Field field = builder.AddInternalField(GetUniqueName(entity.Name), _mapper.MapType(entity.Type));
                _referencedEntities[entity] = (InternalField)field.Entity;
            }

            // single constructor taking all referenced entities
            BooMethodBuilder constructor = builder.AddConstructor();

            constructor.Modifiers = TypeMemberModifiers.Public;
            constructor.Body.Add(CodeBuilder.CreateSuperConstructorInvocation(builder.Entity.BaseType));
            foreach (var entity in _referencedEntities.Keys)
            {
                InternalField        field     = _referencedEntities[entity];
                ParameterDeclaration parameter = constructor.AddParameter(field.Name, ((ITypedEntity)entity).Type);
                constructor.Body.Add(
                    CodeBuilder.CreateAssignment(CodeBuilder.CreateReference(field),
                                                 CodeBuilder.CreateReference(parameter)));
            }
        }
Ejemplo n.º 4
0
        private void CreateSharedLocalsClass()
        {
            _shared.Clear();

            CollectSharedLocalEntities(_currentMethod.Locals);
            CollectSharedLocalEntities(_currentMethod.Parameters);

            if (_shared.Count > 0)
            {
                BooClassBuilder builder = CodeBuilder.CreateClass(Context.GetUniqueName(_currentMethod.Name, "locals"));
                builder.Modifiers |= TypeMemberModifiers.Internal;
                builder.AddBaseType(TypeSystemServices.ObjectType);

                var genericsSet = new HashSet <string>();
                var replacer    = new GeneratorTypeReplacer();
                foreach (ILocalEntity local in _shared)
                {
                    CheckTypeForGenericParams(local.Type, genericsSet, builder, replacer);
                    Field field = builder.AddInternalField(
                        string.Format("${0}", local.Name),
                        replacer.MapType(local.Type));

                    _mappings[local] = (IField)field.Entity;
                }

                builder.AddConstructor().Body.Add(
                    CodeBuilder.CreateSuperConstructorInvocation(TypeSystemServices.ObjectType));

                _sharedLocalsClass = builder.ClassDefinition;
            }
        }
Ejemplo n.º 5
0
        void CreateSharedLocalsClass()
        {
            _shared.Clear();

            CollectSharedLocalEntities(_currentMethod.Locals);
            CollectSharedLocalEntities(_currentMethod.Parameters);

            if (_shared.Count > 0)
            {
                BooClassBuilder builder = CodeBuilder.CreateClass(Context.GetUniqueName(_currentMethod.Name, "locals"));
                builder.Modifiers |= TypeMemberModifiers.Internal;
                builder.AddBaseType(TypeSystemServices.ObjectType);

                var genericsSet = new System.Collections.Generic.HashSet <string>();
                foreach (ILocalEntity local in _shared)
                {
                    Field field = builder.AddInternalField(
                        string.Format("${0}", local.Name),
                        local.Type);
                    if (local.Type is IGenericParameter && !genericsSet.Contains(local.Type.Name))
                    {
                        builder.AddGenericParameter(local.Type.Name);
                        genericsSet.Add(local.Type.Name);
                    }

                    _mappings[local] = field.Entity;
                }

                builder.AddConstructor().Body.Add(
                    CodeBuilder.CreateSuperConstructorInvocation(TypeSystemServices.ObjectType));

                _sharedLocalsClass = builder.ClassDefinition;
            }
        }
 public void ChainConstructorsFromBaseType(BooClassBuilder builder)
 {
     foreach (IConstructor constructor in builder.Entity.BaseType.GetConstructors())
     {
         ExpressionStatement        stmt       = this.CodeBuilder.CreateSuperConstructorInvocation(constructor);
         MethodInvocationExpression expression = stmt.Expression as MethodInvocationExpression;
         BooMethodBuilder           builder2   = builder.AddConstructor();
         int          index      = 0;
         IParameter[] parameters = constructor.GetParameters();
         int          length     = parameters.Length;
         while (index < length)
         {
             ParameterDeclaration parameter = builder2.AddParameter(parameters[index].Name, parameters[index].Type);
             expression.Arguments.Add(this.CodeBuilder.CreateReference(parameter));
             index++;
         }
         builder2.Body.Add(stmt);
     }
 }
 public void ChainConstructorsFromBaseType(BooClassBuilder builder)
 {
     foreach (IConstructor constructor in TypeSystemExtensions.GetConstructors(builder.get_Entity().get_BaseType()))
     {
         ExpressionStatement statement = this.get_CodeBuilder().CreateSuperConstructorInvocation(constructor);
         MethodInvocationExpression expression = statement.get_Expression() as MethodInvocationExpression;
         BooMethodBuilder builder2 = builder.AddConstructor();
         int index = 0;
         IParameter[] parameters = constructor.GetParameters();
         int length = parameters.Length;
         while (index < length)
         {
             ParameterDeclaration declaration = builder2.AddParameter(parameters[index].get_Name(), parameters[index].get_Type());
             expression.get_Arguments().Add(this.get_CodeBuilder().CreateReference(declaration));
             index++;
         }
         builder2.get_Body().Add(statement);
     }
 }
Ejemplo n.º 8
0
        public void DeclareFieldsAndConstructor(BooClassBuilder builder)
        {
            // referenced entities turn into fields
            foreach (ITypedEntity entity in Builtins.array(_referencedEntities.Keys))
            {
                Field field = builder.AddField("__" + entity.Name + _context.AllocIndex(), entity.Type);
                field.Modifiers             = TypeMemberModifiers.Internal;
                _referencedEntities[entity] = field.Entity;
            }

            // single constructor taking all referenced entities
            BooMethodBuilder constructor = builder.AddConstructor();

            constructor.Body.Add(CodeBuilder.CreateSuperConstructorInvocation(builder.Entity.BaseType));
            foreach (ITypedEntity entity in _referencedEntities.Keys)
            {
                InternalField        field     = (InternalField)_referencedEntities[entity];
                ParameterDeclaration parameter = constructor.AddParameter(field.Name, entity.Type);
                constructor.Body.Add(
                    CodeBuilder.CreateAssignment(CodeBuilder.CreateReference(field),
                                                 CodeBuilder.CreateReference(parameter)));
            }
        }
Ejemplo n.º 9
0
		BooMethodBuilder CreateConstructor(BooClassBuilder builder)
		{
			BooMethodBuilder constructor = builder.AddConstructor();
			constructor.Body.Add(CodeBuilder.CreateSuperConstructorInvocation(builder.Entity.BaseType));
			return constructor;
		}
Ejemplo n.º 10
0
        ClassDefinition CreateAdaptor(ICallableType to, ICallableType from)
        {
            BooClassBuilder adaptor = CodeBuilder.CreateClass("$adaptor$" + from.Name + "$" + to.Name + "$" + _adaptors.Count);

            adaptor.AddBaseType(TypeSystemServices.ObjectType);
            adaptor.Modifiers = TypeMemberModifiers.Final | TypeMemberModifiers.Internal;

            Field callable = adaptor.AddField("$from", from);

            BooMethodBuilder     constructor = adaptor.AddConstructor();
            ParameterDeclaration param       = constructor.AddParameter("from", from);

            constructor.Body.Add(
                CodeBuilder.CreateSuperConstructorInvocation(TypeSystemServices.ObjectType));
            constructor.Body.Add(
                CodeBuilder.CreateAssignment(
                    CodeBuilder.CreateReference(callable),
                    CodeBuilder.CreateReference(param)));

            CallableSignature signature = to.GetSignature();
            BooMethodBuilder  invoke    = adaptor.AddMethod("Invoke", signature.ReturnType);

            foreach (IParameter parameter in signature.Parameters)
            {
                invoke.AddParameter(parameter.Name, parameter.Type, parameter.IsByRef);
            }
            MethodInvocationExpression mie = CodeBuilder.CreateMethodInvocation(
                CodeBuilder.CreateReference(callable),
                GetInvokeMethod(from));
            int fromParameterCount = from.GetSignature().Parameters.Length;

            for (int i = 0; i < fromParameterCount; ++i)
            {
                mie.Arguments.Add(
                    CodeBuilder.CreateReference(invoke.Parameters[i]));
            }
            if (signature.ReturnType != TypeSystemServices.VoidType &&
                from.GetSignature().ReturnType != TypeSystemServices.VoidType)
            {
                invoke.Body.Add(new ReturnStatement(mie));
            }
            else
            {
                invoke.Body.Add(mie);
            }

            BooMethodBuilder adapt = adaptor.AddMethod("Adapt", to);

            adapt.Modifiers = TypeMemberModifiers.Static | TypeMemberModifiers.Public;
            param           = adapt.AddParameter("from", from);
            adapt.Body.Add(
                new ReturnStatement(
                    CodeBuilder.CreateConstructorInvocation(
                        to.GetConstructors().First(),
                        CodeBuilder.CreateConstructorInvocation(
                            (IConstructor)constructor.Entity,
                            CodeBuilder.CreateReference(param)),
                        CodeBuilder.CreateAddressOfExpression(invoke.Entity))));

            RegisterAdaptor(to, from, adaptor.ClassDefinition);

            return(adaptor.ClassDefinition);
        }
Ejemplo n.º 11
0
        public void DeclareFieldsAndConstructor(BooClassBuilder builder)
        {
            // referenced entities turn into fields
            foreach (ITypedEntity entity in Builtins.array(_referencedEntities.Keys))
            {
                Field field = builder.AddInternalField(GetUniqueName(entity.Name), entity.Type);
                _referencedEntities[entity] = field.Entity;
            }

            // single constructor taking all referenced entities
            BooMethodBuilder constructor = builder.AddConstructor();
            constructor.Modifiers = TypeMemberModifiers.Public;
            constructor.Body.Add(CodeBuilder.CreateSuperConstructorInvocation(builder.Entity.BaseType));
            foreach (ITypedEntity entity in _referencedEntities.Keys)
            {
                InternalField field = (InternalField)_referencedEntities[entity];
                ParameterDeclaration parameter = constructor.AddParameter(field.Name, entity.Type);
                constructor.Body.Add(
                    CodeBuilder.CreateAssignment(CodeBuilder.CreateReference(field),
                                    CodeBuilder.CreateReference(parameter)));
            }
        }
Ejemplo n.º 12
0
        protected override BooMethodBuilder CreateConstructor(BooClassBuilder builder)
        {
            BooMethodBuilder constructor = builder.AddConstructor();

            return(constructor);
        }