Bug 269553 - Integrate JavaXPCOM into build. r=bsmedberg, sr=bryner

This commit is contained in:
pedemont%us.ibm.com 2004-12-01 17:33:16 +00:00
Родитель c8e3b14a0d
Коммит c6f2de7c1e
26 изменённых файлов: 7892 добавлений и 98 удалений

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

@ -1323,6 +1323,13 @@ for extension in $MOZ_EXTENSIONS; do
inspector ) MAKEFILES_extensions="$MAKEFILES_extensions
$MAKEFILES_inspector"
;;
java ) MAKEFILES_extensions="$MAKEFILES_extensions
extensions/java/Makefile
extensions/java/xpcom/Makefile
extensions/java/xpcom/build/Makefile
extensions/java/xpcom/tests/Makefile
extensions/java/xpcom/tools/xpidl/Makefile
" ;;
typeaheadfind ) MAKEFILES_extensions="$MAKEFILES_extensions
$MAKEFILES_typeaheadfind"
;;

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

@ -130,6 +130,11 @@ MOZ_PROFILESHARING = @MOZ_PROFILESHARING@
MOZ_PROFILELOCKING = @MOZ_PROFILELOCKING@
MOZ_STORAGE = @MOZ_STORAGE@
MOZ_ENABLE_JAVAXPCOM = @MOZ_ENABLE_JAVAXPCOM@
JAVA_INCLUDE_PATH=@JAVA_INCLUDE_PATH@
JAVAC=@JAVAC@
JAR=@JAR@
# The MOZ_UI_LOCALE var is used to build a particular locale. Do *not*
# use the var to change any binary files. Do *not* use this var unless you
# write rules for the "clean-locale" and "locale" targets.

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

@ -588,6 +588,10 @@ XPIDL_COMPILE = $(CYGWIN_WRAPPER) $(DIST)/bin/xpidl$(BIN_SUFFIX)
XPIDL_LINK = $(CYGWIN_WRAPPER) $(DIST)/bin/xpt_link$(BIN_SUFFIX)
endif
# Java macros
JAVA_IDL_COMPILE = $(CYGWIN_WRAPPER) $(DIST)/bin/java_xpidl$(BIN_SUFFIX)
JAVA_DIST_DIR = $(DIST)/java
REQ_INCLUDES = $(foreach d,$(REQUIRES),-I$(DIST)/include/$d)
INCLUDES = $(LOCAL_INCLUDES) $(REQ_INCLUDES) -I$(PUBLIC) -I$(DIST)/include $(OS_INCLUDES)

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

