コード例 #1
0
        static void setNewExpectVariable(expectType expect, VariableTypes newType, int lineNumber, Logic[] logicOrder)
        {
            if (expect.currentType == VariableTypes.unknown)
            {
                return;
            }

            if (expect.currentType == VariableTypes.unsigned)
            {
                expect.currentType = newType;
            }
            else if (expect.currentType != newType)
            {
                var firstSumType  = SumParser.TypeToString(expect.currentType);
                var secondSumType = SumParser.TypeToString(newType);

                string errorMessage;

                if (firstSumType == "" || secondSumType == "")
                {
                    errorMessage = "Misslyckades med att para ihop " + expect.currentType + " med " + newType;
                }
                else
                {
                    errorMessage = "Kan inte para ihop " + firstSumType + " med " + secondSumType + ".";
                }

                ErrorMessage.sendErrorMessage(lineNumber, errorMessage);
            }

            if (expect.currentType == VariableTypes.boolean)
            {
                BooleanSumParser.validBoolSum(logicOrder, lineNumber);
            }
        }
コード例 #2
0
 public static string TypeToString(VariableTypes variableType)
 {
     if (variableType == VariableTypes.number)
     {
         return("ett tal");
     }
     if (variableType == VariableTypes.textString)
     {
         return("en sträng");
     }
     if (variableType == VariableTypes.boolean)
     {
         return("ett boolskt värde");
     }
     if (variableType == VariableTypes.None)
     {
         return("None");
     }
     if (variableType == VariableTypes.unknown)
     {
         return("ett okänt värde");
     }
     if (variableType == VariableTypes.unsigned)
     {
         return("ett odefinierat värde");
     }
     return("");
 }
コード例 #3
0
        private static void setNewExpectVariable(expectType expect, VariableTypes newType, int lineNumber)
        {
            if (expect.currentType == VariableTypes.unsigned)
            {
                expect.currentType = newType;
            }
            else if (expect.currentType != newType)
            {
                var firstSumType  = TypeToString(expect.currentType);
                var secondSumType = TypeToString(newType);

                string errorMessage;

                if (firstSumType == "" || secondSumType == "")
                {
                    errorMessage = "Misslyckades med att para ihop " + expect.currentType + " med " + newType;
                }
                else
                {
                    errorMessage = "Kan inte lägga ihop " + firstSumType + " med " + secondSumType + ".";
                }

                ErrorMessage.sendErrorMessage(lineNumber, errorMessage);
                expect.currentType = VariableTypes.unknown;
            }
        }
コード例 #4
0
        public VariableDescription(AALocalDecl localDecl, VariableTypes type)
        {
            Name = localDecl.GetName().Text;
            Type = Util.TypeToString(localDecl.GetType());
            switch (type)
            {
            case VariableTypes.LocalVariable:
                PlacementPrefix = "Local";
                break;

            case VariableTypes.Parameter:
                PlacementPrefix = "Parameter";
                break;

            case VariableTypes.StructVariable:
                PlacementPrefix = "Struct field";
                break;

            default:
                PlacementPrefix = "";
                break;
            }
            VariableType = type;
            Const        = localDecl.GetConst() != null;
            IsStatic     = localDecl.GetStatic() != null;
            Visibility   = localDecl.GetVisibilityModifier();
            realType     = (PType)localDecl.GetType().Clone();
            init         = localDecl.GetInit();
            Line         = localDecl.GetName().Line;
            Position     = TextPoint.FromCompilerCoords(localDecl.GetName());
        }
コード例 #5
0
        public static bool checkSumsToOperator(VariableTypes theSum, ComparisonType theOperator, int lineNumber)
        {
            if (theSum == VariableTypes.number)
            {
                return(true);
            }

            if (theSum == VariableTypes.boolean)
            {
                if (theOperator == ComparisonType.equalsTo || theOperator == ComparisonType.notEqualsTo)
                {
                    return(true);
                }
            }

            if (theSum == VariableTypes.textString)
            {
                if (theOperator == ComparisonType.equalsTo || theOperator == ComparisonType.notEqualsTo)
                {
                    return(true);
                }
            }


            ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, "Okänd operator kombination av " + theSum);
            return(false);
        }
コード例 #6
0
        /// <summary>
        ///     Returns a type from a name.  For example: System.Collections or System.Collections.ArrayList
        /// </summary>
        /// <param name="name">The name</param>
        /// <returns>The type or null if its not a valid type</returns>
        protected Type TryGetType(string name)
        {
            if (ImportedTypes.ContainsKey(name))
            {
                return(ImportedTypes[name]);
            }

            if (VariableTypes.ContainsKey(name))
            {
                return(VariableTypes[name]);
            }

            string  tryGetType = name + ".GetType()";
            dynamic type       = null;

            try
            {
                type = scope.Engine.CreateScriptSourceFromString(tryGetType, SourceCodeKind.Expression).Execute(scope);
            }
            catch (Exception e)
            {
                Log(e.ToString());
                Log("Failed to look up type");
            }
            return(type as Type);
        }
コード例 #7
0
 public VariableDescription(AALocalDecl localDecl, VariableTypes type)
 {
     Name = localDecl.GetName().Text;
     Type = Util.TypeToString(localDecl.GetType());
     switch (type)
     {
         case VariableTypes.LocalVariable:
             PlacementPrefix = "Local";
             break;
         case VariableTypes.Parameter:
             PlacementPrefix = "Parameter";
             break;
         case VariableTypes.StructVariable:
             PlacementPrefix = "Struct field";
             break;
         default:
             PlacementPrefix = "";
             break;
     }
     VariableType = type;
     Const = localDecl.GetConst() != null;
     IsStatic = localDecl.GetStatic() != null;
     Visibility = localDecl.GetVisibilityModifier();
     realType = (PType) localDecl.GetType().Clone();
     init = localDecl.GetInit();
     Line = localDecl.GetName().Line;
     Position = TextPoint.FromCompilerCoords(localDecl.GetName());
 }
コード例 #8
0
ファイル: ChepinMetrics.cs プロジェクト: Jetmix/Metrics
 private void AddVariable(String line, String template, Variable variable, VariableTypes type)
 {
     if (new Regex(String.Format(template, variable.Name)).IsMatch(line))
     {
         variable.AddType(type);
     }
 }
コード例 #9
0
ファイル: Level.cs プロジェクト: Jodacam/LevelEditorTFG
        public void ChangeVariableType(IData v, VariableTypes e)
        {
            int index = varList.IndexOf(v);

            varList.RemoveAt(index);
            switch (e)

            {
            case VariableTypes.String:
                var newString = new VariableString();
                newString.Init(v.varName);
                varList.Insert(index, newString);
                break;

            case VariableTypes.Boolean:
                var newBool = new VariableBool();
                newBool.Init(v.varName);
                varList.Insert(index, newBool);
                break;

            case VariableTypes.Int:
                var newInt = new VariableInt();
                newInt.Init(v.varName);
                varList.Insert(index, newInt);
                break;

            case VariableTypes.Float:
                var newFloat = new VariableFloat();
                newFloat.Init(v.varName);
                varList.Insert(index, newFloat);
                break;
            }
        }
コード例 #10
0
ファイル: Variable.cs プロジェクト: Jetmix/Metrics
 public void AddType(VariableTypes type)
 {
     if (!Type.Any(x => x == type))
     {
         Type.Add(type);
     }
 }
コード例 #11
0
 public Variable(string name, double newValue, bool isCalcVar = false)
 {
     this.name      = name;
     this.word      = name;
     variableType   = VariableTypes.number;
     numberValue    = newValue;
     this.isCalcVar = isCalcVar;
 }
