public override bool TryGetVariable(string name, out VariableDef variable) {
     if (name == _name) {
         variable = _variable;
         return true;
     }
     return base.TryGetVariable(name, out variable);
 }
 internal override void ReplaceVariable(string name, VariableDef def) {
     if (_name != name) {
         Parent.ReplaceVariable(name, def);
     } else {
         _variable = def;
     }
 }
Esempio n. 3
0
 public GeneratorInfo(JAnalyzer projectState, Node node)
     : base(projectState._generatorType)
 {
     _node = node;
     Yields = new VariableDef();
     Sends = new VariableDef();
     Returns = new VariableDef();
 }
Esempio n. 4
0
 internal FunctionInfo(AnalysisUnit unit, ProjectEntry entry)
     : base(unit)
 {
     _entry = entry;
     _returnValue = new VariableDef();
     _declVersion = entry.Version;
     // TODO: pass NoneInfo if we can't determine the function always returns
 }
Esempio n. 5
0
 public FunctionScope(FunctionInfo function, Node node, InterpreterScope declScope)
     : base(function, node, declScope)
 {
     ReturnValue = new VariableDef();
     if (Function.FunctionDefinition.IsGenerator) {
         Generator = new GeneratorInfo(function.ProjectState, Function.FunctionDefinition);
         ReturnValue.AddTypes(function.ProjectEntry, Generator.SelfSet, false);
     }
 }
        public override void SetVariable(VariableDef value, object obj) {
            base.SetVariable(value, obj);

            if (value != null)
            { setProperty(value.Value, "", false, obj); }

            else
            { update(); }
        }
 public GeneratorInfo(PythonAnalyzer projectState, IPythonProjectEntry entry)
     : base(projectState.ClassInfos[BuiltinTypeId.Generator]) {
     
     _declaringModule = entry;
     _declaringVersion = entry.AnalysisVersion;
     Yields = new VariableDef();
     Sends = new VariableDef();
     Returns = new VariableDef();
 }
 private static VariableDef CopyVariableDef(VariableDef original) {
     LocatedVariableDef locVarDef = original as LocatedVariableDef;
     if (locVarDef != null) {
         return new LocatedVariableDef(
             locVarDef.Entry,
             locVarDef.Node
         );
     }
     return new VariableDef();
 }
        public override void SetVariable(VariableDef variable, object obj) {
            base.SetVariable(variable, obj);

            if (variable != null) {
                Type valueType = variable.GetValueType();

                if (valueType == typeof(bool))
                { checkBox.Checked = (bool)variable.Value; }
            }
        }
Esempio n. 10
0
        public CoroutineInfo(PythonAnalyzer projectState, IPythonProjectEntry entry)
            : base(projectState.ClassInfos[BuiltinTypeId.Generator]) {
            // Internally, coroutines are represented by generators with a CO_*
            // flag on the code object. Here we represent it as a separate info,
            // but reuse the underlying class info.

            _declaringModule = entry;
            _declaringVersion = entry.AnalysisVersion;
            Returns = new VariableDef();
        }
Esempio n. 11
0
 public VariableDef CreateVariable(Node node, AnalysisUnit unit, string name, bool addRef = true)
 {
     var res = GetVariable(node, unit, name, addRef);
     if (res == null) {
         _variables[name] = res = new VariableDef();
         if (addRef) {
             res.AddReference(node, unit);
         }
     }
     return res;
 }
        public CartesianProductFunctionAnalysisUnit(UserFunctionValue funcInfo, EnvironmentRecord environment, AnalysisUnit outerUnit, UserFunctionValue.CallArgs callArgs, VariableDef returnValue)
            : base(funcInfo, outerUnit, environment.Parent, outerUnit.ProjectEntry, environment) {
            _callArgs = callArgs;
            _returnValue = returnValue;
            _this = new VariableDef();

            var funcScope = environment as FunctionEnvironmentRecord;

            var specLocals = new List<CartesianLocalVariable>();
            ProcessVariablesForScope(funcScope, specLocals);
            _specializedLocals = specLocals.ToArray();
        }
Esempio n. 13
0
        public GeneratorInfo(FunctionInfo functionInfo)
            : base(functionInfo.ProjectState._generatorType)
        {
            _functionInfo = functionInfo;
            var nextMeth = VariableDict["next"];
            var sendMeth = VariableDict["send"];

            _nextMethod = new GeneratorNextBoundBuiltinMethodInfo(this, (BuiltinMethodInfo)nextMeth.First());
            _sendMethod = new GeneratorSendBoundBuiltinMethodInfo(this, (BuiltinMethodInfo)sendMeth.First());

            _sends = new VariableDef();
        }
Esempio n. 14
0
        public override void SetVariable(VariableDef value, object obj)
        {
            base.SetVariable(value, obj);

            string selectionName = "";
            if (value != null)
            {
                ParInfo par = value.Value as ParInfo;
                if (par != null)
                    selectionName = par.Name;
            }

            setComboBox(selectionName);
        }
Esempio n. 15
0
 public FunctionScope(
     FunctionInfo function,
     Node node,
     InterpreterScope declScope,
     IPythonProjectEntry declModule
 )
     : base(function, node, declScope) {
     ReturnValue = new VariableDef();
     if (Function.FunctionDefinition.IsCoroutine) {
         Coroutine = new CoroutineInfo(function.ProjectState, declModule);
         ReturnValue.AddTypes(function.ProjectEntry, Coroutine.SelfSet, false);
     } else if (Function.FunctionDefinition.IsGenerator) {
         Generator = new GeneratorInfo(function.ProjectState, declModule);
         ReturnValue.AddTypes(function.ProjectEntry, Generator.SelfSet, false);
     }
 }
        //public readonly GeneratorInfo Generator;

        public FunctionEnvironmentRecord(
            UserFunctionValue function,
            FunctionAnalysisUnit analysisUnit,
            Node node,
            EnvironmentRecord declScope,
            IJsProjectEntry declModule
        )
            : base(node, declScope) {
            _function = function;
            _this = new VariableDef();
            AnalysisUnit = analysisUnit;
#if FALSE
            if (Function.FunctionObject.IsGenerator) {
                Generator = new GeneratorInfo(function.ProjectState, declModule);
                ReturnValue.AddTypes(function.ProjectEntry, Generator.SelfSet, false);
            }
#endif
        }
Esempio n. 17
0
        private List <MethodDef> getMethods()
        {
            List <MethodDef> methods = new List <MethodDef>();

            Nodes.Behavior behavior  = GetBehavior();
            AgentType      agentType = (behavior != null) ? behavior.AgentType : null;

            object      action = _property.Property.GetValue(_object, null);
            VariableDef var    = action as VariableDef;

            Debug.Check(var == null);

            RightValueDef varRV = action as RightValueDef;

            if (varRV != null && Plugin.IsInstanceName(varRV.ValueClassReal, behavior))
            {
                agentType = Plugin.GetInstanceAgentType(varRV.ValueClassReal, behavior, agentType);
            }

            if (agentType != null)
            {
                DesignerRightValueEnum enumAttRV  = _property.Attribute as DesignerRightValueEnum;
                DesignerMethodEnum     attrMethod = _property.Attribute as DesignerMethodEnum;
                MethodType             methodType = attrMethod != null ? attrMethod.MethodType : MethodType.Getter;

                if (enumAttRV != null)
                {
                    methodType = enumAttRV.MethodType;
                }

                IList <MethodDef> actions = agentType.GetMethods(methodType);
                foreach (MethodDef actionType in actions)
                {
                    if (Plugin.IsCompatibleType(this.ValueType, this.FilterType, actionType.ReturnType, false))
                    {
                        methods.Add(actionType);
                    }
                }
            }

            return(methods);
        }
