Example #1
0
 /// <summary>
 /// Match this typeName to a candidate typeName. This type support wildcard matching against the candidate
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public bool Match(TypeName t)
 {
     if (IsWildcard)
     {
         return true;
     }
     if (Qualifiers.Count != t.Qualifiers.Count)
     {
         return false;
     }
     if (BaseName != t.BaseName)
     {
         return false;
     }
     for (int i = 0; i < Qualifiers.Count; ++i)
     {
         if (!Qualifiers[i].Match(t.Qualifiers[i]))
         {
             return false;
         }
     }
     // args must match one-for one, 
     // or if last arg is a wildcard it will match any number of additional args
     if (Args.Count > t.Args.Count || (Args.Count == 0 && t.Args.Count > 0) || (Args.Count < t.Args.Count && !Args[Args.Count - 1].IsWildcard))
     {
         return false;
     }
     for (int arg = 0; arg < Args.Count; ++arg)
     {
         if (!Args[arg].Match(t.Args[arg]))
         {
             return false;
         }
     }
     if (IsArray != t.IsArray)
     {
         return false;
     }
     if (IsArray)
     {
         if (Dimensions.Length != t.Dimensions.Length)
         {
             return false;
         }
         for (int i = 0; i < Dimensions.Length; i++)
         {
             if (Dimensions[i] != t.Dimensions[i])
             {
                 if (Dimensions[i] != -1)
                 {
                     return false;
                 }
             }
         }
     }
     return true;
 }
Example #2
0
 static TypeName()
 {
     s_identifier = new Regex("^[a-zA-Z$_][a-zA-Z$_0-9]*");
     s_numeric = new Regex("^[0-9]+(u|l|ul)*");        // only decimal constants
     s_simpleType = new Regex(
             @"^(signed\s+char|unsigned\s+char|char16_t|char32_t|wchar_t|char|"
             + @"signed\s+short\s+int|signed\s+short|unsigned\s+short\s+int|unsigned\s+short|short\s+int|short|"
             + @"signed\s+int|unsigned\s+int|int|"
             + @"signed\s+long\s+int|unsigned\s+long\s+int|long\s+int|long|"
             + @"signed\s+long\s+long\s+int|long\s+long\s+int|unsigned\s+long\s+long\s+int|long\s+long"
             + @"float|double|"
             + @"long\s+double|bool|void)\b" // matches prefixes ending in '$' (e.g. void$Foo), these are checked for below
         );
     s_any = new TypeName();
     s_any.IsWildcard = true;
 }
Example #3
0
 private static void MatchArray(TypeName t, string name, out string rest)
 {
     if (name.StartsWith("[]", StringComparison.Ordinal))
     {
         t.SetArraySize(new int[] { -1 });
         rest = name.Substring(2).Trim();
     }
     else if (name.StartsWith("[", StringComparison.Ordinal))  // TODO: handle multiple dimensions
     {
         string num = MatchConstant(name.Substring(1).Trim(), out rest);
         if (rest.StartsWith("]", StringComparison.Ordinal))
         {
             t.SetArraySize(new int[] { Int32.Parse(num, CultureInfo.InvariantCulture) });
         }
         rest = rest.Substring(1).Trim();
     }
     else
     {
         rest = name;
     }
 }
Example #4
0
 private static bool MatchTemplateList(string templist, out string rest, List<TypeName> args)
 {
     TypeName t;
     string arg = MatchConstant(templist, out rest); // no constants allowed in parameter lists
     if (!String.IsNullOrEmpty(arg))
     {
         var constantArg = new TypeName(arg);
         constantArg.FullyQualifiedName = arg;
         args.Add(constantArg);
     }
     else if (templist.StartsWith("*", StringComparison.Ordinal))
     {
         rest = templist.Substring(1).Trim();
         args.Add(TypeName.s_any);
     }
     else if ((t = MatchTypeName(templist, out rest)) != null)
     {
         args.Add(t);
     }
     else
     {
         return false;
     }
     if (rest.Length > 1 && rest[0] == ',')
     {
         return MatchTemplateList(rest.Substring(1).Trim(), out rest, args);
     }
     return true;
 }
Example #5
0
 private static TypeName MatchUnqualifiedName(string name, out string rest)
 {
     string basename = MatchIdentifier(name, out rest);
     if (String.IsNullOrEmpty(basename))
     {
         return null;
     }
     TypeName t = new TypeName(basename);
     if (rest.Length > 0 && rest[0] == '<')
     {
         if (!MatchTemplateList(rest.Substring(1).Trim(), out rest, t.Args) || rest.Length < 1 || rest[0] != '>')
         {
             return null;
         }
         rest = rest.Substring(1).Trim();
     }
     return t;
 }
Example #6
0
 public AliasInfo(TypeName name, AliasType alias)
 {
     ParsedName = name;
     Alias = alias;
 }
Example #7
0
 public VisualizerInfo(VisualizerType viz, TypeName name)
 {
     Visualizer = viz;
     // add the template parameter macro values
     ScopedNames = new Dictionary<string, string>();
     for (int i = 0; i < name.Args.Count; ++i)
     {
         ScopedNames["$T" + (i + 1)] = name.Args[i].FullyQualifiedName;
     }
 }
Example #8
0
        private VisualizerInfo Scan(TypeName name, IVariableInformation variable)
        {
            int aliasChain = 0;
            tryAgain:
            foreach (var autoVis in _typeVisualizers)
            {
                var visualizer = autoVis.Visualizers.Find((v) => v.ParsedName.Match(name));   // TODO: match on View, version, etc
                if (visualizer != null)
                {
                    _vizCache[variable.TypeName] = new VisualizerInfo(visualizer.Visualizer, name);
                    return _vizCache[variable.TypeName];
                }
            }
            // failed to find a visualizer for the type, try looking for a typedef
            foreach (var autoVis in _typeVisualizers)
            {
                var alias = autoVis.Aliases.Find((v) => v.ParsedName.Match(name));   // TODO: match on View, version, etc
                if (alias != null)
                {
                    // add the template parameter macro values
                    var scopedNames = new Dictionary<string, string>();
                    int t = 1;
                    for (int i = 0; i < name.Qualifiers.Count; ++i)
                    {
                        for (int j = 0; j < name.Qualifiers[i].Args.Count; ++j)
                        {
                            scopedNames["$T" + t] = name.Qualifiers[i].Args[j].FullyQualifiedName;
                            t++;
                        }
                    }

                    string newName = ReplaceNamesInExpression(alias.Alias.Value, null, scopedNames);
                    name = TypeName.Parse(newName);
                    aliasChain++;
                    if (aliasChain > MAX_ALIAS_CHAIN)
                    {
                        break;
                    }
                    goto tryAgain;
                }
            }
            return null;
        }
Example #9
0
 public TypeInfo(TypeName name, VisualizerType visualizer)
 {
     ParsedName = name;
     Visualizer = visualizer;
 }