コード例 #12
0
 public Variable(string name, bool newValue, bool isCalcVar = false)
 {
     this.name      = name;
     this.word      = name;
     variableType   = VariableTypes.boolean;
     boolValue      = newValue;
     this.isCalcVar = isCalcVar;
 }
コード例 #13
0
 public Variable(string name, string newValue, bool isCalcVar = false)
 {
     this.name      = name;
     this.word      = name;
     variableType   = VariableTypes.textString;
     stringValue    = newValue;
     this.isCalcVar = isCalcVar;
 }
コード例 #14
0
        private void checkType(VariableTypes type)
        {
            if (type != this.type)
            {
                switch (type)
                {
                case VariableTypes.UINT8:
                    value_uint8 = 0;
                    break;

                case VariableTypes.UINT16:
                    value_uint16 = 0;
                    break;

                case VariableTypes.UINT32:
                    value_uint32 = 0;
                    break;

                case VariableTypes.INT8:
                    value_int8 = 0;
                    break;

                case VariableTypes.INT16:
                    value_int16 = 0;
                    break;

                case VariableTypes.INT32:
                    value_int32 = 0;
                    break;

                case VariableTypes.ENUM:
                    value_enum = 0;
                    break;

                case VariableTypes.BOOL:
                    value_bool = false;
                    break;

                case VariableTypes.COLOR:
                    value_color = Color.EMPTY;
                    break;

                case VariableTypes.VECTOR2:
                case VariableTypes.UNKNOWN:
                    value_vector2.x = 0;
                    value_vector2.y = 0;
                    break;

                case VariableTypes.STRING:
                    value_string = string.Empty;
                    break;

                default:
                    throw new Exception("Unexpected value type.");
                }
            }
        }
コード例 #15
0
        public Token(ETokenTypes tokenType, string lexeme)
        {
            _tokenType          = tokenType;
            _lexeme             = lexeme;
            _keyword            = EKeywords.None;
            _variableType       = EVariableTypes.None;
            _variableNumber     = 0;
            _constantType       = EConstantTypes.None;
            _operatorPrecedence = -1;
            _symbol             = Symbols.Noop;
            switch (_tokenType)
            {
            case ETokenTypes.Identifier:
            {
                EKeywords keyword;
                if (Keywords.TryGetValue(_lexeme, out keyword))
                {
                    _keyword = keyword;
                }
                else
                {
                    int variableNumber;
                    if (int.TryParse(_lexeme.Substring(1), out variableNumber))
                    {
                        EVariableTypes variableType;
                        if (VariableTypes.TryGetValue(_lexeme[0], out variableType))
                        {
                            _variableType   = variableType;
                            _variableNumber = variableNumber;
                        }
                    }
                }
                if (_keyword == EKeywords.None && _variableType == EVariableTypes.None)
                {
                    throw new TokenizerException(string.Format("\"{0}\" is not a valid identifier: It's neither a keyword, an input variable Xn or a working variable Yn.", _lexeme));
                }
            }
            break;

            case ETokenTypes.IntegerLiteral:
                _constantType = EConstantTypes.IntegerConstant;
                break;

            case ETokenTypes.FloatLiteral:
                _constantType = EConstantTypes.FloatConstant;
                break;
            }
            Symbols operatorSymbol;

            if (BoolOpTable.TryGetValue(_keyword, out operatorSymbol) || SymbolTable.TryGetValue(_tokenType, out operatorSymbol))
            {
                _symbol             = operatorSymbol;
                _operatorPrecedence = OperatorPrecendences[_symbol];
            }
        }
コード例 #16
0
ファイル: Mission.cs プロジェクト: JeffM2501/Horizons
            public override void ReadXml(XmlReader reader)
            {
                if (!Enum.TryParse <VariableTypes>(reader.GetAttribute("type") ?? string.Empty, out type))
                {
                    type = VariableTypes.Unknown;
                }


                name  = reader.GetAttribute("name") ?? string.Empty;
                value = reader.GetAttribute("value") ?? string.Empty;
            }
