bool EvaluateReference(string str, List <MSBuildItemEvaluated> evaluatedItemsCollection, ref int i, out object val, out bool needsItemEvaluation)
        {
            needsItemEvaluation = false;

            val = null;
            var tag   = str[i];
            int start = i;

            i += 2;
            int j = FindClosingChar(str, i, ')');

            if (j == -1)
            {
                val = StringInternPool.AddShared(str, start, str.Length - start);
                i   = str.Length;
                return(false);
            }

            string prop = StringInternPool.AddShared(str, i, j - i).Trim();

            i = j + 1;

            bool res = false;

            if (prop.Length > 0)
            {
                switch (tag)
                {
                case '$': {
                    bool nie;
                    res = EvaluateProperty(prop, evaluatedItemsCollection != null, out val, out nie);
                    needsItemEvaluation |= nie;
                    break;
                }

                case '%': res = EvaluateMetadata(prop, out val); break;

                case '@':
                    if (evaluatedItemsCollection != null)
                    {
                        res = EvaluateList(prop, evaluatedItemsCollection, out val);
                    }
                    else
                    {
                        res = false;
                        needsItemEvaluation = true;
                    }
                    break;
                }
            }
            if (!res)
            {
                val = StringInternPool.AddShared(str, start, j - start + 1);
            }

            return(res);
        }
        string Evaluate(string str, StringBuilder sb, List <MSBuildItemEvaluated> evaluatedItemsCollection, out bool needsItemEvaluation)
        {
            needsItemEvaluation = false;

            if (str == null)
            {
                return(null);
            }
            int i = FindNextTag(str, 0);

            if (i == -1)
            {
                return(str);
            }

            int last = 0;

            if (sb == null)
            {
                sb = GetEvaluationSb();
            }

            try {
                do
                {
                    sb.Append(str, last, i - last);
                    int    j = i;
                    object val;
                    bool   nie;
                    if (!EvaluateReference(str, evaluatedItemsCollection, ref j, out val, out nie))
                    {
                        allResolved = false;
                    }
                    needsItemEvaluation |= nie;
                    sb.Append(ValueToString(val));
                    last = j;

                    i = FindNextTag(str, last);
                }while (i != -1);

                sb.Append(str, last, str.Length - last);
                return(StringInternPool.AddShared(sb));
            } finally {
                evaluationSbs.Enqueue(sb);
            }
        }
Beispiel #3
0
        static bool ProcessTaskParameter(MSBuildOutputProcessor processor, BuildMessageEventArgs e, StringInternPool stringPool)
        {
            if (e.Message.IndexOf('\n') == -1)
            {
                var message = stringPool.Add(e.Message, TaskParameterMessagePrefix.Length, e.Message.Length - TaskParameterMessagePrefix.Length);
                processor.CurrentNode.AddParameter(message, message);
            }
            else
            {
                string content   = e.Message.Substring(TaskParameterMessagePrefix.Length);
                int    equalSign = content.IndexOf('=');
                if (equalSign < 0)
                {
                    return(false);
                }

                content = $"{content.Substring (0, equalSign).Trim ()}={content.Substring (equalSign + 1, content.Length - equalSign - 1).Trim ()}";
                processor.CurrentNode.AddParameter(stringPool.Add(content), stringPool.Add(e.Message));
            }

            return(true);
        }
