Exemplo n.º 1
0
        public string GetShortName(ReferenceCollector refs)
        {
            Type type = unprojectedType;

            refs.AddReference(type);
            string name = GetAbiTypeShortName(type);

            if (type.GenericTypeArguments.Count() > 0)
            {
                name += "<" + String.Join(", ", type.GenericTypeArguments.Where(
                                              typeArg => AbiTypeRuntimeClass.IsValidType(typeArg)
                                              ).Select(typeArgument =>
                                                       (new AbiTypeRuntimeClass(typeArgument)).GetShortName(refs)
                                                       )) + ">";
            }

            return(name);
        }
Exemplo n.º 2
0
        public string GetParameters(ReferenceCollector refs, bool commentOutParamNames = false, bool shortNames = true)
        {
            List <string> parameters = this.methodInfo.GetParameters().Where(
                parameter => AbiTypeRuntimeClass.IsValidType(parameter.ParameterType)
                ).Select(parameter => {
                string paramName = parameter.Name;
                if (commentOutParamNames)
                {
                    paramName = "/* " + paramName + " */";
                }
                IAbiType paramType   = (new AbiTypeRuntimeClass(parameter.ParameterType)).DefaultInterface;
                string paramTypeName = "";
                if (parameter.IsIn)
                {
                    paramTypeName = shortNames ? paramType.GetShortNameAsInParam(refs) : paramType.GetFullNameAsInParam(refs);
                }
                else
                {
                    paramTypeName = shortNames ? paramType.GetShortNameAsOutParam(refs) : paramType.GetFullNameAsOutParam(refs);
                }
                return(paramTypeName + " " + paramName);
            }).ToList();

            if (methodInfo.ReturnType != null && methodInfo.ReturnType.Name != "Void")
            {
                string paramName = "value";
                if (commentOutParamNames)
                {
                    paramName = "/* " + paramName + " */";
                }

                var    defaultInterface = (new AbiTypeRuntimeClass(methodInfo.ReturnType)).DefaultInterface;
                string paramType        = shortNames ? defaultInterface.GetShortNameAsOutParam(refs) : defaultInterface.GetFullNameAsOutParam(refs);
                parameters.Add(paramType + " " + paramName);
            }

            return(String.Join(", ", parameters));
        }