@ -548,6 +548,12 @@ endif
endif
endif
ifdef MOZ_ENABLE_JAVAXPCOM
JAVA_XPIDLSRCS += $(SDK_XPIDLSRCS)
else
JAVA_XPIDLSRCS =
endif
################################################################################
all::
@ -1210,6 +1216,11 @@ $(SDK_PUBLIC) $(PUBLIC)::
@if test ! -d $@; then echo Creating $@; rm -rf $@; $(NSINSTALL) -D $@; else true; fi
endif
ifneq ($(JAVA_XPIDLSRCS),)
$(JAVA_DIST_DIR)::
@if test ! -d $@; then echo Creating $@; rm -rf $@; $(NSINSTALL) -D $@; else true; fi
endif
ifneq ($(EXPORTS),)
ifndef NO_DIST_INSTALL
export:: $(EXPORTS) $(PUBLIC)
@ -1451,6 +1462,44 @@ endif
endif # SDK_XPIDLSRCS
ifneq ($(JAVA_XPIDLSRCS),)
# A single IDL file can contain multiple interfaces, which result in multiple
# Java interface files. So use hidden dependency files.
JAVADEPFILES = $(addprefix $(XPIDL_GEN_DIR)/org/mozilla/xpcom/.,$(JAVA_XPIDLSRCS:.idl=.java.pp))
# generate .java files into $(XPIDL_GEN_DIR)
$(XPIDL_GEN_DIR)/org/mozilla/xpcom/.done: $(XPIDL_GEN_DIR)/.done
@if test ! -d $(XPIDL_GEN_DIR)/org/mozilla/xpcom; then echo Creating $(XPIDL_GEN_DIR)/org/mozilla/xpcom/.done; rm -rf $(XPIDL_GEN_DIR)/org; mkdir $(XPIDL_GEN_DIR)/org; mkdir $(XPIDL_GEN_DIR)/org/mozilla; mkdir $(XPIDL_GEN_DIR)/org/mozilla/xpcom; fi
@touch $@
$(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/.done: $(XPIDL_GEN_DIR)/org/mozilla/xpcom/.done
@if test ! -d $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs; then echo Creating $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/.done; rm -rf $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs; mkdir $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs; fi
@touch $@
$(XPIDL_GEN_DIR)/org/mozilla/xpcom/.%.java.pp: %.idl $(JAVA_IDL_COMPILE) $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/.done
$(REPORT_BUILD)
$(ELOG) $(JAVA_IDL_COMPILE) -m java -p org.mozilla.xpcom -w -I$(srcdir) -I$(IDL_DIR) -o $(XPIDL_GEN_DIR)/org/mozilla/xpcom/$* $(_VPATH_SRCS)
$(ELOG) $(JAVA_IDL_COMPILE) -m javastub -p org.mozilla.xpcom -w -I$(srcdir) -I$(IDL_DIR) -o $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/$*_Stub $(_VPATH_SRCS)
@touch $@
export:: $(JAVA_DIST_DIR)
# Use a wildcard to install the generated Java files since there is no strict
# one-to-one mapping between IDL files and Java files (IDL files can have
# multiple interfaces).
export:: $(JAVADEPFILES)
ifndef NO_DIST_INSTALL
$(INSTALL) $(IFLAGS1) $(XPIDL_GEN_DIR)/org/mozilla/xpcom/*.java $(JAVA_DIST_DIR)/org/mozilla/xpcom/
$(INSTALL) $(IFLAGS1) $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/*.java $(JAVA_DIST_DIR)/org/mozilla/xpcom/stubs/
endif
endif # JAVA_XPIDLSRCS
################################################################################
# Copy each element of EXTRA_COMPONENTS to $(DIST)/bin/components
ifdef EXTRA_COMPONENTS

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

@ -456,6 +456,19 @@ if test "$MACOS_SDK_DIR"; then
LIBS="-L${MACOS_SDK_DIR}/usr/lib/gcc/darwin/${GCC_VERSION} -L${MACOS_SDK_DIR}/usr/lib $LIBS"
fi
dnl ========================================================
dnl Java SDK support
dnl ========================================================
JAVA_INCLUDE_PATH=
MOZ_ARG_WITH_STRING(java-include-path,
[ --with-java-include-path=dir Location of Java SDK headers],
JAVA_INCLUDE_PATH=$withval)
JAVA_BIN_PATH=
MOZ_ARG_WITH_STRING(java-bin-path,
[ --with-java-bin-path=dir Location of Java binaries (java, javac, jar)],
JAVA_BIN_PATH=$withval)
dnl ========================================================
dnl Checks for programs.
dnl ========================================================
@ -4135,6 +4148,50 @@ if test `echo "$MOZ_EXTENSIONS" | grep -c xforms` -ne 0 && test `echo "$MOZ_EXTE
MOZ_EXTENSIONS=`echo $MOZ_EXTENSIONS | sed -e 's|xforms||g'`
fi
MOZ_ENABLE_JAVAXPCOM=
JAVAC=
JAR=
if test `echo "$MOZ_EXTENSIONS" | grep -c java` -ne 0; then
MOZ_ENABLE_JAVAXPCOM=1
if test -n "${JAVA_INCLUDE_PATH}"; then
dnl Make sure jni.h exists in the given include path.
if test ! -f $JAVA_INCLUDE_PATH/jni.h; then
AC_MSG_ERROR([jni.h was not found in given include path $JAVA_INCLUDE_PATH.])
fi
else
case "$target_os" in
darwin*)
dnl Default to java system location
JAVA_INCLUDE_PATH=/System/Library/Frameworks/JavaVM.framework/Headers
;;
*)
dnl Try $JAVA_HOME
JAVA_INCLUDE_PATH=$JAVA_HOME/include
;;
esac
if test ! -f $JAVA_INCLUDE_PATH/jni.h; then
AC_MSG_ERROR([The header jni.h was not found. Set \$JAVA_HOME or use --with-java-include-path={java-include-dir}.])
fi
fi
if test -n "${JAVA_BIN_PATH}"; then
dnl Look for javac and jar in the specified path.
AC_PATH_PROG(JAVAC, javac, :, $JAVA_BIN_PATH)
AC_PATH_PROG(JAR, jar, :, $JAVA_BIN_PATH)
if test -z "$JAVAC" || test "$JAVAC" = ":" || test -z "$JAR" || test "$JAR" = ":"; then
AC_MSG_ERROR([The programs javac and jar were not found in given path $JAVA_BIN_PATH.])
fi
else
dnl No path specified, so look for javac and jar are in $JAVA_HOME & $PATH.
AC_PATH_PROG(JAVAC, javac, :, [$JAVA_HOME/bin:$PATH])
AC_PATH_PROG(JAR, jar, :, [$JAVA_HOME/bin:$PATH])
if test -z "$JAVAC" || test "$JAVAC" = ":" || test -z "$JAR" || test "$JAR" = ":"; then
AC_MSG_ERROR([The programs javac and jar were not found. Set \$JAVA_HOME or use --with-java-bin-path={java-bin-dir}.])
fi
fi
fi
dnl ========================================================
dnl Check for GSSAPI libraries and headers needed for
dnl integrated windows authentication support (disable
@ -5824,6 +5881,11 @@ AC_SUBST(LDAP_LIBS)
AC_SUBST(LIBICONV)
AC_SUBST(MOZ_STORAGE)
AC_SUBST(MOZ_ENABLE_JAVAXPCOM)
AC_SUBST(JAVA_INCLUDE_PATH)
AC_SUBST(JAVAC)
AC_SUBST(JAR)
AC_SUBST(MOZ_PROFILESHARING)
AC_SUBST(MOZ_PROFILELOCKING)

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

@ -87,6 +87,10 @@ SDK_XPIDLSRCS = \
nsIGlobalHistory.idl \
$(NULL)
JAVA_XPIDLSRCS = \
nsIWebNavigation.idl \
$(NULL)
XPIDLSRCS = \
nsCDocShell.idl \
nsCDefaultURIFixup.idl \

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

@ -45,6 +45,10 @@ include $(DEPTH)/config/autoconf.mk
MODULE = progressDlg
XPIDL_MODULE = progressDlg
JAVA_XPIDLSRCS = \
nsIProgressDialog.idl \
$(NULL)
XPIDLSRCS = \
nsIProgressDialog.idl \
$(NULL)

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

@ -0,0 +1,48 @@
# ***** 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 Java XPCOM Bindings.
#
# The Initial Developer of the Original Code is
# IBM Corporation.
# Portions created by the Initial Developer are Copyright (C) 2004
# IBM Corporation. All Rights Reserved.
#
# Contributor(s):
# Javier Pedemonte (jhpedemonte@gmail.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 = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = xpcom
include $(topsrcdir)/config/rules.mk

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

@ -46,15 +46,13 @@ include $(topsrcdir)/config/config.mk
MODULE = javaxpcom
LIBRARY_NAME = javaxpcom
EMBED_JAR = mozembed.jar
EMBED_JAR_SRC = $(patsubst %.jar,%-src.jar,$(EMBED_JAR))
PACKAGE_NAME = org.mozilla.xpcom
REQUIRES = xpcom \
string \
embed_base \
$(NULL)
DIRS = build
CPPSRCS = \
nsJavaInterfaces.cpp \
nsJavaWrapper.cpp \
@ -63,18 +61,19 @@ CPPSRCS = \
nsJavaXPCOMBindingUtils.cpp \
$(NULL)
# Can't use JAVA_SRCS for now, since that one is referenced in config.mk
JAVA_SRCS_ = \
JAVA_SRCS = \
XPCOM.java \
XPCOMException.java \
GeckoEmbed.java \
$(NULL)
LOCAL_INCLUDES = \
-I$(JAVA_HOME)/include \
$(NULL)
LOCAL_INCLUDES = -I$(JAVA_INCLUDE_PATH)
LOCAL_INCLUDES += -I$(JAVA_HOME)/include/linux
ifeq ($(OS_ARCH),WINNT)
LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/win32
else
LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/linux
endif
EXTRA_DSO_LIBS = \
embed_base_s \
@ -86,89 +85,8 @@ EXTRA_DSO_LDOPTS = \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
IDL_FILES := $(filter-out nsrootidl.idl,$(wildcard $(DIST)/idl/*))
JAVA_IFACES = $(addprefix $(XPIDL_GEN_DIR)/org/mozilla/xpcom/,$($(notdir $(IDL_FILES)):.idl=.java))
JAVA_STUBS = $(patsubst %.idl,$(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/%_Stub.java,$(notdir $(IDL_FILES)))
_JAVA_IFACE_CLASSES = $(patsubst %.idl,org/mozilla/xpcom/%.class,$(notdir $(IDL_FILES)))
_JAVA_STUB_CLASSES = $(patsubst %.idl,org/mozilla/xpcom/stubs/%_Stub.class,$(notdir $(IDL_FILES)))
_IGNORE_IFACES = domstubs
IGNORE_IFACES = $(patsubst %,org/mozilla/xpcom/%.class,$(_IGNORE_IFACES))
JAVA_IFACE_CLASSES = $(filter-out $(IGNORE_IFACES),$(_JAVA_IFACE_CLASSES))
_IGNORE_STUBS = domstubs gfxIFormats
IGNORE_STUBS = $(patsubst %,org/mozilla/xpcom/stubs/%_Stub.class,$(_IGNORE_STUBS))
JAVA_STUB_CLASSES = $(filter-out $(IGNORE_STUBS),$(_JAVA_STUB_CLASSES))
GARBAGE += $(EMBED_JAR) $(EMBED_JAR_SRC)
GARBAGE_DIRS += $(XPIDL_GEN_DIR) org
include $(topsrcdir)/config/rules.mk
$(XPIDL_GEN_DIR)/.done:
@if test ! -d $(XPIDL_GEN_DIR); then echo Creating $(XPIDL_GEN_DIR)/.done; rm -rf $(XPIDL_GEN_DIR); mkdir $(XPIDL_GEN_DIR); fi
@touch $@
$(XPIDL_GEN_DIR)/org/mozilla/xpcom/.done: $(XPIDL_GEN_DIR)/.done
@if test ! -d $(XPIDL_GEN_DIR)/org/mozilla/xpcom; then echo Creating $(XPIDL_GEN_DIR)/org/mozilla/xpcom/.done; rm -rf $(XPIDL_GEN_DIR)/org; mkdir $(XPIDL_GEN_DIR)/org; mkdir $(XPIDL_GEN_DIR)/org/mozilla; mkdir $(XPIDL_GEN_DIR)/org/mozilla/xpcom; fi
@touch $@
$(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/.done: $(XPIDL_GEN_DIR)/org/mozilla/xpcom/.done
@if test ! -d $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs; then echo Creating $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/.done; rm -rf $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs; mkdir $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs; fi
@touch $@
org/mozilla/xpcom/.done:
@if test ! -d org/mozilla/xpcom; then echo Creating org/mozilla/xpcom/.done; rm -rf org; mkdir org; mkdir org/mozilla; mkdir org/mozilla/xpcom; fi
@touch $@
org/mozilla/xpcom/stubs/.done: org/mozilla/xpcom/.done
@if test ! -d org/mozilla/xpcom/stubs; then echo Creating org/mozilla/xpcom/stubs/.done; rm -rf org/mozilla/xpcom/stubs; mkdir org/mozilla/xpcom/stubs; fi
@touch $@
#$(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/%.java: $(XPIDL_COMPILE) $(XPIDL_GEN_DIR)/.done
# $(ELOG) $(XPIDL_COMPILE) -m javastub -w -I$(srcdir) -I$(IDL_DIR) -o $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/$* $(_VPATH_SRCS)
$(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/.java_done: $(XPIDL_COMPILE) $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/.done
@echo Making Java stub files
@for idl in $(IDL_FILES); do \
$(XPIDL_COMPILE) -m javastub -p $(PACKAGE_NAME) -w -I$(srcdir) -I$(IDL_DIR) -o $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/`basename $$idl`_Stub $$idl; \
done
@touch $@
#$(XPIDL_GEN_DIR)/org/mozilla/xpcom/%.java: $(XPIDL_COMPILE) $(XPIDL_GEN_DIR)/.done
# $(ELOG) $(XPIDL_COMPILE) -m java -w -I$(srcdir) -I$(IDL_DIR) -o $(XPIDL_GEN_DIR)/org/mozilla/xpcom/$* $(_VPATH_SRCS)
$(XPIDL_GEN_DIR)/org/mozilla/xpcom/.java_done: $(XPIDL_COMPILE) $(XPIDL_GEN_DIR)/org/mozilla/xpcom/.done $(JAVA_SRCS_)
@echo Making Java interface files
@for idl in $(IDL_FILES); do \
$(XPIDL_COMPILE) -m java -p $(PACKAGE_NAME) -w -I$(srcdir) -I$(IDL_DIR) -o $(XPIDL_GEN_DIR)/org/mozilla/xpcom/`basename $$idl` $$idl; \
done
@$(INSTALL) -m 644 $(addprefix $(srcdir)/,$(JAVA_SRCS_)) $(XPIDL_GEN_DIR)/org/mozilla/xpcom
@touch $@
#org/mozilla/xpcom/stubs/%.class: $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/.java_done org/mozilla/xpcom/stubs/.done
# @javac -classpath org/mozilla/xpcom:org/mozilla/xpcom/stubs -sourcepath $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs -d org/mozilla/xpcom/stubs $(XPIDL_GEN_DIR)/$(patsubst %.class,%.java,$@)
#org/mozilla/xpcom/%.class: $(XPIDL_GEN_DIR)/org/mozilla/xpcom/.java_done org/mozilla/xpcom/.done
# @javac -classpath org/mozilla/xpcom -sourcepath $(XPIDL_GEN_DIR)/org/mozilla/xpcom -d org/mozilla/xpcom $(XPIDL_GEN_DIR)/$(patsubst %.class,%.java,$@)
org/mozilla/xpcom/.class_done: $(XPIDL_GEN_DIR)/org/mozilla/xpcom/.java_done
@echo Compiling Java interface classes
@javac -classpath . -d . $(filter-out $(addprefix $(XPIDL_GEN_DIR)/,$(IGNORE_STUBS:.class=.java)),$(wildcard $(XPIDL_GEN_DIR)/org/mozilla/xpcom/*.java))
@touch $@
org/mozilla/xpcom/stubs/.class_done: org/mozilla/xpcom/.class_done $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/.java_done
@echo Compiling Java stub classes
@javac -classpath . -d . $(filter-out $(addprefix $(XPIDL_GEN_DIR)/,$(IGNORE_STUBS:.class=.java)),$(wildcard $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/*.java))
@touch $@
#$(EMBED_JAR): $(JAVA_IFACE_CLASSES) $(JAVA_STUB_CLASSES)
$(EMBED_JAR): org/mozilla/xpcom/.class_done org/mozilla/xpcom/stubs/.class_done
$(ZIP) $(EMBED_JAR) -qq -r org
$(EMBED_JAR_SRC): $(XPIDL_GEN_DIR)/org/mozilla/xpcom/.java_done $(XPIDL_GEN_DIR)/org/mozilla/xpcom/stubs/.java_done
@cd $(XPIDL_GEN_DIR); $(ZIP) ../$(EMBED_JAR_SRC) -qq -r org
jar:: $(EMBED_JAR) $(EMBED_JAR_SRC)
$(INSTALL) $(IFLAGS1) $^ $(DIST)/bin
export::
@$(INSTALL) -m 644 $(addprefix $(srcdir)/,$(JAVA_SRCS)) $(JAVA_DIST_DIR)/org/mozilla/xpcom

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

@ -0,0 +1,72 @@
# ***** 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 Java XPCOM Bindings.
#
# The Initial Developer of the Original Code is
# IBM Corporation.
# Portions created by the Initial Developer are Copyright (C) 2004
# IBM Corporation. All Rights Reserved.
#
# Contributor(s):
# Javier Pedemonte (jhpedemonte@gmail.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 = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
JARFILE = mozjava.jar
JARFILE_SRC = $(patsubst %.jar,%-src.jar,$(JARFILE))
GARBAGE += $(JARFILE) $(JARFILE_SRC)
GARBAGE_DIRS += org
include $(topsrcdir)/config/rules.mk
org/mozilla/xpcom/.class_done:
@echo Compiling Java interface classes
@$(JAVAC) -classpath . -d . $(JAVA_DIST_DIR)/org/mozilla/xpcom/*.java
@touch $@
org/mozilla/xpcom/stubs/.class_done:
@echo Compiling Java stub classes
@$(JAVAC) -classpath . -d . $(JAVA_DIST_DIR)/org/mozilla/xpcom/stubs/*.java
@touch $@
$(JARFILE): org/mozilla/xpcom/.class_done org/mozilla/xpcom/stubs/.class_done
$(JAR) cf $@ org
$(JARFILE_SRC):
$(JAR) cf $@ -C $(JAVA_DIST_DIR) org
libs:: $(JARFILE) $(JARFILE_SRC)
$(INSTALL) $(IFLAGS1) $^ $(DIST)/bin

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

@ -44,17 +44,23 @@ include $(DEPTH)/config/autoconf.mk
XPIDL_MODULE = javaxpcomtest
# From our interface file, we need to create an XPT file, so Mozilla knows
# about this interface.
XPIDLSRCS = \
IFoo.idl \
$(NULL)
JAVA_SRCS_ = \
JAVA_SRCS = \
TestArray.java \
$(NULL)
ifeq ($(OS_ARCH),WINNT)
SEP = \;
else
SEP = :
endif
JAVA_CLASSPATH = ./..$(SEP)$(XPIDL_GEN_DIR)
JAVA_CLASSPATH = ./../build$(SEP)$(XPIDL_GEN_DIR)
GARBAGE += *.class
@ -62,7 +68,7 @@ include $(topsrcdir)/config/rules.mk
$(XPIDL_GEN_DIR)/%.java: %.idl $(XPIDL_COMPILE) $(XPIDL_GEN_DIR)/.done
$(REPORT_BUILD)
$(ELOG) $(XPIDL_COMPILE) -m java -w -I$(srcdir) -I$(IDL_DIR) -o $(XPIDL_GEN_DIR)/$* $(_VPATH_SRCS)
$(ELOG) $(JAVA_IDL_COMPILE) -m java -w -I$(srcdir) -I$(IDL_DIR) -o $(XPIDL_GEN_DIR)/$* $(_VPATH_SRCS)
ifdef JAVA_CLASSPATH
_JAVA_CLASSPATH = .$(SEP)$(srcdir)$(SEP)$(JAVA_CLASSPATH)
@ -72,8 +78,8 @@ endif
%.class: %.java Makefile Makefile.in
$(REPORT_BUILD)
$(ELOG) javac -classpath $(_JAVA_CLASSPATH) -d . $(_VPATH_SRCS)
$(ELOG) $(CYGWIN_WRAPPER) $(JAVAC) -classpath $(_JAVA_CLASSPATH) -d . $(_VPATH_SRCS)
export:: $(XPIDL_GEN_DIR)/$(XPIDLSRCS:.idl=.java)
libs:: $(JAVA_SRCS_:.java=.class)
libs:: $(JAVA_SRCS:.java=.class)

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

@ -0,0 +1,93 @@
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = javaxpcom
PROGRAM = java_xpidl$(BIN_SUFFIX)
INTERNAL_TOOLS = 1
REQUIRES = \
xpcom \
$(NULL)
# glib and libIDL link against the non-debug msvcrt
MOZ_NO_DEBUG_RTL=1
CSRCS = \
xpidl.c \
xpidl_idl.c \
xpidl_util.c \
xpidl_header.c \
xpidl_typelib.c \
xpidl_doc.c \
xpidl_java.c \
xpidl_javastub.c \
$(NULL)
SDK_BINARY = \
$(PROGRAM) \
$(NULL)
ifdef CROSS_COMPILE
HOST_PROGRAM = host_xpidl$(HOST_BIN_SUFFIX)
HOST_CSRCS = $(CSRCS)
endif
include $(topsrcdir)/config/rules.mk
CFLAGS += $(LIBIDL_CFLAGS)
# Compile directly against the static lib, so we can use xpidl during the build
# without the shared library path being set.
ifeq (WINNT,$(OS_ARCH))
DEFINES += -DEXPORT_XPT_API
ifndef GNU_CC
LDFLAGS += -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRTD
endif
endif
# Tell the $(PROGRAM) target that we need to be recompiled when libxpt changes.
LIBS = $(DIST)/lib/$(LIB_PREFIX)xpt.$(LIB_SUFFIX) $(LIBIDL_LIBS)
EXTRA_DEPS = $(wildcard $(DIST)/lib/$(LIB_PREFIX)xpt.*)
ifdef CROSS_COMPILE
HOST_CFLAGS += $(HOST_LIBIDL_CFLAGS)
HOST_LIBS = $(DIST)/host/lib/libhostxpt.$(LIB_SUFFIX) $(HOST_LIBIDL_LIBS)
HOST_EXTRA_DEPS = $(wildcard $(DIST)/host/lib/libhostxpt.*)
ifdef HOST_NSPR_MDCPUCFG
HOST_CFLAGS += -DMDCPUCFG=$(HOST_NSPR_MDCPUCFG)
endif
endif
ifdef MACOS_SDK_DIR
NEXT_ROOT=
OS_LIBS := $(patsubst -L$(MACOS_SDK_DIR)/usr/lib%,,$(OS_LIBS))
endif
export::
@$(MAKE) libs

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

@ -0,0 +1,299 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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):
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Main xpidl program entry point.
*/
#include "xpidl.h"
static ModeData modes[] = {
{"header", "Generate C++ header", "h", xpidl_header_dispatch},
{"typelib", "Generate XPConnect typelib", "xpt", xpidl_typelib_dispatch},
{"doc", "Generate HTML documentation", "html", xpidl_doc_dispatch},
{"java", "Generate Java interface", "java", xpidl_java_dispatch},
{"javastub","Generate Java Stub", "java", xpidl_javastub_dispatch},
{0, 0, 0, 0}
};
static ModeData *
FindMode(char *mode)
{
int i;
for (i = 0; modes[i].mode; i++) {
if (!strcmp(modes[i].mode, mode))
return &modes[i];
}
return NULL;
}
gboolean enable_debug = FALSE;
gboolean enable_warnings = FALSE;
gboolean verbose_mode = FALSE;
gboolean emit_typelib_annotations = FALSE;
gboolean explicit_output_filename = FALSE;
/* The following globals are explained in xpt_struct.h */
PRUint8 major_version = XPT_MAJOR_VERSION;
PRUint8 minor_version = XPT_MINOR_VERSION;
static char xpidl_usage_str[] =
"Usage: %s -m mode [-w] [-v] [-t version number]\n"
" [-I path] [-o basename | -e filename.ext]\n"
" [-p Java package] filename.idl\n"
" -a emit annotations to typelib\n"
" -w turn on warnings (recommended)\n"
" -v verbose mode (NYI)\n"
" -t create a typelib of a specific version number\n"
" -I add entry to start of include path for ``#include \"nsIThing.idl\"''\n"
" -o use basename (e.g. ``/tmp/nsIThing'') for output\n"
" -e use explicit output filename\n"
" -p specify package name (Java mode only)\n"
" -m specify output mode:\n";
static void
xpidl_usage(int argc, char *argv[])
{
int i;
fprintf(stderr, xpidl_usage_str, argv[0]);
for (i = 0; modes[i].mode; i++) {
fprintf(stderr, " %-12s %-30s (.%s)\n", modes[i].mode,
modes[i].modeInfo, modes[i].suffix);
}
}
#if defined(XP_MAC) && defined(XPIDL_PLUGIN)
#define main xpidl_main
int xpidl_main(int argc, char *argv[]);
#endif
int main(int argc, char *argv[])
{
int i;
IncludePathEntry *inc, *inc_head, **inc_tail;
char *file_basename = NULL, *package = NULL;
ModeData *mode = NULL;
gboolean create_old_typelib = FALSE;
/* turn this on for extra checking of our code */
/* IDL_check_cast_enable(TRUE); */
inc_head = xpidl_malloc(sizeof *inc);
#ifndef XP_MAC
inc_head->directory = ".";
#else
inc_head->directory = "";
#endif
inc_head->next = NULL;
inc_tail = &inc_head->next;
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-')
break;
switch (argv[i][1]) {
case '-':
argc++; /* pretend we didn't see this */
/* fall through */
case 0: /* - is a legal input filename (stdin) */
goto done_options;
case 'a':
emit_typelib_annotations = TRUE;
break;
case 'w':
enable_warnings = TRUE;
break;
case 'v':
verbose_mode = TRUE;
break;
case 't':
{
/* Parse for "-t version number" and store it into global boolean
* and string variables.
*/
const gchar* typelib_version_string = NULL;
/*
* If -t is the last argument on the command line, we have a problem
*/
if (i + 1 == argc) {
fprintf(stderr, "ERROR: missing version number after -t\n");
xpidl_usage(argc, argv);
return 1;
}
/* Do not allow more than one "-t" definition */
if (create_old_typelib) {
fprintf(stderr,
"ERROR: -t argument used twice. "
"Cannot specify more than one version\n");
xpidl_usage(argc, argv);
return 1;
}
/*
* Assume that the argument after "-t" is the version number string
* and search for it in our internal list of acceptable version
* numbers.
*/
switch (XPT_ParseVersionString(argv[++i], &major_version,
&minor_version)) {
case XPT_VERSION_CURRENT:
break;
case XPT_VERSION_OLD:
create_old_typelib = TRUE;
break;
case XPT_VERSION_UNSUPPORTED:
fprintf(stderr, "ERROR: version \"%s\" not supported.\n",
argv[i]);
xpidl_usage(argc, argv);
return 1;
case XPT_VERSION_UNKNOWN:
default:
fprintf(stderr, "ERROR: version \"%s\" not recognised.\n",
argv[i]);
xpidl_usage(argc, argv);
return 1;
}
break;
}
case 'I':
if (argv[i][2] == '\0' && i == argc) {
fputs("ERROR: missing path after -I\n", stderr);
xpidl_usage(argc, argv);
return 1;
}
inc = xpidl_malloc(sizeof *inc);
if (argv[i][2] == '\0') {
/* is it the -I foo form? */
inc->directory = argv[++i];
} else {
/* must be the -Ifoo form. Don't preincrement i. */
inc->directory = argv[i] + 2;
}
#ifdef DEBUG_shaver_includes
fprintf(stderr, "adding %s to include path\n", inc->directory);
#endif
inc->next = NULL;
*inc_tail = inc;
inc_tail = &inc->next;
break;
case 'o':
if (i == argc) {
fprintf(stderr, "ERROR: missing basename after -o\n");
xpidl_usage(argc, argv);
return 1;
}
file_basename = argv[++i];
explicit_output_filename = FALSE;
break;
case 'e':
if (i == argc) {
fprintf(stderr, "ERROR: missing basename after -e\n");
xpidl_usage(argc, argv);
return 1;
}
file_basename = argv[++i];
explicit_output_filename = TRUE;
break;
case 'm':
if (i + 1 == argc) {
fprintf(stderr, "ERROR: missing modename after -m\n");
xpidl_usage(argc, argv);
return 1;
}
if (mode) {
fprintf(stderr,
"ERROR: must specify exactly one mode "
"(first \"%s\", now \"%s\")\n", mode->mode,
argv[i + 1]);
xpidl_usage(argc, argv);
return 1;
}
mode = FindMode(argv[++i]);
if (!mode) {
fprintf(stderr, "ERROR: unknown mode \"%s\"\n", argv[i]);
xpidl_usage(argc, argv);
return 1;
}
break;
case 'p':
if (i + 1 == argc) {
fprintf(stderr, "ERROR: missing package name after -p\n");
xpidl_usage(argc, argv);
return 1;
}
if (package) {
fprintf(stderr,
"ERROR: must specify exactly one package "
"(first \"%s\", now \"%s\")\n", package,
argv[i + 1]);
xpidl_usage(argc, argv);
return 1;
}
package = argv[++i];
if (!package) {
fprintf(stderr, "ERROR: unknown package \"%s\"\n", argv[i]);
xpidl_usage(argc, argv);
return 1;
}
break;
default:
fprintf(stderr, "unknown option %s\n", argv[i]);
xpidl_usage(argc, argv);
return 1;
}
}
done_options:
if (!mode) {
fprintf(stderr, "ERROR: must specify output mode\n");
xpidl_usage(argc, argv);
return 1;
}
if (argc != i + 1) {
fprintf(stderr, "ERROR: extra arguments after input file\n");
}
/*
* Don't try to process multiple files, given that we don't handle -o
* multiply.
*/
if (xpidl_process_idl(argv[i], inc_head, file_basename, package, mode))
return 0;
return 1;
}

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

