Beispiel #1
0
 public FieldDeclaration(string name, Expression defaultValue, TokenPosition position)
     : base(position)
 {
     SetName(name);
     this.defaultValue = defaultValue;
     this.variable = null;
 }
Beispiel #2
0
 public AttributeArgument(Expression value, string name, TokenPosition position)
     : base(position)
 {
     SetName(name);
     this.value = value;
     this.property = null;
     this.attributeClass = null;
 }
Beispiel #3
0
 public void SetAliasVariable(Variable variable)
 {
     this.aliasVariable = variable;
 }
Beispiel #4
0
 public VariableReference(string name, TokenPosition position)
     : base(position)
 {
     SetName(name);
     this.aliasVariable = null;
 }
Beispiel #5
0
 public void SetProperty(Variable property)
 {
     this.property = property;
 }
Beispiel #6
0
        private void PerformAssignment(AstNode node, Variable variable)
        {
            // Store the value into the variable.
            if(variable.IsLocal())
            {
                LocalVariable local = (LocalVariable)variable;
                if(local.IsPseudoLocal)
                {
                    // Store the closure local.
                    builder.CreateLoadArg(0);
                    builder.CreatePush(1);
                    builder.CreateStoreField((FieldVariable)local.ActualVariable);
                    builder.CreatePop();
                }
                else
                {
                    builder.CreateStoreLocal(local);
                }
            }
            else if(variable.IsField())
            {
                FieldVariable field = (FieldVariable) variable;
                if(field.IsStatic())
                    builder.CreateStoreGlobal(field);
                else
                    builder.CreateStoreField(field);
            }
            else if(variable.IsArraySlot())
            {
                ArraySlot slot = (ArraySlot)variable;
                builder.CreateStoreArraySlot(slot.GetArrayType());
            }
            else if(variable.IsReferencedSlot() || variable.IsPointedSlot())
            {
                builder.CreateStoreValue();
            }
            else if(variable.IsSwizzleVariable())
            {
                SwizzleVariable swizzle = (SwizzleVariable)variable;
                if(!swizzle.IsSettable())
                    Error(node, "cannot set vector members.");
                builder.CreateStoreSwizzle(swizzle.Components, swizzle.Mask);
            }
            else if(variable.IsProperty() || variable.IsDirectPropertySlot())
            {
                // Get the property.
                PropertyVariable property;
                bool direct = false;
                if(variable.IsDirectPropertySlot())
                {
                    DirectPropertySlot directProp = (DirectPropertySlot)variable;
                    property = directProp.Property;
                    direct = true;
                }
                else
                {
                    property = (PropertyVariable)variable;
                }

                if(property.SetAccessor == null)
                    Error(node, "cannot set property without a set accessor.");

                Function setAccessor = property.SetAccessor;
                uint argCount = (uint)setAccessor.GetFunctionType().GetArgumentCount();
                if(setAccessor.IsMethod())
                {
                    Method method = (Method)setAccessor;

                    if((method.IsOverride() || method.IsVirtual() || method.IsAbstract() || method.IsContract())
                       && !method.GetParentScope().IsStructure() && !direct)
                        builder.CreateCallVirtual(method, argCount);
                    else
                        builder.CreateCall(method, argCount);
                }
                else
                {
                    builder.CreateCall(setAccessor, argCount);
                }
            }
            else if(variable.IsEvent())
            {
                // Make sure the field is accessible.
                EventVariable eventVar = (EventVariable)variable;
                FieldVariable field = eventVar.AssociatedField;
                if(field == null)
                    Error(node, "cannot invoke/modify custom explicit event.");

                // Check the field access.
                CheckMemberVisibility(node, field);

                // Assign the field.
                PerformAssignment(node, field);
            }
            else
                Error(node, "unimplemented variable type.");
        }
