This class aids in code generation by making substitutions in a given tree. It will be extended as needed to deal with additional types of substitution. See the static methods on the class for a description of what is supported.
Inheritance: System.Compiler.StandardVisitor
示例#1
0
        /// <summary>
        /// Within "node", replace occurrences of identifiers matching oldName (by
        /// value) with the given newNode. newNode must be an expression.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="oldName"></param>
        /// <param name="newNode"></param>
        public static void Replace(Node node, Identifier oldName, Node newNode)
        {
            if (!(newNode is Expression))
                throw new ArgumentException("Replace: newNode must be an Expression");

            Replacer replacer = new Replacer(oldName, newNode);
            replacer.Visit(node);
        }
示例#2
0
 /// <summary>
 /// Within "node", find a labeled statement whose label matches the given
 /// string, and replace it with the supplied statement block.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="labelName"></param>
 /// <param name="block"></param>
 public static void Replace(Node node, string labelName, Block block)
 {
     Replacer replacer = new Replacer(new Identifier(labelName), block);
     replacer.Visit(node);
 }