Beispiel #1
0
 public override Node Clone(Node newParent)
 {
     var newMethodCall = new MethodCall(newParent);
     newMethodCall.Name = Name;
     newMethodCall.Parameters = (Parameters)Parameters.Clone(newMethodCall);
     newMethodCall.CalculatedValue = CalculatedValue.Clone(newParent);
     return newMethodCall;
 }
Beispiel #2
0
        internal static bool TryParse(Node parent, Queue<Word> remainingWords, out MethodCall methodCall)
        {
            if (remainingWords.Count < 2 ||
                remainingWords.Skip(1).First().Text != "(")
            {
                methodCall = null;
                return false;
            }

            methodCall = new MethodCall(parent);

            methodCall.Name = remainingWords.Dequeue().Text;
            Parameters parameters;
            if (!Parameters.TryParse(methodCall, remainingWords, out parameters))
            {
                methodCall = null;
                return false;
            }

            methodCall.Parameters = parameters;

            return true;
        }
Beispiel #3
0
        private bool TryMatchMethodCalls(
            MixinDefinition definition, 
            out MethodCall includeMethodCall, 
            out MethodCall mixinSignature)
        {
            includeMethodCall = Name.Children.First() as MethodCall;
            if (includeMethodCall == null)
            {
                includeMethodCall = null;
                mixinSignature = null;
                return false;
            }
            mixinSignature = definition.Name.Children.First() as MethodCall;
            if (mixinSignature == null)
            {
                includeMethodCall = null;
                mixinSignature = null;
                return false;
            }

            if (includeMethodCall.Name != mixinSignature.Name)
            {
                includeMethodCall = null;
                mixinSignature = null;
                return false;
            }

            return true;
        }
Beispiel #4
0
        private void ApplyMethodCall(MixinDefinition definition, MethodCall includeMethodCall, MethodCall mixinSignature)
        {
            var targetBlock = Parent as Block;
            var sourceBlock = definition.Value as Block;
            foreach (var child in sourceBlock.Children)
            {
                var newChild = child.Clone(targetBlock);
                targetBlock.Children.Add(newChild);
            }

            var enumerator = new LineDanceEnumerator(
                                    mixinSignature.Parameters.Children,
                                    includeMethodCall.Parameters.Children);

            while (enumerator.MoveNext())
            {
                var currents = enumerator.Currents;

                var mixinParameterExpression = currents.First() as Expression;
                var mixinVariable = mixinParameterExpression.Children.First() as Variable;

                var methodArgumentExpression = currents.Skip(1).First() as Expression;
                var argumentValue = methodArgumentExpression.Children.First();

                var variableReferences = new List<Node>();
                targetBlock.Find(n => (n is Variable &&
                    ((Variable)n).Name == mixinVariable.Name),
                    variableReferences);

                foreach (var variableReference in variableReferences)
                {
                    var variableContainer = variableReference.Parent as Expression;
                    var variableOrdinal = variableContainer.Children.IndexOf(variableReference);
                    var newValue = argumentValue.Clone(variableContainer);
                    variableContainer.Children[variableOrdinal] = newValue;
                }
            }
        }