Esempio n. 18
0
            public String GetColumnAttributes(EntityDef r, VariableDef f, int Index)
            {
                var a = f.Attribute.Column;
                var l = new List <String>();

                l.Add(String.Format(@"Column(""{0}"", Order = {1})", f.Name, Index.ToInvariantString()));
                if (r.PrimaryKey.Columns.Select(co => co.Name).Contains(f.Name, StringComparer.OrdinalIgnoreCase))
                {
                    l.Add("Key");
                }
                if (a.IsIdentity)
                {
                    l.Add("DatabaseGenerated(DatabaseGeneratedOption.Identity)");
                }
                if (!f.Type.OnOptional)
                {
                    l.Add("Required");
                }
                return(String.Join(", ", l.ToArray()));
            }
        //public readonly GeneratorInfo Generator;

        public FunctionEnvironmentRecord(
            UserFunctionValue function,
            FunctionAnalysisUnit analysisUnit,
            Node node,
            EnvironmentRecord declScope,
            IJsProjectEntry declModule
            )
            : base(node, declScope)
        {
            _function    = function;
            _this        = new VariableDef();
            AnalysisUnit = analysisUnit;
#if FALSE
            if (Function.FunctionObject.IsGenerator)
            {
                Generator = new GeneratorInfo(function.ProjectState, declModule);
                ReturnValue.AddTypes(function.ProjectEntry, Generator.SelfSet, false);
            }
#endif
        }
Esempio n. 20
0
            public List <String> GetVariable(VariableDef v)
            {
                String TypeSpecString;

                if (v.Attribute.OnColumn)
                {
                    TypeSpecString = GetTypeString(v.Type, true);
                }
                else if (v.Attribute.OnNavigation)
                {
                    TypeSpecString = GetEscaped("[导航] ") + GetTypeString(v.Type, true);
                }
                else
                {
                    throw new InvalidOperationException();
                }
                var l = GetTemplate("Variable").Substitute("Name", GetEscaped(v.Name)).Substitute("TypeSpec", TypeSpecString).Substitute("Description", GetEscaped(v.Description));

                return(l);
            }
Esempio n. 21
0
 public FunctionScope(
     FunctionInfo function,
     Node node,
     InterpreterScope declScope,
     IPythonProjectEntry declModule
     )
     : base(function, node, declScope)
 {
     ReturnValue = new VariableDef();
     if (Function.FunctionDefinition.IsCoroutine)
     {
         Coroutine = new CoroutineInfo(function.ProjectState, declModule);
         ReturnValue.AddTypes(function.ProjectEntry, Coroutine.SelfSet, false, declModule);
     }
     else if (Function.FunctionDefinition.IsGenerator)
     {
         Generator = new GeneratorInfo(function.ProjectState, declModule);
         ReturnValue.AddTypes(function.ProjectEntry, Generator.SelfSet, false, declModule);
     }
 }
        /// <summary>
        /// Обработка используемого в ограничении описания поля.
        /// Получение значения поля.
        /// </summary>
        /// <param name="variableDef">Используемое в ограничении описание поля.</param>
        /// <param name="target">Объект, из которого будет получено значение поля по описанию.</param>
        /// <param name="involved">Список полей со значениями из проверяемого объекта (записи добавляются при первом извлечении значения поля из объекта).</param>
        /// <returns>Значение поля.</returns>
        private static object ProcessVariableDef(VariableDef variableDef, DataObject target, ref Dictionary <string, object> involved)
        {
            if (variableDef.Type.StringedView == "Details")
            {
                throw new NotSupportedException();
            }

            string propertyPath = variableDef.StringedView;

            if (involved.ContainsKey(propertyPath))
            {
                return(involved[propertyPath]);
            }

            object currentPropertyValue = Information.GetPropValueByName(target, propertyPath);

            CheckLoadedProperty(target, propertyPath);
            involved[propertyPath] = Information.GetPropValueByName(target, propertyPath);
            return(currentPropertyValue);
        }
Esempio n. 23
0
        protected static VariableDef setProperty(List <Nodes.Node.ErrorCheck> result, DefaultObject node, AgentType agentType, string propertyName, string arrayIndexStr, string valueType)
        {
            if (agentType != null)
            {
                // basic name
                int lastIndex = propertyName.LastIndexOf("::");

                if (lastIndex >= 0)
                {
                    propertyName = propertyName.Substring(lastIndex + 2, propertyName.Length - lastIndex - 2);
                }

                IList <PropertyDef> properties = agentType.GetProperties();

                foreach (PropertyDef p in properties)
                {
                    if (p.BasicName == propertyName
#if BEHAVIAC_NAMESPACE_FIX
                        || p.Name.EndsWith(propertyName)
#endif
                        )
                    {
                        PropertyDef prop = p.Clone();
                        prop.Owner = valueType;

                        VariableDef v = new VariableDef(prop, valueType);

                        if (v != null && !string.IsNullOrEmpty(arrayIndexStr))
                        {
                            v.ArrayIndexElement = new MethodDef.Param("ArrayIndex", typeof(int), "int", "ArrayIndex", "ArrayIndex");
                            v.ArrayIndexElement.IsArrayIndex = true;
                            DesignerMethodEnum.parseParam(result, node, null, v.ArrayIndexElement, arrayIndexStr);
                        }

                        return(v);
                    }
                }
            }

            return(null);
        }
