Bug 592191 - Remove embedding/browser/src/tlb2xpt/, r=bsmedberg, a=NPOTB

This commit is contained in:
Phil Ringnalda 2010-08-31 19:42:50 -07:00
Родитель b0e8d71218
Коммит 693f7115dd
8 изменённых файлов: 0 добавлений и 843 удалений

Просмотреть файл

@ -1 +0,0 @@
Utility for turning ActiveX typelibrary files into XPCOM xpt, idl & stub files

Просмотреть файл

@ -1,8 +0,0 @@
// stdafx.cpp : source file that includes just the standard includes
// tlb2xpt.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

Просмотреть файл

@ -1,32 +0,0 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__55CC9557_F6D1_4BE8_A84D_BBCC8E265BDC__INCLUDED_)
#define AFX_STDAFX_H__55CC9557_F6D1_4BE8_A84D_BBCC8E265BDC__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <windows.h>
#include <comdef.h>
#include <stddef.h>
#include <stdio.h>
#include <string>
#include <locale>
#include <crtdbg.h>
#include <atlconv.h>
#include "TypeDesc.h"
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__55CC9557_F6D1_4BE8_A84D_BBCC8E265BDC__INCLUDED_)

Просмотреть файл

@ -1,242 +0,0 @@
#include "stdafx.h"
#include "TypeDesc.h"
TypeDesc::TypeDesc(ITypeInfo* pti, TYPEDESC* ptdesc)
{
if (ptdesc->vt == VT_PTR)
{
// ptdesc->lptdesc points to a TYPEDESC that specifies the thing pointed to
mType = T_POINTER;
mData.mPtr = new TypeDesc(pti, ptdesc->lptdesc);
}
else if ((ptdesc->vt & 0x0FFF) == VT_CARRAY)
{
mType = T_UNSUPPORTED;
mData.mName = strdup("VT_CARRAY");
/*
// ptdesc->lpadesc points to an ARRAYDESC
str = TYPEDESCtoString(pti, &ptdesc->lpadesc->tdescElem );
// Allocate cDims * lstrlen("[123456]")
char buf[20];
for (USHORT n = 0; n < ptdesc->lpadesc->cDims; n++)
{
sprintf(buf, "[%d]", ptdesc->lpadesc->rgbounds[n].cElements);
str += buf;
}
return str;
*/
}
else if ((ptdesc->vt & 0x0FFF) == VT_SAFEARRAY)
{
mType = T_UNSUPPORTED;
mData.mName = strdup("VT_SAFEARRAY");
/*
str = "SAFEARRAY(" + TYPEDESCtoString( pti, ptdesc->lptdesc ) + ")";
return str;
*/
}
else switch(ptdesc->vt)
{
case VT_VOID:
mType = T_VOID;
break;
case VT_HRESULT:
mType = T_RESULT;
break;
case VT_I1:
mType = T_INT8;
break;
case VT_I2:
mType = T_INT16;
break;
case VT_INT:
case VT_I4:
mType = T_INT32;
break;
case VT_I8:
mType = T_INT64;
break;
case VT_UI1:
mType = T_UINT8;
break;
case VT_UI2:
mType = T_UINT16;
break;
case VT_UINT:
case VT_UI4:
mType = T_UINT32;
break;
case VT_UI8:
mType = T_UINT64;
break;
case VT_BSTR:
case VT_LPWSTR:
mType = T_WSTRING;
break;
case VT_LPSTR:
mType = T_STRING;
break;
case VT_UNKNOWN:
case VT_DISPATCH:
mType = T_INTERFACE;
break;
case VT_BOOL:
mType = T_BOOL;
break;
case VT_R4:
mType = T_FLOAT;
break;
case VT_R8:
mType = T_DOUBLE;
break;
case VT_EMPTY:
mType = T_UNSUPPORTED;
mData.mName = strdup("VT_EMPTY");
break;
case VT_NULL:
mType = T_UNSUPPORTED;
mData.mName = strdup("VT_NULL");
break;
case VT_CY:
mType = T_UNSUPPORTED;
mData.mName = strdup("VT_CY");
break;
case VT_DATE:
mType = T_UNSUPPORTED;
mData.mName = strdup("VT_DATE");
break;
case VT_ERROR:
mType = T_UNSUPPORTED;
mData.mName = strdup("VT_ERROR");
break;
case VT_VARIANT:
mType = T_UNSUPPORTED;
mData.mName = strdup("VT_VARIANT");
break;
case VT_USERDEFINED:
mType = T_UNSUPPORTED;
mData.mName = strdup("VT_USERDEFINED");
break;
default:
{
char szBuf[50];
sprintf(szBuf, "VT = %08x", ptdesc->vt);
mType = T_UNSUPPORTED;
mData.mName = strdup(szBuf);
}
break;
}
}
TypeDesc::~TypeDesc()
{
if (mType == T_ARRAY)
{
delete mData.mArray.mElements;
}
else if (mType == T_POINTER)
{
delete mData.mPtr;
}
else if (mType == T_UNSUPPORTED)
{
free(mData.mName);
}
}
std::string TypeDesc::ToCString()
{
std::string str;
if (mType == T_POINTER)
{
// ptdesc->lptdesc points to a TYPEDESC that specifies the thing pointed to
str = mData.mPtr->ToXPIDLString();
str += " *";
return str;
}
else if (mType == T_ARRAY)
{
// TODO
str = "void * /* T_ARRAY */";
return str;
}
else switch (mType) {
case T_VOID: return "void";
case T_RESULT: return "nsresult";
case T_CHAR: return "char";
case T_WCHAR: return "PRUnichar";
case T_INT8: return "PRInt8";
case T_INT16: return "PRInt16";
case T_INT32: return "PRInt32";
case T_INT64: return "PRInt64";
case T_UINT8: return "PRUint8";
case T_UINT16: return "PRUint16";
case T_UINT32: return "PRUint32";
case T_UINT64: return "PRUint64";
case T_STRING: return "char*";
case T_WSTRING: return "PRUnichar*";
case T_FLOAT: return "float";
case T_DOUBLE: return "double";
case T_BOOL: return "PRBool";
case T_INTERFACE: return "nsISupports *";
default:
case T_UNSUPPORTED:
{
std::string str = "/*";
str += mData.mName;
str += " */ void ";
return str;
}
}
}
std::string TypeDesc::ToXPIDLString()
{
std::string str;
if (mType == T_POINTER)
{
// ptdesc->lptdesc points to a TYPEDESC that specifies the thing pointed to
str = mData.mPtr->ToXPIDLString();
str += " *";
return str;
}
else if (mType == T_ARRAY)
{
// TODO
str = "void * /* T_ARRAY */";
return str;
}
else switch (mType) {
case T_VOID: return "void";
case T_RESULT: return "nsresult";
case T_CHAR: return "char";
case T_WCHAR: return "wchar";
case T_INT8: return "octet";
case T_INT16: return "short";
case T_INT32: return "long";
case T_INT64: return "long long";
case T_UINT8: return "octect";
case T_UINT16: return "unsigned short";
case T_UINT32: return "unsigned long";
case T_UINT64: return "unsigned long long";
case T_STRING: return "string";
case T_WSTRING: return "wstring";
case T_FLOAT: return "float";
case T_DOUBLE: return "double";
case T_BOOL: return "boolean";
case T_INTERFACE: return "nsISupports";
default:
case T_UNSUPPORTED:
{
std::string str = "/* ";
str += mData.mName;
str += " */ void";
return str;
}
}
}