Exemplo n.º 3
0
        List <FileOutput> ProcessType(string rootTemplate, IAbiType type, bool shortNames)
        {
            List <FileOutput>  results = new List <FileOutput>();
            ReferenceCollector refs    = new ReferenceCollector(type.Namespace);
            string             result  = rootTemplate.
                                         Replace("$namespaceDefinitionBegin", type.NamespaceDefinitionBeginStatement).
                                         Replace("$namespaceDefinitionEnd", type.NamespaceDefinitionEndStatement).
                                         Replace("$className", type.ShortNameNoTypeParameters).
                                         Replace("$runtimeclassStringName", type.RuntimeClassName).
                                         Replace("$parentHelperClass", type.ParentHelperClassName).
                                         Replace("$inspectableClassKind", type.InspectableClassKind).
                                         Replace("$activatableClassStatements", String.Join(Environment.NewLine, type.GetActivatableClassStatements(refs)));

            var parentClasses = type.GetParentClasses(refs).
                                Where(parent => !parent.ImplicitParent).
                                Select(parent => "    " + (shortNames ? parent.GetShortName(refs) : parent.GetFullName(refs)));

            if (type.IsAgile)
            {
                parentClasses = new string[] { "    Microsoft::WRL::FtmBase" }.Concat(parentClasses);
            }

            result = result.
                     Replace("$parentClasses", String.Join("," + Environment.NewLine, parentClasses));

            result = result.Replace("$interfaceImplementationDeclarations",
                                    String.Join(Environment.NewLine, type.GetParentClasses(refs).Select(tinterface =>
            {
                string[] header = new string[] { "    // " + tinterface.GetFullName(refs) };
                string[] tail   = new string[] { "" };

                IEnumerable <string> methods = tinterface.Methods.SelectMany(method => new string[] {
                    "    IFACEMETHOD(" + method.Name + ")(" + method.GetParameters(refs, true, shortNames) + ");"
                });

                IEnumerable <string> events = tinterface.Events.SelectMany(tevent => new string[] {
                    "    IFACEMETHOD(add_" + tevent.Name + ")(" + (shortNames ? tevent.EventHandlerType.GetShortNameAsInParam(refs) : tevent.EventHandlerType.GetFullNameAsInParam(refs)) + " eventHandler, _Out_ EventRegistrationToken* token);",
                    "    IFACEMETHOD(remove_" + tevent.Name + ")(_In_ EventRegistrationToken token);",
                });

                IEnumerable <string> readOnlyProperties = tinterface.ReadOnlyProperties.SelectMany(property => new string[] {
                    "    IFACEMETHOD(get_" + property.Name + ")(" + (shortNames ? property.PropertyType.GetShortNameAsOutParam(refs) : property.PropertyType.GetFullNameAsOutParam(refs)) + " value);"
                });

                IEnumerable <string> readWriteProperties = tinterface.ReadWriteProperties.SelectMany(property => new string[] {
                    "    IFACEMETHOD(get_" + property.Name + ")(" + (shortNames ? property.PropertyType.GetShortNameAsOutParam(refs) : property.PropertyType.GetFullNameAsOutParam(refs)) + " value);",
                    "    IFACEMETHOD(put_" + property.Name + ")(" + (shortNames ? property.PropertyType.GetShortNameAsInParam(refs) : property.PropertyType.GetFullNameAsInParam(refs)) + " value);"
                });

                return(String.Join(Environment.NewLine, header.Concat(methods).Concat(readOnlyProperties).Concat(readWriteProperties).Concat(events).Concat(tail)));
            })));

            result = result.Replace("$interfaceImplementationDefinitions",
                                    String.Join(Environment.NewLine, type.GetParentClasses(refs).Select(tinterface =>
            {
                string header = "// " + tinterface.GetFullName(refs);

                IEnumerable <string> methods = tinterface.Methods.SelectMany(method => new string[] {
                    header,
                    "IFACEMETHODIMP " + type.ShortNameNoTypeParameters + "::" + method.Name + "(" + method.GetParameters(refs, true, shortNames) + ")",
                    "{",
                    "    return E_NOTIMPL;",
                    "}",
                    ""
                });

                IEnumerable <string> events = tinterface.Events.SelectMany(tevent => new string[] {
                    header,
                    "IFACEMETHODIMP " + type.ShortNameNoTypeParameters + "::add_" + tevent.Name + "(" + (shortNames ? tevent.EventHandlerType.GetShortNameAsInParam(refs) : tevent.EventHandlerType.GetFullNameAsInParam(refs)) + " eventHandler, _Out_ EventRegistrationToken* token)",
                    "{",
                    "    return m_" + tevent.Name + "EventHandlers.Add(eventHandler, token);",
                    "}",
                    "",
                    header,
                    "IFACEMETHODIMP " + type.ShortNameNoTypeParameters + "::remove_" + tevent.Name + "(_In_ EventRegistrationToken token)",
                    "{",
                    "    return m_" + tevent.Name + "EventHandlers.Remove(token);",
                    "}",
                    ""
                });

                IEnumerable <string> readOnlyProperties = tinterface.ReadOnlyProperties.SelectMany(property => new string[] {
                    header,
                    "IFACEMETHODIMP " + type.ShortNameNoTypeParameters + "::get_" + property.Name + "(" + (shortNames ? property.PropertyType.GetShortNameAsOutParam(refs) : property.PropertyType.GetFullNameAsOutParam(refs)) + " /* value */)",
                    "{",
                    "    return E_NOTIMPL;",
                    "}",
                    ""
                });

                IEnumerable <string> readWriteProperties = tinterface.ReadWriteProperties.SelectMany(property => new string[] {
                    header,
                    "IFACEMETHODIMP " + type.ShortNameNoTypeParameters + "::get_" + property.Name + "(" + (shortNames ? property.PropertyType.GetShortNameAsOutParam(refs) : property.PropertyType.GetFullNameAsOutParam(refs)) + " /* value */)",
                    "{",
                    "    return E_NOTIMPL;",
                    "}",
                    "",
                    header,
                    "IFACEMETHODIMP " + type.ShortNameNoTypeParameters + "::put_" + property.Name + "(" + (shortNames ? property.PropertyType.GetShortNameAsInParam(refs) : property.PropertyType.GetFullNameAsInParam(refs)) + " /* value */)",
                    "{",
                    "    return E_NOTIMPL;",
                    "}",
                    ""
                });

                return(String.Join(Environment.NewLine, methods.Concat(events).Concat(readOnlyProperties).Concat(readWriteProperties)));
            })));

            result = result.Replace("$eventHelperDeclaration",
                                    String.Join(Environment.NewLine, type.GetParentClasses(refs).SelectMany(
                                                    tinterface => tinterface.Events
                                                    ).Select(
                                                    tevent => "    AgileEventSource<" + (shortNames ? tevent.EventHandlerType.GetShortName(refs) : tevent.EventHandlerType.GetFullName(refs)) + "> m_" + tevent.Name + "EventHandlers;"
                                                    )));

            // Do these last once refs has been fully populated.

            var headerIncludeStatements = refs.IncludeStatements;

            if (type.Factory != null)
            {
                headerIncludeStatements = headerIncludeStatements.Concat(new string[] { "#include \"" + type.Factory.ShortNameNoTypeParameters + ".h\"" }).ToArray();
            }

            result = result.
                     Replace("$headerIncludeStatements", String.Join(Environment.NewLine, headerIncludeStatements)).
                     Replace("$sourceIncludeStatements", "#include \"" + type.ShortNameNoTypeParameters + ".h\"").
                     Replace("$usingNamespaceStatements", String.Join(Environment.NewLine, refs.UsingNamespaceStatements));

            results.Add(new FileOutput(type.ShortNameNoTypeParameters, result));

            return(results);
        }
