Exemplo n.º 1
0
        public FlowBranchingToplevel StartFlowBranching(ParametersBlock stmt, FlowBranching parent)
        {
            FlowBranchingToplevel branching = new FlowBranchingToplevel(parent, stmt);

            current_flow_branching = branching;
            return(branching);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Visits the specified params block.
        /// </summary>
        /// <param name="paramsBlock">The params block.</param>
        public override void Visit(ParametersBlock paramsBlock)
        {
            Write("[DataContract]");
            WriteLinkLine(paramsBlock);
            Write("public partial class");
            Write(" ");
            Write(paramsBlock.Name);
            WriteSpace();
            Write(": ShaderMixinParameters");
            {
                OpenBrace();

                foreach (DeclarationStatement parameter in paramsBlock.Body.Statements.OfType <DeclarationStatement>())
                {
                    var variable = parameter.Content as Variable;
                    if (variable == null)
                    {
                        continue;
                    }

                    WriteLinkLine(parameter);
                    VisitDynamic(variable);
                }

                CloseBrace(false).Write(";").WriteLine();
            }
        }
Exemplo n.º 3
0
 public Iterator(ParametersBlock block, IMethodData method, TypeDefinition host, TypeSpec iterator_type, bool is_enumerable)
     : base(block, host, host.Compiler.BuiltinTypes.Bool)
 {
     this.OriginalMethod       = method;
     this.OriginalIteratorType = iterator_type;
     this.IsEnumerable         = is_enumerable;
     this.type = method.ReturnType;
 }
Exemplo n.º 4
0
 //
 // Our constructor
 //
 public Iterator(ParametersBlock block, IMethodData method, TypeContainer host, TypeSpec iterator_type, bool is_enumerable)
     : base(block, host.Compiler.BuiltinTypes.Bool, block.StartLocation)
 {
     this.OriginalMethod       = method;
     this.OriginalIteratorType = iterator_type;
     this.IsEnumerable         = is_enumerable;
     this.Host = host;
     this.type = method.ReturnType;
 }
Exemplo n.º 5
0
        public FlowAnalysisContext(CompilerContext ctx, ParametersBlock parametersBlock, int definiteAssignmentLength)
        {
            this.ctx             = ctx;
            this.ParametersBlock = parametersBlock;

            DefiniteAssignment = definiteAssignmentLength == 0 ?
                                 DefiniteAssignmentBitSet.Empty :
                                 new DefiniteAssignmentBitSet(definiteAssignmentLength);
        }
Exemplo n.º 6
0
        public Form1()
        {
            InitializeComponent();

            m_Instance = new ParametersBlock() {
            // 				SunIntensity = 100.0f,				// Should never change!
            // 				AverageGroundReflectance = 0.1f,	// Should never change!
            };
            m_StructSize = System.Runtime.InteropServices.Marshal.SizeOf(m_Instance);
            InitFromUI();

            m_MMF = MemoryMappedFile.CreateOrOpen( @"GlobalIllumination", m_StructSize, MemoryMappedFileAccess.ReadWrite );
            m_View = m_MMF.CreateViewAccessor( 0, m_StructSize, MemoryMappedFileAccess.ReadWrite );
            UpdateMMF();
        }
Exemplo n.º 7
0
        public Form1()
        {
            InitializeComponent();

            m_Instance = new ParametersBlock()
            {
//              SunIntensity = 100.0f,				// Should never change!
//              AverageGroundReflectance = 0.1f,	// Should never change!
            };
            m_StructSize = System.Runtime.InteropServices.Marshal.SizeOf(m_Instance);
            InitFromUI();

            m_MMF  = MemoryMappedFile.CreateOrOpen(@"GlobalIllumination", m_StructSize, MemoryMappedFileAccess.ReadWrite);
            m_View = m_MMF.CreateViewAccessor(0, m_StructSize, MemoryMappedFileAccess.ReadWrite);
            UpdateMMF();
        }
Exemplo n.º 8
0
        public static void Create(IMemberContext context, ParametersBlock block, ParametersCompiled parameters, TypeContainer host, TypeSpec returnType, Location loc)
        {
            if (returnType != null && returnType.Kind != MemberKind.Void &&
                returnType != host.Module.PredefinedTypes.Task.TypeSpec &&
                !returnType.IsGenericTask)
            {
                host.Compiler.Report.Error(1983, loc, "The return type of an async method must be void, Task, or Task<T>");
            }

            for (int i = 0; i < parameters.Count; i++)
            {
                Parameter          p   = parameters[i];
                Parameter.Modifier mod = p.ModFlags;
                if ((mod & Parameter.Modifier.ISBYREF) != 0)
                {
                    host.Compiler.Report.Error(1988, p.Location,
                                               "Async methods cannot have ref or out parameters");
                    return;
                }

                // TODO:
                if (p is ArglistParameter)
                {
                    host.Compiler.Report.Error(1636, p.Location,
                                               "__arglist is not allowed in parameter list of iterators");
                    return;
                }

                // TODO:
                if (parameters.Types[i].IsPointer)
                {
                    host.Compiler.Report.Error(1637, p.Location,
                                               "Iterators cannot have unsafe parameters or yield types");
                    return;
                }
            }

            if (!block.IsAsync)
            {
                host.Compiler.Report.Warning(1998, 1, loc,
                                             "Async block lacks `await' operator and will run synchronously");
            }

            block.WrapIntoAsyncTask(context, host, returnType);
        }
Exemplo n.º 9
0
        public static void Create(IMemberContext context, ParametersBlock block, ParametersCompiled parameters, TypeContainer host, TypeSpec returnType, Location loc)
        {
            for (int i = 0; i < parameters.Count; i++)
            {
                Parameter          p   = parameters[i];
                Parameter.Modifier mod = p.ModFlags;
                if ((mod & Parameter.Modifier.ISBYREF) != 0)
                {
                    host.Compiler.Report.Error(1988, p.Location,
                                               "Async methods cannot have ref or out parameters");
                    return;
                }

                if (p is ArglistParameter)
                {
                    host.Compiler.Report.Error(4006, p.Location,
                                               "__arglist is not allowed in parameter list of async methods");
                    return;
                }

                if (parameters.Types[i].IsPointer)
                {
                    host.Compiler.Report.Error(4005, p.Location,
                                               "Async methods cannot have unsafe parameters");
                    return;
                }
            }

            if (!block.IsAsync)
            {
                host.Compiler.Report.Warning(1998, 1, loc,
                                             "Async block lacks `await' operator and will run synchronously");
            }

            block.WrapIntoAsyncTask(context, host, returnType);
        }
Exemplo n.º 10
0
        private void buttonLoadPreset_Click( object sender, EventArgs e )
        {
            if ( openFileDialog.ShowDialog( this ) != DialogResult.OK )
                return;

            try
            {
                XmlDocument	Doc = new XmlDocument();
                Doc.Load( openFileDialog.FileName );

                XmlElement	Root = Doc["Root"];
                if ( Root == null )
                    throw new Exception( "Failed to find root element!" );

                FieldInfo[]	Fields = typeof(ParametersBlock).GetFields( BindingFlags.Instance | BindingFlags.Public );
                Dictionary<string,FieldInfo>	Name2Field = new Dictionary<string,FieldInfo>();
                foreach ( FieldInfo Field in Fields )
                    Name2Field.Add( Field.Name, Field );

                object	BoxedInstance = (object) m_Instance;	// Struct needs to be boxed to be referenced and not passed by value...

                string	Warnings = "";
                foreach ( XmlNode ChildNode in Root.ChildNodes )
                    if ( ChildNode is XmlElement )
                    {
                        XmlElement	FieldElement = ChildNode as XmlElement;
                        if ( !Name2Field.ContainsKey( FieldElement.Name ) )
                        {	// Unknown field...
                            Warnings += "	Unrecognized field \"" + FieldElement.Name + "\".\r\n";
                            continue;
                        }

                        FieldInfo	Field = Name2Field[FieldElement.Name];
                        string		Value = FieldElement.GetAttribute( "Value" );

                        if ( Field.FieldType == typeof(float) )
                            Field.SetValue( BoxedInstance, float.Parse( Value ) );
                        else if ( Field.FieldType == typeof(int) )
                            Field.SetValue( BoxedInstance, int.Parse( Value ) );
                        else if ( Field.FieldType == typeof(bool) )
                            Field.SetValue( BoxedInstance, bool.Parse( Value ) );
                        else
                        {
                            Warnings += "	Unsupported field type \"" + Field.FieldType + "\" for field \"" + Field.Name + "\" (Value = " + Value + ")\r\n";
                            continue;
                        }
                    }

                // Unbox
                m_Instance = (ParametersBlock) BoxedInstance;

                // Update the sliders
                UpdateFromParams();

                if ( Warnings == "" )
                    MessageBox.Show( this, "Success!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information );
                else
                    MessageBox.Show( this, "Success with warnings:\r\n\r\n" + Warnings, "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning );
            }
            catch ( Exception _e )
            {
                MessageBox.Show( this, "An error occurred while loading preset file: " + _e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
            }
        }
Exemplo n.º 11
0
		public LambdaMethod (ParametersCompiled parameters,
					ParametersBlock block, TypeSpec return_type, TypeSpec delegate_type,
					Location loc)
			: base (parameters, block, return_type, delegate_type, loc)
		{
		}
Exemplo n.º 12
0
 public override void Visit(ParametersBlock paramsBlock)
 {
     HasMixin = true;
 }
Exemplo n.º 13
0
		protected virtual AnonymousMethodBody CompatibleMethodFactory (TypeSpec return_type, TypeSpec delegate_type, ParametersCompiled p, ParametersBlock b)
		{
			return new AnonymousMethodBody (p, b, return_type, delegate_type, loc);
		}
Exemplo n.º 14
0
        private void buttonLoadPreset_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            try
            {
                XmlDocument Doc = new XmlDocument();
                Doc.Load(openFileDialog.FileName);

                XmlElement Root = Doc["Root"];
                if (Root == null)
                {
                    throw new Exception("Failed to find root element!");
                }

                FieldInfo[] Fields = typeof(ParametersBlock).GetFields(BindingFlags.Instance | BindingFlags.Public);
                Dictionary <string, FieldInfo> Name2Field = new Dictionary <string, FieldInfo>();
                foreach (FieldInfo Field in Fields)
                {
                    Name2Field.Add(Field.Name, Field);
                }

                object BoxedInstance = (object)m_Instance;                      // Struct needs to be boxed to be referenced and not passed by value...

                string Warnings = "";
                foreach (XmlNode ChildNode in Root.ChildNodes)
                {
                    if (ChildNode is XmlElement)
                    {
                        XmlElement FieldElement = ChildNode as XmlElement;
                        if (!Name2Field.ContainsKey(FieldElement.Name))
                        {                               // Unknown field...
                            Warnings += "	Unrecognized field \""+ FieldElement.Name + "\".\r\n";
                            continue;
                        }

                        FieldInfo Field = Name2Field[FieldElement.Name];
                        string    Value = FieldElement.GetAttribute("Value");

                        if (Field.FieldType == typeof(float))
                        {
                            Field.SetValue(BoxedInstance, float.Parse(Value));
                        }
                        else if (Field.FieldType == typeof(int))
                        {
                            Field.SetValue(BoxedInstance, int.Parse(Value));
                        }
                        else if (Field.FieldType == typeof(bool))
                        {
                            Field.SetValue(BoxedInstance, bool.Parse(Value));
                        }
                        else
                        {
                            Warnings += "	Unsupported field type \""+ Field.FieldType + "\" for field \"" + Field.Name + "\" (Value = " + Value + ")\r\n";
                            continue;
                        }
                    }
                }

                // Unbox
                m_Instance = (ParametersBlock)BoxedInstance;

                // Update the sliders
                UpdateFromParams();

                if (Warnings == "")
                {
                    MessageBox.Show(this, "Success!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(this, "Success with warnings:\r\n\r\n" + Warnings, "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception _e)
            {
                MessageBox.Show(this, "An error occurred while loading preset file: " + _e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 15
0
 protected StateMachine(ParametersBlock block, TypeDefinition parent, MemberBase host, TypeParameters tparams, string name, MemberKind kind)
     : base(block, parent, host, tparams, name, kind)
 {
     OriginalTypeParameters = tparams;
 }
Exemplo n.º 16
0
 protected StateMachineInitializer(ParametersBlock block, TypeDefinition host, TypeSpec returnType)
     : base(block, returnType, block.StartLocation)
 {
     this.Host = host;
 }
Exemplo n.º 17
0
		public AnonymousMethodBody (ParametersCompiled parameters,
					ParametersBlock block, TypeSpec return_type, TypeSpec delegate_type,
					Location loc)
			: base (block, return_type, loc)
		{
			this.type = delegate_type;
			this.parameters = parameters;
		}
Exemplo n.º 18
0
		protected AnonymousExpression (ParametersBlock block, TypeSpec return_type, Location loc)
		{
			this.ReturnType = return_type;
			this.block = block;
			this.loc = loc;
		}
Exemplo n.º 19
0
		protected override AnonymousMethodBody CompatibleMethodFactory (TypeSpec returnType, TypeSpec delegateType, ParametersCompiled p, ParametersBlock b)
		{
			return new LambdaMethod (p, b, returnType, delegateType, loc);
		}
Exemplo n.º 20
0
/*
 * Completes the anonymous method processing, if lambda_expr is null, this
 * means that we have a Statement instead of an Expression embedded 
 */
AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
{
	AnonymousMethodExpression retval;

	if (async_block)
		anon_block.IsAsync = true;

	current_anonymous_method.Block = anon_block;
	retval = current_anonymous_method;

	async_block = (bool) oob_stack.Pop ();
	current_variable = (BlockVariable) oob_stack.Pop ();
	current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
	current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();

	return retval;
}
Exemplo n.º 21
0
 public AsyncInitializer(ParametersBlock block, TypeDefinition host, TypeSpec returnType)
     : base(block, host, returnType)
 {
 }
Exemplo n.º 22
0
 protected override AnonymousMethodBody CompatibleMethodFactory(TypeSpec returnType, TypeSpec delegateType, ParametersCompiled p, ParametersBlock b)
 {
     return(new LambdaMethod(p, b, returnType, delegateType, loc));
 }
Exemplo n.º 23
0
 public AsyncInitializer(ParametersBlock block, TypeContainer host, TypeSpec returnType)
     : base(block, host, returnType)
 {
 }
Exemplo n.º 24
0
		public void CaptureParameter (ResolveContext ec, ParametersBlock.ParameterInfo parameterInfo, ParameterReference parameterReference)
		{
			if (!(this is StateMachine)) {
				ec.CurrentBlock.Explicit.HasCapturedVariable = true;
			}

			var hoisted = parameterInfo.Parameter.HoistedVariant;

			if (parameterInfo.Block.StateMachine != null) {
				//
				// Another storey in same block exists but state machine does not
				// have parameter captured. We need to add it there as well to
				// proxy parameter value correctly.
				//
				if (hoisted == null && parameterInfo.Block.StateMachine != this) {
					var storey = parameterInfo.Block.StateMachine;

					hoisted = new HoistedParameter (storey, parameterReference);
					parameterInfo.Parameter.HoistedVariant = hoisted;

					if (storey.hoisted_params == null)
						storey.hoisted_params = new List<HoistedParameter> ();

					storey.hoisted_params.Add (hoisted);
				}

				//
				// Lift captured parameter from value type storey to reference type one. Otherwise
				// any side effects would be done on a copy
				//
				if (hoisted != null && hoisted.Storey != this && hoisted.Storey is StateMachine) {
					if (hoisted_local_params == null)
						hoisted_local_params = new List<HoistedParameter> ();

					hoisted_local_params.Add (hoisted);
					hoisted = null;
				}
			}

			if (hoisted == null) {
				hoisted = new HoistedParameter (this, parameterReference);
				parameterInfo.Parameter.HoistedVariant = hoisted;

				if (hoisted_params == null)
					hoisted_params = new List<HoistedParameter> ();

				hoisted_params.Add (hoisted);
			}

			//
			// Register link between current block and parameter storey. It will
			// be used when setting up storey definition to deploy storey reference
			// when parameters are used from multiple blocks
			//
			if (ec.CurrentBlock.Explicit != parameterInfo.Block) {
				hoisted.Storey.AddReferenceFromChildrenBlock (ec.CurrentBlock.Explicit);
			}
		}
Exemplo n.º 25
0
 private void Visit(ParametersBlock paramsBlock)
 {
     HasMixin = true;
 }
Exemplo n.º 26
0
 public LambdaMethod(ParametersCompiled parameters,
                     ParametersBlock block, TypeSpec return_type, TypeSpec delegate_type,
                     Location loc)
     : base(parameters, block, return_type, delegate_type, loc)
 {
 }
		public FlowBranchingToplevel (FlowBranching parent, ParametersBlock stmt)
			: base (parent, BranchingType.Toplevel, SiblingType.Conditional, stmt, stmt.loc)
		{
		}
Exemplo n.º 28
0
 public AsyncTaskStorey(ParametersBlock block, IMemberContext context, AsyncInitializer initializer, TypeSpec type)
     : base(block, initializer.Host, context.CurrentMemberDefinition as MemberBase, context.CurrentTypeParameters, "async", MemberKind.Struct)
 {
     return_type    = type;
     awaiter_fields = new Dictionary <TypeSpec, List <Field> > ();
 }
Exemplo n.º 29
0
		public FlowAnalysisContext (CompilerContext ctx, ParametersBlock parametersBlock, int definiteAssignmentLength)
		{
			this.ctx = ctx;
			this.ParametersBlock = parametersBlock;

			DefiniteAssignment = definiteAssignmentLength == 0 ?
				DefiniteAssignmentBitSet.Empty :
				new DefiniteAssignmentBitSet (definiteAssignmentLength);
		}