コード例 #1
0
        internal static ISubRangeType Create(string name, IDataTypeResolver resolver)
        {
            string baseType = null;

            if (DataTypeStringParser.TryParseSubRange(name, out baseType))
            {
                IDataType type = null;
                if (resolver.TryResolveType(baseType, out type))
                {
                    Create(name, type);
                }
            }
            return(null);
        }
コード例 #2
0
        internal static ISubRangeType Create(AdsDataTypeEntry entry, IDataTypeResolver resolver)
        {
            ISubRangeType type     = null;
            string        baseType = null;

            if (DataTypeStringParser.TryParseSubRange(entry.entryName, out baseType))
            {
                IDataType type2 = null;
                if (resolver.TryResolveType(baseType, out type2))
                {
                    type = Create(entry.entryName, type2);
                }
            }
            return(type);
        }
コード例 #3
0
        private static ISubRangeType Create(string name, IDataType baseType)
        {
            ISubRangeType type = null;
            string        str;
            Type          managedType = ((IManagedMappableType)baseType).ManagedType;

            if (managedType == typeof(sbyte))
            {
                sbyte num;
                sbyte num2;
                DataTypeStringParser.TryParseSubRange <sbyte>(name, out str, out num, out num2);
                type = new SubRangeType <sbyte>(name, baseType.Name, 1, num, num2);
            }
            else if (managedType == typeof(byte))
            {
                byte num3;
                byte num4;
                DataTypeStringParser.TryParseSubRange <byte>(name, out str, out num3, out num4);
                type = new SubRangeType <byte>(name, baseType.Name, 1, num3, num4);
            }
            else if (managedType == typeof(short))
            {
                short num5;
                short num6;
                DataTypeStringParser.TryParseSubRange <short>(name, out str, out num5, out num6);
                type = new SubRangeType <short>(name, baseType.Name, 2, num5, num6);
            }
            else if (managedType == typeof(ushort))
            {
                ushort num7;
                ushort num8;
                DataTypeStringParser.TryParseSubRange <ushort>(name, out str, out num7, out num8);
                type = new SubRangeType <ushort>(name, baseType.Name, 2, num7, num8);
            }
            else if (managedType == typeof(int))
            {
                int num9;
                int num10;
                DataTypeStringParser.TryParseSubRange <int>(name, out str, out num9, out num10);
                type = new SubRangeType <int>(name, baseType.Name, 4, num9, num10);
            }
            else if (managedType == typeof(uint))
            {
                uint num11;
                uint num12;
                DataTypeStringParser.TryParseSubRange <uint>(name, out str, out num11, out num12);
                type = new SubRangeType <uint>(name, baseType.Name, 4, num11, num12);
            }
            else if (managedType == typeof(long))
            {
                long num13;
                long num14;
                DataTypeStringParser.TryParseSubRange <long>(name, out str, out num13, out num14);
                type = new SubRangeType <long>(name, baseType.Name, 8, num13, num14);
            }
            else
            {
                ulong num15;
                ulong num16;
                if (managedType != typeof(ulong))
                {
                    throw new AdsException($"Could not create range type '{name}'");
                }
                DataTypeStringParser.TryParseSubRange <ulong>(name, out str, out num15, out num16);
                type = new SubRangeType <ulong>(name, baseType.Name, 8, num15, num16);
            }
            return(type);
        }
