Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
Generate Class Reference
Collaboration diagram for Generate:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Generate (nsILocalFile *aOutputDir)
 ~Generate ()
nsresult GenerateInterfaces ()
nsresult WriteOneInterface (nsIInterfaceInfo *aIInfo)
nsresult OpenIfaceFileStream (const char *aIfaceName, nsIOutputStream **aResult)
nsresult CloseIfaceFileStream (nsIOutputStream *out)
nsresult WriteHeader (nsIOutputStream *out, const char *aIfaceName)
nsresult WriteInterfaceStart (nsIOutputStream *out, nsIInterfaceInfo *aIInfo, nsIInterfaceInfo *aParentInfo)
nsresult WriteInterfaceEnd (nsIOutputStream *out)
nsresult WriteIID (nsIOutputStream *out, nsIInterfaceInfo *aIInfo)
nsresult WriteConstants (nsIOutputStream *out, nsIInterfaceInfo *aIInfo, PRUint16 aParentConstCount)
nsresult WriteConstantValue (nsIOutputStream *out, const nsXPTType *aType, const nsXPTCMiniVariant *aValue)
nsresult WriteMethods (nsIOutputStream *out, nsIInterfaceInfo *aIInfo, PRUint16 aParentMethodCount)
nsresult WriteOneMethod (nsIOutputStream *out, nsIInterfaceInfo *aIInfo, const nsXPTMethodInfo *aMethodInfo, PRUint16 aMethodIndex)
nsresult WriteParam (nsIOutputStream *out, nsIInterfaceInfo *aIInfo, PRUint16 aMethodIndex, const nsXPTParamInfo *aParamInfo, PRUint8 aIndex)
nsresult WriteType (nsIOutputStream *out, const nsXPTType *aType, nsIInterfaceInfo *aIInfo, PRUint16 aMethodIndex, const nsXPTParamInfo *aParamInfo)
 Write out the Java type for the given XPIDL type.

Static Public Member Functions

static void Main (String[] args)

Private Member Functions

Type FixupInterfaceType (TypeInfo.ParamDescriptor desc)
void GenerateInterfaceMethod (TypeBuilder tb, TypeInfo.MethodDescriptor desc)
Type EmitOneInterface (String name)
void GenerateInterfaceAssembly (string[] args)

Private Attributes

nsILocalFilemOutputDir
nsCStringHashSet mIfaceTable
nsCStringHashSet mJavaKeywords
nsCStringHashSet mNoscriptMethodsTable
ModuleBuilder mb
Hashtable ifaceTable = new Hashtable()
bool verbose = false
PropertyBuilder lastProperty = null
const PropertyAttributes PROPERTY_ATTRS = PropertyAttributes.None
const MethodAttributes METHOD_ATTRS

Detailed Description

Definition at line 185 of file GenerateJavaInterfaces.cpp.


Constructor & Destructor Documentation

Generate::Generate ( nsILocalFile aOutputDir) [inline]

Definition at line 195 of file GenerateJavaInterfaces.cpp.

    : mOutputDir(aOutputDir)
  {
    mIfaceTable.Init(100);

    PRUint32 size = NS_ARRAY_LENGTH(kJavaKeywords);
    mJavaKeywords.Init(size);
    for (PRUint32 i = 0; i < size; i++) {
      mJavaKeywords.Put(nsDependentCString(kJavaKeywords[i]));
    }

#ifdef WRITE_NOSCRIPT_METHODS
    size = NS_ARRAY_LENGTH(kNoscriptMethodIfaces);
    mNoscriptMethodsTable.Init(size);
    for (PRUint32 j = 0; j < size; j++) {
      mNoscriptMethodsTable.Put(nsDependentCString(kNoscriptMethodIfaces[j]));
    }
#endif
  }

Here is the caller graph for this function:

Generate::~Generate ( ) [inline]

Definition at line 215 of file GenerateJavaInterfaces.cpp.

  {
  }

Member Function Documentation

Definition at line 340 of file GenerateJavaInterfaces.cpp.

  {
    return out->Close();
  }

