Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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("");
 }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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());
        }
        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);
        }
        /// <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);
        }
 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());
 }
Ejemplo n.º 8
0
 private void AddVariable(String line, String template, Variable variable, VariableTypes type)
 {
     if (new Regex(String.Format(template, variable.Name)).IsMatch(line))
     {
         variable.AddType(type);
     }
 }
Ejemplo n.º 9
0
        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;
            }
        }
Ejemplo n.º 10
0
 public void AddType(VariableTypes type)
 {
     if (!Type.Any(x => x == type))
     {
         Type.Add(type);
     }
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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.");
                }
            }
        }
Ejemplo n.º 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];
            }
        }
Ejemplo n.º 16
0
            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;
            }
Ejemplo n.º 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);
    }
Ejemplo n.º 18
0
        public Type GetEditor(Type variableType)
        {
            if (variableType.IsGenericType)
            {
                variableType = variableType.GetGenericTypeDefinition();
            }

            Type type = null;

            VariableTypes.TryGetValue(variableType, out type);
            return(type);
        }
 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());
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 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());
 }
 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());
 }
Ejemplo n.º 23
0
        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);
            }
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
                    }
                }
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 32
0
 public LevelAnswer(params bool[] answers)
 {
     parameterAmount = answers.Length;
     type            = VariableTypes.boolean;
     this.answer     = answers.Select(ans => ans.ToString()).ToArray();
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="name"></param>
 /// <param name="type"></param>
 public Variable(string name, VariableTypes type)
 {
     this.Name = name;
     this.Type = type;
 }
Ejemplo n.º 34
0
 /// <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;
 }
Ejemplo n.º 35
0
 /// <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);
 }
        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();
            }
        }
        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();
                }
            }
        }
 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());
 }