示例#1
0
        /// <summary>
        /// Transforms the given node into some other node if necessary.
        /// </summary>
        /// <param name="node">The node to transform.</param>
        /// <returns>The transformed node.</returns>
        private static BaseNode TransformNode(BaseNode node)
        {
            var custom = GetCustomCodeGeneratorForNode(node);

            if (custom != null)
            {
                return(custom.TransformNode(node));
            }

            BaseNode GetCharacterNodeForEncoding(Encoding encoding)
            {
                if (encoding.IsSameCodePage(Encoding.Unicode))
                {
                    return(new Utf16CharacterNode());
                }
                if (encoding.IsSameCodePage(Encoding.UTF32))
                {
                    return(new Utf32CharacterNode());
                }
                return(new Utf8CharacterNode());
            }

            if (node is BaseTextNode textNode)
            {
                var arrayNode = new ArrayNode {
                    Count = textNode.Length
                };
                arrayNode.CopyFromNode(node);
                arrayNode.ChangeInnerNode(GetCharacterNodeForEncoding(textNode.Encoding));
                return(arrayNode);
            }

            if (node is BaseTextPtrNode textPtrNode)
            {
                var pointerNode = new PointerNode();
                pointerNode.CopyFromNode(node);
                pointerNode.ChangeInnerNode(GetCharacterNodeForEncoding(textPtrNode.Encoding));
                return(pointerNode);
            }

            if (node is BitFieldNode bitFieldNode)
            {
                var underlayingNode = bitFieldNode.GetUnderlayingNode();
                underlayingNode.CopyFromNode(node);
                return(underlayingNode);
            }

            if (node is BaseHexNode hexNode)
            {
                var arrayNode = new ArrayNode {
                    Count = hexNode.MemorySize
                };
                arrayNode.CopyFromNode(node);
                arrayNode.ChangeInnerNode(new Utf8CharacterNode());
                return(arrayNode);
            }

            return(node);
        }
示例#2
0
        public BaseNode GetEquivalentNode(ClassNode classNode)
        {
            var classInstanceNode = new ClassInstanceNode();

            classInstanceNode.ChangeInnerNode(classNode);

            var pointerNode = new PointerNode();

            pointerNode.ChangeInnerNode(classInstanceNode);
            pointerNode.CopyFromNode(this);

            return(pointerNode);
        }