Beispiel #4
0
        static void ProcessMessageEvent(MSBuildOutputProcessor processor, BuildMessageEventArgs e, StringInternPool stringPool)
        {
            if (String.IsNullOrEmpty(e.Message))
            {
                return;
            }

            switch (e.Message[0])
            {
            case 'S':
                if (e.Message.StartsWith(SkippingTargetMessagePrefix, StringComparison.Ordinal))
                {
                    // "Skipping target ..." messages
                    if (e.Message [SkippingTargetMessagePrefix.Length] == '"')
                    {
                        int nextQuoteIndex = e.Message.IndexOf('"', SkippingTargetMessagePrefix.Length + 1);
                        if (nextQuoteIndex >= 0)
                        {
                            if (processor.CurrentNode.NodeType == BuildOutputNodeType.Target &&
                                e.Message.IndexOf(processor.CurrentNode.Message,
                                                  SkippingTargetMessagePrefix.Length + 1,
                                                  nextQuoteIndex - 1 - SkippingTargetMessagePrefix.Length,
                                                  StringComparison.Ordinal) == SkippingTargetMessagePrefix.Length + 1)
                            {
                                processor.CurrentNode.NodeType = BuildOutputNodeType.TargetSkipped;
                                return;
                            }
                        }
                    }
                }
                break;

            case 'T':
                if (e.Message.StartsWith(TaskParameterMessagePrefix, StringComparison.Ordinal))
                {
                    // Task parameters are added to a special folder
                    if (ProcessTaskParameter(processor, e, stringPool))
                    {
                        return;
                    }
                }
                else if (e.Message.StartsWith(TargetMessagePrefix, StringComparison.Ordinal))
                {
                    // "Target ... skipped" messages
                    int nextQuoteIndex = e.Message.IndexOf('"', TargetMessagePrefix.Length + 1);
                    if (nextQuoteIndex >= 0)
                    {
                        if (e.Message.IndexOf(SkippedSuffix, nextQuoteIndex + 1, SkippedSuffix.Length, StringComparison.Ordinal) == nextQuoteIndex + 1)
                        {
                            processor.AddNode(BuildOutputNodeType.TargetSkipped,
                                              stringPool.Add(e.Message, TargetMessagePrefix.Length, nextQuoteIndex - TargetMessagePrefix.Length),
                                              stringPool.Add(e.Message),
                                              false,
                                              e.Timestamp);
                            return;
                        }
                    }
                }
                break;
            }

            string shortMessage = stringPool.Add(e.Message);

            processor.AddNode(e.Importance == MessageImportance.Low ? BuildOutputNodeType.Diagnostics : BuildOutputNodeType.Message,
                              shortMessage, shortMessage,
                              false,
                              e.Timestamp,
                              !String.IsNullOrEmpty(e.File) ? stringPool.Add(e.File) : null,
                              !String.IsNullOrEmpty(e.ProjectFile) ? stringPool.Add(e.ProjectFile) : null,
                              e.LineNumber);
        }
Beispiel #5
0
 public void Setup() => _stringPool = new StringInternPool();
        public static object ConsumeUntilNewLine(ref object ws)
        {
            if (ws == null)
            {
                return(null);
            }

            var s = ws as string;

            if (s != null)
            {
                for (int n = s.Length - 1; n >= 0; n--)
                {
                    var c = s [n];
                    if (c == '\r' || c == '\n')
                    {
                        if (n == s.Length - 1)
                        {
                            break;                             // Default case, consume the whole string
                        }
                        int    len = n + 1;
                        string res = StringInternPool.AddShared(s, 0, len);
                        ws = StringInternPool.AddShared(s, len, s.Length - len);
                        return(res);
                    }
                }
                var result = ws;
                ws = null;
                return(result);
            }
            var sb = ws as StringBuilder;

            if (sb != null)
            {
                for (int n = sb.Length - 1; n >= 0; n--)
                {
                    var c = sb [n];
                    if (c == '\r' || c == '\n')
                    {
                        if (n == sb.Length - 1)
                        {
                            break;                             // Default case, consume the whole string
                        }
                        var res = sb.ToString(0, n + 1);
                        sb.Remove(0, n + 1);
                        return(res);
                    }
                }
                string result = StringInternPool.AddShared(sb);
                ws = null;
                return(result);
            }

            // It's a MSBuildWhitespace

            var mw = (MSBuildWhitespace)ws;

            mw.GenerateStrings();

            var toSplit = mw.FindLastWithNewLine();

            if (toSplit == null)
            {
                var result = ws;
                ws = null;
                return(result);
            }
            else
            {
                var remaining = toSplit.content;
                var result    = ConsumeUntilNewLine(ref remaining);

                // Set the remaining value

                if (toSplit.next == null)
                {
                    // New line found in last node. The remaining is just the split string
                    ws = remaining;
                }
                else
                {
                    if (remaining == null)
                    {
                        return(toSplit.next);                        // Consumed the whole string of this node. The remaining is the next node
                    }
                    // New line found in the middle of the chain. A new node with the remaining has to be created
                    ws = new MSBuildWhitespace {
                        content = remaining,
                        next    = toSplit.next
                    };
                }

                // Generate the consumed value

                if (toSplit != mw)
                {
                    // New line found in the middle of the chain. Update the node content and split the chain.
                    toSplit.content = result;
                    toSplit.next    = null;
                    return(mw);
                }
                else
                {
                    // New line found in first node. The result is just the consumed string. Nothing else to do.
                    return(result);
                }
            }
        }