コード例 #17
0
    public static bool GetVariableType(Type t, int var, VariableTypes vTypes)
    {
        LoadedRuntimeParameters lRP = loadedParamInstances[t].runtimeParameters[var];

        if (lRP.vT != null)
        {
            return(lRP.vT.Contains(vTypes));
        }

        return(false);
    }
コード例 #18
0
        public Type GetEditor(Type variableType)
        {
            if (variableType.IsGenericType)
            {
                variableType = variableType.GetGenericTypeDefinition();
            }

            Type type = null;

            VariableTypes.TryGetValue(variableType, out type);
            return(type);
        }
コード例 #19
0
 public VariableDescription(ATriggerDecl triggerDecl)
 {
     Name = triggerDecl.GetName().Text;
     Type = "trigger";
     PlacementPrefix = "Field";
     VariableType = VariableTypes.Field;
     Const = false;
     IsStatic = false;
     realType = new ANamedType(new TIdentifier("trigger"), null);
     Visibility = (PVisibilityModifier)triggerDecl.GetVisibilityModifier().Clone();
     Line = triggerDecl.GetName().Line;
     Position = TextPoint.FromCompilerCoords(triggerDecl.GetActionsToken());
 }
コード例 #20
0
 public VariableDescription(ATriggerDecl triggerDecl)
 {
     Name            = triggerDecl.GetName().Text;
     Type            = "trigger";
     PlacementPrefix = "Field";
     VariableType    = VariableTypes.Field;
     Const           = false;
     IsStatic        = false;
     realType        = new ANamedType(new TIdentifier("trigger"), null);
     Visibility      = (PVisibilityModifier)triggerDecl.GetVisibilityModifier().Clone();
     Line            = triggerDecl.GetName().Line;
     Position        = TextPoint.FromCompilerCoords(triggerDecl.GetActionsToken());
 }
コード例 #21
0
 public VariableDescription(AFieldDecl fieldDecl)
 {
     Name            = fieldDecl.GetName().Text;
     Type            = Util.TypeToString(fieldDecl.GetType());
     PlacementPrefix = "Field";
     VariableType    = VariableTypes.Field;
     Const           = fieldDecl.GetConst() != null;
     IsStatic        = fieldDecl.GetStatic() != null;
     Visibility      = fieldDecl.GetVisibilityModifier();
     realType        = (PType)fieldDecl.GetType().Clone();
     init            = fieldDecl.GetInit();
     Line            = fieldDecl.GetName().Line;
     Position        = TextPoint.FromCompilerCoords(fieldDecl.GetName());
 }
コード例 #22
0
 public VariableDescription(AFieldDecl fieldDecl)
 {
     Name = fieldDecl.GetName().Text;
     Type = Util.TypeToString(fieldDecl.GetType());
     PlacementPrefix = "Field";
     VariableType = VariableTypes.Field;
     Const = fieldDecl.GetConst() != null;
     IsStatic = fieldDecl.GetStatic() != null;
     Visibility = fieldDecl.GetVisibilityModifier();
     realType = (PType)fieldDecl.GetType().Clone();
     init = fieldDecl.GetInit();
     Line = fieldDecl.GetName().Line;
     Position = TextPoint.FromCompilerCoords(fieldDecl.GetName());
 }
コード例 #23
0
ファイル: CompileContext.cs プロジェクト: aarondh/TxMark
        public void RegisterVariable(VariableTypes variableType, string variableName)
        {
            VariableTypes originalType;

            if (_variableTypeByName.TryGetValue(variableName, out originalType))
            {
                if (originalType != variableType)
                {
                    Log(LogLevel.Error, $"Variable ${variableName} was already registered as a {originalType} variable", 0, 0);
                }
            }
            else
            {
                _variableTypeByName.Add(variableName, variableType);
            }
        }