@ -0,0 +1,287 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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):
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Intramodule declarations.
*/
#ifndef __xpidl_h
#define __xpidl_h
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <string.h> /* After glib.h to avoid warnings about shadowing 'index'. */
#ifndef XP_MAC
#include <libIDL/IDL.h>
#else
#include <IDL.h>
#endif
#include <xpt_struct.h>
/*
* IDL_tree_warning bombs on libIDL version 6.5, and I don't want to not write
* warnings... so I define a versioned one here. Thanks to Mike Shaver for the
* this solution, which allows us to pass through varargs calls.
*/
#if !(LIBIDL_MAJOR_VERSION == 0 && LIBIDL_MINOR_VERSION == 6 && \
LIBIDL_MICRO_VERSION == 5) && !defined(DEBUG_shaver)
/*
* This turns a varargs call to XPIDL_WARNING directly into a varargs
* call to IDL_tree_warning or xpidl_tree_warning as appropriate. The
* only tricky bit is that you must call XPIDL_WARNING with extra
* parens, e.g. XPIDL_WARNING((foo, bar, "sil"))
*
* Probably best removed when we leave 6.5. */
#define XPIDL_WARNING(x) IDL_tree_warning x
#else
extern void xpidl_tree_warning(IDL_tree p, int level, const char *fmt, ...);
#define XPIDL_WARNING(x) xpidl_tree_warning x
#endif
/*
* Internal operation flags.
*/
extern gboolean enable_debug;
extern gboolean enable_warnings;
extern gboolean verbose_mode;
extern gboolean emit_typelib_annotations;
extern gboolean explicit_output_filename;
extern PRUint8 major_version;
extern PRUint8 minor_version;
typedef struct TreeState TreeState;
/*
* A function to handle an IDL_tree type.
*/
typedef gboolean (*nodeHandler)(TreeState *);
/*
* Struct containing functions to define the behavior of a given output mode.
*/
typedef struct backend {
nodeHandler *dispatch_table; /* nodeHandlers table, indexed by node type. */
nodeHandler emit_prolog; /* called at beginning of output generation. */
nodeHandler emit_epilog; /* called at end. */
} backend;
/* Function that produces a struct of output-generation functions */
typedef backend *(*backendFactory)();
extern backend *xpidl_header_dispatch(void);
extern backend *xpidl_typelib_dispatch(void);
extern backend *xpidl_doc_dispatch(void);
extern backend *xpidl_java_dispatch(void);
extern backend *xpidl_javastub_dispatch(void);
typedef struct ModeData {
char *mode;
char *modeInfo;
char *suffix;
backendFactory factory;
} ModeData;
typedef struct IncludePathEntry {
char *directory;
struct IncludePathEntry *next;
} IncludePathEntry;
struct TreeState {
FILE *file;
char *filename;
/* Maybe supplied by -o. Not related to (g_)basename from string.h or glib */
char *basename;
char *package;
IDL_ns ns;
IDL_tree tree;
GSList *base_includes;
nodeHandler *dispatch;
void *priv; /* mode-private data */
};
struct java_priv_data {
GHashTable *typedefTable;
int numMethods;
gboolean bHasBaseClass;
gboolean bCountingMethods;
GHashTable *keywords;
char *filename;
};
/*
* Process an IDL file, generating InterfaceInfo, documentation and headers as
* appropriate.
*/
int
xpidl_process_idl(char *filename, IncludePathEntry *include_path,
char *file_basename, char *package, ModeData *mode);
/*
* Iterate over an IDLN_LIST -- why is this not part of libIDL?
*/
void
xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data);
/*
* Wrapper whines to stderr then exits after null return from malloc or strdup.
*/
void *
xpidl_malloc(size_t nbytes);
char *
xpidl_strdup(const char *s);
/*
* Return a pointer to the start of the base filename of path
*/
const char *
xpidl_basename(const char * path);
/*
* Process an XPIDL node and its kids, if any.
*/
gboolean
xpidl_process_node(TreeState *state);
/*
* Write a newline folllowed by an indented, one-line comment containing IDL
* source decompiled from state->tree.
*/
void
xpidl_write_comment(TreeState *state, int indent);
/*
* Functions for parsing and printing UUIDs.
*/
/*
* How large should the buffer supplied to xpidl_sprint_IID be?
*/
#define UUID_LENGTH 37
/*
* Print an iid to into a supplied buffer; the buffer should be at least
* UUID_LENGTH bytes.
*/
gboolean
xpidl_sprint_iid(nsID *iid, char iidbuf[]);
/*
* Parse a uuid string into an nsID struct. We cannot link against libxpcom,
* so we re-implement nsID::Parse here.
*/
gboolean
xpidl_parse_iid(nsID *id, const char *str);
/* Try to common a little node-handling stuff. */
/* is this node from an aggregate type (interface)? */
#define UP_IS_AGGREGATE(node) \
(IDL_NODE_UP(node) && \
(IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_INTERFACE || \
IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_FORWARD_DCL))
#define UP_IS_NATIVE(node) \
(IDL_NODE_UP(node) && \
IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_NATIVE)
/* is this type output in the form "<foo> *"? */
#define STARRED_TYPE(node) (IDL_NODE_TYPE(node) == IDLN_TYPE_STRING || \
IDL_NODE_TYPE(node) == IDLN_TYPE_WIDE_STRING || \
(IDL_NODE_TYPE(node) == IDLN_IDENT && \
UP_IS_AGGREGATE(node)))
#define DIPPER_TYPE(node) \
(NULL != IDL_tree_property_get(node, "domstring") || \
NULL != IDL_tree_property_get(node, "utf8string") || \
NULL != IDL_tree_property_get(node, "cstring") || \
NULL != IDL_tree_property_get(node, "astring"))
/*
* Find the underlying type of an identifier typedef. Returns NULL
* (and doesn't complain) on failure.
*/
IDL_tree /* IDL_TYPE_DCL */
find_underlying_type(IDL_tree typedef_ident);
/*
* Check that const declarations match their stated sign and are of the
* appropriate types.
*/
gboolean
verify_const_declaration(IDL_tree const_tree);
/*
* Check that scriptable attributes in scriptable interfaces actually are.
*/
gboolean
verify_attribute_declaration(IDL_tree method_tree);
/*
* Perform various validation checks on methods.
*/
gboolean
verify_method_declaration(IDL_tree method_tree);
/*
* Verifies the interface declaration
*/
gboolean
verify_interface_declaration(IDL_tree method_tree);
/*
* Verify that a native declaration has an associated C++ expression, i.e. that
* it's of the form native <idl-name>(<c++-name>)
*/
gboolean
check_native(TreeState *state);
void
printlist(FILE *outfile, GSList *slist);
#endif /* __xpidl_h */

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

