📄 nsinterfaceinfotoidl.js
字号:
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- *//* ***** 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) 2002 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * 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 ***** *//* The nsInterfaceInfoToIDL implementation.*//***************************************************************************/// nsInterfaceInfoToIDL part...const IInfo = new Components.Constructor("@mozilla.org/scriptableInterfaceInfo;1", "nsIScriptableInterfaceInfo", "init");const nsIDataType = Components.interfaces.nsIDataType;const nsISupports = Components.interfaces.nsISupports;const PARAM_NAME_PREFIX = "arg";const MISSING_INTERFACE = "@"; // flag to indicate missing interfaceinfo// helpers.../********************************************************/// accumulate a string with a stream-ish abstractionfunction Buffer() { this.buffer = "";}Buffer.prototype = { write : function(s) { if(s) this.buffer += s; }, writeln : function(s) { if(s) this.buffer += s + "\n"; else this.buffer += "\n"; }}/********************************************************//*** takes: {xxx}* returns: uuid(xxx)*/function formatID(str){ return "uuid("+str.substring(1,str.length-1)+")";}function formatConstType(type){ switch(type) { case nsIDataType.VTYPE_INT16: return "PRInt16"; case nsIDataType.VTYPE_INT32: return "PRInt32"; case nsIDataType.VTYPE_UINT16: return "PRUint16"; case nsIDataType.VTYPE_UINT32: return "PRUint32"; default: return "!!!! bad const type !!!"; }}function formatTypeName(info, methodIndex, param, dimension){ var type = info.getTypeForParam(methodIndex, param, dimension); switch(type.dataType) { case nsIDataType.VTYPE_INT8 : return "PRInt8"; case nsIDataType.VTYPE_INT16: return "PRInt16"; case nsIDataType.VTYPE_INT32: return "PRInt32"; case nsIDataType.VTYPE_INT64: return "PRInt64"; case nsIDataType.VTYPE_UINT8: return "PRUint8"; case nsIDataType.VTYPE_UINT16: return "PRUint16"; case nsIDataType.VTYPE_UINT32: return "PRUint32"; case nsIDataType.VTYPE_UINT64: return "PRUint64"; case nsIDataType.VTYPE_FLOAT: return "float"; case nsIDataType.VTYPE_DOUBLE: return "double"; case nsIDataType.VTYPE_BOOL: return "PRBool"; case nsIDataType.VTYPE_CHAR: return "char"; case nsIDataType.VTYPE_WCHAR: return "PRUnichar"; case nsIDataType.VTYPE_VOID: if(type.isPointer) return "voidPtr"; return "void"; case nsIDataType.VTYPE_ID: // order matters here... if(type.isReference) return "nsIDRef"; if(type.isPointer) return "nsIDPtr"; return "nsID"; case nsIDataType.VTYPE_DOMSTRING: return "DOMString"; case nsIDataType.VTYPE_CHAR_STR: return "string"; case nsIDataType.VTYPE_WCHAR_STR: return "wstring"; case nsIDataType.VTYPE_INTERFACE: try { return info.getInfoForParam(methodIndex, param).name; } catch(e) { return "/*!!! missing interface info, guessing!!!*/ nsISupports"; } case nsIDataType.VTYPE_INTERFACE_IS: return "nsQIResult"; case nsIDataType.VTYPE_ARRAY: return formatTypeName(info, methodIndex, param, dimension+1); case nsIDataType.VTYPE_STRING_SIZE_IS: return "string"; case nsIDataType.VTYPE_WSTRING_SIZE_IS: return "wstring"; case nsIDataType.VTYPE_UTF8STRING: return "AUTF8String"; case nsIDataType.VTYPE_CSTRING: return "ACString"; case nsIDataType.VTYPE_ASTRING: return "AString"; default: return "!!!! bad data type !!!"; }}function formatBracketForParam(info, methodIndex, param){ var type = param.type; var str = "["; var found = 0; var size_is_ArgNum; var length_is_ArgNum; if(param.isRetval) { if(found++) str += ", "; str += "retval" } if(param.isShared) { if(found++) str += ", "; str += "shared" } if(type.isArray) { if(found++) str += ", "; str += "array" } if(type.dataType == nsIDataType.VTYPE_INTERFACE_IS) { if(found++) str += ", "; str += "iid_is("+ PARAM_NAME_PREFIX + info.getInterfaceIsArgNumberForParam(methodIndex, param) + ")"; } if(type.isArray || type.dataType == nsIDataType.VTYPE_STRING_SIZE_IS || type.dataType == nsIDataType.VTYPE_WSTRING_SIZE_IS) { if(found++) str += ", "; size_is_ArgNum = info.getSizeIsArgNumberForParam(methodIndex, param, 0); str += "size_is("+ PARAM_NAME_PREFIX + size_is_ArgNum + ")"; length_is_ArgNum = info.getLengthIsArgNumberForParam(methodIndex, param, 0); if(length_is_ArgNum != size_is_ArgNum) { str += ", "; str += "length_is("+ PARAM_NAME_PREFIX + length_is_ArgNum + ")"; } } if(!found) return ""; str += "] "; return str}function doInterface(out, iid){ var i, k, t, m, m2, c, p, readonly, bracketed, paramCount, retvalTypeName; var info = new IInfo(iid); var parent = info.parent; var constBaseIndex = parent ? parent.constantCount : 0; var constTotalCount = info.constantCount; var constLocalCount = constTotalCount - constBaseIndex; var methodBaseIndex = parent ? parent.methodCount : 0; var methodTotalCount = info.methodCount; var methodLocalCount = methodTotalCount - methodBaseIndex; // maybe recurring to emit parent declarations is not a good idea...// if(parent)// doInterface(parent.interfaceID); out.writeln(); // comment out nsISupports// if(iid.equals(nsISupports))// out.writeln("/*\n"); out.writeln("[" + (info.isScriptable ? "scriptable, " : "") + formatID(info.interfaceID.number) + "]"); out.writeln("interface "+ info.name + (parent ? (" : "+parent.name) : "") + " {"); if(constLocalCount) { for(i = constBaseIndex; i < constTotalCount; i++) { c = info.getConstant(i); out.writeln(" const " + formatConstType(c.type.dataType) + " " + c.name + " = " + c.value + ";"); } } if(constLocalCount && methodLocalCount) out.writeln(); if(methodLocalCount) { for(i = methodBaseIndex; i < methodTotalCount; i++) { m = info.getMethodInfo(i); if(m.isNotXPCOM)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -