예제 #1
0
        void PropagateReferences(MethodInvocationExpression enumerableConstructorInvocation,
                                 MethodInvocationExpression enumeratorConstructorInvocation)
        {
            // propagate the necessary parameters from
            // the enumerable to the enumerator
            foreach (ParameterDeclaration parameter in _generator.Method.Parameters)
            {
                InternalParameter entity = (InternalParameter)parameter.Entity;
                if (entity.IsUsed)
                {
                    enumerableConstructorInvocation.Arguments.Add(
                        CodeBuilder.CreateReference(parameter));

                    PropagateFromEnumerableToEnumerator(enumeratorConstructorInvocation,
                                                        entity.Name,
                                                        entity.Type);
                }
            }

            // propagate the external self reference if necessary
            if (null != _externalEnumeratorSelf)
            {
                IType type = (IType)_externalEnumeratorSelf.Type.Entity;
                enumerableConstructorInvocation.Arguments.Add(
                    CodeBuilder.CreateSelfReference(type));

                PropagateFromEnumerableToEnumerator(enumeratorConstructorInvocation,
                                                    "self_",
                                                    type);
            }
        }
예제 #2
0
        override public void Run()
        {
            _generatorItemType = (IType)_generator.Method["GeneratorItemType"];
            _enumerable        = (BooClassBuilder)_generator.Method["GeneratorClassBuilder"];
            if (null == _enumerable)
            {
                Errors.Add(CompilerErrorFactory.InternalError(_generator.Method, null));
            }

            CreateEnumerableConstructor();
            CreateEnumerator();

            MethodInvocationExpression enumerableConstructorInvocation = CodeBuilder.CreateConstructorInvocation(_enumerable.ClassDefinition);
            MethodInvocationExpression enumeratorConstructorInvocation = CodeBuilder.CreateConstructorInvocation(_enumerator.ClassDefinition);

            // propagate the necessary parameters from
            // the enumerable to the enumerator
            foreach (ParameterDeclaration parameter in _generator.Method.Parameters)
            {
                InternalParameter entity = (InternalParameter)parameter.Entity;
                if (entity.IsUsed)
                {
                    enumerableConstructorInvocation.Arguments.Add(
                        CodeBuilder.CreateReference(parameter));

                    PropagateFromEnumerableToEnumerator(enumeratorConstructorInvocation,
                                                        entity.Name,
                                                        entity.Type);
                }
            }

            // propagate the external self reference if necessary
            if (null != _externalEnumeratorSelf)
            {
                IType type = (IType)_externalEnumeratorSelf.Type.Entity;
                enumerableConstructorInvocation.Arguments.Add(
                    CodeBuilder.CreateSelfReference(type));

                PropagateFromEnumerableToEnumerator(enumeratorConstructorInvocation,
                                                    "self_",
                                                    type);
            }


            CreateGetEnumerator(enumeratorConstructorInvocation);

            Block body = _generator.Method.Body;

            body.Clear();

            body.Add(
                new ReturnStatement(
                    GeneratorReturnsIEnumerator()
                                        ? CreateGetEnumeratorInvocation(enumerableConstructorInvocation)
                                        : enumerableConstructorInvocation));
        }
예제 #3
0
	    private CallableSignature CallableSignatureFor(CallableTypeReference node)
	    {
	        var parameters = new IParameter[node.Parameters.Count];
	        for (int i=0; i<parameters.Length; ++i)
	            parameters[i] = new InternalParameter(node.Parameters[i], i);
			
	        var returnType = node.ReturnType != null
                   ? GetType(node.ReturnType)
                   : TypeSystemServices.VoidType;

	        return new CallableSignature(parameters, returnType, node.Parameters.HasParamArray);
	    }
예제 #4
0
        private CallableSignature CallableSignatureFor(CallableTypeReference node)
        {
            var parameters = new IParameter[node.Parameters.Count];

            for (int i = 0; i < parameters.Length; ++i)
            {
                parameters[i] = new InternalParameter(node.Parameters[i], i);
            }

            var returnType = node.ReturnType != null
                   ? GetType(node.ReturnType)
                   : TypeSystemServices.VoidType;

            return(new CallableSignature(parameters, returnType, node.Parameters.HasParamArray));
        }
예제 #5
0
 void InitializeSharedParameters(Block block, InternalLocal locals)
 {
     foreach (Node node in _currentMethod.Parameters)
     {
         InternalParameter param = (InternalParameter)node.Entity;
         if (param.IsShared)
         {
             block.Add(
                 CodeBuilder.CreateAssignment(
                     CodeBuilder.CreateMemberReference(
                         CodeBuilder.CreateReference(locals),
                         (IField)_mappings[param]),
                     CodeBuilder.CreateReference(param)));
         }
     }
 }