Esempio n. 24
0
        public override void Update(object sender, DesignerPropertyInfo property)
        {
            if (_obj != null)
            {
                DesignerPropertyEditor oplEditor = GetEditor(_obj, "Opl");
                Debug.Check(oplEditor != null);

                if (oplEditor == sender)
                {
                    VariableDef opl = (VariableDef)GetProperty(_obj, "Opl");

                    if (opl != null)
                    {
                        RightValueDef opr1 = (RightValueDef)GetProperty(_obj, "Opr1");
                        RightValueDef opr2 = (RightValueDef)GetProperty(_obj, "Opr2");

                        if (opr1 != null && opl.ValueType != opr1.ValueType)
                        {
                            DesignerPropertyEditor opr1Editor = GetEditor(_obj, "Opr1");
                            Debug.Check(opr1Editor != null);

                            if (opr1Editor != null)
                            {
                                opr1Editor.Clear();
                            }
                        }

                        if (opr2 != null && opl.ValueType != opr2.ValueType)
                        {
                            DesignerPropertyEditor opr2Editor = GetEditor(_obj, "Opr2");
                            Debug.Check(opr2Editor != null);

                            if (opr2Editor != null)
                            {
                                opr2Editor.Clear();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 25
0
        public static void GenerateOperand(StreamWriter stream, string indent, RightValueDef operand, string operandName, string nodeName)
        {
            if (operand != null)
            {
                string typeName = DataCppExporter.GetGeneratedNativeType(operand.ValueType);

                if (operand.IsMethod) // method
                {
                    RightValueCppExporter.GenerateCode(operand, stream, indent, typeName, operandName, string.Empty);
                    RightValueCppExporter.PostGenerateCode(operand, stream, indent, typeName, operandName, string.Empty);
                }
                else
                {
                    VariableDef var = operand.Var;
                    if (var != null)
                    {
                        if (var.IsProperty) // property
                        {
                            PropertyDef prop = var.Property;
                            if (prop != null)
                            {
                                string property = PropertyCppExporter.GetProperty(prop, var.ArrayIndexElement, stream, indent, operandName, nodeName);
                                string propName = prop.BasicName.Replace("[]", "");

                                if (prop.IsArrayElement && var.ArrayIndexElement != null)
                                {
                                    ParameterCppExporter.GenerateCode(var.ArrayIndexElement, stream, indent, "int", operandName + "_index", nodeName + "_opl");
                                    property = string.Format("({0})[{1}_index]", property, operandName);
                                }

                                stream.WriteLine("{0}{1}& {2} = {3};", indent, typeName, operandName, property);
                            }
                        }
                        else if (var.IsConst) // const
                        {
                            RightValueCppExporter.GenerateCode(operand, stream, indent, typeName, operandName, string.Empty);
                        }
                    }
                }
            }
        }
Esempio n. 26
0
        public override bool Walk(FunctionDefinition node)
        {
            if (node.Body == null || node.Name == null)
            {
                return(false);
            }

            var queue  = _entry.ProjectState.Queue;
            var scopes = new InterpreterScope[_scopes.Count + 1];

            _scopes.CopyTo(scopes);

            _analysisStack.Push(_curUnit);
            var unit      = _curUnit = new AnalysisUnit(node, scopes, _curUnit);
            var function  = new FunctionInfo(unit, _entry);
            var funcScope = new FunctionScope(function);

            _entry.MyScope.GetOrMakeNodeVariable(node, x => function.SelfSet);
            _scopes.Push(funcScope);
            scopes[scopes.Length - 1] = funcScope;

            if (!node.IsLambda)
            {
                // lambdas don't have their names published
                var scope = _scopes[_scopes.Count - 2];
                scope.SetVariable(node, unit, node.Name, function.SelfSet);
            }

            var newParams = new VariableDef[node.Parameters.Count];
            int index     = 0;

            foreach (var param in node.Parameters)
            {
                newParams[index++] = funcScope.DefineVariable(param, _curUnit);
            }
            function.SetParameters(newParams);

            PushPositionScope(node, funcScope);

            return(true);
        }
Esempio n. 27
0
        public override void SetVariable(VariableDef variable, object obj)
        {
            base.SetVariable(variable, obj);

            if (variable != null)
            {
                string str = trimQuotes(variable.Value.ToString());
                if (textBox.Text != str)
                {
                    textBox.Text = str;

                    _modified = true;
                    valueChanged();
                }

                if (Plugin.IsCharType(variable.GetValueType()))
                {
                    textBox.MaxLength = 1;
                }
            }
        }
Esempio n. 28
0
        protected VariableDef setProperty(AgentType agentType, string propertyName, string valueType)
        {
            if (agentType != null)
            {
                IList <PropertyDef> properties = agentType.GetProperties();
                foreach (PropertyDef p in properties)
                {
                    if (p.Name == propertyName
#if BEHAVIAC_NAMESPACE_FIX
                        || p.Name.EndsWith(propertyName)
#endif
                        )
                    {
                        VariableDef v = new VariableDef(p, valueType);
                        return(v);
                    }
                }
            }

            return(null);
        }
Esempio n. 29
0
        protected VariableDef setParameter(NodeTag.DefaultObject node, string propertyType, string propertyName)
        {
            List <ParInfo> allPars = new List <ParInfo>();

            ((Nodes.Node)node.Behavior).GetAllPars(ref allPars);
            if (allPars.Count > 0)
            {
                string fullname = string.Format("{0} {1}", propertyType, propertyName);
                foreach (ParInfo p in allPars)
                {
                    if (p.ToString() == fullname)
                    {
                        VariableDef v = new VariableDef(p);
                        v.SetValue(p, VariableDef.kPar);
                        return(v);
                    }
                }
            }

            return(null);
        }
Esempio n. 30
0
            public String GetAssociationParameters(EntityDef r, VariableDef f)
            {
                var        a = f.Attribute.Navigation;
                var        l = new List <String>();
                ForeignKey fk;

                if (a.IsReverse)
                {
                    EntityDef ThisTable = null;
                    if (f.Type.OnTypeRef)
                    {
                        ThisTable = Records[f.Type.TypeRef.Value];
                    }
                    else if (f.Type.OnOptional)
                    {
                        ThisTable = Records[f.Type.Optional.Value];
                    }
                    else if (f.Type.OnList)
                    {
                        ThisTable = Records[f.Type.List.Value];
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                    fk = new ForeignKey {
                        ThisTableName = ThisTable.CollectionName, ThisKeyColumns = f.Attribute.Navigation.OtherKey, OtherTableName = r.CollectionName, OtherKeyColumns = f.Attribute.Navigation.ThisKey
                    };
                }
                else
                {
                    fk = new ForeignKey {
                        ThisTableName = r.CollectionName, ThisKeyColumns = f.Attribute.Navigation.ThisKey, OtherTableName = Records[f.Type.TypeRef.Value].CollectionName, OtherKeyColumns = f.Attribute.Navigation.OtherKey
                    };
                }
                var AssociationName = fk.ThisTableName + "_" + String.Join("_", fk.ThisKeyColumns) + "_" + fk.OtherTableName + "_" + String.Join("_", fk.OtherKeyColumns);

                l.Add(String.Format(@"Association(""{0}"", ""{1}"", ""{2}"", IsForeignKey = {3})", AssociationName, String.Join(", ", a.ThisKey), String.Join(", ", a.OtherKey), !a.IsReverse ? "true" : "false"));
                return(String.Join(", ", l.ToArray()));
            }
        public IAnalysisSet GetValue(Node node, AnalysisUnit unit, ProjectEntry declaringScope, IAnalysisSet @this, bool addRef) {
            if (Values == null) {
                Values = new EphemeralVariableDef();
            }

            var res = Values.GetTypes(unit, declaringScope);

            if (res.Count > 0) {
                // Don't add references to ephemeral values...  If they
                // gain types we'll re-enqueue and the reference will be
                // added then.
                if (addRef && !Values.IsEphemeral) {
                    Values.AddReference(node, unit);
                }
            }

            if (Getter != null) {
                res = res.Union(Getter.GetTypesNoCopy(unit, declaringScope).Call(node, unit, @this, ExpressionEvaluator.EmptySets));
            }

            return res;
        }
Esempio n. 32
0
        public override void SetVariable(VariableDef variable, object obj)
        {
            base.SetVariable(variable, obj);

            _valueWasAssigned = false;

            clear();

            if (variable != null)
            {
                Type enumtype = variable.ValueType;

                if (enumtype.IsEnum)
                {
                    string enumName = DesignerEnum.GetDisplayName(variable.Value);

                    filterEnums(null, enumName, enumtype);
                }
            }

            _valueWasAssigned = true;
        }
Esempio n. 33
0
        public void SetupCastSettings(object obj)
        {
            if (obj != null && obj is Behaviac.Design.Nodes.Node)
            {
                Behaviac.Design.Nodes.Node assignNode = obj as Behaviac.Design.Nodes.Node;

                if (assignNode != null)
                {
                    bool bCasting = assignNode.IsCasting;

                    if (bCasting)
                    {
                        DesignerPropertyInfo leftPropInfo = DesignerProperty.GetDesignerProperty(assignNode.GetType(), "Opl");
                        VariableDef          opl          = (VariableDef)leftPropInfo.GetValue(assignNode);

                        Type leftType = opl.ValueType;

                        // if number
                        if (Plugin.IsIntergerNumberType(leftType) || Plugin.IsFloatType(leftType))
                        {
                            this.ValueType = ValueTypes.Int | ValueTypes.Float;

                            this.FilterType = null;
                        }
                        else if (Plugin.IsRefType(leftType))
                        {
                            //ref type/pointer type
                            this.ValueType = ValueTypes.RefType;

                            this.FilterType = leftType;
                        }
                        else
                        {
                            //
                        }
                    }
                }
            }
        }
Esempio n. 34
0
        public virtual void AddProperty(MemberAddInfo member)
        {
            var desc = GetDescriptor(member.Name);

            VariableDef def = desc.Getter;

            if (def == null)
            {
                desc.Getter = def = new VariableDef();
            }

            FunctionValue func;

            if (member.Value is LazyPropertyFunctionValue)
            {
                func = member.Value as LazyPropertyFunctionValue;
            }
            else
            {
                func = new ReturningFunctionValue(ProjectEntry, member.Name, member.Value.Proxy);
            }
            def.AddTypes(ProjectState._builtinEntry, func.Proxy);
        }
Esempio n. 35
0
        private Type getPropertyType(DesignerPropertyInfo prop, object obj, string valueClass)
        {
            if (prop.Property != null && obj != null)
            {
                object propertyMember = prop.Property.GetValue(obj, null);

                if (propertyMember != null)
                {
                    VariableDef variable = propertyMember as VariableDef;

                    if (variable != null)
                    {
                        variable.ValueClass = valueClass;
                        return(variable.ValueType);
                    }

                    RightValueDef varRV = propertyMember as RightValueDef;

                    if (varRV != null)
                    {
                        return(varRV.ValueType);
                    }
                }
            }

            if (prop.Attribute != null)
            {
                DesignerPropertyEnum enumAtt = prop.Attribute as DesignerPropertyEnum;

                if (enumAtt != null)
                {
                    return(enumAtt.FilterType);
                }
            }

            return(null);
        }
        private Type getDependedPropertyType(DesignerPropertyInfo prop, object obj)
        {
            Debug.Check(obj != null);

            if (obj != null)
            {
                PropertyInfo pi = getDependedProperty(prop, obj);

                if (pi != null)
                {
                    object propertyMember = pi.GetValue(obj, null);

                    VariableDef variable = propertyMember as VariableDef;

                    if (variable != null)
                    {
                        return(variable.ValueType);
                    }

                    RightValueDef varRV = propertyMember as RightValueDef;

                    if (varRV != null)
                    {
                        return(varRV.ValueType);
                    }

                    MethodDef method = propertyMember as MethodDef;

                    if (method != null)
                    {
                        return(method.ReturnType);
                    }
                }
            }

            return(null);
        }
        public override void SetParameter(MethodDef.Param param, object obj, bool bReadonly)
        {
            base.SetParameter(param, obj, bReadonly);

            _resetProperties = false;

            Behaviac.Design.Attachments.Attach evt      = obj as Behaviac.Design.Attachments.Attach;
            Behaviac.Design.Nodes.BaseNode     baseNode = (evt != null) ? evt.Node : obj as Behaviac.Design.Nodes.BaseNode;
            Behaviac.Design.Nodes.Behavior     behavior = (baseNode != null) ? baseNode.Behavior as Behaviac.Design.Nodes.Behavior : null;

            string      selectionName = string.Empty;
            VariableDef variable      = param.Value as VariableDef;

            if (variable != null)
            {
                _valueOwner   = variable.ValueClass;
                selectionName = (variable.Property != null) ? variable.Property.DisplayName : variable.DisplayName;
            }
            else
            {
                RightValueDef variableRV = param.Value as RightValueDef;

                if (variableRV != null)
                {
                    _valueOwner   = variableRV.ValueClassReal;
                    selectionName = variableRV.DisplayName;
                }
            }

            _agentType = (behavior != null) ? behavior.AgentType : null;
            if (_valueOwner != VariableDef.kSelf)
            {
                _agentType = Plugin.GetInstanceAgentType(_valueOwner);
            }

            setComboBox(selectionName);
        }
Esempio n. 38
0
 protected void variable(string name, string type, Action act)
 {
     _curVar = new VariableDef {
         Name = name, TypeName = type
     };
     act();
     if (_curTask != null)
     {
         if (_curTask.Variables == null)
         {
             _curTask.Variables = new List <VariableDef>();
         }
         _curTask.Variables.Add(_curVar);
     }
     else
     {
         if (_currentCompositeTask.Variables == null)
         {
             _currentCompositeTask.Variables = new List <VariableDef>();
         }
         _currentCompositeTask.Variables.Add(_curVar);
     }
     _curVar = null;
 }
        public override void SetParameter(MethodDef.Param param, object obj, bool bReadonly)
        {
            base.SetParameter(param, obj, bReadonly);

            SetTypes();

            int typeIndex = -1;
            DesignerPropertyEditor editor = null;

            if (param.IsFromStruct)
            {
                string instance = string.Empty;
                string vt       = VariableDef.kConst;

                if (_param.Value is VariableDef)
                {
                    VariableDef v = _param.Value as VariableDef;
                    vt = v.ValueClass;

                    instance = vt;

                    if (instance != VariableDef.kSelf)
                    {
                        instance = Plugin.GetInstanceNameFromClassName(instance);
                    }
                }

                typeIndex = getComboIndex(vt, instance, "");

                editor = createEditor(vt);
            }
            else
            {
                string valueType    = "Self";
                string instance     = "Self";
                string propertyName = "";

                if (param.Value != null)
                {
                    bool bSet = ClearValueIfChanged(param);

                    if (bSet)
                    {
                        string[] tokens = param.Value.ToString().Split(' ');
                        propertyName = tokens[tokens.Length - 1];
                        instance     = Plugin.GetInstanceName(propertyName);
                        valueType    = string.Empty;

                        if (!string.IsNullOrEmpty(instance))
                        {
                            propertyName = propertyName.Substring(instance.Length + 1, propertyName.Length - instance.Length - 1);
                            valueType    = getValueType(param, instance, propertyName);
                        }
                        else
                        {
                            valueType = getValueType(param, propertyName);
                        }
                    }
                }

                typeIndex = getComboIndex(valueType, instance, propertyName);

                editor = createEditor(valueType);
            }

            if (editor != null)
            {
                setPropertyEditor(editor);
            }

            if (typeIndex > -1)
            {
                // Keep only one type for efficiency.
                this.typeComboBox.Items.Clear();
                this.typeComboBox.Items.Add(_types[typeIndex]);
                this.typeComboBox.SelectedIndex = 0;
            }
        }
        private void setEditor(DesignerPropertyEditor editor, string valueType)
        {
            if (editor == null)
            {
                return;
            }

            Type filterTypeCandidate = null;

            if (valueType == VariableDef.kConst)
            {
                if (_param.Value != null && (_param.Value is VariableDef || _param.Value is PropertyDef || _param.Value is ParInfo))
                {
                    if (!(_param.IsFromStruct))
                    {
                        _param.Value = Plugin.DefaultValue(_param.Type);
                    }
                    else
                    {
                        if (_param.Value is VariableDef)
                        {
                            VariableDef v = _param.Value as VariableDef;
                            _param.Value = Plugin.DefaultValue(v.ValueType);
                        }
                        else if (_param.Value is ParInfo)
                        {
                            ParInfo v = _param.Value as ParInfo;
                            _param.Value = Plugin.DefaultValue(v.Variable.ValueType);
                        }
                    }
                }
            }
            else
            {
                if (_param.Value is VariableDef)
                {
                    VariableDef v = _param.Value as VariableDef;

                    filterTypeCandidate = v.ValueType;

                    if (v.ValueClass != valueType)
                    {
                        Type   t1 = v.ValueType != null ? v.ValueType : _param.Type;
                        object dv = Plugin.DefaultValue(t1);
                        _param.Value = new VariableDef(dv, valueType);
                    }
                }
                else if (_param.Value is ParInfo)
                {
                    ParInfo v = _param.Value as ParInfo;

                    filterTypeCandidate = v.Variable.ValueType;

                    if (v.Variable.ValueClass != valueType)
                    {
                        object dv = Plugin.DefaultValue(v.Variable.ValueType);
                        _param.Value = new VariableDef(dv, valueType);
                    }
                }
                else
                {
                    _param.Value        = new VariableDef(_param.Value, valueType);
                    filterTypeCandidate = _param.Type;
                }
            }

            this.SetFilterType(editor, filterTypeCandidate);
            SetupCastSettings(_object);
            editor.SetParameter(_param, _object, false);

            editor.ValueWasAssigned();
            editor.ValueWasChanged += editor_ValueWasChanged;
        }
Esempio n. 41
0
 public DictParameterVariableDef(AnalysisUnit unit, Node location, VariableDef copy)
     : base(unit.DeclaringModule.ProjectEntry, location, copy) {
     Dict = new StarArgsDictionaryInfo(unit.ProjectEntry, location);
     AddTypes(unit, Dict);
 }
Esempio n. 42
0
 internal bool RemoveVariable(string name, out VariableDef value)
 {
     return(_variables.TryGetValue(name, out value) && _variables.Remove(name));
 }
Esempio n. 43
0
 public virtual VariableDef AddVariable(string name, VariableDef variable = null)
 {
     return(_variables[name] = variable ?? new VariableDef());
 }
Esempio n. 44
0
        protected VariableDef setProperty(AgentType agentType, string propertyName, string valueType)
        {
            if (agentType != null)
            {
                IList<PropertyDef> properties = agentType.GetProperties();
                foreach (PropertyDef p in properties)
                {
                    if (p.Name == propertyName
            #if BEHAVIAC_NAMESPACE_FIX
                        || p.Name.EndsWith(propertyName)
            #endif
                        )
                    {
                        VariableDef v = new VariableDef(p, valueType);
                        return v;
                    }
                }
            }

            return null;
        }
        public void TestLoadingObjectIndex()
        {
            foreach (IDataService dataService in DataServices)
            {
                var ds   = (SQLDataService)dataService;
                var ldef = SQLWhereLanguageDef.LanguageDef;

                // Сначала создаём структуру данных, требуемую для теста.
                var forest = new Лес();
                var bear1  = new Медведь()
                {
                    ЛесОбитания = forest, ПорядковыйНомер = 2
                };
                var bear2 = new Медведь()
                {
                    ЛесОбитания = forest, ПорядковыйНомер = 5
                };
                var bear3 = new Медведь()
                {
                    ЛесОбитания = forest, ПорядковыйНомер = 8
                };
                var updateObjectsArray = new DataObject[] { forest, bear3, bear1, bear2 };
                ds.UpdateObjects(ref updateObjectsArray);

                // Формируем функцию ограничения, что нас интересуют только медведи из текущего леса.
                Function functionCurrentForest = ldef.GetFunction(
                    ldef.funcEQ,
                    new VariableDef(ldef.GuidType, Information.ExtractPropertyPath <Медведь>(x => x.ЛесОбитания)),
                    forest.__PrimaryKey);

                var    view = Медведь.Views.OrderNumberTest;
                string numberPropertyName = Information.ExtractPropertyPath <Медведь>(x => x.ПорядковыйНомер);

                // Проверка индекса первого элемента.
                var lcs1 = LoadingCustomizationStruct.GetSimpleStruct(typeof(Медведь), view);
                lcs1.ColumnsSort = new[] { new ColumnsSortDef(numberPropertyName, SortOrder.Asc) };

                Function func1 = ldef.GetFunction(
                    ldef.funcAND,
                    functionCurrentForest,
                    ldef.GetFunction(ldef.funcEQ, new VariableDef(ldef.GuidType, SQLWhereLanguageDef.StormMainObjectKey),
                                     bear2.__PrimaryKey));

                int index1 = ds.GetObjectIndex(lcs1, func1);
                Assert.Equal(2, index1);

                // Проверка индекса первого элемента c учетом ограничения на номер записи.
                var lcs2 = LoadingCustomizationStruct.GetSimpleStruct(typeof(Медведь), view);
                lcs2.ColumnsSort = new[] { new ColumnsSortDef(numberPropertyName, SortOrder.Asc) };
                lcs2.RowNumber   = new RowNumberDef(2, 3);

                Function func2 = ldef.GetFunction(
                    ldef.funcAND,
                    functionCurrentForest,
                    ldef.GetFunction(ldef.funcEQ, new VariableDef(ldef.GuidType, SQLWhereLanguageDef.StormMainObjectKey),
                                     bear2.__PrimaryKey));

                int index2 = ds.GetObjectIndex(lcs2, func2);
                Assert.Equal(1, index2);

                // Проверка индекса нескольких элементов.
                var lcs3 = LoadingCustomizationStruct.GetSimpleStruct(typeof(Медведь), view);
                lcs3.ColumnsSort = new[] { new ColumnsSortDef(numberPropertyName, SortOrder.Asc) };

                var variableDef3 = new VariableDef(ldef.NumericType, numberPropertyName);
                var func3        = ldef.GetFunction(ldef.funcG, variableDef3, 3);

                int[] indexes3 = ds.GetObjectIndexes(lcs3, func3);
                Assert.NotNull(indexes3);
                Assert.Equal(indexes3.Length, 2);
                Assert.Equal(indexes3[0], 2);
                Assert.Equal(indexes3[1], 3);

                // Проверка индексов с первичными ключами элементов.
                IDictionary <int, string> indexesWithPk3 = ds.GetObjectIndexesWithPks(lcs3, func3);
                Assert.NotNull(indexesWithPk3);
                Assert.Equal(indexesWithPk3.Count, 2);
                Assert.Equal(indexesWithPk3[2], bear2.__PrimaryKey.ToString());
                Assert.Equal(indexesWithPk3[3], bear3.__PrimaryKey.ToString());
            }
        }
        internal FunctionAnalysisUnit AddFunction(FunctionObject node, AnalysisUnit outerUnit, bool isExpression = false) {
            EnvironmentRecord scope;
            if (!_scope.GlobalEnvironment.TryGetNodeEnvironment(node, out scope)) {
                if (node.Body == null) {
                    return null;
                }

                IAnalysisSet functionObj;
                UserFunctionValue func = null;
                if (!_scope.GlobalEnvironment.TryGetNodeValue(NodeEnvironmentKind.UserFunctionValue, node, out functionObj)) {
                    func = CreateUserFunction(node, outerUnit);
                } else {
                    func = (UserFunctionValue)functionObj;
                }

                var funcScope = GetFunctionEnvironment(func);
                scope = funcScope;

                VariableDef[] parameters = new VariableDef[node.ParameterDeclarations != null ? node.ParameterDeclarations.Length : 0];
                for (int i = 0; i < parameters.Length; i++) {
                    parameters[i] = funcScope.AddLocatedVariable(
                        node.ParameterDeclarations[i].Name,
                        node.ParameterDeclarations[i],
                        _curUnit.ProjectEntry
                    );
                }

                _scope.Children.Add(scope);
                _scope.GlobalEnvironment.AddNodeEnvironment(node, scope);

                if (!isExpression && node.Name != null) {
                    // lambdas don't have their names published
                    var funcVar = _scope.AddLocatedVariable(node.Name, node, funcScope.AnalysisUnit);
                    funcVar.AddTypes(funcScope.AnalysisUnit, func.SelfSet);
                }

                funcScope.AnalysisUnit.Enqueue();
            }

            return ((FunctionEnvironmentRecord)scope).AnalysisUnit;
        }
Esempio n. 47
0
 public override VariableDef AddVariable(string name, VariableDef variable = null) {
     return OuterScope.AddVariable(name, variable);
 }
Esempio n. 48
0
        public override IAnalysisSet GetMember(Node node, AnalysisUnit unit, string name) {
            var res = AnalysisSet.Empty;

            if (name == "func") {
                AddReference(node, unit);
                return _function;
            } else if (name == "args") {
                AddReference(node, unit);
                if (_argsTuple == null) {
                    _argsTuple = new SequenceInfo(_args.Take(_args.Length - _keywordArgNames.Length)
                        .Select(v => {
                            var vd = new VariableDef();
                            vd.AddTypes(unit, v, false, DeclaringModule);
                            return vd;
                        }).ToArray(),
                        unit.ProjectState.ClassInfos[BuiltinTypeId.Tuple],
                        node,
                        unit.ProjectEntry
                    );
                }
                return _argsTuple;
            } else if (name == "keywords") {
                AddReference(node, unit);
                if (_keywordsDict == null) {
                    var dict = new DictionaryInfo(unit.ProjectEntry, node);
                    _keywordsDict = dict;
                    for (int i = 0; i < _keywordArgNames.Length; ++i) {
                        int j = i + _args.Length - _keywordArgNames.Length;
                        if (j >= 0 && j < _args.Length) {
                            dict._keysAndValues.AddTypes(
                                unit,
                                unit.ProjectState.GetConstant(_keywordArgNames[i].Name),
                                _args[j],
                                false
                            );
                        }
                    }
                }
                return _keywordsDict;
            }
            return res;
        }
Esempio n. 49
0
        private static VariableDef createVariable(List<Nodes.Node.ErrorCheck> result, DefaultObject node, AgentType agentType, string instacneName, string propertyName)
        {
            List<string> tokens = DesignerPropertyEnum.SplitTokens(propertyName);
            Debug.Check(tokens.Count > 0);
            string arrayIndexStr = null;

            if (tokens.Count > 1) {
                propertyName = tokens[0] + "[]";
                arrayIndexStr = tokens[1];
            }

            Nodes.Behavior behavior = node.Behavior as Nodes.Behavior;
            agentType = Plugin.GetInstanceAgentType(instacneName, behavior, agentType);

            if (agentType != null) {
                IList<PropertyDef> properties = agentType.GetProperties();
                foreach(PropertyDef p in properties) {
                    if (p.Name == propertyName
#if BEHAVIAC_NAMESPACE_FIX
                        || p.Name.EndsWith(propertyName)
#endif
                       ) {
                        VariableDef v = new VariableDef(p, instacneName);

                        if (v != null && !string.IsNullOrEmpty(arrayIndexStr)) {
                            v.ArrayIndexElement = new MethodDef.Param("ArrayIndex", typeof(int), "int", "ArrayIndex", "ArrayIndex");
                            v.ArrayIndexElement.IsArrayIndex = true;
                            DesignerMethodEnum.parseParam(result, node, null, v.ArrayIndexElement, arrayIndexStr);
                        }

                        return v;
                    }
                }
            }

            return null;
        }
Esempio n. 50
0
        public override void SetVariable(VariableDef variable, object obj)
        {
            base.SetVariable(variable, obj);

            _valueWasAssigned = false;

            clear();

            if (variable != null)
            {
                Type enumtype = variable.GetValueType();
                if (enumtype.IsEnum)
                {
                    Array list = Enum.GetValues(enumtype);
                    string enumName = DesignerEnum.GetDisplayName(variable.Value);

                    foreach (object enumVal in list)
                    {
                        _allValues.Add(enumVal);

                        if (DesignerEnum.GetDisplayName(enumVal) == enumName)
                        {
                            _values.Add(enumVal);
                            comboBox.Items.Add(enumName);
                        }
                    }

                    comboBox.Text = enumName;
                }
            }

            _valueWasAssigned = true;
        }
Esempio n. 51
0
        protected VariableDef parseConstVar(NodeTag.DefaultObject node, object parentObject, string str)
        {
            Debug.Check(str.StartsWith("const"));

            //const Int32 1
            object propertyMemberDepended = null;
            Type objType = node.GetType();
            if (this.DependedProperty != "")
            {
                System.Reflection.PropertyInfo pi = objType.GetProperty(this.DependedProperty);

                if (pi != null)
                {
                    propertyMemberDepended = pi.GetValue(node, null);
                }
                else if (pi == null && parentObject != null)
                {
                    Type parentType = parentObject.GetType();
                    pi = parentType.GetProperty(this.DependedProperty);
                    propertyMemberDepended = pi.GetValue(parentObject, null);
                }
            }

            Type valueType = null;
            VariableDef variableDepended = propertyMemberDepended as VariableDef;
            if (variableDepended != null)
            {
                valueType = variableDepended.GetValueType();
            }
            else if (propertyMemberDepended != null)
            {
                MethodDef methodDepended = propertyMemberDepended as MethodDef;
                if (methodDepended != null)
                {
                    valueType = methodDepended.ReturnType;
                }
                else
                {
                    RightValueDef varRV = propertyMemberDepended as RightValueDef;
                    if (varRV != null)
                    {
                        valueType = varRV.ValueType;
                    }
                }
            }
            else
            {
                string[] tokens = str.Split(' ');
                Debug.Check(tokens.Length == 3);

                valueType = Plugin.GetTypeFromName(tokens[1]);
            }

            if (valueType != null)
            {
                VariableDef variable = new VariableDef(null);

                string[] tokens = str.Split(' ');
                Debug.Check(tokens.Length == 3);

                Plugin.InvokeTypeParser(valueType, tokens[2],
                    (object value) => variable.Value = value,
                    node);

                return variable;
            }

            return null;
        }
        public void TestLoadingObjectIndexesWithMaxResultsCount()
        {
            foreach (IDataService dataService in DataServices)
            {
                var ds   = (SQLDataService)dataService;
                var ldef = SQLWhereLanguageDef.LanguageDef;

                // Сначала создаём структуру данных, требуемую для теста.
                var forest = new Лес();
                var bear1  = new Медведь()
                {
                    ЛесОбитания = forest, ПорядковыйНомер = 2
                };
                var bear2 = new Медведь()
                {
                    ЛесОбитания = forest, ПорядковыйНомер = 5
                };
                var bear3 = new Медведь()
                {
                    ЛесОбитания = forest, ПорядковыйНомер = 8
                };
                var updateObjectsArray = new DataObject[] { forest, bear3, bear1, bear2 };

                ds.UpdateObjects(ref updateObjectsArray);

                var    view = Медведь.Views.OrderNumberTest;
                string numberPropertyName = Information.ExtractPropertyPath <Медведь>(x => x.ПорядковыйНомер);
                var    lcs = LoadingCustomizationStruct.GetSimpleStruct(typeof(Медведь), view);
                lcs.ColumnsSort = new[] { new ColumnsSortDef(numberPropertyName, SortOrder.Asc) };

                var      variable = new VariableDef(ldef.NumericType, numberPropertyName);
                Function func     = ldef.GetFunction(
                    ldef.funcAND,
                    ldef.GetFunction(
                        ldef.funcEQ,
                        new VariableDef(ldef.GuidType, Information.ExtractPropertyPath <Медведь>(x => x.ЛесОбитания)),
                        forest.__PrimaryKey),
                    ldef.GetFunction(ldef.funcG, variable, 3));

                // Меньше чем всего результатов.
                IDictionary <int, string> indexes1 = ds.GetObjectIndexesWithPks(lcs, func, 1);

                // Столько же, сколько всего результатов.
                IDictionary <int, string> indexes2 = ds.GetObjectIndexesWithPks(lcs, func, 2);

                // Больше чем число результатов.
                IDictionary <int, string> indexes3 = ds.GetObjectIndexesWithPks(lcs, func, 3);

                Assert.NotNull(indexes1);
                Assert.Equal(1, indexes1.Count);
                Assert.Equal(bear2.__PrimaryKey.ToString(), indexes1[2]);

                Assert.NotNull(indexes2);
                Assert.Equal(2, indexes2.Count);
                Assert.Equal(bear2.__PrimaryKey.ToString(), indexes2[2]);
                Assert.Equal(bear3.__PrimaryKey.ToString(), indexes2[3]);

                Assert.NotNull(indexes3);
                Assert.Equal(2, indexes3.Count);
                Assert.Equal(bear2.__PrimaryKey.ToString(), indexes3[2]);
                Assert.Equal(bear3.__PrimaryKey.ToString(), indexes3[3]);
            }
        }
Esempio n. 53
0
        protected VariableDef setParameter(NodeTag.DefaultObject node, string propertyType, string propertyName)
        {
            List<ParInfo> allPars = new List<ParInfo>();
            ((Nodes.Node)node.Behavior).GetAllPars(ref allPars);
            if (allPars.Count > 0)
            {
                string fullname = string.Format("{0} {1}", propertyType, propertyName);
                foreach (ParInfo p in allPars)
                {
                    if (p.ToString() == fullname)
                    {
                        VariableDef v = new VariableDef(p);
                        v.SetValue(p, VariableDef.kPar);
                        return v;
                    }
                }
            }

            return null;
        }
Esempio n. 54
0
 /// <summary>
 /// Handles the base assignment case for assign to a variable, minus variable creation.
 /// </summary>
 protected static bool AssignVariableWorker(Node location, AnalysisUnit unit, IAnalysisSet values, VariableDef vars)
 {
     vars.AddAssignment(location, unit);
     vars.MakeUnionStrongerIfMoreThan(unit.ProjectState.Limits.AssignedTypes, values);
     return(vars.AddTypes(unit, values));
 }
Esempio n. 55
0
        public override void SetMember(Node node, AnalysisUnit unit, string name, IAnalysisSet value) {
            if (_instanceAttrs == null) {
                _instanceAttrs = new Dictionary<string, VariableDef>();
            }

            VariableDef instMember;
            if (!_instanceAttrs.TryGetValue(name, out instMember) || instMember == null) {
                _instanceAttrs[name] = instMember = new VariableDef();
            }
            instMember.AddAssignment(node, unit);
            instMember.MakeUnionStrongerIfMoreThan(ProjectState.Limits.InstanceMembers, value);
            instMember.AddTypes(unit, value);
        }
Esempio n. 56
0
        public override void SetVariable(VariableDef variable, object obj)
        {
            base.SetVariable(variable, obj);

            if (variable != null)
            {
                string str = trimQuotes(variable.Value.ToString());
                if (textBox.Text != str)
                {
                    textBox.Text = str;

                    _modified = true;
                    valueChanged();
                }

                if (Plugin.IsCharType(variable.GetValueType()))
                {
                    textBox.MaxLength = 1;
                }
            }
        }
Esempio n. 57
0
        private void PropagateIsInstanceTypes(Node node, AnalysisUnit unit, IAnalysisSet typeSet, VariableDef variable) {
            foreach (var typeObj in typeSet) {
                ClassInfo classInfo;
                BuiltinClassInfo builtinClassInfo;
                SequenceInfo seqInfo;

                if ((classInfo = typeObj as ClassInfo) != null) {
                    variable.AddTypes(unit, classInfo.Instance, false);
                } else if ((builtinClassInfo = typeObj as BuiltinClassInfo) != null) {
                    variable.AddTypes(unit, builtinClassInfo.Instance, false);
                } else if ((seqInfo = typeObj as SequenceInfo) != null) {
                    if (seqInfo.Push()) {
                        try {
                            foreach (var indexVar in seqInfo.IndexTypes) {
                                PropagateIsInstanceTypes(node, unit, indexVar.Types, variable);
                            }
                        } finally {
                            seqInfo.Pop();
                        }
                    }
                }
            }
        }
Esempio n. 58
0
        public override void DeleteMember(Node node, AnalysisUnit unit, string name) {
            if (_instanceAttrs == null) {
                _instanceAttrs = new Dictionary<string, VariableDef>();
            }
            
            VariableDef instMember;
            if (!_instanceAttrs.TryGetValue(name, out instMember) || instMember == null) {
                _instanceAttrs[name] = instMember = new VariableDef();
            }

            instMember.AddReference(node, unit);

            _classInfo.GetMember(node, unit, name);
        }
Esempio n. 59
0
        public override void Update(object sender, DesignerPropertyInfo property)
        {
            if (_obj != null)
            {
                DesignerPropertyEditor oplEditor = GetEditor(_obj, "Opl");
                Debug.Check(oplEditor != null);

                if (oplEditor == sender)
                {
                    VariableDef opl = (VariableDef)GetProperty(_obj, "Opl");

                    if (opl != null)
                    {
                        RightValueDef opr = (RightValueDef)GetProperty(_obj, "Opr");

                        if (opr != null)
                        {
                            if (opl.ValueType != opr.ValueType)
                            {
                                DesignerPropertyEditor oprEditor = GetEditor(_obj, "Opr");
                                Debug.Check(oprEditor != null);
                                if (oprEditor != null)
                                {
                                    oprEditor.Clear();
                                }
                            }
                        }
                    }
                }
                else
                {
                    DesignerPropertyEditor oplEditorCast = GetEditor(_obj, "CastRight");
                    Debug.Check(oplEditorCast != null);

                    if (oplEditorCast == sender)
                    {
                        PluginBehaviac.Nodes.Assignment assignNode = _obj as PluginBehaviac.Nodes.Assignment;

                        if (assignNode != null)
                        {
                            RightValueDef opr = (RightValueDef)GetProperty(_obj, "Opr");

                            if (opr != null)
                            {
                                DesignerPropertyEditor oprEditor = GetEditor(_obj, "Opr");
                                Debug.Check(oprEditor != null);

                                // oprEditor.ValueType might be overwritten in SetupCastSettings if casting
                                // so that here to backup it first so that it can be restored later if not casting
                                if (assignNode.IsCasting)
                                {
                                    _valueTypesBackup = oprEditor.ValueType;
                                }
                                else
                                {
                                    oprEditor.ValueType = _valueTypesBackup;
                                }

                                oprEditor.Clear();
                                oprEditor.FilterType = null;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 60
0
        private Func <ColumnVal, Node> GetColumnWriter(VariableDef c)
        {
            String  TypeName;
            Boolean IsOptional;

            if (c.Type.OnTypeRef)
            {
                TypeName   = c.Type.TypeRef.Value;
                IsOptional = false;
            }
            else if (c.Type.OnOptional)
            {
                TypeName   = c.Type.Optional.Value;
                IsOptional = true;
            }
            else if (c.Type.OnList)
            {
                var ElementTypeName = c.Type.List.Value;
                if (!ElementTypeName.Equals("Byte", StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException("InvalidColumnListType: List<{0}>".Formats(ElementTypeName));
                }

                TypeName   = "Binary";
                IsOptional = false;
            }
            else
            {
                throw new InvalidOperationException();
            }
            Dictionary <Int64, String> EnumWriter = null;

            if (EnumUnderlyingTypes.ContainsKey(TypeName))
            {
                EnumWriter = EnumWriters[TypeName];
                TypeName   = EnumUnderlyingTypes[TypeName];
            }

            Func <ColumnVal, Node> Writer;

            if (!IsOptional)
            {
                if (TypeName.Equals("Boolean", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnPrimitive)
                        {
                            throw new InvalidOperationException();
                        }
                        var vv = v.Primitive;
                        if (!vv.OnBooleanValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.BooleanValue.ToInvariantString())
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("String", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnPrimitive)
                        {
                            throw new InvalidOperationException();
                        }
                        var vv = v.Primitive;
                        if (!vv.OnStringValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.StringValue)
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("Int", StringComparison.OrdinalIgnoreCase))
                {
                    if (EnumWriter != null)
                    {
                        Writer = v =>
                        {
                            if (!v.OnPrimitive)
                            {
                                throw new InvalidOperationException();
                            }
                            var vv = v.Primitive;
                            if (!vv.OnIntValue)
                            {
                                throw new InvalidOperationException();
                            }
                            if (EnumWriter.ContainsKey(vv.IntValue))
                            {
                                return(Node.CreateStem(new Stem {
                                    Name = c.Name, Children = new List <Node> {
                                        Node.CreateLeaf(EnumWriter[vv.IntValue])
                                    }
                                }));
                            }
                            else
                            {
                                return(Node.CreateStem(new Stem {
                                    Name = c.Name, Children = new List <Node> {
                                        Node.CreateLeaf(vv.IntValue.ToInvariantString())
                                    }
                                }));
                            }
                        };
                    }
                    else
                    {
                        Writer = v =>
                        {
                            if (!v.OnPrimitive)
                            {
                                throw new InvalidOperationException();
                            }
                            var vv = v.Primitive;
                            if (!vv.OnIntValue)
                            {
                                throw new InvalidOperationException();
                            }
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateLeaf(vv.IntValue.ToInvariantString())
                                }
                            }));
                        };
                    }
                }
                else if (TypeName.Equals("Int64", StringComparison.OrdinalIgnoreCase))
                {
                    if (EnumWriter != null)
                    {
                        Writer = v =>
                        {
                            if (!v.OnPrimitive)
                            {
                                throw new InvalidOperationException();
                            }
                            var vv = v.Primitive;
                            if (!vv.OnInt64Value)
                            {
                                throw new InvalidOperationException();
                            }
                            if (EnumWriter.ContainsKey(vv.Int64Value))
                            {
                                return(Node.CreateStem(new Stem {
                                    Name = c.Name, Children = new List <Node> {
                                        Node.CreateLeaf(EnumWriter[vv.Int64Value])
                                    }
                                }));
                            }
                            else
                            {
                                return(Node.CreateStem(new Stem {
                                    Name = c.Name, Children = new List <Node> {
                                        Node.CreateLeaf(vv.Int64Value.ToInvariantString())
                                    }
                                }));
                            }
                        };
                    }
                    else
                    {
                        Writer = v =>
                        {
                            if (!v.OnPrimitive)
                            {
                                throw new InvalidOperationException();
                            }
                            var vv = v.Primitive;
                            if (!vv.OnInt64Value)
                            {
                                throw new InvalidOperationException();
                            }
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateLeaf(vv.Int64Value.ToInvariantString())
                                }
                            }));
                        };
                    }
                }
                else if (TypeName.Equals("Real", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnPrimitive)
                        {
                            throw new InvalidOperationException();
                        }
                        var vv = v.Primitive;
                        if (!vv.OnRealValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.RealValue.ToInvariantString())
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("Binary", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnPrimitive)
                        {
                            throw new InvalidOperationException();
                        }
                        var vv = v.Primitive;
                        if (!vv.OnBinaryValue)
                        {
                            throw new InvalidOperationException();
                        }
                        var ByteString = String.Join(" ", vv.BinaryValue.Select(b => b.ToString("X2", System.Globalization.CultureInfo.InvariantCulture)).ToArray());
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(ByteString)
                            }
                        }));
                    };
                }
                else
                {
                    throw new InvalidOperationException("InvalidType: {0}".Formats(TypeName));
                }
            }
            else
            {
                if (TypeName.Equals("Boolean", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnOptional)
                        {
                            throw new InvalidOperationException();
                        }
                        if (v.Optional.OnNone)
                        {
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateEmpty()
                                }
                            }));
                        }
                        var vv = v.Optional.Some;
                        if (!vv.OnBooleanValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.BooleanValue.ToInvariantString())
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("String", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnOptional)
                        {
                            throw new InvalidOperationException();
                        }
                        if (v.Optional.OnNone)
                        {
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateEmpty()
                                }
                            }));
                        }
                        var vv = v.Optional.Some;
                        if (!vv.OnStringValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.StringValue)
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("Int", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnOptional)
                        {
                            throw new InvalidOperationException();
                        }
                        if (v.Optional.OnNone)
                        {
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateEmpty()
                                }
                            }));
                        }
                        var vv = v.Optional.Some;
                        if (!vv.OnIntValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.IntValue.ToInvariantString())
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("Int64", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnOptional)
                        {
                            throw new InvalidOperationException();
                        }
                        if (v.Optional.OnNone)
                        {
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateEmpty()
                                }
                            }));
                        }
                        var vv = v.Optional.Some;
                        if (!vv.OnInt64Value)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.Int64Value.ToInvariantString())
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("Real", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnOptional)
                        {
                            throw new InvalidOperationException();
                        }
                        if (v.Optional.OnNone)
                        {
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateEmpty()
                                }
                            }));
                        }
                        var vv = v.Optional.Some;
                        if (!vv.OnRealValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.RealValue.ToInvariantString())
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("Binary", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnOptional)
                        {
                            throw new InvalidOperationException();
                        }
                        if (v.Optional.OnNone)
                        {
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateEmpty()
                                }
                            }));
                        }
                        var vv = v.Optional.Some;
                        if (!vv.OnBinaryValue)
                        {
                            throw new InvalidOperationException();
                        }
                        var ByteString = String.Join(" ", vv.BinaryValue.Select(b => b.ToString("X2", System.Globalization.CultureInfo.InvariantCulture)).ToArray());
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(ByteString)
                            }
                        }));
                    };
                }
                else
                {
                    throw new InvalidOperationException("InvalidType: {0}".Formats(TypeName));
                }
            }
            return(Writer);
        }