コード例 #24
0
        public void LoadVariableTypes(Assembly assembly)
        {
            var varRegisters = assembly.GetCustomAttributes(typeof(VariableRegisterAttribute), false);

            foreach (VariableRegisterAttribute attr in varRegisters)
            {
                if (!VariableTypes.ContainsKey(attr.VariableType) || attr.EditorType != null)
                {
                    VariableTypes[attr.VariableType] = attr.EditorType;
                }
                if (attr.Hidden)
                {
                    HiddenVariables.Add(attr.VariableType);
                }
            }
        }
コード例 #25
0
        private VariableTypes GetVariableType(string name)
        {
            VariableTypes type = VariableTypes.Unknown;

            if (name.StartsWith("local", StringComparison.InvariantCultureIgnoreCase))
            {
                type = VariableTypes.Local;
            }
            else if (name.StartsWith("global", StringComparison.InvariantCultureIgnoreCase))
            {
                type = VariableTypes.Global;
            }
            else if (name.StartsWith("sys", StringComparison.InvariantCultureIgnoreCase))
            {
                type = VariableTypes.System;
            }
            return(type);
        }
コード例 #26
0
 public VariableDescription(APropertyDecl property)
 {
     Name            = property.GetName().Text;
     IsArrayProperty = Name == "array property";
     if (IsArrayProperty)
     {
         Name = "";
     }
     Type            = Util.TypeToString(property.GetType());
     PlacementPrefix = "Property";
     VariableType    = VariableTypes.Field;
     Const           = false;
     IsStatic        = property.GetStatic() != null;
     Visibility      = property.GetVisibilityModifier();
     realType        = (PType)property.GetType().Clone();
     Line            = property.GetName().Line;
     Position        = TextPoint.FromCompilerCoords(property.GetName());
 }
コード例 #27
0
        /// <summary>
        ///     Traverse the given source code and define variable types based on
        ///     the current scope
        /// </summary>
        /// <param name="line">The source code to look through</param>
        public void UpdateVariableTypes(string line)
        {
            this.VariableTypes.Clear(); // for now...

            var vars = this.FindAllVariables(line);

            foreach (var varData in vars)
            {
                if (this.VariableTypes.ContainsKey(varData.Key))
                {
                    VariableTypes[varData.Key] = varData.Value.Item3;
                }
                else
                {
                    VariableTypes.Add(varData.Key, varData.Value.Item3);
                }
            }
        }
コード例 #28
0
        public int containsVariableOfType(string name, VariableTypes checkType)
        {
            for (int i = 0; i < variableList.Count; i++)
            {
                if (variableList [i].name == name)
                {
                    if (variableList [i].variableType == checkType)
                    {
                        return(i);
                    }
                    else
                    {
                        return(-1);
                    }
                }
            }

            return(-1);
        }
コード例 #29
0
        public void read(Reader reader, List <string> variableNames = null)
        {
            name = new NameIdentifier(reader);
            type = (VariableTypes)reader.ReadByte();

            // if we have possible names, search em
            if (variableNames != null)
            {
                string hashString = name.hashString();
                foreach (string varName in variableNames)
                {
                    NameIdentifier currentName       = new NameIdentifier(varName);
                    String         currentHashedName = currentName.hashString();
                    if (currentHashedName == hashString)
                    {
                        name = currentName;
                        break;
                    }
                }
            }
        }
コード例 #30
0
        public static VariableData make_variable(VariableTypes type, int vnum, string tag)
        {
            var var = new VariableData
            {
                Type  = type,
                Flags = 0,
                vnum  = vnum,
                Tag   = tag,
                CTime = DateTime.Now,
                MTime = DateTime.Now,
                RTime = DateTime.MinValue,
                Timer = 0
            };

            if (type == VariableTypes.ExtendedBit)
            {
                var.Data = new ExtendedBitvector();
            }

            return(var);
        }
コード例 #31
0
        public Variable(VariableTypes type, string name = "")
        {
            Type = type;

            switch (type)
            {
            case VariableTypes.Integer:
            case VariableTypes.Continuous:
                VariableId = _nextVariableId++;
                break;

            case VariableTypes.PreperationTime:
            case VariableTypes.ExecutionTime:
            case VariableTypes.CalculationTime:
            case VariableTypes.ArrivalTime:
                VariableId = (int)type;
                break;

            default:
                throw new ArgumentOutOfRangeException(type.ToString(), type, null);
            }

            Name = name;
        }
コード例 #32
0
 public LevelAnswer(params bool[] answers)
 {
     parameterAmount = answers.Length;
     type            = VariableTypes.boolean;
     this.answer     = answers.Select(ans => ans.ToString()).ToArray();
 }
コード例 #33
0
ファイル: Variable.cs プロジェクト: xyuan/BoSSS
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="name"></param>
 /// <param name="type"></param>
 public Variable(string name, VariableTypes type)
 {
     this.Name = name;
     this.Type = type;
 }
コード例 #34
0
ファイル: Variable.cs プロジェクト: xyuan/BoSSS
 /// <summary>
 /// See <see cref="Variable"/> and <see cref="UpdateFunction"/>
 /// </summary>
 /// <param name="name"></param>
 /// <param name="type"></param>
 /// <param name="updateFunction"></param>
 public DerivedVariable(string name, VariableTypes type, Action <DGField, CellMask, IProgram <CNSControl> > updateFunction)
     : base(name, type)
 {
     this.UpdateFunction = updateFunction;
 }
コード例 #35
0
ファイル: PythonServices.cs プロジェクト: martinstacey/Dynamo
 /// <summary>
 /// Traverse the given source code and define variable types based on
 /// the current scope
 /// </summary>
 /// <param name="code">The source code to look through</param>
 internal void UpdateVariableTypes(string code)
 {
     VariableTypes.Clear();
     VariableTypes = FindAllVariableAssignments(code);
 }
コード例 #36
0
        private static bool IsVariableTypeValidForAddress(PlcMemoryModes operatingMode, MemoryAreas area, VariableTypes variableType, int memoryAddress, bool writeRequired)
        {
            if (operatingMode == PlcMemoryModes.CSCJMode)
            {
                switch (area)
                {
                    case MemoryAreas.CIO:

                        switch (variableType)
                        {
                            case VariableTypes.Bit:
                            case VariableTypes.BitWithForcedStatus:
                                Contract.Assert(memoryAddress.Between(0, 614315), String.Format("This memory address is out of range for {0} using the {1} data type", area, variableType));
                                return true;
                            case VariableTypes.Word:
                            case VariableTypes.WordWithForcedStatus:
                                Contract.Assert(memoryAddress.Between(0, 6143), String.Format("This memory address is out of range for {0} using the {1} data type", area, variableType));
                                return true;
                            default:
                                throw new InvalidOperationException("The variable type is not valid for this memory address");
                        }
                    case MemoryAreas.WR:
                        switch (variableType)
                        {
                            case VariableTypes.Bit:
                            case VariableTypes.BitWithForcedStatus:
                                Contract.Assert(memoryAddress.Between(0, 51115), String.Format("This memory address is out of range for {0} using the {1} data type", area, variableType));
                                return true;
                            case VariableTypes.Word:
                            case VariableTypes.WordWithForcedStatus:
                                Contract.Assert(memoryAddress.Between(0, 511), String.Format("This memory address is out of range for {0} using the {1} data type", area, variableType));
                                return true;
                            default:
                                throw new InvalidOperationException("The variable type is not valid for this memory address");
                        }
                    case MemoryAreas.DM:
                        switch (variableType)
                        {
                            case VariableTypes.Bit:
                                Contract.Assert(memoryAddress.Between(0, 3276715), String.Format("This memory address is out of range for {0} using the {1} data type", area, variableType));
                                return true;
                            case VariableTypes.Word:
                                Contract.Assert(memoryAddress.Between(0, 32767), String.Format("This memory address is out of range for {0} using the {1} data type", area, variableType));
                                return true;
                            default:
                                throw new InvalidOperationException("The variable type is not valid for this memory address");
                        }
                    case MemoryAreas.HR:
                        switch (variableType)
                        {
                            case VariableTypes.Bit:
                            case VariableTypes.BitWithForcedStatus:
                                Contract.Assert(memoryAddress.Between(0, 51115), String.Format("This memory address is out of range for {0} using the {1} data type", area, variableType));
                                return true;
                            case VariableTypes.Word:
                            case VariableTypes.WordWithForcedStatus:
                                Contract.Assert(memoryAddress.Between(0, 511), String.Format("This memory address is out of range for {0} using the {1} data type", area, variableType));
                                return true;
                            default:
                                throw new InvalidOperationException("The variable type is not valid for this memory address");
                        }

                    case MemoryAreas.AR:
                        switch (variableType)
                        {
                            case VariableTypes.Bit:
                            case VariableTypes.BitWithForcedStatus:
                                if (writeRequired)
                                {
                                    Contract.Assert(memoryAddress.Between(44800, 95915), String.Format("This memory address is out of range for {0} using the {1} data type. As this is a write operation the memory area must be between: {2} and {3}", area, variableType, 44800, 95915));
                                }
                                else
                                {
                                    Contract.Assert(memoryAddress.Between(0, 44715), String.Format("This memory address is out of range for {0} using the {1} data type", area, variableType));
                                }
                                return true;
                            default:
                                throw new InvalidOperationException("The variable type is not valid for this memory address");
                        }

                    case MemoryAreas.TIM:
                        switch (variableType)
                        {
                            case VariableTypes.CompletionFlag:
                            case VariableTypes.CompletionFlagWithForcedStatus:
                                Contract.Assert(memoryAddress.Between(0, 4095), String.Format("This memory address is out of range for {0} using the {1} data type", area, variableType));
                                return true;
                            default:
                                throw new InvalidOperationException("The variable type is not valid for this memory address");
                        }
                    case MemoryAreas.CNT:
                        switch (variableType)
                        {
                            case VariableTypes.CompletionFlag:
                            case VariableTypes.CompletionFlagWithForcedStatus:
                                Contract.Assert(memoryAddress.Between(0, 4095), String.Format("This memory address is out of range for {0} using the {1} data type", area, variableType));
                                return true;
                            default:
                                throw new InvalidOperationException("The variable type is not valid for this memory address");
                        }

                    default:
                        throw new InvalidOperationException(String.Format("Invalid memory area detected {0}", area));
                }

            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #37
0
        private static byte ParseMemoryAreaCode(VariableTypes variableType, PlcMemoryModes mode, MemoryAreas memoryArea)
        {
            {
                if (mode == PlcMemoryModes.CSCJMode)
                {
                    switch (variableType)
                    {
                        case VariableTypes.Bit:
                            switch (memoryArea)
                            {
                                case MemoryAreas.CIO:
                                    return Convert.ToByte("30", 16);
                                case MemoryAreas.WR:
                                    return Convert.ToByte("31", 16);
                                case MemoryAreas.HR:
                                    return Convert.ToByte("32", 16);
                                case MemoryAreas.AR:
                                    return Convert.ToByte("33", 16);
                                case MemoryAreas.DM:
                                    return Convert.ToByte("02", 16);
                                case MemoryAreas.TK:
                                    return Convert.ToByte("06", 16);
                                default:
                                    throw new InvalidOperationException(String.Format("The memory area {0} is not valid when using {1} mode when using the memory area as {2} ", memoryArea, mode, variableType));
                            }
                        case VariableTypes.BitWithForcedStatus:
                            switch (memoryArea)
                            {
                                case MemoryAreas.CIO:
                                    return Convert.ToByte("70", 16);
                                case MemoryAreas.WR:
                                    return Convert.ToByte("71", 16);
                                case MemoryAreas.HR:
                                    return Convert.ToByte("72", 16);
                                default:
                                    throw new InvalidOperationException(String.Format("The memory area {0} is not valid when using {1} mode when using the memory area as {2} ", memoryArea, mode, variableType));
                            }
                        case VariableTypes.Word:
                            switch (memoryArea)
                            {
                                case MemoryAreas.CIO:
                                    return Convert.ToByte("B0", 16);
                                case MemoryAreas.WR:
                                    return Convert.ToByte("B1", 16);
                                case MemoryAreas.HR:
                                    return Convert.ToByte("B2", 16);
                                case MemoryAreas.AR:
                                    return Convert.ToByte("B3", 16);
                                case MemoryAreas.DM:
                                    return Convert.ToByte("82", 16);
                                default:
                                    throw new InvalidOperationException(String.Format("The memory area {0} is not valid when using {1} mode when using the memory area as {2} ", memoryArea, mode, variableType));
                            }
                        case VariableTypes.WordWithForcedStatus:
                            switch (memoryArea)
                            {
                                case MemoryAreas.CIO:
                                    return Convert.ToByte("F0", 16);
                                case MemoryAreas.WR:
                                    return Convert.ToByte("F1", 16);
                                case MemoryAreas.HR:
                                    return Convert.ToByte("F2", 16);
                                default:
                                    throw new InvalidOperationException(String.Format("The memory area {0} is not valid when using {1} mode when using the memory area as {2} ", memoryArea, mode, variableType));
                            }
                        case VariableTypes.CompletionFlag:
                            switch (memoryArea)
                            {
                                case MemoryAreas.TIM:
                                case MemoryAreas.CNT:
                                    return Convert.ToByte("09", 16);
                                default:
                                    throw new InvalidOperationException(String.Format("The memory area {0} is not valid when using {1} mode when using the memory area as {2} ", memoryArea, mode, variableType));
                            }
                        case VariableTypes.Status:
                            switch (memoryArea)
                            {
                                case MemoryAreas.TK:
                                    return Convert.ToByte("46", 16);
                                default:
                                    throw new InvalidOperationException(String.Format("The memory area {0} is not valid when using {1} mode when using the memory area as {2} ", memoryArea, mode, variableType));
                            }
                        case VariableTypes.PV:
                            switch (memoryArea)
                            {
                                case MemoryAreas.IR:
                                    return Convert.ToByte("DC", 16);
                                case MemoryAreas.DR:
                                    return Convert.ToByte("DC", 16);
                                case MemoryAreas.TIM:
                                case MemoryAreas.CNT:
                                    return Convert.ToByte("89", 16);
                                default:
                                    throw new InvalidOperationException(String.Format("The memory area {0} is not valid when using {1} mode when using the memory area as {2} ", memoryArea, mode, variableType));
                            }
                        default:
                            throw new InvalidOperationException(String.Format("An invalid variable type {0} was used. ", variableType));
                    }

                }
                else
                {
                    //CV Mode
                    throw new NotImplementedException();
                }
            }
        }
コード例 #38
0
 public VariableDescription(APropertyDecl property)
 {
     Name = property.GetName().Text;
     IsArrayProperty = Name == "array property";
     if (IsArrayProperty)
         Name = "";
     Type = Util.TypeToString(property.GetType());
     PlacementPrefix = "Property";
     VariableType = VariableTypes.Field;
     Const = false;
     IsStatic = property.GetStatic() != null;
     Visibility = property.GetVisibilityModifier();
     realType = (PType)property.GetType().Clone();
     Line = property.GetName().Line;
     Position = TextPoint.FromCompilerCoords(property.GetName());
 }