static void DumpClasses(TextWriter writer, ASTContext ctx, IEnumerable <string> types, bool optional = false) { foreach (var @struct in types) { var @class = ctx.FindCompleteClass(@struct); if (@class == null) { @class = ctx.FindCompleteClass("_" + @struct); } if (@class == null) { var typedef = ctx.FindTypedef(@struct).FirstOrDefault( decl => !decl.IsIncomplete); if (typedef != null) { @class = GetClassFromTypedef(typedef); } } if (@class == null && optional) { continue; } if (@class == null) { throw new Exception("Expected to find struct definition for " + @struct); } DumpStruct(writer, @class); } }
protected AST.Type GetType(string typeName) { if (typeCache == null) { typeCache = new Dictionary <string, AST.Type>(); } AST.Type result; if (!typeCache.TryGetValue(typeName, out result)) { var typeDef = ASTContext.FindTypedef(typeName) .FirstOrDefault(); if (typeDef != null) { result = new TypedefType() { Declaration = typeDef } } ; typeCache.Add(typeName, result); } return(result); }
public static TypedefNameDecl Typedef(this ASTContext context, string name) { return(context.FindTypedef(name).First()); }
static void DumpClasses(TextWriter writer, ASTContext ctx, IEnumerable<string> types, bool optional = false) { foreach (var @struct in types) { var @class = ctx.FindCompleteClass(@struct); if (@class == null) @class = ctx.FindCompleteClass("_" + @struct); if (@class == null) { var typedef = ctx.FindTypedef(@struct).FirstOrDefault( decl => !decl.IsIncomplete); if (typedef != null) @class = GetClassFromTypedef(typedef); } if (@class == null && optional) continue; if (@class == null) throw new Exception("Expected to find struct definition for " + @struct); DumpStruct(writer, @class); } }
private bool VerifyAnonymousEnums(ASTContext context) { bool retVal = true; foreach (var anonEnum in Configuration.AnonymousEnums) { var typeDefs = context.FindTypedef(anonEnum.Value).ToList(); if (typeDefs.Count == 0) { retVal = false; Diagnostics.Warning("typedef {0} for anonymous enum not found in source" , anonEnum.Value ); } else if (typeDefs.Count > 1) { retVal = false; Diagnostics.Warning("Multiple type definitions for Anonymous enum ({0},{1}) found in source" , anonEnum.Key , anonEnum.Value ); foreach (var td in typeDefs) { Diagnostics.Warning("\t{0} in {1}@{2}", td.Name, td.TranslationUnit.FileRelativePath, td.LineNumberStart); } } /*At this point: typdefs.Count == 1 && typedefs[0] is the matching type - so good to go on that front */ var sourceEnums = (from unit in context.TranslationUnits let @enum = unit.FindEnumWithItem(anonEnum.Key) where @enum != null select @enum ).ToList(); if (sourceEnums.Count == 0) { retVal = false; Diagnostics.Warning("no enum found in source with first item matching {0}" , anonEnum.Key ); } else if (sourceEnums.Count > 1) { retVal = false; Diagnostics.Warning("Multiple enums found in source with first item matching {0}" , anonEnum.Key ); foreach (var e in sourceEnums) { Diagnostics.Warning("\t{1}@{2}", e.TranslationUnit.FileRelativePath, e.LineNumberStart); } } else if (!string.IsNullOrEmpty(sourceEnums[0].Name)) { retVal = false; var wrongEnum = sourceEnums[0]; Diagnostics.Warning("Found enum {0} in {1}@{2} with value {3} but expected an anonymous enum" , wrongEnum.Name , wrongEnum.TranslationUnit.FileRelativePath , wrongEnum.LineNumberStart , anonEnum.Key ); } } return(retVal); }