@ -0,0 +1,312 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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):
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "xpidl.h"
/*
* Generates documentation from javadoc-style comments in XPIDL files.
*/
static gboolean
doc_prolog(TreeState *state)
{
fprintf(state->file, "<html>\n");
fprintf(state->file, "<head>\n");
fprintf(state->file,
"<!-- this file is generated from %s.idl -->\n",
state->basename);
fprintf(state->file, "<title>documentation for %s.idl interfaces</title>\n",
state->basename);
fprintf(state->file, "</head>\n\n");
fprintf(state->file, "<body>\n");
return TRUE;
}
static gboolean
doc_epilog(TreeState *state)
{
fprintf(state->file, "</body>\n");
fprintf(state->file, "</html>\n");
return TRUE;
}
static gboolean
doc_list(TreeState *state)
{
IDL_tree iter;
for (iter = state->tree; iter; iter = IDL_LIST(iter).next) {
state->tree = IDL_LIST(iter).data;
if (!xpidl_process_node(state))
return FALSE;
}
return TRUE;
}
static gboolean
print_list(FILE *outfile, IDL_tree list)
{
if (list == NULL)
return TRUE;
fprintf(outfile, "<ul>\n");
while (list != NULL) {
fprintf(outfile, " <li>%s\n",
IDL_IDENT(IDL_LIST(list).data).str);
list = IDL_LIST(list).next;
}
fprintf(outfile, "</ul>\n");
return TRUE;
}
static gboolean
doc_interface(TreeState *state)
{
IDL_tree iface = state->tree;
IDL_tree iter;
IDL_tree orig;
char *classname = IDL_IDENT(IDL_INTERFACE(iface).ident).str;
GSList *doc_comments = IDL_IDENT(IDL_INTERFACE(iface).ident).comments;
fprintf(state->file, "interface %s<br>\n", classname);
/* Much more could happen at this step. */
/*
* If parsing doc comments, you might need to take some care with line
* endings, as the xpidl frontend will return comments containing of /r,
* /n, /r/n depending on the platform. It's best to leave out platform
* #defines and just treat them all as equivalent.
*/
if (doc_comments != NULL) {
fprintf(state->file, "doc comments:<br>\n");
fprintf(state->file, "<pre>\n");
printlist(state->file, doc_comments);
fprintf(state->file, "</pre>\n");
fprintf(state->file, "<br>\n");
}
/* inherits from */
/*
* Note that we accept multiple inheritance here (for e.g. gnome idl)
* even though the header backend (specific to mozilla idl) rejects it.
*/
if ((iter = IDL_INTERFACE(iface).inheritance_spec)) {
fprintf(state->file, "%s inherits from:<br>\n", classname);
print_list(state->file, iter);
fprintf(state->file, "<br>\n");
}
/*
* Call xpidl_process_node to recur through list of declarations in
* interface body; another option would be to explicitly iterate through
* the list. xpidl_process_node currently requires twiddling the state to
* get the right node; I'll fix that soon to just take the node. Makes it
* easier to follow what's going on, I think...
*/
orig = state->tree;
state->tree = IDL_INTERFACE(iface).body;
if (state->tree && !xpidl_process_node(state))
return FALSE;
state->tree = orig;
return TRUE;
}
/*
* Copied from xpidl_header.c. You'll probably want to change it; if you can
* use it verbatim or abstract it, we could move it to xpidl_util.c and share
* it from there.
*/
static gboolean
write_type(IDL_tree type_tree, FILE *outfile)
{
if (!type_tree) {
fputs("void", outfile);
return TRUE;
}
switch (IDL_NODE_TYPE(type_tree)) {
case IDLN_TYPE_INTEGER: {
gboolean sign = IDL_TYPE_INTEGER(type_tree).f_signed;
switch (IDL_TYPE_INTEGER(type_tree).f_type) {
case IDL_INTEGER_TYPE_SHORT:
fputs(sign ? "PRInt16" : "PRUint16", outfile);
break;
case IDL_INTEGER_TYPE_LONG:
fputs(sign ? "PRInt32" : "PRUint32", outfile);
break;
case IDL_INTEGER_TYPE_LONGLONG:
fputs(sign ? "PRInt64" : "PRUint64", outfile);
break;
default:
g_error("Unknown integer type %d\n",
IDL_TYPE_INTEGER(type_tree).f_type);
return FALSE;
}
break;
}
case IDLN_TYPE_CHAR:
fputs("char", outfile);
break;
case IDLN_TYPE_WIDE_CHAR:
fputs("PRUnichar", outfile); /* wchar_t? */
break;
case IDLN_TYPE_WIDE_STRING:
fputs("PRUnichar *", outfile);
break;
case IDLN_TYPE_STRING:
fputs("char *", outfile);
break;
case IDLN_TYPE_BOOLEAN:
fputs("PRBool", outfile);
break;
case IDLN_TYPE_OCTET:
fputs("PRUint8", outfile);
break;
case IDLN_TYPE_FLOAT:
switch (IDL_TYPE_FLOAT(type_tree).f_type) {
case IDL_FLOAT_TYPE_FLOAT:
fputs("float", outfile);
break;
case IDL_FLOAT_TYPE_DOUBLE:
fputs("double", outfile);
break;
/* XXX 'long double' just ignored, or what? */
default:
fprintf(outfile, "unknown_type_%d", IDL_NODE_TYPE(type_tree));
break;
}
break;
case IDLN_IDENT:
if (UP_IS_NATIVE(type_tree)) {
fputs(IDL_NATIVE(IDL_NODE_UP(type_tree)).user_type, outfile);
if (IDL_tree_property_get(type_tree, "ptr")) {
fputs(" *", outfile);
} else if (IDL_tree_property_get(type_tree, "ref")) {
fputs(" &", outfile);
}
} else {
fputs(IDL_IDENT(type_tree).str, outfile);
}
if (UP_IS_AGGREGATE(type_tree))
fputs(" *", outfile);
break;
default:
fprintf(outfile, "unknown_type_%d", IDL_NODE_TYPE(type_tree));
break;
}
return TRUE;
}
/* handle ATTR_DCL (attribute declaration) nodes */
static gboolean
doc_attribute_declaration(TreeState *state)
{
IDL_tree attr = state->tree;
if (!verify_attribute_declaration(attr))
return FALSE;
/*
* Attribute idents can also take doc comments. They're ignored here;
* should they be?
*/
if (IDL_ATTR_DCL(attr).f_readonly)
fprintf(state->file, "readonly ");
fprintf(state->file, "attribute ");
if (!write_type(IDL_ATTR_DCL(attr).param_type_spec, state->file))
return FALSE;
fprintf(state->file, "\n");
print_list(state->file, IDL_ATTR_DCL(attr).simple_declarations);
fprintf(state->file, "<br>\n");
return TRUE;
}
/* handle OP_DCL (method declaration) nodes */
static gboolean
doc_method_declaration(TreeState *state)
{
/*
* Doc comment for attributes also applies here.
*/
/*
* Look at 'write_method_signature' in xpidl_header.c for an example of how
* to navigate parse trees for methods. For here, I just print the method
* name.
*/
fprintf(state->file,
"method %s<br>\n",
IDL_IDENT(IDL_OP_DCL(state->tree).ident).str);
return TRUE;
}
backend *
xpidl_doc_dispatch(void)
{
static backend result;
static nodeHandler table[IDLN_LAST];
static gboolean initialized = FALSE;
result.emit_prolog = doc_prolog;
result.emit_epilog = doc_epilog;
if (!initialized) {
/* Initialize non-NULL elements */
/* I just handle a few... many still to be filled in! */
table[IDLN_LIST] = doc_list;
table[IDLN_INTERFACE] = doc_interface;
table[IDLN_ATTR_DCL] = doc_attribute_declaration;
table[IDLN_OP_DCL] = doc_method_declaration;
initialized = TRUE;
}
result.dispatch_table = table;
return &result;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -0,0 +1,849 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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):
* Michael Ang <mang@subcarrier.org>
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Common IDL-processing code.
*/
#include "xpidl.h"
#include "limits.h"
#ifdef XP_MAC
#include <stat.h>
#endif
static gboolean parsed_empty_file;
/*
* The bulk of the generation happens here.
*/
gboolean
xpidl_process_node(TreeState *state)
{
gint type;
nodeHandler *dispatch, handler;
XPT_ASSERT(state->tree);
type = IDL_NODE_TYPE(state->tree);
if ((dispatch = state->dispatch) && (handler = dispatch[type]))
return handler(state);
return TRUE;
}
#if defined(XP_MAC) && defined(XPIDL_PLUGIN)
extern void mac_warning(const char* warning_message);
#endif
static int
msg_callback(int level, int num, int line, const char *file,
const char *message)
{
char *warning_message;
/*
* Egregious hack to permit empty files.
* XXX libIDL needs an API to detect this case robustly.
*/
if (0 == strcmp(message, "File empty after optimization")) {
parsed_empty_file = TRUE;
return 1;
}
if (!file)
file = "<unknown file>";
warning_message = g_strdup_printf("%s:%d: %s\n", file, line, message);
#if defined(XP_MAC) && defined(XPIDL_PLUGIN)
mac_warning(warning_message);
#else
fputs(warning_message, stderr);
#endif
g_free(warning_message);
return 1;
}
/*
* To keep track of the state associated with a given input file. The 'next'
* field lets us maintain a stack of input files.
*/
typedef struct input_data {
char *filename; /* where did I come from? */
unsigned int lineno; /* last lineno processed */
char *buf; /* contents of file */
char *point; /* next char to feed to libIDL */
char *max; /* 1 past last char in buf */
struct input_data *next; /* file from which we were included */
} input_data;
/*
* Passed to us by libIDL. Holds global information and the current stack of
* include files.
*/
typedef struct input_callback_state {
struct input_data *input_stack; /* linked list of input_data */
GHashTable *already_included; /* to prevent redundant includes */
IncludePathEntry *include_path; /* search path for included files */
GSList *base_includes; /* to accumulate #includes from *first* file;
* for passing thru TreeState to
* xpidl_header backend. */
} input_callback_state;
static FILE *
fopen_from_includes(const char *filename, const char *mode,
IncludePathEntry *include_path)
{
IncludePathEntry *current_path = include_path;
char *pathname;
FILE *inputfile;
if (!strcmp(filename, "-"))
return stdin;
if (filename[0] != '/') {
while (current_path) {
pathname = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
current_path->directory, filename);
if (!pathname)
return NULL;
inputfile = fopen(pathname, mode);
g_free(pathname);
if (inputfile)
return inputfile;
current_path = current_path->next;
}
} else {
inputfile = fopen(filename, mode);
if (inputfile)
return inputfile;
}
return NULL;
}
#if defined(XP_MAC) && defined(XPIDL_PLUGIN)
extern FILE* mac_fopen(const char* filename, const char *mode);
#endif
static input_data *
new_input_data(const char *filename, IncludePathEntry *include_path)
{
input_data *new_data;
FILE *inputfile;
char *buffer = NULL;
size_t offset = 0;
size_t buffer_size;
#ifdef XP_MAC
size_t i;
#endif
#if defined(XP_MAC) && defined(XPIDL_PLUGIN)
/* on Mac, fopen knows how to find files. */
inputfile = fopen(filename, "r");
#elif defined(XP_OS2) || defined(XP_WIN32)
/*
* if filename is fully qualified (starts with driver letter), then
* just call fopen(); else, go with fopen_from_includes()
*/
if( filename[1] == ':' )
inputfile = fopen(filename, "r");
else
inputfile = fopen_from_includes(filename, "r", include_path);
#else
inputfile = fopen_from_includes(filename, "r", include_path);
#endif
if (!inputfile)
return NULL;
#ifdef XP_MAC
{
struct stat input_stat;
if (fstat(fileno(inputfile), &input_stat))
return NULL;
buffer = malloc(input_stat.st_size + 1);
if (!buffer)
return NULL;
offset = fread(buffer, 1, input_stat.st_size, inputfile);
if (ferror(inputfile))
return NULL;
}
#else
/*
* Rather than try to keep track of many different varieties of state
* around the boundaries of a circular buffer, we just read in the entire
* file.
*
* We iteratively grow the buffer here; an alternative would be to use
* stat to find the exact buffer size we need, as xpt_dump does.
*/
for (buffer_size = 8191; ; buffer_size *= 2) {
size_t just_read;
buffer = realloc(buffer, buffer_size + 1); /* +1 for trailing nul */
just_read = fread(buffer + offset, 1, buffer_size - offset, inputfile);
if (ferror(inputfile))
return NULL;
if (just_read < buffer_size - offset || just_read == 0) {
/* Done reading. */
offset += just_read;
break;
}
offset += just_read;
}
#endif
fclose(inputfile);
#ifdef XP_MAC
/*
* libIDL doesn't speak '\r' properly - always make sure lines end with
* '\n'.
*/
for (i = 0; i < offset; i++) {
if (buffer[i] == '\r')
buffer[i] = '\n';
}
#endif
new_data = xpidl_malloc(sizeof (struct input_data));
new_data->point = new_data->buf = buffer;
new_data->max = buffer + offset;
*new_data->max = '\0';
new_data->filename = xpidl_strdup(filename);
/* libIDL expects the line number to be that of the *next* line */
new_data->lineno = 2;
new_data->next = NULL;
return new_data;
}
/* process pending raw section */
static int
NextIsRaw(input_data *data, char **startp, int *lenp)
{
char *end, *start;
/*
* XXXmccabe still needed: an in_raw flag to handle the case where we're in
* a raw block, but haven't managed to copy it all to xpidl. This will
* happen when we have a raw block larger than
* IDL_input_data->fill.max_size (currently 8192.)
*/
if (!(data->point[0] == '%' && data->point[1] == '{'))
return 0;
start = *startp = data->point;
end = NULL;
while (start < data->max && (end = strstr(start, "%}"))) {
if (end[-1] == '\r' ||
end[-1] == '\n')
break;
start = end + 1;
}
if (end && start < data->max) {
*lenp = end - data->point + 2;
return 1;
} else {
const char *filename;
int lineno;
IDL_file_get(&filename, &lineno);
msg_callback(IDL_ERROR, 0, lineno, filename,
"unterminated %{ block");
return -1;
}
}
/* process pending comment */
static int
NextIsComment(input_data *data, char **startp, int *lenp)
{
char *end;
if (!(data->point[0] == '/' && data->point[1] == '*'))
return 0;
end = strstr(data->point, "*/");
*lenp = 0;
if (end) {
int skippedLines = 0;
char *tempPoint;
/* get current lineno */
IDL_file_get(NULL,(int *)&data->lineno);
/* get line count */
for (tempPoint = data->point; tempPoint < end; tempPoint++) {
if (*tempPoint == '\n')
skippedLines++;
}
data->lineno += skippedLines;
IDL_file_set(data->filename, (int)data->lineno);
*startp = end + 2;
/* If it's a ** comment, tell libIDL about it. */
if (data->point[2] == '*') {
/* hack termination. +2 to get past '*' '/' */
char t = *(end + 2);
*(end + 2) = '\0';
IDL_queue_new_ident_comment(data->point);
*(end + 2) = t;
}
data->point = *startp; /* XXXmccabe move this out of function? */
return 1;
} else {
const char *filename;
int lineno;
IDL_file_get(&filename, &lineno);
msg_callback(IDL_ERROR, 0, lineno, filename,
"unterminated comment");
return -1;
}
}
static int
NextIsInclude(input_callback_state *callback_state, char **startp,
int *lenp)
{
input_data *data = callback_state->input_stack;
input_data *new_data;
char *filename, *end;
const char *scratch;
/* process the #include that we're in now */
if (strncmp(data->point, "#include \"", 10)) {
return 0;
}
filename = data->point + 10; /* skip #include " */
XPT_ASSERT(filename < data->max);
end = filename;
while (end < data->max) {
if (*end == '\"' || *end == '\n' || *end == '\r')
break;
end++;
}
if (*end != '\"') {
/*
* Didn't find end of include file. Scan 'til next whitespace to find
* some reasonable approximation of the filename, and use it to report
* an error.
*/
end = filename;
while (end < data->max) {
if (*end == ' ' || *end == '\n' || *end == '\r' || *end == '\t')
break;
end++;
}
*end = '\0';
/* make sure we have accurate line info */
IDL_file_get(&scratch, (int *)&data->lineno);
fprintf(stderr,
"%s:%d: didn't find end of quoted include name \"%s\n",
scratch, data->lineno, filename);
return -1;
}
*end = '\0';
*startp = end + 1;
if (data->next == NULL) {
/*
* If we're in the initial file, add this filename to the list
* of filenames to be turned into #include "filename.h"
* directives in xpidl_header.c. We do it here rather than in the
* block below so it still gets added to the list even if it's
* already been recursively included from some other file.
*/
char *filename_cp = xpidl_strdup(filename);
/* note that g_slist_append accepts and likes null as list-start. */
callback_state->base_includes =
g_slist_append(callback_state->base_includes, filename_cp);
}
/* store offset for when we pop, or if we skip this one */
data->point = *startp;
if (!g_hash_table_lookup(callback_state->already_included, filename)) {
filename = xpidl_strdup(filename);
g_hash_table_insert(callback_state->already_included,
filename, (void *)TRUE);
new_data = new_input_data(filename, callback_state->include_path);
if (!new_data) {
char *error_message;
IDL_file_get(&scratch, (int *)&data->lineno);
error_message =
g_strdup_printf("can't open included file %s for reading\n",
filename);
msg_callback(IDL_ERROR, 0,
data->lineno, scratch, error_message);
g_free(error_message);
return -1;
}
new_data->next = data;
/* tell libIDL to exclude this IDL from the toplevel tree */
IDL_inhibit_push();
IDL_file_get(&scratch, (int *)&data->lineno);
callback_state->input_stack = new_data;
IDL_file_set(new_data->filename, (int)new_data->lineno);
}
*lenp = 0; /* this is magic, see the comment below */
return 1;
}
static void
FindSpecial(input_data *data, char **startp, int *lenp)
{
char *point = data->point;
/* magic sequences are:
* "%{" raw block
* "/\*" comment
* "#include \"" include
* The first and last want a newline [\r\n] before, or the start of the
* file.
*/
#define LINE_START(data, point) (point == data->buf || \
(point > data->point && \
(point[-1] == '\r' || point[-1] == '\n')))
while (point < data->max) {
if (point[0] == '/' && point[1] == '*')
break;
if (LINE_START(data, point)) {
if (point[0] == '%' && point[1] == '{')
break;
if (point[0] == '#' && !strncmp(point + 1, "include \"", 9))
break;
}
point++;
}
#undef LINE_START
*startp = data->point;
*lenp = point - data->point;
}
/* set this with a debugger to see exactly what libIDL sees */
static FILE *tracefile;
static int
input_callback(IDL_input_reason reason, union IDL_input_data *cb_data,
gpointer user_data)
{
input_callback_state *callback_state = user_data;
input_data *data = callback_state->input_stack;
input_data *new_data = NULL;
unsigned int len, copy;
int rv;
char *start;
switch(reason) {
case IDL_INPUT_REASON_INIT:
if (data == NULL || data->next == NULL) {
/*
* This is the first file being processed. As it's the target
* file, we only look for it in the first entry in the include
* path, which we assume to be the current directory.
*/
/* XXXmccabe proper assumption? Do we handle files in other
directories? */
IncludePathEntry first_entry;
first_entry.directory = callback_state->include_path->directory;
first_entry.next = NULL;
new_data = new_input_data(cb_data->init.filename,
&first_entry);
} else {
new_data = new_input_data(cb_data->init.filename,
callback_state->include_path);
}
if (!new_data)
return -1;
IDL_file_set(new_data->filename, (int)new_data->lineno);
callback_state->input_stack = new_data;
return 0;
case IDL_INPUT_REASON_FILL:
start = NULL;
len = 0;
while (data->point >= data->max) {
if (!data->next)
return 0;
/* Current file is done; revert to including file */
callback_state->input_stack = data->next;
free(data->filename);
free(data->buf);
free(data);
data = callback_state->input_stack;
IDL_file_set(data->filename, (int)data->lineno);
IDL_inhibit_pop();
}
/*
* Now we scan for sequences which require special attention:
* \n#include begins an include statement
* \n%{ begins a raw-source block
* /\* begins a comment
*
* We used to be fancier here, so make sure that we sent the most
* data possible at any given time. To that end, we skipped over
* \n%{ raw \n%} blocks and then _continued_ the search for special
* sequences like \n#include or /\* comments .
*
* It was really ugly, though -- liberal use of goto! lots of implicit
* state! what fun! -- so now we just do this:
*
* if (special at start) {
* process that special -
* - raw: send it to libIDL, and don't look inside for specials
* - comments: adjust point and start over
* - includes: push new input_data struct for included file, and
* start over
* } else {
* scan for next special
* send data up to that special to libIDL
* }
*
* If len is set to zero, it is a sentinel value indicating we a comment
* or include was found, and parsing should start over.
*
* XXX const string foo = "/\*" will just screw us horribly.
* Hm but. We could treat strings as we treat raw blocks, eh?
*/
/*
* Order is important, so that you can have /\* comments and
* #includes within raw sections, and so that you can comment out
* #includes.
*/
rv = NextIsRaw(data, &start, (int *)&len);
if (rv == -1) return -1;
if (!rv) {
/*
* When NextIsComment succeeds, it returns a 0 len (requesting a
* restart) and adjusts data->point to pick up after the comment.
*/
rv = NextIsComment(data, &start, (int *)&len);
if (rv == -1) return -1;
if (!rv) {
/*
* NextIsInclude might push a new input_data struct; if so, it
* will return a 0 len, letting the callback pick up the new
* file the next time around.
*/
rv = NextIsInclude(callback_state, &start, (int *)&len);
if (rv == -1) return -1;
if (!rv)
FindSpecial(data, &start, (int *)&len);
}
}
if (len == 0) {
/*
* len == 0 is a sentinel value that means we found a comment or
* include. If we found a comment, point has been adjusted to
* point past the comment. If we found an include, a new input_data
* has been pushed. In both cases, calling the input_callback again
* will pick up the new state.
*/
return input_callback(reason, cb_data, user_data);
}
copy = MIN(len, (unsigned int) cb_data->fill.max_size);
memcpy(cb_data->fill.buffer, start, copy);
data->point = start + copy;
if (tracefile)
fwrite(cb_data->fill.buffer, copy, 1, tracefile);
return copy;
case IDL_INPUT_REASON_ABORT:
case IDL_INPUT_REASON_FINISH:
while (data != NULL) {
input_data *next;
next = data->next;
free(data->filename);
free(data->buf);
free(data);
data = next;
}
return 0;
default:
g_error("unknown input reason %d!", reason);
return -1;
}
}
static void
free_ghash_key(gpointer key, gpointer value, gpointer user_data)
{
/* We're only storing TRUE in the value... */
free(key);
}
static void
free_gslist_data(gpointer data, gpointer user_data)
{
free(data);
}
/* Pick up unlink. */
#ifdef XP_UNIX
#include <unistd.h>
#elif XP_WIN
/* We get it from stdio.h. */
#endif
int
xpidl_process_idl(char *filename, IncludePathEntry *include_path,
char *file_basename, char* package, ModeData *mode)
{
char *tmp, *outname, *real_outname = NULL;
IDL_tree top;
TreeState state;
int rv;
input_callback_state callback_state;
gboolean ok = TRUE;
backend *emitter;
memset(&state, 0, sizeof(state));
callback_state.input_stack = NULL;
callback_state.base_includes = NULL;
callback_state.include_path = include_path;
callback_state.already_included = g_hash_table_new(g_str_hash, g_str_equal);
if (!callback_state.already_included) {
fprintf(stderr, "failed to create hashtable. out of memory?\n");
return 0;
}
state.basename = xpidl_strdup(filename);
if (package)
state.package = xpidl_strdup(package);
/* if basename has an .extension, truncate it. */
tmp = strrchr(state.basename, '.');
if (tmp)
*tmp = '\0';
if (!file_basename)
outname = xpidl_strdup(state.basename);
else
outname = xpidl_strdup(file_basename);
/* so we don't include it again! */
g_hash_table_insert(callback_state.already_included,
xpidl_strdup(filename), (void *)TRUE);
parsed_empty_file = FALSE;
rv = IDL_parse_filename_with_input(filename, input_callback, &callback_state,
msg_callback, &top,
&state.ns,
IDLF_IGNORE_FORWARDS |
IDLF_XPIDL,
enable_warnings ? IDL_WARNING1 :
IDL_ERROR);
if (parsed_empty_file) {
/*
* If we've detected (via hack in msg_callback) that libIDL returned
* failure because it found a file with no IDL, set the parse tree to
* null and proceed. Allowing this is useful to permit .idl files that
* collect #includes.
*/
top = NULL;
state.ns = NULL;
} else if (rv != IDL_SUCCESS) {
if (rv == -1) {
g_warning("Parse of %s failed: %s", filename, g_strerror(errno));
} else {
g_warning("Parse of %s failed", filename);
}
return 0;
}
state.basename = xpidl_strdup(filename);
tmp = strrchr(state.basename, '.');
if (tmp)
*tmp = '\0';
/* so xpidl_header.c can use it to generate a list of #include directives */
state.base_includes = callback_state.base_includes;
emitter = mode->factory();
state.dispatch = emitter->dispatch_table;
if (strcmp(outname, "-")) {
const char *fopen_mode;
const char *out_basename;
/* explicit_output_filename can't be true without a filename */
if (explicit_output_filename) {
real_outname = g_strdup(outname);
} else {
/*
*This combination seems a little strange, what about OS/2?
* Assume it's some build issue
*/
#if defined(XP_UNIX) || defined(XP_WIN)
if (!file_basename) {
out_basename = xpidl_basename(outname);
} else {
out_basename = outname;
}
#else
out_basename = outname;
#endif
real_outname = g_strdup_printf("%s.%s", out_basename, mode->suffix);
}
/* don't create/open file here for Java */
if (strcmp(mode->mode, "java") == 0 ||
strcmp(mode->mode, "javastub") == 0)
{
state.filename = real_outname;
} else {
/* Use binary write for typelib mode */
fopen_mode = (strcmp(mode->mode, "typelib")) ? "w" : "wb";
state.file = fopen(real_outname, fopen_mode);
if (!state.file) {
perror("error opening output file");
return 0;
}
}
} else {
state.file = stdout;
}
state.tree = top;
if (emitter->emit_prolog)
emitter->emit_prolog(&state);
if (state.tree) /* Only if we have a tree to process. */
ok = xpidl_process_node(&state);
if (emitter->emit_epilog)
emitter->emit_epilog(&state);
if (strcmp(mode->mode, "java") != 0 &&
strcmp(mode->mode, "javastub") != 0)
{
if (state.file != stdout)
fclose(state.file);
}
free(state.basename);
free(state.package);
free(outname);
g_hash_table_foreach(callback_state.already_included, free_ghash_key, NULL);
g_hash_table_destroy(callback_state.already_included);
g_slist_foreach(callback_state.base_includes, free_gslist_data, NULL);
if (state.ns)
IDL_ns_free(state.ns);
if (top)
IDL_tree_free(top);
if (real_outname != NULL) {
/*
* Delete partial output file on failure. (Mac does this in the plugin
* driver code, if the compiler returns failure.)
*/
#if defined(XP_UNIX) || defined(XP_WIN)
if (!ok)
unlink(real_outname);
#endif
g_free(real_outname);
}
return ok;
}
/*
* Our own version of IDL_tree_warning, which we use when IDL_tree_warning
* would crash on us.
*/
void
xpidl_tree_warning(IDL_tree p, int level, const char *fmt, ...)
{
va_list ap;
char *msg, *file;
int lineno;
/* XXX need to check against __IDL_max_msg_level, no accessor */
va_start(ap, fmt);
msg = g_strdup_vprintf(fmt, ap);
if (p) {
file = p->_file;
lineno = p->_line;
} else {
file = NULL;
lineno = 0;
}
/* call our message callback, like IDL_tree_warning would */
msg_callback(level, 0, lineno, file, msg);
g_free(msg);
va_end(ap);
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -0,0 +1,855 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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):
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Utility functions called by various backends.
*/
#include "xpidl.h"
/* XXXbe static */ char OOM[] = "ERROR: out of memory\n";
void *
xpidl_malloc(size_t nbytes)
{
void *p = malloc(nbytes);
if (!p) {
fputs(OOM, stderr);
exit(1);
}
return p;
}
#ifdef XP_MAC
static char *strdup(const char *c)
{
char *newStr = malloc(strlen(c) + 1);
if (newStr)
{
strcpy(newStr, c);
}
return newStr;
}
#endif
char *
xpidl_strdup(const char *s)
{
char *ns = strdup(s);
if (!ns) {
fputs(OOM, stderr);
exit(1);
}
return ns;
}
void
xpidl_write_comment(TreeState *state, int indent)
{
fprintf(state->file, "%*s/* ", indent, "");
IDL_tree_to_IDL(state->tree, state->ns, state->file,
IDLF_OUTPUT_NO_NEWLINES |
IDLF_OUTPUT_NO_QUALIFY_IDENTS |
IDLF_OUTPUT_PROPERTIES);
fputs(" */\n", state->file);
}
/*
* Print an iid to into a supplied buffer; the buffer should be at least
* UUID_LENGTH bytes.
*/
gboolean
xpidl_sprint_iid(nsID *id, char iidbuf[])
{
int printed;
printed = sprintf(iidbuf,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(PRUint32) id->m0, (PRUint32) id->m1,(PRUint32) id->m2,
(PRUint32) id->m3[0], (PRUint32) id->m3[1],
(PRUint32) id->m3[2], (PRUint32) id->m3[3],
(PRUint32) id->m3[4], (PRUint32) id->m3[5],
(PRUint32) id->m3[6], (PRUint32) id->m3[7]);
#ifdef SPRINTF_RETURNS_STRING
return (printed && strlen((char *)printed) == 36);
#else
return (printed == 36);
#endif
}
/* We only parse the {}-less format. */
static const char nsIDFmt2[] =
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
/*
* Parse a uuid string into an nsID struct. We cannot link against libxpcom,
* so we re-implement nsID::Parse here.
*/
gboolean
xpidl_parse_iid(nsID *id, const char *str)
{
PRInt32 count = 0;
PRInt32 n1, n2, n3[8];
PRInt32 n0, i;
XPT_ASSERT(str != NULL);
if (strlen(str) != 36) {
return FALSE;
}
#ifdef DEBUG_shaver_iid
fprintf(stderr, "parsing iid %s\n", str);
#endif
count = sscanf(str, nsIDFmt2,
&n0, &n1, &n2,
&n3[0],&n3[1],&n3[2],&n3[3],
&n3[4],&n3[5],&n3[6],&n3[7]);
id->m0 = (PRInt32) n0;
id->m1 = (PRInt16) n1;
id->m2 = (PRInt16) n2;
for (i = 0; i < 8; i++) {
id->m3[i] = (PRInt8) n3[i];
}
#ifdef DEBUG_shaver_iid
if (count == 11) {
fprintf(stderr, "IID parsed to ");
print_IID(id, stderr);
fputs("\n", stderr);
}
#endif
return (gboolean)(count == 11);
}
gboolean
verify_const_declaration(IDL_tree const_tree) {
struct _IDL_CONST_DCL *dcl = &IDL_CONST_DCL(const_tree);
const char *name = IDL_IDENT(dcl->ident).str;
IDL_tree real_type;
/* const -> list -> interface */
if (!IDL_NODE_UP(IDL_NODE_UP(const_tree)) ||
IDL_NODE_TYPE(IDL_NODE_UP(IDL_NODE_UP(const_tree)))
!= IDLN_INTERFACE) {
IDL_tree_error(const_tree,
"const declaration \'%s\' outside interface",
name);
return FALSE;
}
/* Could be a typedef; try to map it to the real type. */
real_type = find_underlying_type(dcl->const_type);
real_type = real_type ? real_type : dcl->const_type;
if (IDL_NODE_TYPE(real_type) == IDLN_TYPE_INTEGER &&
(IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_SHORT ||
IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_LONG))
{
if (!IDL_TYPE_INTEGER(real_type).f_signed &&
IDL_INTEGER(dcl->const_exp).value < 0)
{
#ifndef G_HAVE_GINT64
/*
* For platforms without longlong support turned on we can get
* confused by the high bit of the long value and think that it
* represents a negative value in an unsigned declaration.
* In that case we don't know if it is the programmer who is
* confused or the compiler. So we issue a warning instead of
* an error.
*/
if (IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_LONG)
{
XPIDL_WARNING((const_tree, IDL_WARNING1,
"unsigned const declaration \'%s\' "
"initialized with (possibly) negative constant",
name));
return TRUE;
}
#endif
IDL_tree_error(const_tree,
"unsigned const declaration \'%s\' initialized with "
"negative constant",
name);
return FALSE;
}
} else {
IDL_tree_error(const_tree,
"const declaration \'%s\' must be of type short or long",
name);
return FALSE;
}
return TRUE;
}
/*
* This method consolidates error checking needed when coercing the XPIDL compiler
* via the -t flag to generate output for a specific version of XPConnect.
*/
static gboolean
verify_type_fits_version(IDL_tree in_tree, IDL_tree error_tree)
{
if (major_version == 1 && minor_version == 1)
{
/* XPIDL Version 1.1 checks */
/* utf8string, cstring, and astring types are not supported */
if (IDL_tree_property_get(in_tree, "utf8string") != NULL ||
IDL_tree_property_get(in_tree, "cstring") != NULL ||
IDL_tree_property_get(in_tree, "astring") != NULL)
{
IDL_tree_error(error_tree,
"Cannot use [utf8string], [cstring] and [astring] "
"types when generating version 1.1 typelibs\n");
return FALSE;
}
}
return TRUE;
}
gboolean
verify_attribute_declaration(IDL_tree attr_tree)
{
IDL_tree iface;
IDL_tree ident;
IDL_tree attr_type;
gboolean scriptable_interface;
/* We don't support attributes named IID, conflicts with static GetIID
* member. The conflict is due to certain compilers (VC++) choosing a
* different vtable order, placing GetIID at the beginning regardless
* of it's placement
*/
if (strcmp(
IDL_IDENT(
IDL_LIST(IDL_ATTR_DCL(attr_tree).simple_declarations).data).str,
"IID") == 0) {
IDL_tree_error(attr_tree,
"Attributes named IID not supported, causes vtable "
"ordering problems");
return FALSE;
}
/*
* Verify that we've been called on an interface, and decide if the
* interface was marked [scriptable].
*/
if (IDL_NODE_UP(attr_tree) && IDL_NODE_UP(IDL_NODE_UP(attr_tree)) &&
IDL_NODE_TYPE(iface = IDL_NODE_UP(IDL_NODE_UP(attr_tree)))
== IDLN_INTERFACE)
{
scriptable_interface =
(IDL_tree_property_get(IDL_INTERFACE(iface).ident, "scriptable")
!= NULL);
} else {
IDL_tree_error(attr_tree,
"verify_attribute_declaration called on a non-interface?");
return FALSE;
}
/*
* Grab the first of the list of idents and hope that it'll
* say scriptable or no.
*/
ident = IDL_LIST(IDL_ATTR_DCL(attr_tree).simple_declarations).data;
/*
* If the interface isn't scriptable, or the attribute is marked noscript,
* there's no need to check.
*/
if (!scriptable_interface ||
IDL_tree_property_get(ident, "noscript") != NULL)
return TRUE;
/*
* If it should be scriptable, check that the type is non-native. nsid,
* domstring, utf8string, cstring, astring are exempted.
*/
attr_type = IDL_ATTR_DCL(attr_tree).param_type_spec;
if (attr_type != NULL)
{
if (UP_IS_NATIVE(attr_type) &&
IDL_tree_property_get(attr_type, "nsid") == NULL &&
IDL_tree_property_get(attr_type, "domstring") == NULL &&
IDL_tree_property_get(attr_type, "utf8string") == NULL &&
IDL_tree_property_get(attr_type, "cstring") == NULL &&
IDL_tree_property_get(attr_type, "astring") == NULL)
{
IDL_tree_error(attr_tree,
"attributes in [scriptable] interfaces that are "
"non-scriptable because they refer to native "
"types must be marked [noscript]\n");
return FALSE;
}
/*
* We currently don't support properties of type nsid that aren't
* pointers or references, unless they are marked [notxpcom} and
* must be read-only
*/
if ((IDL_tree_property_get(ident, "notxpcom") == NULL || !(IDL_ATTR_DCL(attr_tree).f_readonly)) &&
IDL_tree_property_get(attr_type,"nsid") != NULL &&
IDL_tree_property_get(attr_type,"ptr") == NULL &&
IDL_tree_property_get(attr_type,"ref") == NULL)
{
IDL_tree_error(attr_tree,
"Feature not currently supported: "
"attributes with a type of nsid must be marked "
"either [ptr] or [ref], or "
"else must be marked [notxpcom] "
"and must be read-only\n");
return FALSE;
}
/*
* Run additional error checks on the attribute type if targetting an
* older version of XPConnect.
*/
if (!verify_type_fits_version(attr_type, attr_tree))
return FALSE;
}
if (IDL_LIST(IDL_ATTR_DCL(attr_tree).simple_declarations).next != NULL)
{
IDL_tree_error(attr_tree,
"multiple attributes in a single declaration is not supported\n");
return FALSE;
}
return TRUE;
}
/*
* Find the underlying type of an identifier typedef.
*
* All the needed tree-walking seems pretty shaky; isn't there something in
* libIDL to automate this?
*/
IDL_tree /* IDL_TYPE_DCL */
find_underlying_type(IDL_tree typedef_ident)
{
IDL_tree up;
if (typedef_ident == NULL || IDL_NODE_TYPE(typedef_ident) != IDLN_IDENT)
return NULL;
up = IDL_NODE_UP(typedef_ident);
if (up == NULL || IDL_NODE_TYPE(up) != IDLN_LIST)
return NULL;
up = IDL_NODE_UP(up);
if (up == NULL || IDL_NODE_TYPE(up) != IDLN_TYPE_DCL)
return NULL;
return IDL_TYPE_DCL(up).type_spec;
}
static IDL_tree /* IDL_PARAM_DCL */
find_named_parameter(IDL_tree method_tree, const char *param_name)
{
IDL_tree iter;
for (iter = IDL_OP_DCL(method_tree).parameter_dcls; iter;
iter = IDL_LIST(iter).next)
{
IDL_tree param = IDL_LIST(iter).data;
IDL_tree simple_decl = IDL_PARAM_DCL(param).simple_declarator;
const char *current_name = IDL_IDENT(simple_decl).str;
if (strcmp(current_name, param_name) == 0)
return param;
}
return NULL;
}
typedef enum ParamAttrType {
IID_IS,
LENGTH_IS,
SIZE_IS
} ParamAttrType;
/*
* Check that parameters referred to by attributes such as size_is exist and
* refer to parameters of the appropriate type.
*/
static gboolean
check_param_attribute(IDL_tree method_tree, IDL_tree param,
ParamAttrType whattocheck)
{
const char *method_name = IDL_IDENT(IDL_OP_DCL(method_tree).ident).str;
const char *referred_name = NULL;
IDL_tree param_type = IDL_PARAM_DCL(param).param_type_spec;
IDL_tree simple_decl = IDL_PARAM_DCL(param).simple_declarator;
const char *param_name = IDL_IDENT(simple_decl).str;
const char *attr_name;
const char *needed_type;
if (whattocheck == IID_IS) {
attr_name = "iid_is";
needed_type = "IID";
} else if (whattocheck == LENGTH_IS) {
attr_name = "length_is";
needed_type = "unsigned long (or PRUint32)";
} else if (whattocheck == SIZE_IS) {
attr_name = "size_is";
needed_type = "unsigned long (or PRUint32)";
} else {
XPT_ASSERT("asked to check an unknown attribute type!");
return TRUE;
}
referred_name = IDL_tree_property_get(simple_decl, attr_name);
if (referred_name != NULL) {
IDL_tree referred_param = find_named_parameter(method_tree,
referred_name);
IDL_tree referred_param_type;
if (referred_param == NULL) {
IDL_tree_error(method_tree,
"attribute [%s(%s)] refers to missing "
"parameter \"%s\"",
attr_name, referred_name, referred_name);
return FALSE;
}
if (referred_param == param) {
IDL_tree_error(method_tree,
"attribute [%s(%s)] refers to it's own parameter",
attr_name, referred_name);
return FALSE;
}
referred_param_type = IDL_PARAM_DCL(referred_param).param_type_spec;
if (whattocheck == IID_IS) {
/* require IID type */
if (IDL_tree_property_get(referred_param_type, "nsid") == NULL) {
IDL_tree_error(method_tree,
"target \"%s\" of [%s(%s)] attribute "
"must be of %s type",
referred_name, attr_name, referred_name,
needed_type);
return FALSE;
}
} else if (whattocheck == LENGTH_IS || whattocheck == SIZE_IS) {
/* require PRUint32 type */
IDL_tree real_type;
/* Could be a typedef; try to map it to the real type. */
real_type = find_underlying_type(referred_param_type);
real_type = real_type ? real_type : referred_param_type;
if (IDL_NODE_TYPE(real_type) != IDLN_TYPE_INTEGER ||
IDL_TYPE_INTEGER(real_type).f_signed != FALSE ||
IDL_TYPE_INTEGER(real_type).f_type != IDL_INTEGER_TYPE_LONG)
{
IDL_tree_error(method_tree,
"target \"%s\" of [%s(%s)] attribute "
"must be of %s type",
referred_name, attr_name, referred_name,
needed_type);
return FALSE;
}
}
}
return TRUE;
}
/*
* Common method verification code, called by *op_dcl in the various backends.
*/
gboolean
verify_method_declaration(IDL_tree method_tree)
{
struct _IDL_OP_DCL *op = &IDL_OP_DCL(method_tree);
IDL_tree iface;
IDL_tree iter;
gboolean notxpcom;
gboolean scriptable_interface;
gboolean scriptable_method;
gboolean seen_retval = FALSE;
const char *method_name = IDL_IDENT(IDL_OP_DCL(method_tree).ident).str;
/* We don't support attributes named IID, conflicts with static GetIID
* member. The conflict is due to certain compilers (VC++) choosing a
* different vtable order, placing GetIID at the beginning regardless
* of it's placement
*/
if (strcmp(method_name, "GetIID") == 0) {
IDL_tree_error(method_tree,
"Methods named GetIID not supported, causes vtable "
"ordering problems");
return FALSE;
}
if (op->f_varargs) {
/* We don't currently support varargs. */
IDL_tree_error(method_tree, "varargs are not currently supported");
return FALSE;
}
/*
* Verify that we've been called on an interface, and decide if the
* interface was marked [scriptable].
*/
if (IDL_NODE_UP(method_tree) && IDL_NODE_UP(IDL_NODE_UP(method_tree)) &&
IDL_NODE_TYPE(iface = IDL_NODE_UP(IDL_NODE_UP(method_tree)))
== IDLN_INTERFACE)
{
scriptable_interface =
(IDL_tree_property_get(IDL_INTERFACE(iface).ident, "scriptable")
!= NULL);
} else {
IDL_tree_error(method_tree,
"verify_method_declaration called on a non-interface?");
return FALSE;
}
/*
* Require that any method in an interface marked as [scriptable], that
* *isn't* scriptable because it refers to some native type, be marked
* [noscript] or [notxpcom].
*
* Also check that iid_is points to nsid, and length_is, size_is points
* to unsigned long.
*/
notxpcom = IDL_tree_property_get(op->ident, "notxpcom") != NULL;
scriptable_method = scriptable_interface &&
!notxpcom &&
IDL_tree_property_get(op->ident, "noscript") == NULL;
/* Loop through the parameters and check. */
for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {
IDL_tree param = IDL_LIST(iter).data;
IDL_tree param_type =
IDL_PARAM_DCL(param).param_type_spec;
IDL_tree simple_decl =
IDL_PARAM_DCL(param).simple_declarator;
const char *param_name = IDL_IDENT(simple_decl).str;
/*
* Reject this method if it should be scriptable and some parameter is
* native that isn't marked with either nsid, domstring, utf8string,
* cstring, astring or iid_is.
*/
if (scriptable_method &&
UP_IS_NATIVE(param_type) &&
IDL_tree_property_get(param_type, "nsid") == NULL &&
IDL_tree_property_get(simple_decl, "iid_is") == NULL &&
IDL_tree_property_get(param_type, "domstring") == NULL &&
IDL_tree_property_get(param_type, "utf8string") == NULL &&
IDL_tree_property_get(param_type, "cstring") == NULL &&
IDL_tree_property_get(param_type, "astring") == NULL)
{
IDL_tree_error(method_tree,
"methods in [scriptable] interfaces that are "
"non-scriptable because they refer to native "
"types (parameter \"%s\") must be marked "
"[noscript]", param_name);
return FALSE;
}
/*
* nsid's parameters that aren't ptr's or ref's are not currently
* supported in xpcom or non-xpcom (marked with [notxpcom]) methods
* as input parameters
*/
if (!(notxpcom && IDL_PARAM_DCL(param).attr != IDL_PARAM_IN) &&
IDL_tree_property_get(param_type, "nsid") != NULL &&
IDL_tree_property_get(param_type, "ptr") == NULL &&
IDL_tree_property_get(param_type, "ref") == NULL)
{
IDL_tree_error(method_tree,
"Feature currently not supported: "
"parameter \"%s\" is of type nsid and "
"must be marked either [ptr] or [ref] "
"or method \"%s\" must be marked [notxpcom] "
"and must not be an input parameter",
param_name,
method_name);
return FALSE;
}
/*
* Sanity checks on return values.
*/
if (IDL_tree_property_get(simple_decl, "retval") != NULL) {
if (IDL_LIST(iter).next != NULL) {
IDL_tree_error(method_tree,
"only the last parameter can be marked [retval]");
return FALSE;
}
if (op->op_type_spec) {
IDL_tree_error(method_tree,
"can't have [retval] with non-void return type");
return FALSE;
}
/* In case XPConnect relaxes the retval-is-last restriction. */
if (seen_retval) {
IDL_tree_error(method_tree,
"can't have more than one [retval] parameter");
return FALSE;
}
seen_retval = TRUE;
}
/*
* Confirm that [shared] attributes are only used with string, wstring,
* or native (but not nsid, domstring, utf8string, cstring or astring)
* and can't be used with [array].
*/
if (IDL_tree_property_get(simple_decl, "shared") != NULL) {
IDL_tree real_type;
real_type = find_underlying_type(param_type);
real_type = real_type ? real_type : param_type;
if (IDL_tree_property_get(simple_decl, "array") != NULL) {
IDL_tree_error(method_tree,
"[shared] parameter \"%s\" cannot "
"be of array type", param_name);
return FALSE;
}
if (!(IDL_NODE_TYPE(real_type) == IDLN_TYPE_STRING ||
IDL_NODE_TYPE(real_type) == IDLN_TYPE_WIDE_STRING ||
(UP_IS_NATIVE(real_type) &&
!IDL_tree_property_get(real_type, "nsid") &&
!IDL_tree_property_get(real_type, "domstring") &&
!IDL_tree_property_get(real_type, "utf8string") &&
!IDL_tree_property_get(real_type, "cstring") &&
!IDL_tree_property_get(real_type, "astring"))))
{
IDL_tree_error(method_tree,
"[shared] parameter \"%s\" must be of type "
"string, wstring or native", param_name);
return FALSE;
}
}
/*
* inout is not allowed with "domstring", "UTF8String", "CString"
* and "AString" types
*/
if (IDL_PARAM_DCL(param).attr == IDL_PARAM_INOUT &&
UP_IS_NATIVE(param_type) &&
(IDL_tree_property_get(param_type, "domstring") != NULL ||
IDL_tree_property_get(param_type, "utf8string") != NULL ||
IDL_tree_property_get(param_type, "cstring") != NULL ||
IDL_tree_property_get(param_type, "astring") != NULL )) {
IDL_tree_error(method_tree,
"[domstring], [utf8string], [cstring], [astring] "
"types cannot be used as inout parameters");
return FALSE;
}
/*
* arrays of domstring, utf8string, cstring, astring types not allowed
*/
if (IDL_tree_property_get(simple_decl, "array") != NULL &&
UP_IS_NATIVE(param_type) &&
(IDL_tree_property_get(param_type, "domstring") != NULL ||
IDL_tree_property_get(param_type, "utf8string") != NULL ||
IDL_tree_property_get(param_type, "cstring") != NULL ||
IDL_tree_property_get(param_type, "astring") != NULL)) {
IDL_tree_error(method_tree,
"[domstring], [utf8string], [cstring], [astring] "
"types cannot be used in array parameters");
return FALSE;
}
if (!check_param_attribute(method_tree, param, IID_IS) ||
!check_param_attribute(method_tree, param, LENGTH_IS) ||
!check_param_attribute(method_tree, param, SIZE_IS))
return FALSE;
/*
* Run additional error checks on the parameter type if targetting an
* older version of XPConnect.
*/
if (!verify_type_fits_version(param_type, method_tree))
return FALSE;
}
/* XXX q: can return type be nsid? */
/* Native return type? */
if (scriptable_method &&
op->op_type_spec != NULL && UP_IS_NATIVE(op->op_type_spec) &&
IDL_tree_property_get(op->op_type_spec, "nsid") == NULL &&
IDL_tree_property_get(op->op_type_spec, "domstring") == NULL &&
IDL_tree_property_get(op->op_type_spec, "utf8string") == NULL &&
IDL_tree_property_get(op->op_type_spec, "cstring") == NULL &&
IDL_tree_property_get(op->op_type_spec, "astring") == NULL)
{
IDL_tree_error(method_tree,
"methods in [scriptable] interfaces that are "
"non-scriptable because they return native "
"types must be marked [noscript]");
return FALSE;
}
/*
* nsid's parameters that aren't ptr's or ref's are not currently
* supported in xpcom
*/
if (!notxpcom &&
op->op_type_spec != NULL &&
IDL_tree_property_get(op->op_type_spec, "nsid") != NULL &&
IDL_tree_property_get(op->op_type_spec, "ptr") == NULL &&
IDL_tree_property_get(op->op_type_spec, "ref") == NULL)
{
IDL_tree_error(method_tree,
"Feature currently not supported: "
"return value is of type nsid and "
"must be marked either [ptr] or [ref], "
"or else method \"%s\" must be marked [notxpcom] ",
method_name);
return FALSE;
}
/*
* Run additional error checks on the return type if targetting an
* older version of XPConnect.
*/
if (op->op_type_spec != NULL &&
!verify_type_fits_version(op->op_type_spec, method_tree))
{
return FALSE;
}
return TRUE;
}
/*
* Verify that a native declaration has an associated C++ expression, i.e. that
* it's of the form native <idl-name>(<c++-name>)
*/
gboolean
check_native(TreeState *state)
{
char *native_name;
/* require that native declarations give a native type */
if (IDL_NATIVE(state->tree).user_type)
return TRUE;
native_name = IDL_IDENT(IDL_NATIVE(state->tree).ident).str;
IDL_tree_error(state->tree,
"``native %s;'' needs C++ type: ``native %s(<C++ type>);''",
native_name, native_name);
return FALSE;
}
/*
* Print a GSList as char strings to a file.
*/
void
printlist(FILE *outfile, GSList *slist)
{
guint i;
guint len = g_slist_length(slist);
for(i = 0; i < len; i++) {
fprintf(outfile,
"%s\n", (char *)g_slist_nth_data(slist, i));
}
}
void
xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data)
{
IDL_tree_func_data tfd;
while (p) {
struct _IDL_LIST *list = &IDL_LIST(p);
tfd.tree = list->data;
if (!foreach(&tfd, user_data))
return;
p = list->next;
}
}
/*
* Verify that the interface declaration is correct
*/
gboolean
verify_interface_declaration(IDL_tree interface_tree)
{
IDL_tree iter;
/*
* If we have the scriptable attribute then make sure all of our direct
* parents have it as well.
* NOTE: We don't recurse since all interfaces will fall through here
*/
if (IDL_tree_property_get(IDL_INTERFACE(interface_tree).ident,
"scriptable")) {
for (iter = IDL_INTERFACE(interface_tree).inheritance_spec; iter;
iter = IDL_LIST(iter).next) {
if (IDL_tree_property_get(
IDL_INTERFACE(iter).ident, "scriptable") == 0) {
XPIDL_WARNING((interface_tree,IDL_WARNING1,
"%s is scriptable but inherits from the non-scriptable interface %s\n",
IDL_IDENT(IDL_INTERFACE(interface_tree).ident).str,
IDL_IDENT(IDL_INTERFACE(iter).ident).str));
}
}
}
return TRUE;
}
/*
* Return a pointer to the start of the base filename of path
*/
const char *
xpidl_basename(const char * path)
{
const char * result = g_basename(path);
/*
*If this is windows then we'll handle either / or \ as a separator
* g_basename only handles \ for windows
*/
#if defined(XP_WIN32)
const char * slash = strrchr(path, '/');
/* If we found a slash and its after the current default OS separator */
if (slash != NULL && (slash > result))
result = slash + 1;
#endif
return result;
}

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

