Esempio n. 1
0
        private bool TryGetSubSymbol(IStructInstance root, string[] relativeInstancePath, int index, out T symbol)
        {
            IList <ISymbol> symbols      = null;
            string          instanceName = relativeInstancePath[index];

            if (!root.MemberInstances.TryGetInstanceByName(instanceName, out symbols) || (symbols.Count <= 0))
            {
                symbol = default(T);
                return(false);
            }
            T local = symbols[0];

            index++;
            if (relativeInstancePath.Length > index)
            {
                return(this.TryGetSubSymbol(local, relativeInstancePath, index, out symbol));
            }
            symbol = local;
            return(true);
        }
Esempio n. 2
0
        private IValueSymbol create(IValueSymbol symbol)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }
            DataTypeCategory category = symbol.Category;

            switch (category)
            {
            case DataTypeCategory.Alias:
            {
                IAliasInstance aliasInstance = symbol as IAliasInstance;
                if (aliasInstance != null)
                {
                    return(new DynamicAliasInstance(aliasInstance));
                }
                Module.Trace.TraceWarning($"'{symbol.InstancePath}' cannot be resolved to alias");
                return(new DynamicSymbol(symbol));
            }

            case DataTypeCategory.Enum:
                break;

            case DataTypeCategory.Array:
                if (symbol is IArrayInstance)
                {
                    return(!(symbol is IOversamplingArrayInstance) ? new DynamicArrayInstance((IArrayInstance)symbol) : new DynamicOversamplingArrayInstance((IOversamplingArrayInstance)symbol));
                }
                Module.Trace.TraceWarning($"'{symbol.InstancePath}' cannot be resolved to array");
                return(new DynamicSymbol(symbol));

            case DataTypeCategory.Struct:
            {
                IStructInstance instance3 = symbol as IStructInstance;
                if (instance3 != null)
                {
                    return(!instance3.HasRpcMethods ? new DynamicStructInstance((IStructInstance)symbol) : new DynamicRpcStructInstance((IRpcStructInstance)symbol));
                }
                Module.Trace.TraceWarning($"'{symbol.InstancePath}' cannot be resolved to struct");
                return(new DynamicSymbol(symbol));
            }

            default:
                switch (category)
                {
                case DataTypeCategory.Pointer:
                {
                    IPointerInstance pointerInstance = symbol as IPointerInstance;
                    if (pointerInstance != null)
                    {
                        return(new DynamicPointerInstance(pointerInstance));
                    }
                    Module.Trace.TraceWarning($"'{symbol.InstancePath}' cannot be resolved to pointer");
                    return(new DynamicSymbol(symbol));
                }

                case DataTypeCategory.Union:
                {
                    IUnionInstance unionInstance = symbol as IUnionInstance;
                    if (unionInstance != null)
                    {
                        return(new DynamicUnionInstance(unionInstance));
                    }
                    Module.Trace.TraceWarning($"'{symbol.InstancePath}' cannot be resolved to union");
                    return(new DynamicSymbol(symbol));
                }

                case DataTypeCategory.Reference:
                {
                    IReferenceInstance refInstance = symbol as IReferenceInstance;
                    if (refInstance != null)
                    {
                        return(new DynamicReferenceInstance(refInstance));
                    }
                    Module.Trace.TraceWarning($"'{symbol.InstancePath}' cannot be resolved to reference");
                    return(new DynamicSymbol(symbol));
                }

                default:
                    break;
                }
                break;
            }
            return(new DynamicSymbol(symbol));
        }
Esempio n. 3
0
 internal DynamicStructInstance(IStructInstance structInstance) : base((IValueSymbol)structInstance)
 {
     this.normalizedDict = new Dictionary <string, ISymbol>(StringComparer.OrdinalIgnoreCase);
     this.normalizedDict = createMemberDictionary(structInstance is IProcessImageAddress, structInstance.MemberInstances);
 }
        public static void AddSymbolRecursive(List <ISymbol> symbols, ISymbol symbol, bool debug = false)
        {
            try
            {
                if (symbol.DataType == null && symbol.Category != DataTypeCategory.Struct)
                {
                    return;
                }
                if (symbol.DataType != null && symbol.DataType.Name.StartsWith("TC2_MC2."))
                {
                    return;
                }
                if (symbol.TypeName != null && symbol.TypeName == "TC2_MC2.MC_Power")
                {
                    Console.WriteLine();
                }
                foreach (ITypeAttribute attribute in symbol.Attributes)
                {
                    if (debug)
                    {
                        Debug.WriteLine($"{attribute.Name} : {attribute.Value}");
                    }
                }

                if (debug)
                {
                    Debug.WriteLine(
                        $"{symbol.InstancePath} : {symbol.TypeName} (IG: 0x{((IAdsSymbol)symbol).IndexGroup:x} IO: 0x{((IAdsSymbol)symbol).IndexOffset:x} size: {symbol.Size})");
                }

                switch (symbol.Category)
                {
                case DataTypeCategory.Array:
                    IArrayInstance arrInstance = (IArrayInstance)symbol;
                    //IArrayType arrType = (IArrayType)symbol.DataType;

                    if (arrInstance.Elements != null)
                    {
                        // int count = 0;
                        foreach (ISymbol arrayElement in arrInstance.Elements)
                        {
                            AddSymbolRecursive(symbols, arrayElement);

                            //count++;
                            //if (count > 20) // Write only the first 20 to limit output
                            //    break;
                        }
                    }
                    else
                    {
                        Debug.WriteLine($"Array elements of {arrInstance.TypeName} are null");
                    }

                    break;

                case DataTypeCategory.Struct:
                    IStructInstance structInstance = (IStructInstance)symbol;
                    //IStructType structType = (IStructType)symbol.DataType;
                    try
                    {
                        foreach (ISymbol member in structInstance.MemberInstances)
                        {
                            AddSymbolRecursive(symbols, member);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }

                    break;

                case DataTypeCategory.Reference:
                    // "REFERENCE TO ..." cannot be read, so filter it out. Comes from InOut variables in function blocks
                    // pass
                    if (symbol.IsPointer || symbol.DataType.Name.StartsWith("POINTER"))
                    {
                        break;
                    }
                    break;

                default:
                    symbols.Add(symbol);
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                throw;
            }
        }