Просмотреть файл

@ -1,53 +0,0 @@
#ifndef TYPEDESC_H
#define TYPEDESC_H
class TypeDesc
{
public:
enum Type
{
T_POINTER, // A pointer to something else
T_ARRAY, // An array of other things
T_VOID,
T_RESULT, // nsresult / HRESULT
T_CHAR,
T_WCHAR,
T_INT8,
T_INT16,
T_INT32,
T_INT64,
T_UINT8,
T_UINT16,
T_UINT32,
T_UINT64,
T_STRING,
T_WSTRING,
T_FLOAT,
T_DOUBLE,
T_BOOL,
T_INTERFACE,
T_OTHER,
T_UNSUPPORTED
};
Type mType;
union {
// T_POINTER
TypeDesc *mPtr;
// T_ARRAY
struct {
long mNumElements;
TypeDesc **mElements;
} mArray;
// T_UNSUPPORTED
char *mName;
} mData;
TypeDesc(ITypeInfo* pti, TYPEDESC* ptdesc);
~TypeDesc();
std::string ToXPIDLString();
std::string ToCString();
};
#endif

Просмотреть файл

@ -1,7 +0,0 @@
#include "nsISupports.idl"
// By happy coincidence, nsISupports implements the same methods as IUnknown
// and the same UUID too!
#define axIUnknown nsISupports