@ -69,11 +69,17 @@ CPPSRCS = \
nsURILoader.cpp \
nsDocLoader.cpp \
$(NULL)
SDK_XPIDLSRCS = \
nsIURIContentListener.idl \
nsIWebProgress.idl \
nsIWebProgressListener.idl \
$(NULL)
JAVA_XPIDLSRCS = \
nsIDownload.idl \
$(NULL)
XPIDLSRCS = \
nsIContentHandler.idl \
nsIURILoader.idl \
@ -81,6 +87,7 @@ XPIDLSRCS = \
nsIDownload.idl \
nsIDocumentLoader.idl \
$(NULL)
EXPORTS = \
nsURILoader.h \
nsDocLoader.h \

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

@ -120,6 +120,11 @@ EXPORTS = \
$(OSDIR)/nsOSHelperAppService.h \
$(NULL)
JAVA_XPIDLSRCS = \
nsIExternalHelperAppService.idl \
nsIHelperAppLauncherDialog.idl \
$(NULL)
XPIDLSRCS = \
nsCExternalHandlerService.idl \
nsIExternalProtocolService.idl \

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

@ -78,6 +78,11 @@ ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
EXPORTS += nsWidgetAtoms.h nsWidgetAtomList.h
endif
JAVA_XPIDLSRCS = \
nsIAppShell.idl \
nsIBaseWindow.idl \
$(NULL)
XPIDLSRCS = \
nsIAppShell.idl \
nsIFilePicker.idl \

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

@ -159,6 +159,10 @@ SDK_XPIDLSRCS = \
nsISupportsPrimitives.idl \
$(NULL)
JAVA_XPIDLSRCS = \
nsIArray.idl \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
# we don't want the shared lib, but we want to force the creation of a static lib.

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

@ -45,5 +45,9 @@ include $(DEPTH)/config/autoconf.mk
MODULE = xpcom
DIRS = xpt xpidl
ifdef MOZ_ENABLE_JAVAXPCOM
DIRS += $(DEPTH)/extensions/java/xpcom/tools/xpidl
endif
include $(topsrcdir)/config/rules.mk