コード例 #4
0
ファイル: SymbolParser.cs プロジェクト: Pravin044/TwinCat
        public static void ParseTypes(AdsStream dataTypeStream, Encoding encoding, IBinder binder, bool buildInTypesInStream, DataTypeCollection <IDataType> buildInTypes)
        {
            AdsBinaryReader reader         = new AdsBinaryReader(dataTypeStream);
            string          referencedType = null;

            while (dataTypeStream.Position < dataTypeStream.Length)
            {
                AdsDataTypeEntry entry = new AdsDataTypeEntry(true, encoding, reader);
                try
                {
                    IDataType type  = null;
                    bool      flag1 = buildInTypes.TryGetType(entry.entryName, out type);
                    DataType  type2 = (DataType)type;
                    if (buildInTypesInStream && flag1)
                    {
                        continue;
                    }
                    DataType type3  = null;
                    int      length = 0;
                    if (DataTypeStringParser.TryParseReference(entry.entryName, out referencedType))
                    {
                        type3 = new ReferenceType(entry, referencedType);
                    }
                    else if (DataTypeStringParser.TryParsePointer(entry.entryName, out referencedType))
                    {
                        type3 = new PointerType(entry, referencedType);
                    }
                    else
                    {
                        bool flag2;
                        if (DataTypeStringParser.TryParseString(entry.entryName, out length, out flag2))
                        {
                            type3 = !flag2 ? ((DataType) new StringType(length)) : ((DataType) new WStringType(length));
                        }
                        else if (entry.methodCount > 0)
                        {
                            type3 = new RpcStructType(entry);
                        }
                        else if (entry.subItems > 0)
                        {
                            bool flag3 = false;
                            bool flag4 = false;
                            if (entry.subItems > 1)
                            {
                                int             num2       = 0;
                                AdsFieldEntry[] subEntries = entry.subEntries;
                                int             index      = 0;
                                while (true)
                                {
                                    if (index >= subEntries.Length)
                                    {
                                        flag3 = entry.BitSize < num2;
                                        break;
                                    }
                                    AdsFieldEntry entry2 = subEntries[index];
                                    if (!entry2.IsStatic && !entry2.IsProperty)
                                    {
                                        int num4 = 0;
                                        num4   = !entry2.IsBitType ? (entry2.Offset * 8) : entry2.Offset;
                                        flag4 |= num4 < num2;
                                        num2  += entry2.BitSize;
                                    }
                                    index++;
                                }
                            }
                            type3 = !flag3 ? ((DataType) new StructType(entry)) : ((DataType) new UnionType(entry));
                        }
                        else if (entry.arrayDim > 0)
                        {
                            type3 = new ArrayType(entry);
                        }
                        else if (entry.enumInfoCount <= 0)
                        {
                            if (DataTypeStringParser.TryParseSubRange(entry.entryName, out referencedType))
                            {
                                type3 = (DataType)SubRangeTypeFactory.Create(entry, binder);
                            }
                            else if (((entry.baseTypeId > AdsDatatypeId.ADST_VOID) && (entry.typeName != null)) && (entry.typeName != string.Empty))
                            {
                                type3 = new AliasType(entry);
                            }
                            else
                            {
                                DataTypeCategory cat = CategoryConverter.FromId(entry.DataTypeId);
                                if (cat != DataTypeCategory.Unknown)
                                {
                                    Type tp = null;
                                    if (PrimitiveTypeConverter.TryGetManagedType(entry.DataTypeId, out tp))
                                    {
                                        if (cat == DataTypeCategory.Primitive)
                                        {
                                            type3 = new PrimitiveType(entry, PrimitiveTypeConverter.GetPrimitiveFlags(entry.DataTypeId), tp);
                                        }
                                        else if (cat == DataTypeCategory.String)
                                        {
                                            type3 = new StringType(entry);
                                        }
                                    }
                                }
                                if (type3 == null)
                                {
                                    type3 = new DataType(cat, entry);
                                }
                            }
                        }
                        else
                        {
                            AdsDatatypeId baseTypeId = entry.baseTypeId;
                            if (baseTypeId == AdsDatatypeId.ADST_INT16)
                            {
                                type3 = new EnumType <short>(entry);
                            }
                            else if (baseTypeId == AdsDatatypeId.ADST_INT32)
                            {
                                type3 = new EnumType <int>(entry);
                            }
                            else
                            {
                                switch (baseTypeId)
                                {
                                case AdsDatatypeId.ADST_INT8:
                                    type3 = new EnumType <sbyte>(entry);
                                    break;

                                case AdsDatatypeId.ADST_UINT8:
                                    type3 = new EnumType <byte>(entry);
                                    break;

                                case AdsDatatypeId.ADST_UINT16:
                                    type3 = new EnumType <ushort>(entry);
                                    break;

                                case AdsDatatypeId.ADST_UINT32:
                                    type3 = new EnumType <uint>(entry);
                                    break;

                                case AdsDatatypeId.ADST_INT64:
                                    type3 = new EnumType <long>(entry);
                                    break;

                                case AdsDatatypeId.ADST_UINT64:
                                    type3 = new EnumType <ulong>(entry);
                                    break;

                                default:
                                    throw new AdsException("Enum base type mismatch!");
                                }
                            }
                        }
                    }
                    binder.RegisterType(type3);
                }
                catch (Exception exception)
                {
                    Module.Trace.TraceWarning($"Cannot parse DataTypeEntry. Skipping dataType '{entry.entryName}'!", exception);
                }
            }
        }
