public override bool VisitDeclContext(DeclarationContext context) { foreach (var decl in context.Declarations) { decl.Visit(this); } return(true); }
private static bool IsNameSpaceStd(DeclarationContext declarationContext) { if (declarationContext == null) return false; var @namespace = declarationContext as Namespace; if (@namespace != null && @namespace.IsInline) return IsNameSpaceStd(declarationContext.Namespace); return declarationContext.OriginalName == "std"; }
public override bool VisitDeclContext(DeclarationContext context) { PushBlock(BlockKind.Namespace); foreach (var @class in context.Classes) { if ([email protected] || @class.IsDependent) { continue; } if (@class.IsOpaque || @class.IsIncomplete) { continue; } @class.Visit(this); } // Generate all the function declarations for the module. foreach (var function in context.Functions.Where(f => f.IsGenerated)) { function.Visit(this); } if (Options.GenerateFunctionTemplates) { foreach (var template in context.Templates) { if (!template.IsGenerated) { continue; } var functionTemplate = template as FunctionTemplate; if (functionTemplate == null) { continue; } if (!functionTemplate.IsGenerated) { continue; } GenerateFunctionTemplate(functionTemplate); } } foreach (var childNamespace in context.Namespaces) { VisitDeclContext(childNamespace); } PopBlock(); return(true); }
private void GenerateDeclContext(DeclarationContext @namespace) { PushBlock(BlockKind.Namespace); foreach (var @class in @namespace.Classes) { if ([email protected] || @class.IsDependent) { continue; } if (@class.IsOpaque || @class.IsIncomplete) { continue; } GenerateClass(@class); } // Generate all the function declarations for the module. foreach (var function in @namespace.Functions.Where(f => f.IsGenerated)) { GenerateFunction(function, @namespace); NewLine(); } if (Options.GenerateFunctionTemplates) { foreach (var template in @namespace.Templates) { if (!template.IsGenerated) { continue; } var functionTemplate = template as FunctionTemplate; if (functionTemplate == null) { continue; } if (!functionTemplate.IsGenerated) { continue; } GenerateFunctionTemplate(functionTemplate); } } foreach (var childNamespace in @namespace.Namespaces) { GenerateDeclContext(childNamespace); } PopBlock(); }
public override void VisitDeclContextFunctions(DeclarationContext context) { var functions = context.Functions.Where(f => !ASTUtils.CheckIgnoreFunction(f)).ToList(); var unique = functions.GroupBy(m => m.Name); foreach (var group in unique) { GenerateFunctionGroup(group.ToList()); } }
/// <summary> /// Generates a new typedef for the given type if necessary and returns the new type. /// </summary> /// <param name="namespace">The namespace the typedef will be added to.</param> /// <param name="type">The type to check.</param> /// <returns>The new type.</returns> private QualifiedType CheckType(DeclarationContext @namespace, QualifiedType type) { var pointerType = type.Type as PointerType; if (pointerType == null) { return(type); } var functionType = pointerType.Pointee as FunctionType; if (functionType == null) { return(type); } List <Typedef> typedefs; if (!allTypedefs.TryGetValue(@namespace.QualifiedName, out typedefs)) { typedefs = new List <Typedef>(); allTypedefs.Add(@namespace.QualifiedName, typedefs); } var typedef = FindMatchingTypedef(typedefs, functionType); if (typedef == null) { for (int i = 0; i < functionType.Parameters.Count; i++) { functionType.Parameters[i].Name = string.Format("_{0}", i); } typedef = new TypedefDecl { Access = AccessSpecifier.Public, Name = string.Format("__AnonymousDelegate{0}", typedefs.Count), Namespace = @namespace, QualifiedType = type, IsSynthetized = true }; typedefs.Add(new Typedef { Context = @namespace, Declaration = typedef }); } var typedefType = new TypedefType { Declaration = typedef }; return(new QualifiedType(typedefType)); }
public virtual void GenerateTypedefs(DeclarationContext decl) { foreach (var typedef in decl.Typedefs) { if (!typedef.IsGenerated) { continue; } typedef.Visit(this); } }
public virtual bool VisitDeclContext(DeclarationContext context) { foreach (var decl in context.Declarations) { if (decl.IsGenerated) { decl.Visit(this); } } return(true); }
public override bool VisitDeclContext(DeclarationContext context) { foreach (var decl in context.Declarations.Where(d => !(d is Enumeration))) { if (decl.IsGenerated) { decl.Visit(this); } } return(true); }
private void RemoveUnusedStdTypes(DeclarationContext context) { for (int i = context.Declarations.Count - 1; i >= 0; i--) { var declaration = context.Declarations[i]; var nestedContext = declaration as Namespace; if (nestedContext != null) RemoveUnusedStdTypes(nestedContext); else if (!this.usedStdTypes.Contains(declaration)) context.Declarations.RemoveAt(i); } }
private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null) { Class type = (Class)context; if (type.Properties.All(p => getter.Name != p.Name || p.ExplicitInterfaceImpl != getter.ExplicitInterfaceImpl)) { Property property = new Property(); property.Name = GetPropertyName(getter.Name); property.Namespace = type; property.QualifiedType = getter.OriginalReturnType; if (getter.IsOverride || (setter != null && setter.IsOverride)) { Property baseVirtualProperty = type.GetRootBaseProperty(property); if (baseVirtualProperty.SetMethod == null) { setter = null; } } property.GetMethod = getter; property.SetMethod = setter; property.ExplicitInterfaceImpl = getter.ExplicitInterfaceImpl; if (property.ExplicitInterfaceImpl == null && setter != null) { property.ExplicitInterfaceImpl = setter.ExplicitInterfaceImpl; } if (getter.Comment != null) { var comment = new RawComment(); comment.Kind = getter.Comment.Kind; comment.BriefText = getter.Comment.BriefText; comment.Text = getter.Comment.Text; if (getter.Comment.FullComment != null) { comment.FullComment = new FullComment(); comment.FullComment.Blocks.AddRange(getter.Comment.FullComment.Blocks); if (setter != null && setter.Comment != null) { comment.BriefText += Environment.NewLine + setter.Comment.BriefText; comment.Text += Environment.NewLine + setter.Comment.Text; comment.FullComment.Blocks.AddRange(setter.Comment.FullComment.Blocks); } } property.Comment = comment; } type.Properties.Add(property); getter.GenerationKind = GenerationKind.Internal; if (setter != null) { setter.GenerationKind = GenerationKind.Internal; } } }
public bool VisitDeclContext(DeclarationContext ctx) { foreach (var decl in ctx.Declarations) { if (!decl.Ignore) { decl.Visit(this); } } return(true); }
void VisitDeclContext(DeclarationContext ctx, AST.DeclarationContext _ctx) { for (uint i = 0; i < ctx.NamespacesCount; ++i) { var decl = ctx.getNamespaces(i); var _decl = Visit(decl) as AST.Namespace; _ctx.Namespaces.Add(_decl); } for (uint i = 0; i < ctx.EnumsCount; ++i) { var decl = ctx.getEnums(i); var _decl = Visit(decl) as AST.Enumeration; _ctx.Enums.Add(_decl); } for (uint i = 0; i < ctx.FunctionsCount; ++i) { var decl = ctx.getFunctions(i); var _decl = Visit(decl) as AST.Function; _ctx.Functions.Add(_decl); } for (uint i = 0; i < ctx.ClassesCount; ++i) { var decl = ctx.getClasses(i); var _decl = Visit(decl) as AST.Class; _ctx.Classes.Add(_decl); } for (uint i = 0; i < ctx.TemplatesCount; ++i) { var decl = ctx.getTemplates(i); var _decl = Visit(decl) as AST.Template; _ctx.Templates.Add(_decl); } for (uint i = 0; i < ctx.TypedefsCount; ++i) { var decl = ctx.getTypedefs(i); var _decl = Visit(decl) as AST.TypedefDecl; _ctx.Typedefs.Add(_decl); } for (uint i = 0; i < ctx.VariablesCount; ++i) { var decl = ctx.getVariables(i); var _decl = Visit(decl) as AST.Variable; _ctx.Variables.Add(_decl); } // Anonymous types }
public void GenerateTypedefs(DeclarationContext decl) { foreach (var typedef in decl.Typedefs) { if (!typedef.IsGenerated) { continue; } GenerateTypedef(typedef); } }
public void GenerateDeclContext(DeclarationContext decl) { // Generate all the type references for the module. foreach (var typeRef in decl.TypeReferences) { WriteLine(typeRef.FowardReference); } // Generate all the enum declarations for the module. foreach (var @enum in decl.Enums) { if ([email protected] || @enum.IsIncomplete) { continue; } PushBlock(CLIBlockKind.Enum, @enum); GenerateEnum(@enum); PopBlock(NewLineKind.BeforeNextBlock); } // Generate all the typedef declarations for the module. GenerateTypedefs(decl); // Generate all the struct/class declarations for the module. foreach (var @class in decl.Classes) { if ([email protected] || @class.IsIncomplete || @class.IsDependent) { continue; } if (@class.IsOpaque) { continue; } PushBlock(CLIBlockKind.Class, @class); GenerateClass(@class); PopBlock(NewLineKind.BeforeNextBlock); } if (decl.HasFunctions) { GenerateFunctions(decl); } foreach (var childNamespace in decl.Namespaces) { GenerateNamespace(childNamespace); } }
private DeclarationContext GetDeclContextForDelegates(DeclarationContext @namespace) { if (Options.IsCLIGenerator) { return(@namespace is Function ? @namespace.Namespace : @namespace); } var module = @namespace.TranslationUnit.Module; if (namespacesDelegates.ContainsKey(module)) { return(namespacesDelegates[module]); } Namespace parent = null; if (string.IsNullOrEmpty(module.OutputNamespace)) { var groups = module.Units.SelectMany(u => u.Declarations).OfType <Namespace>( ).GroupBy(d => d.Name).Where(g => g.Any(d => d.HasDeclarations)).ToList(); if (groups.Count == 1) { parent = groups.Last().Last(); } else { foreach (var g in groups) { parent = g.ToList().Find(ns => ns.Name == module.LibraryName || ns.Name == module.OutputNamespace); if (parent != null) { break; } } } } if (parent == null) { parent = module.Units.Last(); } var namespaceDelegates = new Namespace { Name = "Delegates", Namespace = parent }; namespacesDelegates.Add(module, namespaceDelegates); return(namespaceDelegates); }
public List <LookupListItem> GetList( DeclarationContext declarationContext) { List <LookupListItem> list = new List <LookupListItem>(); foreach (PropertyDefinition property in _properties) { /* * Can only see statics in a static context. */ if (declarationContext == DeclarationContext.Static && !property.IsStatic) { continue; } /* * Add the property to the list. */ LookupListItem listItem = new LookupListItem(); listItem.DisplayText = property.Name; if (property.Visibility == "internal" || property.IsProtectedInternal) { listItem.Category = QuickSharp.CodeAssist.Constants.PROPERTIES_FRIEND; } else if (property.Visibility == "protected") { listItem.Category = QuickSharp.CodeAssist.Constants.PROPERTIES_PROTECTED; } else if (property.Visibility == "private") { listItem.Category = QuickSharp.CodeAssist.Constants.PROPERTIES_PRIVATE; } else { listItem.Category = QuickSharp.CodeAssist.Constants.PROPERTIES; } listItem.ToolTipText = String.Format("{0} {1}", property.ReturnType, property.Name); listItem.InsertText = property.Name; list.Add(listItem); } return(list); }
protected override DeclaredVariables GetDeclaredVariables( string source, bool visibleScopesOnly, DeclarationContext declarationContext) { DeclaredVariables variables = new DeclaredVariables( source, fullNamespaceList, visibleScopesOnly, declarationContext); List <Variable> controls = GetServerControls(); variables.Items.AddRange(controls); return(variables); }
private static bool IsNameSpaceStd(DeclarationContext declarationContext) { if (declarationContext == null) { return(false); } var @namespace = declarationContext as Namespace; if (@namespace != null && @namespace.IsInline) { return(IsNameSpaceStd(declarationContext.Namespace)); } return(declarationContext.OriginalName == "std"); }
public DeclaredVariables(string source, List <string> namespaceList, bool visibleScopesOnly, DeclarationContext declarationContext) { _declaredVariables = new List <Variable>(); _declarationContext = declarationContext; source = CSharpFormattingTools. RemoveNamespaceDeclarations(source); if (visibleScopesOnly) { source = CSharpFormattingTools. RemoveInaccessibleScopes(source); } FindVariableDeclaratons(source); foreach (Variable v in _declaredVariables) { /* * To allow for nested types we need to replace any '.' * that's not part of a namespace with '+'. */ if (v.Type.IndexOf('.') != -1) { int pos = 0; /* * Need to replace all '.' occurring * after the longest possible namespace * match. */ foreach (string ns in namespaceList) { if (v.Type.StartsWith(ns) && pos <= ns.Length) { pos = ns.Length + 1; } } v.Type = v.Type.Substring(0, pos) + v.Type.Substring(pos).Replace(".", "+"); } } }
private static void MarkUsedFieldTypes(DeclarationContext declContext, HashSet <DeclarationContext> visitedDeclarationContexts) { if (visitedDeclarationContexts.Contains(declContext)) { return; } visitedDeclarationContexts.Add(declContext); DeclarationContext decl = null; var @class = declContext as Class; if (@class == null) { return; } foreach (var field in @class.Layout.Fields.Where( f => f.QualifiedType.Type.TryGetDeclaration(out decl))) { DeclarationContext declarationContext = decl; do { if (declarationContext.Ignore) { declarationContext.GenerationKind = GenerationKind.Internal; } var specialization = declarationContext as ClassTemplateSpecialization; Class template = specialization?.TemplatedDecl.TemplatedClass; if (template?.Ignore == true) { template.GenerationKind = GenerationKind.Internal; } Class nested = template?.Classes.FirstOrDefault( c => c.OriginalName == decl.OriginalName); if (nested?.Ignore == true) { nested.GenerationKind = GenerationKind.Internal; } declarationContext = declarationContext.Namespace; } while (declarationContext != null); MarkUsedFieldTypes(decl, visitedDeclarationContexts); } }
/// <summary> /// Generates a new typedef for the given type if necessary and returns the new type. /// </summary> /// <param name="namespace">The namespace the typedef will be added to.</param> /// <param name="type">The type to check.</param> /// <returns>The new type.</returns> private QualifiedType CheckType(DeclarationContext @namespace, QualifiedType type) { if (type.Type.IsDependent) return type; var pointerType = type.Type as PointerType; if (pointerType == null) return type; var functionType = pointerType.Pointee as FunctionType; if (functionType == null) return type; List<Typedef> typedefs; if (!allTypedefs.TryGetValue(@namespace.QualifiedName, out typedefs)) { typedefs = new List<Typedef>(); allTypedefs.Add(@namespace.QualifiedName, typedefs); } var typedef = FindMatchingTypedef(typedefs, functionType); if (typedef == null) { for (int i = 0; i < functionType.Parameters.Count; i++) { functionType.Parameters[i].Name = string.Format("_{0}", i); } typedef = new TypedefDecl { Access = AccessSpecifier.Public, Name = string.Format("__AnonymousDelegate{0}", typedefs.Count), Namespace = @namespace, QualifiedType = type, IsSynthetized = true }; typedefs.Add(new Typedef { Context = @namespace, Declaration = typedef }); } var typedefType = new TypedefType { Declaration = typedef }; return new QualifiedType(typedefType); }
protected override InheritedVariablesBase GetInheritedVariables( string source, DeclarationContext declarationContext, List <string> workspaceAssemblies, List <string> fullNamespaces, List <string> rootNamespaces) { return(new InheritedVariablesWeb( _fullSource, declarationContext, workspaceAssemblies, fullNamespaces, rootNamespaces, configNamespaceList)); }
private TypedefDecl GetDelegate(FunctionType functionType, DeclarationContext declarationContext, bool @private = false) { var delegateName = GetDelegateName(functionType); var access = @private ? AccessSpecifier.Private : AccessSpecifier.Public; Module module = declarationContext.TranslationUnit.Module; var existingDelegate = delegates.Find(t => Match(t, delegateName, module)); if (existingDelegate != null) { // Ensure a delegate used for a virtual method and a type is public if (existingDelegate.Access == AccessSpecifier.Private && access == AccessSpecifier.Public) { existingDelegate.Access = access; } // Check if there is an existing delegate with a different calling convention if (((FunctionType)existingDelegate.Type.GetPointee()).CallingConvention == functionType.CallingConvention) { return(existingDelegate); } // Add a new delegate with the calling convention appended to its name delegateName += '_' + functionType.CallingConvention.ToString(); existingDelegate = delegates.Find(t => Match(t, delegateName, module)); if (existingDelegate != null) { return(existingDelegate); } } var namespaceDelegates = GetDeclContextForDelegates(declarationContext); var delegateType = new QualifiedType(new PointerType(new QualifiedType(functionType))); existingDelegate = new TypedefDecl { Access = access, Name = delegateName, Namespace = namespaceDelegates, QualifiedType = delegateType, IsSynthetized = true }; delegates.Add(existingDelegate); return(existingDelegate); }
public override Tree VisitDeclaration(DeclarationContext context) { FuncDeclarationContext func = context.funcDeclaration(); if (func != null) { return(VisitFuncDeclaration(func)); } StructDefContext sd = context.structDef(); if (sd != null) { return(VisitStructDef(sd)); } throw new ArgumentOutOfRangeException(); }
public InheritedVariablesWeb( string source, DeclarationContext declarationContext, List <string> workspaceAssemblies, List <string> fullNamespaces, List <string> rootNamespaces, List <string> webConfigNamespaces) : base( source, declarationContext, workspaceAssemblies, fullNamespaces, rootNamespaces, webConfigNamespaces) { }
public virtual void GenerateFunctions(DeclarationContext decl) { PushBlock(BlockKind.FunctionsClass); // Generate all the function declarations for the module. foreach (var function in decl.Functions) { if (!function.IsGenerated) { continue; } function.Visit(this); } PopBlock(NewLineKind.BeforeNextBlock); }
private static void IgnorePrivateDeclaration(Declaration declaration) { if (declaration.Name != null && (declaration.Name.StartsWith("Private", StringComparison.Ordinal) || declaration.Name.EndsWith("Private", StringComparison.Ordinal))) { declaration.ExplicitlyIgnore(); } else { DeclarationContext declarationContext = declaration as DeclarationContext; if (declarationContext != null) { IgnorePrivateDeclarations(declarationContext); } } }
private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null) { var type = (Class)context; if (type.Properties.All(p => getter.Name != p.Name || p.ExplicitInterfaceImpl != getter.ExplicitInterfaceImpl)) { var property = new Property { Access = getter.Access == AccessSpecifier.Public || (setter != null && setter.Access == AccessSpecifier.Public) ? AccessSpecifier.Public : AccessSpecifier.Protected, Name = GetPropertyName(getter.Name), Namespace = type, QualifiedType = getter.OriginalReturnType, OriginalNamespace = getter.OriginalNamespace }; if (getter.IsOverride || (setter != null && setter.IsOverride)) { var baseVirtualProperty = type.GetBaseProperty(property, getTopmost: true); if (baseVirtualProperty.SetMethod == null) { setter = null; } } property.GetMethod = getter; property.SetMethod = setter; property.ExplicitInterfaceImpl = getter.ExplicitInterfaceImpl; if (property.ExplicitInterfaceImpl == null && setter != null) { property.ExplicitInterfaceImpl = setter.ExplicitInterfaceImpl; } if (getter.Comment != null) { property.Comment = CombineComments(getter, setter); } type.Properties.Add(property); getter.GenerationKind = GenerationKind.Internal; if (setter != null) { setter.GenerationKind = GenerationKind.Internal; } } }
private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null) { Class type = (Class) context; if (type.Properties.All(p => getter.Name != p.Name || p.ExplicitInterfaceImpl != getter.ExplicitInterfaceImpl)) { Property property = new Property(); property.Name = GetPropertyName(getter.Name); property.Namespace = type; property.QualifiedType = getter.OriginalReturnType; if (getter.IsOverride || (setter != null && setter.IsOverride)) { Property baseVirtualProperty = type.GetRootBaseProperty(property); if (baseVirtualProperty.SetMethod == null) setter = null; } property.GetMethod = getter; property.SetMethod = setter; property.ExplicitInterfaceImpl = getter.ExplicitInterfaceImpl; if (property.ExplicitInterfaceImpl == null && setter != null) { property.ExplicitInterfaceImpl = setter.ExplicitInterfaceImpl; } if (getter.Comment != null) { var comment = new RawComment(); comment.Kind = getter.Comment.Kind; comment.BriefText = getter.Comment.BriefText; comment.Text = getter.Comment.Text; comment.FullComment = new FullComment(); comment.FullComment.Blocks.AddRange(getter.Comment.FullComment.Blocks); if (setter != null && setter.Comment != null) { comment.BriefText += Environment.NewLine + setter.Comment.BriefText; comment.Text += Environment.NewLine + setter.Comment.Text; comment.FullComment.Blocks.AddRange(setter.Comment.FullComment.Blocks); } property.Comment = comment; } type.Properties.Add(property); getter.IsGenerated = false; if (setter != null) setter.IsGenerated = false; } }
public override bool VisitDeclarationContext(DeclarationContext context) { if (!base.VisitDeclarationContext(context)) { return(false); } Check(context.Declarations); var @class = context as Class; if (@class != null) { Check(@class.Fields); } return(true); }
public virtual bool VisitDeclContext(DeclarationContext context) { foreach (var decl in context.Declarations) { if (decl is Function) { continue; } if (decl.IsGenerated) { decl.Visit(this); } } VisitDeclContextFunctions(context); return(true); }
public virtual bool VisitDeclContext(DeclarationContext context) { foreach (var decl in context.Declarations) { if (decl is Function) { continue; } if (decl is Class && !VisitOptions.VisitNamespaceClasses) { continue; } if (decl is Enumeration && !VisitOptions.VisitNamespaceEnums) { continue; } if (decl is Event && !VisitOptions.VisitNamespaceEvents) { continue; } if (decl is Variable && !VisitOptions.VisitNamespaceVariables) { continue; } if (decl.IsGenerated) { decl.Visit(this); } } if (VisitOptions.VisitNamespaceFunctions) { VisitDeclContextFunctions(context); } return(true); }
internal DeclarationContext(DeclarationContext.Internal native) : this(&native) { }
private static string GetFileForDeclarationContext(DeclarationContext declarationContext) { if (string.IsNullOrEmpty(declarationContext.Name)) { return "qtglobal.html"; } StringBuilder fileNameBuilder = new StringBuilder(declarationContext.Name.ToLowerInvariant()); if (declarationContext is Class && ((Class) declarationContext).IsInterface) { fileNameBuilder.Remove(0, 1); } Class parentClass = declarationContext.Namespace as Class; if (parentClass != null) { fileNameBuilder.Insert(0, string.Format("{0}-", parentClass.Name.ToLowerInvariant())); } fileNameBuilder.Append(".html"); return fileNameBuilder.ToString(); }
public override bool VisitDeclarationContext(DeclarationContext context) { return false; }
internal DeclarationContext(DeclarationContext.Internal* native) : this(new global::System.IntPtr(native)) { }
private static void* __CopyValue(DeclarationContext.__Internal native) { var ret = Marshal.AllocHGlobal(248); global::CppSharp.Parser.AST.DeclarationContext.__Internal.cctor_2(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); }
private DeclarationContext(DeclarationContext.Internal native) : this(__CopyValue(native)) { __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; }
private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null) { var type = (Class) context; var name = GetPropertyName(getter.Name); if (type.Properties.Any(p => p.Name == name && p.ExplicitInterfaceImpl == getter.ExplicitInterfaceImpl)) return; var property = new Property { Access = getter.Access == AccessSpecifier.Public || (setter != null && setter.Access == AccessSpecifier.Public) ? AccessSpecifier.Public : AccessSpecifier.Protected, Name = name, Namespace = type, QualifiedType = getter.OriginalReturnType, OriginalNamespace = getter.OriginalNamespace }; if (getter.IsOverride || (setter != null && setter.IsOverride)) { var baseVirtualProperty = type.GetBaseProperty(property, getTopmost: true); if (baseVirtualProperty == null && type.GetBaseMethod(getter, getTopmost: true).IsGenerated) throw new Exception(string.Format( "Property {0} has a base property null but its getter has a generated base method.", getter.QualifiedOriginalName)); if (baseVirtualProperty != null && !baseVirtualProperty.IsVirtual) { // the only way the above can happen is if we are generating properties in abstract implementations // in which case we can have less naming conflicts since the abstract base can also contain non-virtual properties if (getter.SynthKind == FunctionSynthKind.AbstractImplCall) return; throw new Exception(string.Format( "Base of property {0} is not virtual while the getter is.", getter.QualifiedOriginalName)); } if (baseVirtualProperty != null && baseVirtualProperty.SetMethod == null) setter = null; } property.GetMethod = getter; property.SetMethod = setter; property.ExplicitInterfaceImpl = getter.ExplicitInterfaceImpl; if (property.ExplicitInterfaceImpl == null && setter != null) { property.ExplicitInterfaceImpl = setter.ExplicitInterfaceImpl; } if (getter.Comment != null) { property.Comment = CombineComments(getter, setter); } type.Properties.Add(property); getter.GenerationKind = GenerationKind.Internal; if (setter != null) setter.GenerationKind = GenerationKind.Internal; }
private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null) { var type = (Class) context; if (type.Properties.All(p => getter.Name != p.Name || p.ExplicitInterfaceImpl != getter.ExplicitInterfaceImpl)) { var property = new Property { Access = getter.Access == AccessSpecifier.Public || (setter != null && setter.Access == AccessSpecifier.Public) ? AccessSpecifier.Public : AccessSpecifier.Protected, Name = GetPropertyName(getter.Name), Namespace = type, QualifiedType = getter.OriginalReturnType, OriginalNamespace = getter.OriginalNamespace }; if (getter.IsOverride || (setter != null && setter.IsOverride)) { var baseVirtualProperty = type.GetBaseProperty(property, getTopmost: true); if (baseVirtualProperty.SetMethod == null) setter = null; } property.GetMethod = getter; property.SetMethod = setter; property.ExplicitInterfaceImpl = getter.ExplicitInterfaceImpl; if (property.ExplicitInterfaceImpl == null && setter != null) { property.ExplicitInterfaceImpl = setter.ExplicitInterfaceImpl; } if (getter.Comment != null) { property.Comment = CombineComments(getter, setter); } type.Properties.Add(property); getter.GenerationKind = GenerationKind.Internal; if (setter != null) setter.GenerationKind = GenerationKind.Internal; } }
private DeclarationContext(DeclarationContext.Internal native, bool skipVTables = false) : this(__CopyValue(native), skipVTables) { __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; }
private static Property CreateInterfaceProperty(Property property, DeclarationContext @namespace) { var interfaceProperty = new Property(property) { Namespace = @namespace }; if (property.GetMethod != null) interfaceProperty.GetMethod = new Method(property.GetMethod) { OriginalFunction = property.GetMethod, Namespace = @namespace }; if (property.SetMethod != null) // handle indexers interfaceProperty.SetMethod = property.GetMethod == property.SetMethod ? interfaceProperty.GetMethod : new Method(property.SetMethod) { OriginalFunction = property.SetMethod, Namespace = @namespace }; return interfaceProperty; }
private void HandleQSignal(DeclarationContext @class, Method method) { var expansions = method.AccessDecl.PreprocessedEntities.OfType<MacroExpansion>(); if (expansions.All(e => e.Text != "Q_SIGNALS")) { return; } if (method.Parameters.Any()) { Class decl; if (method.Parameters.Last().Type.TryGetClass(out decl) && decl.Name == "QPrivateSignal") { method.Parameters.RemoveAt(method.Parameters.Count - 1); } } var functionType = method.GetFunctionType(); var @event = new Event { OriginalDeclaration = method, Name = method.Name, OriginalName = method.OriginalName, Namespace = method.Namespace, QualifiedType = new QualifiedType(functionType), Parameters = method.Parameters }; method.GenerationKind = GenerationKind.None; @class.Events.Add(@event); this.events.Add(@event); }
public override bool VisitDeclarationContext(DeclarationContext context) { return context.IsGenerated && !context.TranslationUnit.IsSystemHeader && base.VisitDeclarationContext(context); }
private void HandleQSignal(DeclarationContext @class, Method method) { AccessSpecifierDecl access = method.AccessDecl; IEnumerable<MacroExpansion> expansions = access.PreprocessedEntities.OfType<MacroExpansion>(); if (expansions.All(e => e.Text != "Q_SIGNALS")) { return; } if (method.Parameters.Any()) { Declaration decl; if (method.Parameters.Last().Type.IsTagDecl(out decl) && decl.Name == "QPrivateSignal") { method.Parameters.RemoveAt(method.Parameters.Count - 1); } } FunctionType functionType = method.GetFunctionType(); Event @event = new Event { OriginalDeclaration = method, Name = method.Name, OriginalName = method.OriginalName, Namespace = method.Namespace, QualifiedType = new QualifiedType(functionType), Parameters = method.Parameters }; method.IsGenerated = false; @class.Events.Add(@event); this.events.Add(@event); }
public override bool VisitDeclarationContext(DeclarationContext context) { if (!context.IsGenerated) return false; return base.VisitDeclarationContext(context); }
private DeclarationContext(DeclarationContext.Internal native) : this(__CopyValue(native)) { __ownsNativeInstance = true; }
public static DeclarationContext __CreateInstance(DeclarationContext.Internal native, bool skipVTables = false) { return new DeclarationContext(native, skipVTables); }
public static DeclarationContext __CreateInstance(DeclarationContext.Internal native) { return new DeclarationContext(native); }
protected DeclarationContext(DeclarationContext.Internal* native, bool skipVTables = false) : base((CppSharp.Parser.AST.Declaration.Internal*) null) { __PointerAdjustment = 0; if (native == null) return; __Instance = new global::System.IntPtr(native); }
internal DeclarationContext(DeclarationContext.Internal native) : this(__CopyValue(native)) { }
public void GenerateDeclContext(DeclarationContext decl) { // Generate all the type references for the module. foreach (var typeRef in decl.TypeReferences) { WriteLine(typeRef.FowardReference); } // Generate all the enum declarations for the module. foreach (var @enum in decl.Enums) { if ([email protected] || @enum.IsIncomplete) continue; PushBlock(CLIBlockKind.Enum, @enum); GenerateEnum(@enum); PopBlock(NewLineKind.BeforeNextBlock); } // Generate all the typedef declarations for the module. GenerateTypedefs(decl); // Generate all the struct/class declarations for the module. foreach (var @class in decl.Classes) { if ([email protected] || @class.IsIncomplete) continue; if (@class.IsOpaque) continue; PushBlock(CLIBlockKind.Class, @class); GenerateClass(@class); PopBlock(NewLineKind.BeforeNextBlock); } if (decl.HasFunctions) GenerateFunctions(decl); foreach (var childNamespace in decl.Namespaces) GenerateNamespace(childNamespace); }
public override bool VisitDeclarationContext(DeclarationContext context) { return context.IsGenerated && base.VisitDeclarationContext(context); }
public void GenerateFunctions(DeclarationContext decl) { PushBlock(CLIBlockKind.FunctionsClass); WriteLine("public ref class {0}", TranslationUnit.FileNameWithoutExtension); WriteLine("{"); WriteLine("public:"); PushIndent(); // Generate all the function declarations for the module. foreach (var function in decl.Functions) { GenerateFunction(function); } PopIndent(); WriteLine("};"); PopBlock(NewLineKind.BeforeNextBlock); }
public void GenerateTypedefs(DeclarationContext decl) { foreach (var typedef in decl.Typedefs) { if (!typedef.IsGenerated) continue; GenerateTypedef(typedef); } }
private static DeclarationContext.Internal* __CopyValue(DeclarationContext.Internal native) { var ret = Marshal.AllocHGlobal(392); CppSharp.Parser.AST.DeclarationContext.Internal.cctor_2(ret, new global::System.IntPtr(&native)); return (DeclarationContext.Internal*) ret; }
private static void IgnorePrivateDeclarations(DeclarationContext unit) { foreach (var declaration in unit.Declarations) { IgnorePrivateDeclaration(declaration); } }
protected DeclarationContext(DeclarationContext.Internal* native, bool isInternalImpl = false) : base((CppSharp.Parser.AST.Declaration.Internal*) native) { }
private static void IgnorePrivateDeclarations(DeclarationContext unit) { foreach (Namespace ns in unit.Namespaces) { IgnorePrivateDeclaration(ns); } foreach (Enumeration enumeration in unit.Enums) { IgnorePrivateDeclaration(enumeration); } foreach (Function function in unit.Functions) { IgnorePrivateDeclaration(function); } foreach (Class @class in unit.Classes) { IgnorePrivateDeclaration(@class); } foreach (Template template in unit.Templates) { IgnorePrivateDeclaration(template); } foreach (TypedefDecl typedefDecl in unit.Typedefs) { IgnorePrivateDeclaration(typedefDecl); } foreach (Variable variable in unit.Variables) { IgnorePrivateDeclaration(variable); } foreach (Event @event in unit.Events) { IgnorePrivateDeclaration(@event); } }