Просмотреть файл

@ -1,70 +0,0 @@
#!nmake
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Adam Lock <adamlock@netscape.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ..\..\..\..\..
REQUIRES = \
xpcom \
$(NULL)
MAKE_OBJ_TYPE = EXE
PROGRAM = .\$(OBJDIR)\tlb2xpt.exe
LCFLAGS = /D "WIN32" -DEXPORT_XPT_API /GX
LLIBS = \
$(DIST)\lib\xpcomxpt_s.lib \
$(NULL)
OBJS = \
.\$(OBJDIR)\tlb2xpt.obj \
.\$(OBJDIR)\TypeDesc.obj \
$(NULL)
MOZ_NO_COVERAGE = 1
include <$(DEPTH)\config\rules.mak>
export:: $(PROGRAM)
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
clobber::
rm -f $(DIST)\bin\tlb2xpt.exe

Просмотреть файл

@ -1,430 +0,0 @@
// tlb2xpt.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "xpt_xdr.h"
typedef void (*EnumTypeLibProc)(ITypeInfo *typeInfo, TYPEATTR *typeAttr);
void EnumTypeLib(ITypeLib *typeLib, EnumTypeLibProc pfn);
void EnumTypeLibProcVerbose(ITypeInfo *typeInfo, TYPEATTR *typeAttr);
void EnumTypeLibProcXPIDL(ITypeInfo *typeInfo, TYPEATTR *typeAttr);
void EnumTypeLibProcXPT(ITypeInfo *typeInfo, TYPEATTR *typeAttr);
void EnumTypeLibProcStubs(ITypeInfo *typeInfo, TYPEATTR *typeAttr);
void DumpXPCOMInterfaceXPT(FILE *f, ITypeInfo *tiInterface);
void DumpXPCOMInterfaceIDL(FILE *f, ITypeInfo *typeInfo);
void DumpXPCOMInterfaceStubH(FILE *f, ITypeInfo *tiInterface);
void DumpXPCOMInterfaceStubC(FILE *f, ITypeInfo *tiInterface);
FILE *fidl = NULL;
FILE *fxpt = NULL;
FILE *fstubc = NULL;
FILE *fstubh = NULL;
int main(int argc, char* argv[])
{
BOOL verbose = FALSE;
BOOL genIDL = FALSE;
BOOL genXPT = FALSE;
BOOL genStubs = FALSE;
char *inputTLB = NULL;
char *output = NULL;
for (int arg = 1; arg < argc; arg++)
{
if (stricmp(argv[arg], "-verbose") == 0)
{
verbose = TRUE;
}
else if (stricmp(argv[arg], "-idl") == 0)
{
genIDL = TRUE;
}
else if (stricmp(argv[arg], "-xpt") == 0)
{
genXPT = TRUE;
}
else if (stricmp(argv[arg], "-stubs") == 0)
{
genStubs = TRUE;
}
else if (!inputTLB)
{
inputTLB = argv[arg];
}
else if (!output)
{
output = argv[arg];
}
}
if (inputTLB == NULL || output == NULL)
{
fputs("Usage: tlb2xpt [-verbose] [-idl] [-stubs] [-xpt] typelibrary outputname\n"
" -verbose Print out extra information\n"
" -idl Generate an outputname.idl file\n"
" -xpt Generate an outputname.xpt file\n"
" -stubs Generate outputname.cpp and outputname.h stubs\n",
stderr);
return 1;
}
// Open FILE handles to the various things that need to be generated
if (genIDL)
{
if (output)
{
std::string filename(output);
filename += ".idl";
fidl = fopen(filename.c_str(), "wt");
}
else
{
fidl = stdout;
}
}
if (genXPT)
{
if (output)
{
std::string filename(output);
filename += ".xpy";
fxpt = fopen(filename.c_str(), "wb");
}
}
if (genStubs)
{
std::string stubh(output);
std::string stubc(output);
stubh += ".h";
stubc += ".cpp";
fstubh = fopen(stubh.c_str(), "wt");
fstubc = fopen(stubc.c_str(), "wt");
}
if (verbose)
fprintf(stderr, "Opening TLB \"%s\"\n", inputTLB);
ITypeLibPtr typeLib;
USES_CONVERSION;
HRESULT hr = LoadTypeLib(A2W(inputTLB), &typeLib);
if (FAILED(hr))
{
fprintf(stderr, "Error: failed to open \"%s\"\n", inputTLB);
return 1;
}
if (verbose)
EnumTypeLib(typeLib, EnumTypeLibProcVerbose);
if (genIDL)
{
fputs("#include \"axIUnknown.idl\"\n\n", fidl);
EnumTypeLib(typeLib, EnumTypeLibProcXPIDL);
}
if (genXPT)
EnumTypeLib(typeLib, EnumTypeLibProcXPT);
if (genStubs)
{
EnumTypeLib(typeLib, EnumTypeLibProcStubs);
}
return 0;
}
void EnumTypeLibProcVerbose(ITypeInfo *typeInfo, TYPEATTR *typeAttr)
{
char *type;
switch (typeAttr->typekind)
{
case TKIND_ENUM:
type = "TKIND_ENUM";
break;
case TKIND_RECORD:
type = "TKIND_RECORD";
break;
case TKIND_MODULE:
type = "TKIND_MODULE";
break;
case TKIND_INTERFACE:
type = "TKIND_INTERFACE";
break;
case TKIND_DISPATCH:
type = "TKIND_DISPATCH";
break;
case TKIND_COCLASS:
type = "TKIND_COCLASS";
break;
case TKIND_ALIAS:
type = "TKIND_ALIAS";
break;
case TKIND_UNION:
type = "TKIND_UNION";
break;
case TKIND_MAX:
type = "TKIND_MAX";
break;
default:
type = "default";
break;
}
fprintf(stderr, "Reading %s type\n", type);
}
void EnumTypeLibProcXPT(ITypeInfo *typeInfo, TYPEATTR *typeAttr)
{
if (typeAttr->typekind == TKIND_INTERFACE)
{
DumpXPCOMInterfaceXPT(fxpt, typeInfo);
}
}
void EnumTypeLibProcXPIDL(ITypeInfo *typeInfo, TYPEATTR *typeAttr)
{
if (typeAttr->typekind == TKIND_INTERFACE)
{
DumpXPCOMInterfaceIDL(fidl, typeInfo);
}
}
void EnumTypeLibProcStubs(ITypeInfo *typeInfo, TYPEATTR *typeAttr)
{
if (typeAttr->typekind == TKIND_INTERFACE)
{
DumpXPCOMInterfaceStubH(fstubh, typeInfo);
DumpXPCOMInterfaceStubC(fstubc, typeInfo);
}
}
void EnumTypeLib(ITypeLib *typeLib, EnumTypeLibProc pfn)
{
UINT count = typeLib->GetTypeInfoCount();
for (UINT i = 0; i < count; i++)
{
ITypeInfoPtr typeInfo;
typeLib->GetTypeInfo(i, &typeInfo);
TYPEATTR *typeAttr = NULL;
typeInfo->GetTypeAttr(&typeAttr);
pfn(typeInfo, typeAttr);
typeInfo->ReleaseTypeAttr(typeAttr);
}
}
// [scriptable, uuid(00000000-0000-0000-0000-000000000000)]
// interface axIFoo : axIBar
void DumpXPCOMInterfaceXPT(FILE *f, ITypeInfo *tiInterface)
{
XPTArena *arena = XPT_NewArena(1024 * 10, sizeof(double), "main xpt_link arena");
// TODO. Maybe it would be better to just feed an IDL through the regular compiler
// than try and generate some XPT here.
XPT_DestroyArena(arena);
}
void DumpXPCOMInterfaceStubH(FILE *f, ITypeInfo *tiInterface)
{
HRESULT hr;
USES_CONVERSION;
BSTR bstrName = NULL;
hr = tiInterface->GetDocumentation(MEMBERID_NIL, &bstrName, NULL, NULL, NULL);
char *name = strdup(W2A(bstrName));
SysFreeString(bstrName);
fputs("template<class T>\n", f);
fprintf(f, "class nsAX%sImpl : public ax%s\n", name, name);
fputs("{\n}", f);
for (char *c = name; *c; c++)
{
*c = toupper(*c);
}
fprintf(f, " NS_DECL_AX%s\n", name);
fputs("};\n\n", f);
free(name);
}
void DumpXPCOMInterfaceStubC(FILE *f, ITypeInfo *tiInterface)
{
}
void DumpXPCOMInterfaceIDL(FILE *f, ITypeInfo *tiInterface)
{
HRESULT hr;
// [scriptable, uuid(00000000-0000-0000-0000-000000000000)]
// interface axIFoo : axIBar
// {
// void method1();
// };
TYPEATTR *attr;
tiInterface->GetTypeAttr(&attr);
USES_CONVERSION;
//
// Attribute block
//
fputs("[scriptable, ", f);
// uuid()
WCHAR szGUID[64];
StringFromGUID2(attr->guid, szGUID, sizeof(szGUID));
szGUID[0] = L'(';
szGUID[wcslen(szGUID) - 1] = L')';
fprintf(f, "uuid%s", W2A(szGUID));
fputs("]\n", f);
//
// Interface block
//
fprintf(f, "interface ");
BSTR bstrName = NULL;
hr = tiInterface->GetDocumentation(MEMBERID_NIL, &bstrName, NULL, NULL, NULL);
fprintf(f, "ax%s", W2A(bstrName));
SysFreeString(bstrName);
// Check for the base interface
for (UINT n = 0; n < attr->cImplTypes; n++)
{
HREFTYPE href = NULL;
if (FAILED(hr = tiInterface->GetRefTypeOfImplType(n, &href)))
; // TODO
ITypeInfoPtr tiParent;
if (FAILED(hr = tiInterface->GetRefTypeInfo(href, &tiParent)))
; // TODO
if (FAILED(hr = tiParent->GetDocumentation(MEMBERID_NIL, &bstrName, NULL, NULL, NULL)))
; // TODO
fprintf(f, " : ax%s", W2A(bstrName));
SysFreeString(bstrName);
bstrName = NULL;
tiParent.Release();
}
//
// Methods and properties block
//
fprintf(f, "\n");
fprintf(f, "{\n");
for (n = 0; n < attr->cFuncs; n++)
{
FUNCDESC *func;
tiInterface->GetFuncDesc(n, &func);
fprintf(f, " ");
if (func->invkind & INVOKE_PROPERTYPUT ||
func->invkind & INVOKE_PROPERTYGET)
{
}
// Return type
TypeDesc tf(tiInterface, &func->elemdescFunc.tdesc);
if (tf.mType == TypeDesc::T_RESULT)
{
fprintf(f, "void ");
}
else
{
fprintf(f, "%s ", tf.ToXPIDLString().c_str());
}
// Method / property name
BSTR bstrName = NULL;
tiInterface->GetDocumentation(func->memid, &bstrName, NULL, NULL, NULL);
fprintf(f, "%s (\n", W2A(bstrName));
SysFreeString(bstrName);
// Get the names of all the arguments
UINT cNames;
BSTR rgbstrNames[100];
hr = tiInterface->GetNames(func->memid, rgbstrNames, 100, (UINT*) &cNames);
// Dump out all parameters
for (int p = 0; p < func->cParams; p++)
{
fputs(" ", f);
BOOL isIn = FALSE;
BOOL isOut = FALSE;
// Keywords
if (func->lprgelemdescParam[p].idldesc.wIDLFlags & IDLFLAG_FRETVAL)
{
fputs("[retval] ", f);
}
if (func->lprgelemdescParam[p].idldesc.wIDLFlags & IDLFLAG_FIN &&
func->lprgelemdescParam[p].idldesc.wIDLFlags & IDLFLAG_FOUT)
{
fputs("inout ", f);
}
else if (func->lprgelemdescParam[p].idldesc.wIDLFlags & IDLFLAG_FIN)
{
fputs("in ", f);
}
else if (func->lprgelemdescParam[p].idldesc.wIDLFlags & IDLFLAG_FOUT)
{
fputs("out ", f);
}
// Type
// NOTE: If the arg is an out param, lop off the first pointer reference,
// because XPIDL implicitly expects out params to be pointers.
TypeDesc tp(tiInterface, &func->lprgelemdescParam[p].tdesc);
if (tp.mType == TypeDesc::T_POINTER &&
func->lprgelemdescParam[p].idldesc.wIDLFlags & IDLFLAG_FOUT)
{
fprintf(f, "%s ", tp.mData.mPtr->ToXPIDLString().c_str());
}
else
{
// Type
fprintf(f, "%s ", tp.ToXPIDLString().c_str());
}
// Name
fputs(W2A(rgbstrNames[p+1]), f);
if (p < func->cParams - 1)
{
fprintf(f, ",\n");
}
else
{
fprintf(f, "\n");
}
SysFreeString(rgbstrNames[0]);
}
fputs(" );\n", f);
tiInterface->ReleaseFuncDesc(func);
}
// Fin
fputs("};\n\n", f);
tiInterface->ReleaseTypeAttr(attr);
}