コード例 #5
0
 internal TcAdsDataType(AdsDataTypeEntry entry, IDataTypeResolver table) : this()
 {
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     if (table == null)
     {
         throw new ArgumentNullException("table");
     }
     this._table         = table;
     this._size          = entry.size;
     this._typeName      = entry.entryName;
     this._typeHashValue = entry.typeHashValue;
     this._comment       = entry.Comment;
     this._flags         = entry.flags;
     this._offset        = entry.offset;
     this._dataTypeId    = entry.baseTypeId;
     if (entry.nameLength > 0)
     {
         bool   isUnicode            = false;
         int    length               = 0;
         string referencedType       = null;
         AdsDatatypeArrayInfo[] dims = null;
         string baseType             = null;
         if (entry.IsArray)
         {
             if (DataTypeStringParser.TryParseArray(this._typeName, out dims, out baseType))
             {
                 this._category     = DataTypeCategory.Array;
                 this._arrayInfo    = dims;
                 this._baseTypeName = baseType;
             }
             else
             {
                 this._arrayInfo    = entry.arrayInfos;
                 this._category     = DataTypeCategory.Array;
                 this._baseTypeName = entry.Name;
             }
         }
         else if (DataTypeStringParser.TryParseString(this._typeName, out length, out isUnicode))
         {
             this._category = DataTypeCategory.String;
         }
         else if (DataTypeStringParser.TryParseReference(this._typeName, out referencedType))
         {
             this._baseTypeName = referencedType;
             this._category     = DataTypeCategory.Reference;
         }
         else if (DataTypeStringParser.TryParsePointer(this._typeName, out referencedType))
         {
             this._baseTypeName = referencedType;
             this._category     = DataTypeCategory.Pointer;
         }
         else if (DataTypeStringParser.TryParseSubRange(this._typeName, out referencedType))
         {
             this._baseTypeName = entry.Name;
             this._category     = DataTypeCategory.SubRange;
         }
         else if (!string.IsNullOrEmpty(entry.Name))
         {
             this._baseTypeName = entry.Name;
             this._category     = DataTypeCategory.Alias;
         }
     }
     if (entry.subItems <= 0)
     {
         if (entry.IsEnum)
         {
             this._enumInfos = entry.enums;
             this._category  = DataTypeCategory.Enum;
             bool flag3 = PrimitiveTypeConverter.TryGetManagedType(this._dataTypeId, out this._managedType);
         }
     }
     else
     {
         this._subItems = new TcAdsSubItem[entry.subItems];
         bool flag2 = false;
         int  num2  = 0;
         int  index = 0;
         while (true)
         {
             int num1;
             if (index < entry.subItems)
             {
                 if (entry.subEntries[index] != null)
                 {
                     this._subItems[index] = new TcAdsSubItem(entry.subEntries[index], table);
                     if (!this._subItems[index].IsStatic && !this._subItems[index].IsProperty)
                     {
                         int num4 = 0;
                         num4   = !this._subItems[index].IsBitType ? (this._subItems[index].Offset * 8) : this._subItems[index].Offset;
                         flag2 |= num4 < num2;
                         num2  += this._subItems[index].BitSize;
                     }
                     index++;
                     continue;
                 }
                 object[] args = new object[] { index, entry.Name };
                 Module.Trace.TraceError("SubEntry '{0}' missing in TcAdsDataType '{1}'", args);
             }
             if ((entry.subItems <= 1) || (entry.BitSize >= num2))
             {
                 num1 = 0;
             }
             else
             {
                 num1 = (int)!entry.IsBitType;
             }
             this._category = ((num1 & flag2) == 0) ? DataTypeCategory.Struct : DataTypeCategory.Union;
             break;
         }
     }
     if (entry.HasAttributes)
     {
         this._attributes = entry.attributes;
     }
     if (entry.HasRpcMethods)
     {
         this._rpcMethodInfos = entry.methods;
     }
     if (this._category == DataTypeCategory.Unknown)
     {
         this._category = (entry.DataTypeId != AdsDatatypeId.ADST_BIGTYPE) ? DataTypeCategory.Primitive : DataTypeCategory.Interface;
     }
     if ((this._category == DataTypeCategory.Array) && string.IsNullOrEmpty(this._baseTypeName))
     {
         string message = $"Base type of ARRAY '{this._typeName}' not defined!";
         Module.Trace.TraceWarning(message);
     }
 }