Exemplo n.º 4
0
 public string GetFullNameAsOutParam(ReferenceCollector refs)
 {
     return(this.innerClass.GetFullNameAsOutParam(refs) + ClassNameSuffix);
 }
Exemplo n.º 5
0
 public string GetParameters(ReferenceCollector refs, bool commentOutParamNames, bool shortNames)
 {
     return(this.parameters);
 }
Exemplo n.º 6
0
 public string[] GetActivatableClassStatements(ReferenceCollector refs)
 {
     return(new string[] { });
 }
Exemplo n.º 7
0
 public string GetShortNameAsInParam(ReferenceCollector refs)
 {
     return(this.innerClass.GetShortNameAsInParam(refs) + ClassNameSuffix);
 }
Exemplo n.º 8
0
 public string GetFullNameAsOutParam(ReferenceCollector refs)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 9
0
 public IAbiType[] GetFactoryAndStaticInterfaces(ReferenceCollector refs)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 public string GetShortNameAsInParam(ReferenceCollector refs)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
 public string GetShortName(ReferenceCollector refs)
 {
     return("IActivationFactory");
 }
Exemplo n.º 12
0
 public IAbiType[] GetParentClasses(ReferenceCollector refs)
 {
     return(new IAbiType[] { });
 }
Exemplo n.º 13
0
 public IAbiType[] GetFactoryAndStaticInterfaces(ReferenceCollector refs)
 {
     return(new IAbiType[] { });
 }
Exemplo n.º 14
0
 public string[] GetActivatableClassStatements(ReferenceCollector refs)
 {
     throw new NotImplementedException();
 }