Here is the caller graph for this function:

Type Generate.EmitOneInterface ( String  name) [inline, private]

Definition at line 75 of file generate-interfaces.cs.

    {
        if (ifaceTable.ContainsKey(name))
            return (Type)ifaceTable[name];
        Console.WriteLine("Interface: {0}", name);
        
        ushort inheritedMethodCount;
        String parentName = TypeInfo.GetParentInfo(name,
                                                   out inheritedMethodCount);
        Type parentType;

        if (parentName == null)
            parentType = typeof(object);
        else
            parentType = EmitOneInterface(parentName);

        Console.WriteLine ("Emitting: " + name + " : " + parentType);

        TypeBuilder ifaceTb = mb.DefineType("Mozilla.XPCOM.Interfaces." + name,
                                            TypeAttributes.Public | 
                                            TypeAttributes.Interface |
                                            TypeAttributes.Abstract,
                                            parentType);
        ifaceTable.Add(name, ifaceTb);

        TypeInfo.MethodDescriptor[] descs;
        try {
            descs = TypeInfo.GetMethodData(name);
        } catch (Exception ex) {
            Console.WriteLine("skipping interface {0}: {1}", name,
                              ex.Message);
            return null;
        }

        if (descs == null) {
            Console.WriteLine("No descs!");
            return null;
        }

        if (verbose) {
            Console.WriteLine("{0} has {1} methods ({2} inherited from {3})",
                              name, descs.Length, inheritedMethodCount,
                              parentName);
        }
        for (int i = inheritedMethodCount; i < descs.Length; i++) {
            GenerateInterfaceMethod(ifaceTb, descs[i]);
        }

        ifaceTb.CreateType();
        return ifaceTb;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Type Generate.FixupInterfaceType ( TypeInfo.ParamDescriptor  desc) [inline, private]

Definition at line 18 of file generate-interfaces.cs.

    {
        try {
            String ifaceName = desc.GetInterfaceName();
            return EmitOneInterface(ifaceName);
        } catch (Exception e) {
            Console.WriteLine(e);
            return typeof(object);
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void Generate.GenerateInterfaceAssembly ( string[]  args) [inline, private]

Definition at line 127 of file generate-interfaces.cs.

    {
        String dllName = args[0];
        String onlyInterface = null;
        if (args.Length > 1)
            onlyInterface = args[1];
        AssemblyName an = new AssemblyName();
        an.Version = new Version(1, 0, 0, 0);
        an.Name = "Mozilla.XPCOM.Interfaces";
        
        AssemblyBuilder ab = AppDomain.CurrentDomain.
            DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave);
        mb = ab.DefineDynamicModule(an.Name, dllName);

        if (onlyInterface != null) {
            verbose = true;
            EmitOneInterface(onlyInterface);
        } else {
            IntPtr e = TypeInfo.typeinfo_EnumerateInterfacesStart();
            if (e == IntPtr.Zero)
                return;
            
            while (true) {
                String name = TypeInfo.typeinfo_EnumerateInterfacesNext(e);
                if (name == null)
                    break;
                EmitOneInterface(name);
            }
            
            TypeInfo.typeinfo_EnumerateInterfacesStop(e);
        }

        ab.Save(dllName);

        Console.WriteLine("Generated metadata for {0} interfaces in {1}",
                          ifaceTable.Count, dllName);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void Generate.GenerateInterfaceMethod ( TypeBuilder  tb,
TypeInfo.MethodDescriptor  desc 
) [inline, private]

Definition at line 29 of file generate-interfaces.cs.

    {
        if (desc == null || !desc.IsVisible())
            return;

        MethodAttributes methodAttrs = METHOD_ATTRS;

        String methodName = desc.name;
        if (desc.IsGetter()) {
            methodName = "get_" + desc.name;
            methodAttrs |= MethodAttributes.SpecialName;
        } else if (desc.IsSetter()) {
            methodName = "set_" + desc.name;
            methodAttrs |= MethodAttributes.SpecialName;
        }
            
        // Fix up interface types in parameters
        Type ret = desc.resultType;
        if (ret == typeof(object))
            ret = FixupInterfaceType(desc.args[desc.args.Length - 1]);
        Type[] argTypes = (Type[])desc.argTypes.Clone();
        for (int i = 0; i < argTypes.Length; i++) {
            if (argTypes[i] == typeof(object))
                argTypes[i] = FixupInterfaceType(desc.args[i]);
        }
        MethodBuilder meth = tb.DefineMethod(methodName, methodAttrs, ret,
                                             argTypes);

        if (desc.IsSetter()) {
            if (lastProperty != null && lastProperty.Name == desc.name) {
                lastProperty.SetSetMethod(meth);
            } else {
                tb.DefineProperty(desc.name, PROPERTY_ATTRS, ret, new Type[0])
                    .SetSetMethod(meth);
            }
            lastProperty = null;
        } else if (desc.IsGetter()) {
            lastProperty = tb.DefineProperty(desc.name, PROPERTY_ATTRS, ret,
                                             new Type[0]);
            lastProperty.SetGetMethod(meth);
        } else {
            lastProperty = null;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 219 of file GenerateJavaInterfaces.cpp.

  {
    nsresult rv;

    nsCOMPtr<nsIInterfaceInfoManager> iim = XPTI_GetInterfaceInfoManager();
    NS_ASSERTION(iim, "could not get interface info manager");
    nsCOMPtr<nsIEnumerator> etor;
    rv = iim->EnumerateInterfaces(getter_AddRefs(etor));
    NS_ENSURE_SUCCESS(rv, rv);

    // loop over interfaces
    etor->First();
    do {
      // get current interface
      nsCOMPtr<nsISupports> item;
      rv = etor->CurrentItem(getter_AddRefs(item));
      NS_ENSURE_SUCCESS(rv, rv);

      nsCOMPtr<nsIInterfaceInfo> iface(do_QueryInterface(item));
      if (!iface)
        break;

      // we only care about scriptable interfaces, so skip over those
      // that aren't
      PRBool scriptable;
      iface->IsScriptable(&scriptable);
      if (!scriptable) {
        // XXX SWT uses non-scriptable interface 'nsIAppShell' (bug 270892), so
        // include that one.
        const char* iface_name;
        iface->GetNameShared(&iface_name);
        if (strcmp("nsIAppShell", iface_name) != 0)
          continue;
      }

      rv = WriteOneInterface(iface);
      NS_ENSURE_SUCCESS(rv, rv);

    } while (NS_SUCCEEDED(etor->Next()));

    return NS_OK;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static void Generate.Main ( String[]  args) [inline, static]

Definition at line 165 of file generate-interfaces.cs.

Here is the call graph for this function:

nsresult Generate::OpenIfaceFileStream ( const char *  aIfaceName,
nsIOutputStream **  aResult 
) [inline]

Definition at line 307 of file GenerateJavaInterfaces.cpp.

  {
    nsresult rv;

    // create interface file in output dir
    nsCOMPtr<nsIFile> iface_file;
    rv = mOutputDir->Clone(getter_AddRefs(iface_file));
    NS_ENSURE_SUCCESS(rv, rv);
    nsAutoString filename;
    filename.AppendASCII(aIfaceName);
    filename.AppendLiteral(".java");
    rv = iface_file->Append(filename);
    NS_ENSURE_SUCCESS(rv, rv);

    // create interface file
    PRBool exists;
    iface_file->Exists(&exists);
    if (exists)
      iface_file->Remove(PR_FALSE);
    rv = iface_file->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
    NS_ENSURE_SUCCESS(rv, rv);

    // create output stream for writing to file
    nsCOMPtr<nsIOutputStream> out;
    rv = NS_NewLocalFileOutputStream(getter_AddRefs(out), iface_file);
    NS_ENSURE_SUCCESS(rv, rv);

    *aResult = out;
    NS_ADDREF(*aResult);
    return NS_OK;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult Generate::WriteConstants ( nsIOutputStream out,
nsIInterfaceInfo aIInfo,
PRUint16  aParentConstCount 
) [inline]

Definition at line 454 of file GenerateJavaInterfaces.cpp.

  {
    static const char kConstDecl1[] = " = ";
    static const char kConstDecl2[] = ";\n\n";

    PRUint16 constCount;
    nsresult rv = aIInfo->GetConstantCount(&constCount);
    NS_ENSURE_SUCCESS(rv, rv);

    for (PRUint16 i = aParentConstCount; i < constCount; i++) {
      const nsXPTConstant* constInfo;
      rv = aIInfo->GetConstant(i, &constInfo);
      NS_ENSURE_SUCCESS(rv, rv);

      PRUint32 count;
      rv = out->Write("  ", 2, &count);
      NS_ENSURE_SUCCESS(rv, rv);
      const nsXPTType &type = constInfo->GetType();
      rv = WriteType(out, &type, aIInfo, nsnull, nsnull);
      NS_ENSURE_SUCCESS(rv, rv);
      rv = out->Write(" ", 1, &count);
      NS_ENSURE_SUCCESS(rv, rv);
      const char* name = constInfo->GetName();
      rv = out->Write(name, strlen(name), &count);
      NS_ENSURE_SUCCESS(rv, rv);
      rv = out->Write(kConstDecl1, sizeof(kConstDecl1) - 1, &count);
      NS_ENSURE_SUCCESS(rv, rv);

      rv = WriteConstantValue(out, &type, constInfo->GetValue());
      NS_ENSURE_SUCCESS(rv, rv);
      rv = out->Write(kConstDecl2, sizeof(kConstDecl2) - 1, &count);
      NS_ENSURE_SUCCESS(rv, rv);
    }

    return NS_OK;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 492 of file GenerateJavaInterfaces.cpp.

  {
    char buf[32];
    switch (aType->TagPart()) {
      case nsXPTType::T_I8:
        snprintf(buf, sizeof(buf), "%d", aValue->val.i8);
        break;

      case nsXPTType::T_U8:
        snprintf(buf, sizeof(buf), "%u", aValue->val.u8);
        break;

      case nsXPTType::T_I16:
        snprintf(buf, sizeof(buf), "%d", aValue->val.i16);
        break;

      case nsXPTType::T_U16:
        snprintf(buf, sizeof(buf), "%u", aValue->val.u16);
        break;

      case nsXPTType::T_I32:
        snprintf(buf, sizeof(buf), "%d", aValue->val.i32);
        break;

      case nsXPTType::T_U32:
        snprintf(buf, sizeof(buf), "%uL", aValue->val.u32);
        break;

      case nsXPTType::T_I64:
        snprintf(buf, sizeof(buf), "%lldL", aValue->val.i64);
        break;

      case nsXPTType::T_U64:
        snprintf(buf, sizeof(buf), "%lluL", aValue->val.u64);
        break;

      case nsXPTType::T_FLOAT:
        snprintf(buf, sizeof(buf), "%f", aValue->val.f);
        break;

      case nsXPTType::T_DOUBLE:
        snprintf(buf, sizeof(buf), "%f", aValue->val.d);
        break;

      case nsXPTType::T_BOOL:
        if (aValue->val.b)
          sprintf(buf, "true");
        else
          sprintf(buf, "false");
        break;

      case nsXPTType::T_CHAR:
        snprintf(buf, sizeof(buf), "%c", aValue->val.c);
        break;

      case nsXPTType::T_WCHAR:
        snprintf(buf, sizeof(buf), "%c", aValue->val.wc);
        break;

      default:
        NS_WARNING("unexpected constant type");
        return NS_ERROR_UNEXPECTED;
    }

    PRUint32 count;
    return out->Write(buf, strlen(buf), &count);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult Generate::WriteHeader ( nsIOutputStream out,
const char *  aIfaceName 
) [inline]

Definition at line 345 of file GenerateJavaInterfaces.cpp.

  {
    static const char kHeader1[] =
      "/**\n"
      " * NOTE: THIS IS A GENERATED FILE. PLEASE CONSULT THE ORIGINAL IDL FILE\n"
      " * FOR THE FULL DOCUMENTION AND LICENSE.\n"
      " *\n"
      " * @see <a href=\"http://lxr.mozilla.org/mozilla/search?string=";
    static const char kHeader2[]= "\">\n **/\n\n";
    static const char kPackage[] = "package org.mozilla.xpcom;\n\n";

    PRUint32 count;
    nsresult rv = out->Write(kHeader1, sizeof(kHeader1) - 1, &count);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCAutoString searchTerm;
    searchTerm.AppendLiteral("interface+");
    searchTerm.AppendASCII(aIfaceName);
    // LXR limits to 29 chars
    rv = out->Write(searchTerm.get(), PR_MIN(29, searchTerm.Length()), &count);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = out->Write(kHeader2, sizeof(kHeader2) - 1, &count);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = out->Write(kPackage, sizeof(kPackage) - 1, &count);
    return rv;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult Generate::WriteIID ( nsIOutputStream out,
nsIInterfaceInfo aIInfo 
) [inline]

Definition at line 407 of file GenerateJavaInterfaces.cpp.

  {
    static const char kIIDDecl1[] = "  String ";
    static const char kIIDDecl2[] = " =\n    \"";
    static const char kIIDDecl3[] = "\";\n\n";

    nsIID* iid = nsnull;
    aIInfo->GetInterfaceIID(&iid);
    if (!iid)
      return NS_ERROR_OUT_OF_MEMORY;

    // create iid field name
    nsCAutoString iid_name;
    const char* iface_name;
    aIInfo->GetNameShared(&iface_name);
    if (strncmp("ns", iface_name, 2) == 0) {
      iid_name.AppendLiteral("NS_");
      iid_name.Append(iface_name + 2);
    } else {
      iid_name.Append(iface_name);
    }
    iid_name.AppendLiteral("_IID");
    ToUpperCase(iid_name);

    // get iid string
    char* iid_str = iid->ToString();
    if (!iid_str)
      return NS_ERROR_OUT_OF_MEMORY;

    PRUint32 count;
    nsresult rv = out->Write(kIIDDecl1, sizeof(kIIDDecl1) - 1, &count);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = out->Write(iid_name.get(), iid_name.Length(), &count);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = out->Write(kIIDDecl2, sizeof(kIIDDecl2) - 1, &count);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = out->Write(iid_str, strlen(iid_str), &count);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = out->Write(kIIDDecl3, sizeof(kIIDDecl3) - 1, &count);
    NS_ENSURE_SUCCESS(rv, rv);

    // cleanup
    PR_Free(iid_str);
    nsMemory::Free(iid);
    return NS_OK;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 401 of file GenerateJavaInterfaces.cpp.

  {
    PRUint32 count;
    return out->Write("}\n", 2, &count);
  }

Here is the caller graph for this function:

nsresult Generate::WriteInterfaceStart ( nsIOutputStream out,
nsIInterfaceInfo aIInfo,
nsIInterfaceInfo aParentInfo 
) [inline]

Definition at line 373 of file GenerateJavaInterfaces.cpp.

  {
    static const char kIfaceDecl1[] = "public interface ";
    static const char kParentDecl[] = " extends ";
    static const char kIfaceDecl2[] = "\n{\n";

    const char* iface_name;
    aIInfo->GetNameShared(&iface_name);
    PRUint32 count;
    nsresult rv = out->Write(kIfaceDecl1, sizeof(kIfaceDecl1) - 1, &count);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = out->Write(iface_name, strlen(iface_name), &count);
    NS_ENSURE_SUCCESS(rv, rv);

    if (aParentInfo) {
      const char* parent_name;
      aParentInfo->GetNameShared(&parent_name);
      rv = out->Write(kParentDecl, sizeof(kParentDecl) - 1, &count);
      NS_ENSURE_SUCCESS(rv, rv);
      rv = out->Write(parent_name, strlen(parent_name), &count);
      NS_ENSURE_SUCCESS(rv, rv);
    }

    rv = out->Write(kIfaceDecl2, sizeof(kIfaceDecl2) - 1, &count);
    return rv;
  }

Here is the caller graph for this function:

nsresult Generate::WriteMethods ( nsIOutputStream out,
nsIInterfaceInfo aIInfo,
PRUint16  aParentMethodCount 
) [inline]

Definition at line 561 of file GenerateJavaInterfaces.cpp.

  {
    PRUint16 methodCount;
    nsresult rv = aIInfo->GetMethodCount(&methodCount);
    NS_ENSURE_SUCCESS(rv, rv);

    for (PRUint16 i = aParentMethodCount; i < methodCount; i++) {
      const nsXPTMethodInfo* methodInfo;
      rv = aIInfo->GetMethodInfo(i, &methodInfo);
      NS_ENSURE_SUCCESS(rv, rv);

#ifdef WRITE_NOSCRIPT_METHODS
      // XXX
      // SWT makes use of [noscript] methods in some classes, so output them
      // for those classes.

      // skip [notxpcom] methods
      if (methodInfo->IsNotXPCOM())
        continue;

      // skip most hidden ([noscript]) methods
      if (methodInfo->IsHidden()) {
        const char* iface_name;
        aIInfo->GetNameShared(&iface_name);
        if (!mNoscriptMethodsTable.Contains(nsDependentCString(iface_name)))
          continue;
      }
#else
      // skip hidden ([noscript]) or [notxpcom] methods
      if (methodInfo->IsHidden() || methodInfo->IsNotXPCOM())
        continue;
#endif

      rv = WriteOneMethod(out, aIInfo, methodInfo, i);
      NS_ENSURE_SUCCESS(rv, rv);
    }

    return NS_OK;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 262 of file GenerateJavaInterfaces.cpp.

  {
    nsresult rv;

    // write each interface only once
    const char* iface_name;
    aIInfo->GetNameShared(&iface_name);
    if (mIfaceTable.Contains(nsDependentCString(iface_name)))
      return NS_OK;

    // write any parent interface
    nsCOMPtr<nsIInterfaceInfo> parentInfo;
    PRUint16 parentMethodCount, parentConstCount;
    rv = TypeInfo::GetParentInfo(aIInfo, getter_AddRefs(parentInfo),
                                 &parentMethodCount, &parentConstCount);
    NS_ENSURE_SUCCESS(rv, rv);
    if (parentInfo)
      WriteOneInterface(parentInfo);

    mIfaceTable.Put(nsDependentCString(iface_name));

    // create file for interface
    nsCOMPtr<nsIOutputStream> out;
    rv = OpenIfaceFileStream(iface_name, getter_AddRefs(out));
    NS_ENSURE_SUCCESS(rv, rv);

    // write contents to file
    rv = WriteHeader(out, iface_name);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = WriteInterfaceStart(out, aIInfo, parentInfo);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = WriteIID(out, aIInfo);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = WriteConstants(out, aIInfo, parentConstCount);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = WriteMethods(out, aIInfo, parentMethodCount);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = WriteInterfaceEnd(out);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = CloseIfaceFileStream(out);

    return rv;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult Generate::WriteOneMethod ( nsIOutputStream out,
nsIInterfaceInfo aIInfo,
const nsXPTMethodInfo aMethodInfo,
PRUint16  aMethodIndex 
) [inline]

Definition at line 602 of file GenerateJavaInterfaces.cpp.

  {
    static const char kVoidReturn[] = "void";
    static const char kParamSeparator[] = ", ";
    static const char kMethodEnd[] = ");\n\n";

    PRUint32 count;
    nsresult rv = out->Write("  ", 2, &count);
    NS_ENSURE_SUCCESS(rv, rv);

    // write return type
    PRUint8 paramCount = aMethodInfo->GetParamCount();
    const nsXPTParamInfo* resultInfo = nsnull;
    for (PRUint8 i = 0; i < paramCount; i++) {
      const nsXPTParamInfo &paramInfo = aMethodInfo->GetParam(i);
      if (paramInfo.IsRetval()) {
        resultInfo = &paramInfo;
        break;
      }
    }
    if (resultInfo) {
      rv = WriteParam(out, aIInfo, aMethodIndex, resultInfo, 0);
    } else {
      rv = out->Write(kVoidReturn, sizeof(kVoidReturn) - 1, &count);
    }
    NS_ENSURE_SUCCESS(rv, rv);

    // write method name string
    nsCAutoString method_name;
    const char* name = aMethodInfo->GetName();
    if (aMethodInfo->IsGetter() || aMethodInfo->IsSetter()) {
      if (aMethodInfo->IsGetter())
        method_name.AppendLiteral("get");
      else
        method_name.AppendLiteral("set");
      method_name.Append(toupper(name[0]));
      method_name.AppendASCII(name + 1);
    } else {
      method_name.Append(tolower(name[0]));
      method_name.AppendASCII(name + 1);
    }
    // don't use Java keywords as method names
    if (mJavaKeywords.Contains(method_name)) {
      method_name.Insert('_', 0);
    }
    rv = out->Write(" ", 1, &count);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = out->Write(method_name.get(), method_name.Length(), &count);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = out->Write("(", 1, &count);
    NS_ENSURE_SUCCESS(rv, rv);

    // write parameters
    for (PRUint8 j = 0; j < paramCount; j++) {
      const nsXPTParamInfo &paramInfo = aMethodInfo->GetParam(j);
      if (paramInfo.IsRetval())
        continue;

      if (j != 0) {
        rv = out->Write(kParamSeparator, sizeof(kParamSeparator) - 1, &count);
        NS_ENSURE_SUCCESS(rv, rv);
      }

      rv = WriteParam(out, aIInfo, aMethodIndex, &paramInfo, j + 1);
      NS_ENSURE_SUCCESS(rv, rv);
    }

    rv = out->Write(kMethodEnd, sizeof(kMethodEnd) - 1, &count);
    return rv;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult Generate::WriteParam ( nsIOutputStream out,
nsIInterfaceInfo aIInfo,
PRUint16  aMethodIndex,
const nsXPTParamInfo aParamInfo,
PRUint8  aIndex 
) [inline]

Definition at line 675 of file GenerateJavaInterfaces.cpp.

  {
    const nsXPTType &type = aParamInfo->GetType();
    nsresult rv = WriteType(out, &type, aIInfo, aMethodIndex, aParamInfo);
    NS_ENSURE_SUCCESS(rv, rv);

    // if parameter is 'out' or 'inout', make it a Java array
    PRUint32 count;
    if (aParamInfo->IsOut() && !aParamInfo->IsRetval()) {
      rv = out->Write("[]", 2, &count);
      NS_ENSURE_SUCCESS(rv, rv);
    }

    // write name for parameter (but not for 'retval' param)
    if (aIndex) {
      char buf[10];
      snprintf(buf, sizeof(buf), " arg%d", aIndex);
      rv = out->Write(buf, strlen(buf), &count);
      NS_ENSURE_SUCCESS(rv, rv);
    }

    return NS_OK;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult Generate::WriteType ( nsIOutputStream out,
const nsXPTType aType,
nsIInterfaceInfo aIInfo,
PRUint16  aMethodIndex,
const nsXPTParamInfo aParamInfo 
) [inline]

Write out the Java type for the given XPIDL type.

NOTE: Java doesn't support unsigned types. So for any unsigned XPIDL type, we move up to the next largest Java type. This way we ensure that we don't lose any info.

Definition at line 708 of file GenerateJavaInterfaces.cpp.

  {
    nsresult rv;
    PRUint32 count;
    switch (aType->TagPart()) {
      case nsXPTType::T_I8:
        rv = out->Write("byte", 4, &count);
        break;

      case nsXPTType::T_I16:
      case nsXPTType::T_U8:
        rv = out->Write("short", 5, &count);
        break;

      case nsXPTType::T_I32:
      case nsXPTType::T_U16:
        rv = out->Write("int", 3, &count);
        break;

      case nsXPTType::T_I64:
      case nsXPTType::T_U32:
        rv = out->Write("long", 4, &count);
        break;

      case nsXPTType::T_FLOAT:
        rv = out->Write("float", 5, &count);
        break;

      // XXX how should we handle 64-bit values?
      case nsXPTType::T_U64:
      case nsXPTType::T_DOUBLE:
        rv = out->Write("double", 6, &count);
        break;

      case nsXPTType::T_BOOL:
        rv = out->Write("boolean", 7, &count);
        break;

      case nsXPTType::T_CHAR:
      case nsXPTType::T_WCHAR:
        rv = out->Write("char", 4, &count);
        break;

      case nsXPTType::T_CHAR_STR:
      case nsXPTType::T_WCHAR_STR:
      case nsXPTType::T_IID:
      case nsXPTType::T_ASTRING:
      case nsXPTType::T_DOMSTRING:
      case nsXPTType::T_UTF8STRING:
      case nsXPTType::T_CSTRING:
      case nsXPTType::T_PSTRING_SIZE_IS:
      case nsXPTType::T_PWSTRING_SIZE_IS:
        rv = out->Write("String", 6, &count);
        break;

      case nsXPTType::T_INTERFACE:
      {
        char* iface_name = nsnull;
        rv = TypeInfo::GetInterfaceName(aIInfo, aMethodIndex, aParamInfo,
                                        &iface_name);
        if (NS_FAILED(rv) || !iface_name) {
          rv = NS_ERROR_FAILURE;
          break;
        }

        rv = out->Write(iface_name, strlen(iface_name), &count);
        nsMemory::Free(iface_name);
        break;
      }

      case nsXPTType::T_INTERFACE_IS:
        rv = out->Write("nsISupports", 11, &count);
        break;

      case nsXPTType::T_VOID:
        rv = out->Write("long", 4, &count);
        break;

      case nsXPTType::T_ARRAY:
      {
        // get array type
        nsXPTType xpttype;
        rv = aIInfo->GetTypeForParam(aMethodIndex, aParamInfo, 1, &xpttype);
        if (NS_FAILED(rv))
          break;

        rv = WriteType(out, &xpttype, aIInfo, aMethodIndex, aParamInfo);
        if (NS_FAILED(rv))
          break;

        rv = out->Write("[]", 2, &count);
        break;
      }

      default:
        fprintf(stderr, "WARNING: unexpected parameter type %d\n",
                aType->TagPart());
        return NS_ERROR_UNEXPECTED;
    }

    return rv;
  }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Hashtable Generate.ifaceTable = new Hashtable() [private]

Definition at line 10 of file generate-interfaces.cs.

PropertyBuilder Generate.lastProperty = null [private]

Definition at line 12 of file generate-interfaces.cs.

ModuleBuilder Generate.mb [private]

Definition at line 9 of file generate-interfaces.cs.

const MethodAttributes Generate.METHOD_ATTRS [private]
Initial value:
 MethodAttributes.Public |
            MethodAttributes.Abstract | MethodAttributes.Virtual |
            MethodAttributes.NewSlot

Definition at line 14 of file generate-interfaces.cs.

nsCStringHashSet Generate::mIfaceTable [private]

Definition at line 188 of file GenerateJavaInterfaces.cpp.

nsCStringHashSet Generate::mJavaKeywords [private]

Definition at line 189 of file GenerateJavaInterfaces.cpp.

nsCStringHashSet Generate::mNoscriptMethodsTable [private]

Definition at line 191 of file GenerateJavaInterfaces.cpp.

Definition at line 187 of file GenerateJavaInterfaces.cpp.

const PropertyAttributes Generate.PROPERTY_ATTRS = PropertyAttributes.None [private]

Definition at line 13 of file generate-interfaces.cs.

Definition at line 11 of file generate-interfaces.cs.


The documentation for this class was generated from the following files: