Esempio n. 1
0
 public DependencyRuleGroup Combine(DependencyRuleGroup other)
 {
     return(new DependencyRuleGroup(_group,
                                    _allowed.Union(other._allowed),
                                    _questionable.Union(other._questionable),
                                    _forbidden.Union(other._forbidden)));
 }
Esempio n. 2
0
 public DependencyRuleGroup Combine(DependencyRuleGroup other)
 {
     return new DependencyRuleGroup(_group,
         _allowed.Union(other._allowed),
         _questionable.Union(other._questionable),
         _forbidden.Union(other._forbidden));
 }
Esempio n. 3
0
        private bool ProcessText(string fullRuleFilename, uint startLineNo, TextReader tr, string leftParam,
                                 string rightParam)
        {
            uint lineNo   = startLineNo;
            bool textIsOk = true;
            DependencyRuleGroup currentGroup = _mainRuleGroup;

            for (; ;)
            {
                string line = tr.ReadLine();

                if (line == null)
                {
                    break;
                }

                line = line.Trim().Replace(LEFT_PARAM, leftParam).Replace(RIGHT_PARAM, rightParam);
                lineNo++;

                if (line == "" || line.StartsWith("#") || line.StartsWith("//"))
                {
                    // ignore;
                }
                else if (line.StartsWith("+"))
                {
                    string            includeFilename = line.Substring(1).Trim();
                    DependencyRuleSet included        = _checkerContext.Create(new FileInfo(fullRuleFilename).Directory,
                                                                               includeFilename,
                                                                               _defines,
                                                                               _macros);
                    if (included != null)
                    {
                        // Error message when == null has been output by Create.
                        _includedRuleSets.Add(included);

                        // We copy the defines down into the ruleset so that the selection
                        // of the longest name works (_defines implements this by using
                        // a SortedDictionary with a LengthComparer).
                        foreach (var kvp in included._defines)
                        {
                            _defines[kvp.Key] = kvp.Value;
                        }
                        foreach (var kvp in included._macros)
                        {
                            _macros[kvp.Key] = kvp.Value;
                        }
                    }
                }
                else if (line.EndsWith("{"))
                {
                    if (currentGroup.Group != "")
                    {
                        Log.WriteError(String.Format("{0}: Nested '... {{' not possible", fullRuleFilename), fullRuleFilename, lineNo);
                    }
                    else
                    {
                        currentGroup = new DependencyRuleGroup(line.TrimEnd('{').TrimEnd());
                        _ruleGroups.Add(currentGroup);
                    }
                }
                else if (line == "}")
                {
                    if (currentGroup.Group != "")
                    {
                        currentGroup = _mainRuleGroup;
                    }
                    else
                    {
                        Log.WriteError(String.Format("{0}: '}}' without corresponding '... {{'", fullRuleFilename), fullRuleFilename, lineNo);
                    }
                }
                else if (ProcessMacroIfFound(line))
                {
                    // macro is already processed as side effect in ProcessMacroIfFound()
                }
                else if (line.Contains(MAYUSE) || line.Contains(MUSTNOTUSE) ||
                         line.Contains(MAYUSE_WITH_WARNING))
                {
                    currentGroup.AddDependencyRules(this, fullRuleFilename, lineNo, line);
                }
                else if (line.StartsWith(GRAPHIT))
                {
                    AddGraphAbstractions(fullRuleFilename, lineNo, line);
                }
                else if (line.EndsWith(MACRO_DEFINE))
                {
                    string macroName = line.Substring(0, line.Length - MACRO_DEFINE.Length).Trim();
                    if (!CheckDefinedName(macroName, fullRuleFilename, lineNo))
                    {
                        textIsOk = false;
                    }
                    string macroText        = "";
                    uint   macroStartLineNo = lineNo;
                    for (; ;)
                    {
                        line = tr.ReadLine();
                        lineNo++;
                        if (line == null)
                        {
                            Log.WriteError(String.Format("{0}: Missing {1} at end", fullRuleFilename, MACRO_END), fullRuleFilename, lineNo);
                            textIsOk = false;
                            break;
                        }
                        line = line.Trim();
                        if (line == MACRO_END)
                        {
                            var macro = new Macro(macroText, fullRuleFilename, macroStartLineNo);
                            if (_macros.ContainsKey(macroName) && !_macros[macroName].Equals(macro))
                            {
                                throw new ApplicationException("Macro '" + macroName + "' cannot be redefined differently at " + fullRuleFilename + ":" + lineNo);
                            }
                            _macros[macroName] = macro;
                            break;
                        }
                        else
                        {
                            macroText += line + "\n";
                        }
                    }
                }
                else if (line.Contains(DEFINE))
                {
                    AddDefine(fullRuleFilename, lineNo, line);
                }
                else
                {
                    Log.WriteError(fullRuleFilename + ": Cannot parse line " + lineNo + ": " + line, fullRuleFilename, lineNo);
                    textIsOk = false;
                }
            }
            return(textIsOk);
        }
Esempio n. 4
0
 /// <summary>
 /// Constructor for test cases.
 /// </summary>
 public DependencyRuleSet(CheckerContext checkerContext)
 {
     _checkerContext = checkerContext;
     _mainRuleGroup  = new DependencyRuleGroup("");
     _ruleGroups.Add(_mainRuleGroup);
 }