Beispiel #7
0
        private void LoadVariableValue(AstNode where, Variable variable)
        {
            if(variable.IsLocal())
            {
                LocalVariable local = (LocalVariable) variable;
                if(local.IsPseudoLocal)
                {
                    // Load the variable in the generator closure.
                    builder.CreateLoadArg(0);
                    builder.CreateLoadField((FieldVariable)local.ActualVariable);
                }
                else
                {
                    builder.CreateLoadLocal(local);
                }
            }
            else if(variable.IsArgument())
            {
                ArgumentVariable arg = (ArgumentVariable)variable;
                if(arg.IsPseudoArgument)
                {
                    // Load the variable in the generator closure.
                    builder.CreateLoadArg(0);
                    builder.CreateLoadField((FieldVariable)arg.ActualVariable);
                }
                else
                {
                    builder.CreateLoadArg((byte)arg.GetArgumentIndex());
                }
            }
            else if(variable.IsField())
            {
                FieldVariable field = (FieldVariable) variable;
                if(field.IsStatic())
                    builder.CreateLoadGlobal(field);
                else
                    builder.CreateLoadField(field);
            }
            else if(variable.IsArraySlot())
            {
                ArraySlot slot = (ArraySlot)variable;
                builder.CreateLoadArraySlot(slot.GetArrayType());
            }
            else if(variable.IsReferencedSlot() || variable.IsPointedSlot())
            {
                builder.CreateLoadValue();
            }
            else if(variable.IsTemporalReferencedSlot())
            {
                Error(where, "cannot use here ref/out value.");
            }
            else if(variable.IsSwizzleVariable())
            {
                SwizzleVariable swizzle = (SwizzleVariable)variable;
                builder.CreateLoadSwizzle(swizzle.Components, swizzle.Mask);
            }
            else if(variable.IsProperty() || variable.IsDirectPropertySlot())
            {
                PropertyVariable property;
                bool direct = false;
                if(variable.IsDirectPropertySlot())
                {
                    DirectPropertySlot directProp = (DirectPropertySlot)variable;
                    property = directProp.Property;
                    direct = true;
                }
                else
                {
                    // Cast into a property.
                    property= (PropertyVariable)variable;
                }

                // Check the presence of a get accessor.
                if(property.GetAccessor == null)
                    Error(where, "cannot get value from property without get accessor.");

                // Use the get accessor.
                Function getAccessor = property.GetAccessor;
                uint argCount = (uint)getAccessor.GetFunctionType().GetArgumentCount();
                if(getAccessor.IsMethod())
                {
                    // Use the correct method invocation.
                    Method method = (Method)getAccessor;
                    if((method.IsOverride() || method.IsVirtual() || method.IsAbstract() || method.IsContract())
                       && !method.GetParentScope().IsStructure() && !direct)
                        builder.CreateCallVirtual(method, argCount);
                    else
                        builder.CreateCall(method, argCount);
                }
                else
                {
                    builder.CreateCall(getAccessor, argCount);
                }
            }
            else if(variable.IsEvent())
            {
                // Make sure the field is accessible.
                EventVariable eventVar = (EventVariable)variable;
                FieldVariable field = eventVar.AssociatedField;
                if(field == null)
                    Error(where, "cannot invoke/modify custom explicit event.");

                // Check the field access.
                CheckMemberVisibility(where, field);

                // Now, load the field.
                LoadVariableValue(where, field);
            }
        }
Beispiel #8
0
        // Only stack parameters.
        private uint GetVariableParameters(AstNode node, Variable variable)
        {
            if(variable.IsLocal())
            {
                return 0u;
            }
            else if(variable.IsField())
            {
                FieldVariable field = (FieldVariable) variable;
                if(!field.IsStatic())
                    return 1u;
                else
                    return 0u;
            }
            else if(variable.IsReferencedSlot() || variable.IsPointedSlot())
            {
                return 1u;
            }
            else if(variable.IsSwizzleVariable())
            {
                return 1u;
            }
            else if(variable.IsArraySlot())
            {
                ArraySlot slot = (ArraySlot)variable;
                return (uint) (slot.Dimensions + 1);
            }
            else if(variable.IsProperty())
            {
                PropertyVariable property = (PropertyVariable)variable;
                if(!property.IsStatic())
                    return (uint)(property.GetIndexCount() + 1);
                else
                    return (uint)property.GetIndexCount();
            }
            else if(variable.IsEvent())
            {
                EventVariable eventVar = (EventVariable)variable;
                if(eventVar.IsStatic())
                    return 0;
                else
                    return 1;
            }
            else
                Error(node, "unimplemented variable type.");

            // Shouldn't reach here.
            return 0u;
        }
Beispiel #9
0
 private void DuplicateReference(AstNode node, Variable variable)
 {
     // Get the parameter count.
     uint args = GetVariableParameters(node, variable);
     if(args == 0u)
         return;
     else if(args == 1u)
         builder.CreateDup1();
     else if(args == 2u)
         builder.CreateDup2();
     else
         builder.CreateDup(args);
 }
Beispiel #10
0
 public PropertyValue(Variable property, ConstantValue value)
 {
     this.Property = property;
     this.Value = value;
 }
Beispiel #11
0
 /// <summary>
 /// Adds a property value to the attribute constant.
 /// </summary>
 /// <param name="property">
 /// A <see cref="Variable"/>
 /// </param>
 /// <param name="value">
 /// A <see cref="ConstantValue"/>
 /// </param>
 public void AddPropertyValue(Variable property, ConstantValue value)
 {
     this.propertyValues.Add(new PropertyValue(property, value));
 }
Beispiel #12
0
 public void SetVariable(Variable variable)
 {
     this.variable = variable;
 }
Beispiel #13
0
 public void CreateStoreGlobal(Variable globalVar)
 {
     AppendInst1(OpCode.StoreGlobal, globalVar);
 }
Beispiel #14
0
 public void CreateLoadGlobalRef(Variable globalVar)
 {
     AppendInst1(OpCode.LoadGlobalRef, globalVar);
 }
Beispiel #15
0
 private void CheckReadOnlyConstraint(AstNode where, Variable variable)
 {
 }