예제 #6
0
        void CreateMoveNext()
        {
            Method generator = _generator.Method;

            BooMethodBuilder mn = _enumerator.AddVirtualMethod("MoveNext", TypeSystemServices.BoolType);

            mn.Method.LexicalInfo = this.LexicalInfo;
            _moveNext             = mn.Entity;

            foreach (Local local in generator.Locals)
            {
                InternalLocal entity = (InternalLocal)local.Entity;

                Field field = _enumerator.AddField("___" + entity.Name + _context.AllocIndex(), entity.Type);
                field.Modifiers |= TypeMemberModifiers.Internal;
                _mapping[entity] = field.Entity;
            }
            generator.Locals.Clear();

            foreach (ParameterDeclaration parameter in generator.Parameters)
            {
                InternalParameter entity = (InternalParameter)parameter.Entity;
                if (entity.IsUsed)
                {
                    Field field = DeclareFieldInitializedFromConstructorParameter(_enumerator, _enumeratorConstructor,
                                                                                  entity.Name,
                                                                                  entity.Type);
                    _mapping[entity] = field.Entity;
                }
            }

            mn.Body.Add(CreateLabel(generator));
            mn.Body.Add(generator.Body);
            generator.Body.Clear();

            Visit(mn.Body);

            mn.Body.Add(CreateYieldInvocation(null));
            mn.Body.Add(CreateLabel(generator));

            mn.Body.Insert(0,
                           CodeBuilder.CreateSwitch(
                               this.LexicalInfo,
                               CodeBuilder.CreateMemberReference(_state),
                               _labels));
        }
예제 #7
0
        public override string ToString()
        {
            string value = string.Empty;

            switch (InternalParameter.StorageType)
            {
            case Autodesk.Revit.DB.StorageType.String:
                value = InternalParameter.AsString();
                break;

            default:
                var ops = new FormatOptions()
                {
                };
                value = InternalParameter.AsValueString(ops);
                break;
            }
            return(string.Format("{0} : {1}", Name, value));
        }
        public void AddLocalVariablesAsFields(BooClassBuilder builder)
        {
            Field field;

            foreach (Local local in this.CurrentMethodNode.Locals)
            {
                InternalLocal entity = (InternalLocal)this.GetEntity(local);
                if (!entity.IsPrivateScope)
                {
                    field = builder.AddPublicField(entity.Name, entity.Type);
                    this.SetEvaluationContextField(local, (InternalField)this.GetEntity(field));
                }
            }
            foreach (ParameterDeclaration declaration in this.CurrentMethodNode.Parameters)
            {
                InternalParameter parameter = (InternalParameter)this.GetEntity(declaration);
                field = builder.AddPublicField(parameter.Name, parameter.Type);
                this.SetEvaluationContextField(declaration, (InternalField)this.GetEntity(field));
            }
        }
예제 #9
0
        override public void LeaveCallableTypeReference(CallableTypeReference node)
        {
            IParameter[] parameters = new IParameter[node.Parameters.Count];
            for (int i = 0; i < parameters.Length; ++i)
            {
                parameters[i] = new InternalParameter(node.Parameters[i], i);
            }

            IType returnType = null;

            if (null != node.ReturnType)
            {
                returnType = GetType(node.ReturnType);
            }
            else
            {
                returnType = TypeSystemServices.VoidType;
            }

            node.Entity = TypeSystemServices.GetConcreteCallableType(node, new CallableSignature(parameters, returnType));
        }
예제 #10
0
 public ReferenceExpression CreateReference(InternalParameter parameter)
 {
     return new ReferenceExpression(parameter.Name)
            	{
            		Entity = parameter,
            		ExpressionType = parameter.Type
            	};
 }
예제 #11
0
        private void SetByRefParam(InternalParameter param, Expression right, bool leaveValueOnStack)
        {
            LocalBuilder temp = null;
            IType tempType = null;
            if (leaveValueOnStack)
            {
                Visit(right);
                tempType = PopType();
                temp = StoreTempLocal(tempType);
            }

            LoadParam(param);
            if (temp != null)
            {
                LoadLocal(temp, tempType);
            }
            else
            {
                Visit(right);
            }

            EmitCastIfNeeded(param.Type, PopType());

            OpCode storecode = GetStoreRefParamCode(param.Type);
            if (IsStobj(storecode)) //passing struct/decimal byref
            {
                _il.Emit(storecode, GetSystemType(param.Type));
            }
            else
            {
                _il.Emit(storecode);
            }

            if (null != temp)
            {
                LoadLocal(temp, tempType);
            }
        }
예제 #12
0
        void LoadParam(InternalParameter param)
        {
            int index = param.Index;

            switch (index)
            {
                case 0:
                    {
                        _il.Emit(OpCodes.Ldarg_0);
                        break;
                    }

                case 1:
                    {
                        _il.Emit(OpCodes.Ldarg_1);
                        break;
                    }

                case 2:
                    {
                        _il.Emit(OpCodes.Ldarg_2);
                        break;
                    }

                case 3:
                    {
                        _il.Emit(OpCodes.Ldarg_3);
                        break;
                    }

                default:
                    {
                        if (index < 256)
                        {
                            _il.Emit(OpCodes.Ldarg_S, index);
                        }
                        else
                        {
                            _il.Emit(OpCodes.Ldarg, index);
                        }
                        break;
                    }
            }
        }
예제 #13
0
파일: Parameter.cs 프로젝트: hipigod/Dynamo
 public override string ToString()
 {
     return(string.Format("{0} : {1}", Name, InternalParameter.AsValueString(new FormatOptions()
     {
     })));
 }
예제 #14
0
 public ReferenceExpression CreateReference(InternalParameter parameter)
 {
     ReferenceExpression reference = new ReferenceExpression(parameter.Name);
     reference.Entity = parameter;
     reference.ExpressionType = parameter.Type;
     return reference;
 }