From: Rico Tzschichholz Date: Tue, 27 Jun 2017 11:09:30 +0000 (+0200) Subject: Merge valadoc 0.36.0 X-Git-Tag: 0.37.1~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b742fce82eb1326faaee3b2cc4ff993e701ef53;p=thirdparty%2Fvala.git Merge valadoc 0.36.0 Consider valadoc a part of vala's toolchain and therefore let it live in the main repository. With this merge there is no need to maintain multiple driver sources since only one is required from now on. There is no dependency on gee-0.8 and vala's internal gee copy has made to be sufficient. The libvaladoc library will be suffixed with vala's version suffix too. Besides this renaming the rest of the valadoc file layout is kept the same. https://bugzilla.gnome.org/show_bug.cgi?id=782782 --- 2b742fce82eb1326faaee3b2cc4ff993e701ef53 diff --cc .gitignore index 1a59179d7,000000000..b5d79508b mode 100644,000000..100644 --- a/.gitignore +++ b/.gitignore @@@ -1,43 -1,0 +1,44 @@@ +Makefile.in +Makefile +*.o +*.lo +*.la +*.c +*.h +*.stamp +*.gir +.deps ++.dirstamp +.libs +libvala-*.vapi + +config.* +aclocal.m4 +autom4te.cache +ChangeLog +configure +depcomp +INSTALL +install-sh +libtool +m4 +missing +ltmain.sh +ylwrap +compile +stamp-h1 +*.pc +.tarball-version +.version + +*.gcda +*.gcno +coverage +lcov.info + +*~ + +build-aux/test-driver + +tests/_test + diff --cc Makefile.am index 813b3fc08,000000000..e5dc0cc97 mode 100644,000000..100644 --- a/Makefile.am +++ b/Makefile.am @@@ -1,96 -1,0 +1,98 @@@ +ACLOCAL_AMFLAGS = --install -I m4 ${ACLOCAL_FLAGS} + +NULL = + +SUBDIRS = \ + gee \ + vala \ + ccode \ + codegen \ + compiler \ + vapi \ + tests \ + doc \ + gobject-introspection \ + vapigen \ ++ libvaladoc \ ++ valadoc \ + $(NULL) + +if ENABLE_UNVERSIONED +aclocaldir = $(datadir)/aclocal +aclocal_DATA = vala.m4 +endif + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = libvala@PACKAGE_SUFFIX@.pc + +libvala@PACKAGE_SUFFIX@.pc: libvala.pc + cp $< $@ + +.PHONY: bootstrap +bootstrap: all + find $(top_srcdir) -name "*.vala.stamp" | xargs rm -f + $(MAKE) $(AM_MAKEFLAGS) all VALAC=$(abs_top_builddir)/compiler/valac$(EXEEXT) V=$V + +.PHONY: test +test: + cd tests && $(MAKE) $(AM_MAKEFLAGS) check + +#if ENABLE_COVERAGE +.PHONY: coverage coverage-report +coverage: + find $(top_srcdir) -name "*.gcda" | xargs rm -f + $(MAKE) $(AM_MAKEFLAGS) bootstrap + $(MAKE) $(AM_MAKEFLAGS) test + +coverage-report: coverage + lcov --directory $(top_srcdir) --capture --output-file $(top_builddir)/lcov.info + lcov --directory $(top_srcdir) --output-file $(top_builddir)/lcov.info --remove $(top_builddir)/lcov.info "*.c" "*.h" "*.vapi" + rm -rf $(top_builddir)/coverage + $(mkdir_p) $(top_builddir)/coverage + genhtml --title "@PACKAGE_STRING@" --output-directory $(top_builddir)/coverage $(top_builddir)/lcov.info +#endif + +all: version.h + +version.h: $(top_srcdir)/.version + echo '#define BUILD_VERSION "'`cat $(top_srcdir)/.version`'"' > $@-t && mv $@-t $@ + +BUILT_SOURCES = $(top_srcdir)/.version +$(top_srcdir)/.version: gen-version + @true +.PHONY: gen-version +gen-version: + @V=`$(top_srcdir)/build-aux/git-version-gen $(top_srcdir)/.tarball-version` && \ + if [ -e $(top_srcdir)/.version ] && [ "x`cat $(top_srcdir)/.version`" = "x$$V" ]; then \ + true; \ + else \ + echo "$$V" > $(top_srcdir)/.version; \ + fi +dist-hook: gen-ChangeLog + echo $(VERSION) > $(distdir)/.tarball-version + +gen_start_date = 2009-02-25 +.PHONY: gen-ChangeLog +gen-ChangeLog: + if test -d .git; then \ + $(top_srcdir)/build-aux/gitlog-to-changelog \ + --since=$(gen_start_date) > $(distdir)/cl-t; \ + rm -f $(distdir)/ChangeLog; \ + mv $(distdir)/cl-t $(distdir)/ChangeLog; \ + fi + +CLEANFILES = \ + libvala@PACKAGE_SUFFIX@.pc \ + $(NULL) + +EXTRA_DIST = \ + ChangeLog.pre-0-4 \ + ChangeLog.pre-0-5-7 \ + libvala.pc.in \ + vala.m4 \ + .version \ + build-aux/git-version-gen \ + build-aux/gitlog-to-changelog \ + $(NULL) + +DISTCLEANFILES = version.h diff --cc configure.ac index 531eef482,000000000..c73d5d6b1 mode 100644,000000..100644 --- a/configure.ac +++ b/configure.ac @@@ -1,129 -1,0 +1,171 @@@ +AC_PREREQ([2.65]) +AC_INIT([vala], m4_esyscmd([build-aux/git-version-gen .tarball-version]), + [https://bugzilla.gnome.org/browse.cgi?product=vala], + [vala], + [https://wiki.gnome.org/Projects/Vala]) +AC_CONFIG_SRCDIR([Makefile.am]) +AC_CONFIG_AUX_DIR([build-aux]) +AC_CONFIG_HEADERS(config.h) +AC_CONFIG_MACRO_DIR([m4]) - AM_INIT_AUTOMAKE([1.11 dist-xz no-dist-gzip]) ++AM_INIT_AUTOMAKE([1.11 dist-xz no-dist-gzip subdir-objects]) +AM_MAINTAINER_MODE([enable]) + +API_VERSION=0.38 +PACKAGE_SUFFIX="-$API_VERSION" + +dnl http://people.gnome.org/~walters/docs/build-api.txt +dnl We don't support separate builddir when building from git +echo \#buildapi-variable-no-builddir >/dev/null + +AC_SUBST(API_VERSION) +AC_DEFINE_UNQUOTED(API_VERSION, "$API_VERSION", [Define to the api-version of this package]) +AC_SUBST(PACKAGE_SUFFIX) +AC_DEFINE_UNQUOTED(PACKAGE_SUFFIX, "$PACKAGE_SUFFIX", [Define to the suffix of this package]) + +program_transform_name="s,\$\$,${PACKAGE_SUFFIX}," + +AC_SUBST(pkgdatadir, [${datadir}/vala${PACKAGE_SUFFIX}]) + +# Checks for programs. +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_LN_S +AC_PROG_INSTALL +AC_PROG_MKDIR_P + +LT_PREREQ([2.2.6]) +LT_INIT([disable-static]) +PKG_PROG_PKG_CONFIG([0.21]) + +AC_PROG_LEX +if test "$LEX" = :; then + AC_MSG_ERROR([flex not found but required]) +fi + +AC_CHECK_PROGS(YACC, 'bison -y' byacc yacc, :) +if test "$YACC" = :; then + AC_MSG_ERROR([bison not found but required]) +fi + +AC_PATH_PROG(VALAC, valac, valac) +AC_SUBST(VALAC) + +VALAC_BOOTSTRAP_REQUIRED=0.25.1 + +AS_IF([test "$VALAC" != valac], [FOUND_VALAC_VERION=`$VALAC --version | sed 's/Vala *//'` + AS_VERSION_COMPARE(["$VALAC_BOOTSTRAP_REQUIRED"], ["$FOUND_VALAC_VERION"], + [enable_boostrap=yes], [enable_boostrap=yes], [enable_boostrap=no])]) + +VALAFLAGS="$VALAFLAGS --disable-version-header" +if test x$enable_boostrap = xyes; then + VALAFLAGS="$VALAFLAGS --hide-internal" +fi + +AC_SUBST(VALAFLAGS) +AC_SUBST(CFLAGS) +AC_SUBST(CPPFLAGS) +AC_SUBST(LDFLAGS) + +AC_ARG_ENABLE(unversioned, AS_HELP_STRING([--disable-unversioned], [Disable unversioned binaries]), enable_unversioned=$enableval, enable_unversioned=yes) +AM_CONDITIONAL(ENABLE_UNVERSIONED, test x$enable_unversioned = xyes) + +AC_ARG_ENABLE(coverage, AS_HELP_STRING([--enable-coverage], [Enable coverage analysis]), enable_coverage=$enableval, enable_coverage=no) +AM_CONDITIONAL(ENABLE_COVERAGE, test x$enable_coverage = xyes) + +if test "$enable_coverage" = "yes"; then + COVERAGE_VALAFLAGS="-g" + COVERAGE_CFLAGS="-fprofile-arcs -ftest-coverage" + COVERAGE_LIBS="-lgcov" +else + COVERAGE_VALAFLAGS= + COVERAGE_CFLAGS= + COVERAGE_LIBS= +fi +AC_SUBST(COVERAGE_VALAFLAGS) +AC_SUBST(COVERAGE_CFLAGS) +AC_SUBST(COVERAGE_LIBS) + +GLIB_REQUIRED=2.40.0 ++LIBGVC_REQUIRED=2.16 + +PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_REQUIRED gobject-2.0 >= $GLIB_REQUIRED) + +AC_SUBST(GLIB_CFLAGS) +AC_SUBST(GLIB_LIBS) + +PKG_CHECK_MODULES(GMODULE, gmodule-2.0 >= $GLIB_REQUIRED) + +AC_SUBST(GMODULE_CFLAGS) +AC_SUBST(GMODULE_LIBS) + ++PKG_CHECK_MODULES(LIBGVC, libgvc >= $LIBGVC_REQUIRED) ++AC_MSG_CHECKING([for CGRAPH]) ++cgraph_tmp_LIBADD="$LIBADD" ++cgraph_tmp_CFLAGS="$CFLAGS" ++LIBADD="$LIBADD $LIBGVC_LIBS" ++CFLAGS="$CFLAGS $LIBGVC_CFLAGS" ++AC_RUN_IFELSE( ++ [AC_LANG_SOURCE([ ++ #include ++ ++ int main(void) { ++ #ifdef WITH_CGRAPH ++ return 0; ++ #else ++ return -1; ++ #endif ++ } ++ ])], [ ++ AC_MSG_RESULT([yes]) ++ VALAFLAGS="$VALAFLAGS -D WITH_CGRAPH" ++ have_cgraph=yes ++ ], [ ++ AC_MSG_RESULT([no]) ++ have_cgraph=no ++ ] ++) ++LIBADD="$cgraph_tmp_LIBADD" ++CFLAGS="$cgraph_tmp_CFLAGS" ++AM_CONDITIONAL(HAVE_CGRAPH, test "$have_cgraph" = "yes") ++ +AC_PATH_PROG([XSLTPROC], [xsltproc], :) +AM_CONDITIONAL(HAVE_XSLTPROC, test "$XSLTPROC" != :) + +AC_CHECK_PROG([WEASYPRINT], [weasyprint], [weasyprint]) +AM_CONDITIONAL(HAVE_WEASYPRINT, [test x$WEASYPRINT = xweasyprint]) + +AC_CHECK_PROG([HELP2MAN], [help2man], [help2man]) +AM_CONDITIONAL([HAVE_HELP2MAN], [test x$HELP2MAN = xhelp2man]) + +m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) + +AC_CONFIG_FILES([Makefile + libvala.pc + gee/Makefile + ccode/Makefile + vala/Makefile + codegen/Makefile + compiler/Makefile + vapi/Makefile + tests/Makefile + doc/Makefile + doc/manual/Makefile + doc/manual/version.xml + gobject-introspection/Makefile + vapigen/vapigen.pc + vapigen/Makefile + vapigen/vala-gen-introspect/Makefile - vapigen/vala-gen-introspect/vala-gen-introspect]) ++ vapigen/vala-gen-introspect/vala-gen-introspect ++ libvaladoc/valadoc.pc ++ libvaladoc/valadoc.deps ++ libvaladoc/Makefile ++ valadoc/Makefile ++ valadoc/doclets/Makefile ++ valadoc/doclets/html/Makefile ++ valadoc/doclets/devhelp/Makefile ++ valadoc/doclets/gtkdoc/Makefile ++ valadoc/icons/Makefile ++ valadoc/tests/Makefile ++]) + +AC_OUTPUT diff --cc doc/Makefile.am index b6ca6aacc,000000000..d742011b1 mode 100644,000000..100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@@ -1,47 -1,0 +1,55 @@@ +NULL = + +SUBDIRS = \ + manual \ + $(NULL) + +dist_man_MANS = \ + valac.1 \ ++ valadoc.1 \ + vala-gen-introspect.1 \ + vapigen.1 \ + $(NULL) + +EXTRA_DIST = \ + valac.h2m \ ++ valadoc.h2m \ + vala-gen-introspect.h2m \ + vapigen.h2m \ + $(NULL) + +if HAVE_HELP2MAN - manpages: valac.1 vala-gen-introspect.1 vapigen.1 ++manpages: valac.1 valadoc.1 vala-gen-introspect.1 vapigen.1 + @rm $^ + $(MAKE) $(AM_MAKEFLAGS) $^ + +valac.1: + $(HELP2MAN) $(top_builddir)/compiler/valac \ + --include $(srcdir)/valac.h2m \ + --libtool --no-info \ + --output=$@ ++valadoc.1: ++ $(HELP2MAN) $(top_builddir)/valadoc/valadoc \ ++ --include $(srcdir)/valadoc.h2m \ ++ --libtool --no-info \ ++ --output=$@ +vala-gen-introspect.1: + $(HELP2MAN) $(top_builddir)/gobject-introspection/gen-introspect \ + --include $(srcdir)/vala-gen-introspect.h2m \ + --version-string=$(PACKAGE_VERSION) \ + --libtool --no-info \ + --output=$@ +vapigen.1: + $(HELP2MAN) $(top_builddir)/vapigen/vapigen \ + --include $(srcdir)/vapigen.h2m \ + --libtool --no-info \ + --output=$@ +endif + +if ENABLE_UNVERSIONED +install-data-hook: + cd $(DESTDIR)$(man1dir) && $(LN_S) -f valac@PACKAGE_SUFFIX@.1 valac.1 ++ cd $(DESTDIR)$(man1dir) && $(LN_S) -f valadoc@PACKAGE_SUFFIX@.1 valadoc.1 + cd $(DESTDIR)$(man1dir) && $(LN_S) -f vala-gen-introspect@PACKAGE_SUFFIX@.1 vala-gen-introspect.1 + cd $(DESTDIR)$(man1dir) && $(LN_S) -f vapigen@PACKAGE_SUFFIX@.1 vapigen.1 +endif diff --cc libvaladoc/.gitignore index 000000000,000000000..22a1a17fc new file mode 100644 --- /dev/null +++ b/libvaladoc/.gitignore @@@ -1,0 -1,0 +1,2 @@@ ++valadoc*.deps ++valadoc*.vapi diff --cc libvaladoc/Makefile.am index 000000000,a53b08892..4ce79492a mode 000000,100644..100644 --- a/libvaladoc/Makefile.am +++ b/libvaladoc/Makefile.am @@@ -1,0 -1,232 +1,238 @@@ -NULL = ++include $(top_srcdir)/Makefile.common + -DEFAULT_DRIVER = $(shell $(VALAC) --api-version >/dev/null 2>&1; if [ $$? = 0 ]; then $(VALAC) --api-version; else $(VALAC) --version; fi) ++NULL = + + AM_CFLAGS = \ + -DPACKAGE_ICONDIR=\"$(datadir)/valadoc/icons/\" \ + -DPACKAGE_DATADIR=\"$(libdir)/valadoc\" \ + -DPACKAGE_VERSION=\"$(VERSION)\" \ - -DDEFAULT_DRIVER=\"$(DEFAULT_DRIVER)\" \ + $(LIBGVC_CFLAGS) \ + $(GLIB_CFLAGS) \ - $(LIBGEE_CFLAGS) \ + $(GMODULE_CFLAGS) \ - -g \ - -w \ ++ -I$(top_srcdir)/gee \ + $(NULL) + + AM_VALAFLAGS = \ - $(VALAFLAGS) \ - --vapidir $(top_srcdir)/src/vapi/ \ - --basedir $(srcdir) \ - --directory $(builddir) \ - -C \ - -g \ + $(NULL) + + BUILT_SOURCES = \ + libvaladoc.vala.stamp \ - valadoc-1.0.h \ ++ valadoc.h \ + $(NULL) + -lib_LTLIBRARIES = libvaladoc.la ++lib_LTLIBRARIES = libvaladoc@PACKAGE_SUFFIX@.la + + libvaladoc_la_VALASOURCES = \ + doclet.vala \ + errorreporter.vala \ + filehelper.vala \ + moduleloader.vala \ + settings.vala \ + markupwriter.vala \ + gtkdocmarkupwriter.vala \ + devhelp-markupwriter.vala \ + ctyperesolver.vala \ + markupsourcelocation.vala \ + markuptokentype.vala \ + markupreader.vala \ + gtkdocrenderer.vala \ + documentation/commentscanner.vala \ + documentation/documentation.vala \ + documentation/documentationparser.vala \ + documentation/wiki.vala \ + documentation/wikiscanner.vala \ + documentation/gtkdoccommentparser.vala \ + documentation/gtkdoccommentscanner.vala \ + documentation/gtkdocmarkdownparser.vala \ + documentation/gtkdocmarkdownscanner.vala \ + documentation/importerhelper.vala \ + documentation/girmetadata.vala \ + importer/documentationimporter.vala \ + importer/valadocdocumentationimporter.vala \ + importer/valadocdocumentationimporterscanner.vala \ + importer/girdocumentationimporter.vala \ + importer/internalidregistrar.vala \ + api/symbolaccessibility.vala \ + api/sourcecomment.vala \ + api/girsourcecomment.vala \ + api/attributeargument.vala \ + api/attribute.vala \ + api/array.vala \ + api/callable.vala \ + api/childsymbolregistrar.vala \ + api/class.vala \ + api/constant.vala \ + api/delegate.vala \ + api/enum.vala \ + api/enumvalue.vala \ + api/errorcode.vala \ + api/errordomain.vala \ + api/field.vala \ + api/formalparameter.vala \ + api/formalparametertype.vala \ + api/interface.vala \ + api/item.vala \ + api/member.vala \ + api/method.vala \ + api/methodbindingtype.vala \ + api/namespace.vala \ + api/node.vala \ + api/nodetype.vala \ + api/ownership.vala \ + api/package.vala \ + api/pointer.vala \ + api/property.vala \ + api/propertyaccessor.vala \ + api/propertyaccessortype.vala \ + api/propertybindingtype.vala \ + api/signal.vala \ + api/signaturebuilder.vala \ + api/sourcefile.vala \ + api/struct.vala \ + api/symbol.vala \ + api/tree.vala \ + api/typeparameter.vala \ + api/typereference.vala \ + api/typesymbol.vala \ + api/browsable.vala \ + api/visitor.vala \ + api/driver.vala \ + content/block.vala \ + content/blockcontent.vala \ + content/comment.vala \ + content/contentfactory.vala \ + content/contentelement.vala \ + content/contentrenderer.vala \ + content/contentvisitor.vala \ + content/embedded.vala \ + content/headline.vala \ + content/inline.vala \ + content/inlinetaglet.vala \ + content/inlinecontent.vala \ + content/wikilink.vala \ + content/link.vala \ + content/list.vala \ + content/listitem.vala \ + content/page.vala \ + content/paragraph.vala \ + content/warning.vala \ + content/note.vala \ + content/resourcelocator.vala \ + content/run.vala \ + content/sourcecode.vala \ + content/styleattributes.vala \ + content/symbollink.vala \ + content/table.vala \ + content/tablecell.vala \ + content/tablerow.vala \ + content/taglet.vala \ + content/text.vala \ + charts/chart.vala \ + charts/chartfactory.vala \ + charts/hierarchychart.vala \ + charts/simplechartfactory.vala \ + parser/manyrule.vala \ + parser/oneofrule.vala \ + parser/optionalrule.vala \ + parser/parser.vala \ + parser/parsercallback.vala \ + parser/rule.vala \ + parser/scanner.vala \ + parser/sequencerule.vala \ + parser/sourcelocation.vala \ + parser/stubrule.vala \ + parser/token.vala \ + parser/tokentype.vala \ + taglets/tagletdeprecated.vala \ + taglets/tagletinheritdoc.vala \ + taglets/tagletinit.vala \ + taglets/tagletlink.vala \ + taglets/tagletparam.vala \ + taglets/tagletreturn.vala \ + taglets/tagletsee.vala \ + taglets/tagletsince.vala \ + taglets/tagletthrows.vala \ + highlighter/scanner.vala \ + highlighter/codescanner.vala \ + highlighter/xmlscanner.vala \ + highlighter/codetoken.vala \ + highlighter/highlighter.vala \ + html/basicdoclet.vala \ + html/htmlchartfactory.vala \ + html/linkhelper.vala \ + html/cssclassresolver.vala \ + html/htmlmarkupwriter.vala \ + html/htmlrenderer.vala \ + $(NULL) + -nodist_libvaladoc_la_SOURCES = \ ++libvaladoc@PACKAGE_SUFFIX@_la_SOURCES = \ ++ libvaladoc.vala.stamp \ + $(libvaladoc_la_VALASOURCES:.vala=.c) \ + $(NULL) + -valadoc-1.0.vapi valadoc-1.0.h: libvaladoc.vala.stamp -libvaladoc.vala.stamp: $(libvaladoc_la_VALASOURCES) Makefile - $(VALAC) \ - $(AM_VALAFLAGS) \ - -H valadoc-1.0.h \ - --library valadoc-1.0 \ - --vapi valadoc-1.0.vapi \ ++valadoc@PACKAGE_SUFFIX@.vapi valadoc.h: libvaladoc.vala.stamp ++libvaladoc.vala.stamp: $(libvaladoc_la_VALASOURCES) ++ $(VALA_V)$(VALAC) \ ++ $(VALAFLAGS) \ ++ --basedir $(srcdir) \ ++ --directory $(builddir) \ ++ -C \ ++ -H valadoc.h \ ++ --library valadoc \ ++ --vapi valadoc@PACKAGE_SUFFIX@.vapi \ ++ --vapidir $(top_srcdir)/vapi --pkg gmodule-2.0 \ ++ --vapidir $(top_srcdir)/valadoc/vapi --pkg libgvc \ ++ --vapidir $(top_srcdir)/gee --pkg gee \ + --pkg config \ - --pkg gee-0.8 \ - --pkg gmodule-2.0 \ - --pkg libgvc \ + $(filter %.vala %.c,$^) + touch $@ + -libvaladoc_la_LDFLAGS = -no-undefined ++libvaladoc@PACKAGE_SUFFIX@_la_LDFLAGS = \ ++ -no-undefined \ ++ $(NULL) + -libvaladoc_la_LIBADD = \ ++libvaladoc@PACKAGE_SUFFIX@_la_LIBADD = \ + $(LIBGVC_LIBS) \ - $(LIBGEE_LIBS) \ + $(GLIB_LIBS) \ + $(GMODULE_LIBS) \ ++ $(top_builddir)/vala/libvala@PACKAGE_SUFFIX@.la \ + $(NULL) + -libvaladocincludedir = $(includedir)/ -nodist_libvaladocinclude_HEADERS = \ - valadoc-1.0.h \ ++libvaladocincludedir = $(includedir)/valadoc@PACKAGE_SUFFIX@ ++libvaladocinclude_HEADERS = \ ++ valadoc.h \ + $(NULL) + + pkgconfigdir = $(libdir)/pkgconfig -nodist_pkgconfig_DATA = valadoc-1.0.pc ++nodist_pkgconfig_DATA = valadoc@PACKAGE_SUFFIX@.pc ++ ++valadoc@PACKAGE_SUFFIX@.pc: valadoc.pc ++ cp $< $@ + + vapidir = $(datadir)/vala/vapi -nodist_vapi_DATA = \ - valadoc-1.0.vapi \ - valadoc-1.0.deps \ - $(NULL) ++dist_vapi_DATA = valadoc@PACKAGE_SUFFIX@.vapi ++nodist_vapi_DATA = valadoc@PACKAGE_SUFFIX@.deps ++ ++valadoc@PACKAGE_SUFFIX@.deps: valadoc.deps ++ cp $< $@ + + EXTRA_DIST = \ + $(libvaladoc_la_VALASOURCES) \ - valadoc-1.0.deps.in \ - valadoc-1.0.pc.in \ ++ libvaladoc.vala.stamp \ ++ valadoc.deps.in \ ++ valadoc.pc.in \ + $(NULL) + + CLEANFILES = \ - $(BUILT_SOURCES) \ - $(nodist_libvaladoc_la_SOURCES) \ - valadoc-1.0.deps \ - valadoc-1.0.pc \ - valadoc-1.0.vapi \ - valadoc-1.0.h \ ++ valadoc@PACKAGE_SUFFIX@.deps \ ++ valadoc@PACKAGE_SUFFIX@.pc \ ++ $(NULL) ++ ++MAINTAINERCLEANFILES = \ ++ valadoc.deps \ ++ valadoc.pc \ ++ valadoc.vapi \ ++ valadoc.h \ ++ $(libvaladoc_la_VALASOURCES:.vala=.c) \ + $(NULL) + diff --cc libvaladoc/api/array.vala index 000000000,cfbd64291..8e3cbe5fb mode 000000,100644..100644 --- a/libvaladoc/api/array.vala +++ b/libvaladoc/api/array.vala @@@ -1,0 -1,70 +1,69 @@@ + /* array.vala + * + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents an array declaration. + */ + public class Valadoc.Api.Array : Item { + + /** + * The element type. + */ + public Item data_type { + set; + get; + } + + public Array (Item parent, void* data) { + base (data); + + this.parent = parent; + } + + private inline bool element_is_owned () { + TypeReference reference = data_type as TypeReference; + if (reference == null) { + return true; + } + + return !reference.is_unowned && !reference.is_weak; + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + SignatureBuilder builder = new SignatureBuilder (); + if (element_is_owned ()) { + builder.append_content (data_type.signature); + } else { + builder.append ("(", false); + builder.append_content (data_type.signature, false); + builder.append (")", false); + } + builder.append ("[]", false); + return builder.get (); + } + } diff --cc libvaladoc/api/attribute.vala index 000000000,04fac9b18..da6591992 mode 000000,100644..100644 --- a/libvaladoc/api/attribute.vala +++ b/libvaladoc/api/attribute.vala @@@ -1,0 -1,109 +1,108 @@@ + /* attribute.vala + * + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Valadoc.Content; -using Gee; + ++using Valadoc.Content; + + public class Valadoc.Api.Attribute : Item { - private ArrayList args = new ArrayList (); ++ private Vala.ArrayList args = new Vala.ArrayList (); + private SourceFile file; + + public string name { + private set; + get; + } + + public Attribute (Node parent, SourceFile file, string name, void* data) { + base (data); + + this.parent = parent; + this.name = name; + this.file = file; + } + + public AttributeArgument? get_argument (string name) { + if (args != null) { + foreach (AttributeArgument arg in args) { + if (arg.name == name) { + return arg; + } + } + } + + return null; + } + + public AttributeArgument add_boolean (string name, bool value, void* data = null) { + AttributeArgument arg = new AttributeArgument.boolean (this, file, name, value, data); + args.add (arg); + return arg; + } + + public AttributeArgument add_integer (string name, int value, void* data = null) { + AttributeArgument arg = new AttributeArgument.integer (this, file, name, value, data); + args.add (arg); + return arg; + } + + public AttributeArgument add_double (string name, double value, void* data = null) { + AttributeArgument arg = new AttributeArgument.double (this, file, name, value, data); + args.add (arg); + return arg; + } + + public AttributeArgument add_string (string name, string value, void* data = null) { + AttributeArgument arg = new AttributeArgument.string (this, file, name, value, data); + args.add (arg); + return arg; + } + + public SourceFile get_source_file () { + return file; + } + + protected override Inline build_signature () { + SignatureBuilder builder = new SignatureBuilder (); + + builder.append_attribute ("["); + builder.append_type_name (name); + + if (args.size > 0) { + builder.append_attribute ("("); + bool first = true; + + foreach (AttributeArgument arg in args) { + if (first == false) { + builder.append_attribute (", "); + } + builder.append_content (arg.signature); + first = false; + } + builder.append_attribute (")"); + } + + builder.append_attribute ("]"); + + return builder.get (); + } + } + diff --cc libvaladoc/api/attributeargument.vala index 000000000,7bcd0c6d8..1a3b01fab mode 000000,100644..100644 --- a/libvaladoc/api/attributeargument.vala +++ b/libvaladoc/api/attributeargument.vala @@@ -1,0 -1,135 +1,132 @@@ + /* attributeargument.vala + * + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + + + using Valadoc.Content; -using Gee; - - + + public class Valadoc.Api.AttributeArgument : Item { + public enum Type { + BOOLEAN, + INTEGER, + DOUBLE, + STRING + } + + private SourceFile file; + + public string name { + private set; + get; + } + + public AttributeArgument.Type argument_type { + private set; + get; + } + + public string value { + private set; + get; + } + + public AttributeArgument.boolean (Attribute parent, SourceFile file, string name, bool value, void* data) { + this (parent, file, name, Type.BOOLEAN, value.to_string (), data); + } + + public AttributeArgument.integer (Attribute parent, SourceFile file, string name, int value, void* data) { + this (parent, file, name, Type.INTEGER, value.to_string (), data); + } + + public AttributeArgument.double (Attribute parent, SourceFile file, string name, double value, void* data) { + this (parent, file, name, Type.DOUBLE, value.to_string (), data); + } + + public AttributeArgument.string (Attribute parent, SourceFile file, string name, string value, void* data) { + this (parent, file, name, Type.STRING, value, data); + } + + private AttributeArgument (Attribute parent, SourceFile file, string name, Type type, string value, void* data) { + base (data); + + this.argument_type = type; + this.parent = parent; + this.value = value; + this.file = file; + this.name = name; + } + + public SourceFile get_source_file () { + return file; + } + + public bool get_value_as_boolean () { + assert (argument_type == Type.BOOLEAN); + + bool tmp; + + if (bool.try_parse (value, out tmp)) { + return tmp; + } + + assert_not_reached (); + } + + public int get_value_as_integer () { + assert (argument_type == Type.INTEGER); + + double tmp; + + if (global::double.try_parse (value, out tmp) && tmp >= int.MIN && tmp <= int.MAX) { + return (int) tmp; + } + + assert_not_reached (); + } + + public double get_value_as_double () { + assert (argument_type == Type.DOUBLE); + + double tmp; + + if (global::double.try_parse (value, out tmp)) { + return tmp; + } + + assert_not_reached (); + } + + public string get_value_as_string () { + assert (argument_type == Type.STRING); + + return value; + } + + protected override Inline build_signature () { + SignatureBuilder builder = new SignatureBuilder (); + + builder.append_attribute (name); + builder.append_attribute ("="); + builder.append_literal (value); + + return builder.get (); + } + } diff --cc libvaladoc/api/browsable.vala index 000000000,498ba0dd8..7ae9b80fb mode 000000,100644..100644 --- a/libvaladoc/api/browsable.vala +++ b/libvaladoc/api/browsable.vala @@@ -1,0 -1,35 +1,33 @@@ + /* browsable.vala + * + * Copyright (C) 2008 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; - + + /** + * Specifies whether users are able to browse the item. + */ + public interface Valadoc.Api.Browsable : Item { + + /** + * Specifies whether users are able to browse the item. + */ + public abstract bool is_browsable (Settings settings); + } diff --cc libvaladoc/api/callable.vala index 000000000,60515ee1b..29d965dd0 mode 000000,100644..100644 --- a/libvaladoc/api/callable.vala +++ b/libvaladoc/api/callable.vala @@@ -1,0 -1,51 +1,48 @@@ + /* callable.vala + * + * Copyright (C) 2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + + + using Valadoc; -using GLib; -using Gee; - + + /** + * Used to translate imported C-documentation + */ + public interface Valadoc.Api.Callable : Symbol { + /** + * The return type of this symbol. + * + * @return The return type of this symbol or null for void + */ + public abstract TypeReference? return_type { + set; + get; + } + + /** + * Used to avoid warnings for implicit parameters + */ + internal abstract string? implicit_array_length_cparameter_name { + get; + set; + } + } + diff --cc libvaladoc/api/childsymbolregistrar.vala index 000000000,e044327b0..75b072d19 mode 000000,100644..100644 --- a/libvaladoc/api/childsymbolregistrar.vala +++ b/libvaladoc/api/childsymbolregistrar.vala @@@ -1,0 -1,99 +1,98 @@@ + /* childsymbolregistrar.vala + * + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Valadoc.Api; -using Gee; + ++using Valadoc.Api; + + public class Valadoc.Api.ChildSymbolRegistrar : Visitor { + /** + * {@inheritDoc} + */ + public override void visit_tree (Api.Tree item) { + item.accept_children (this); + } + + /** + * {@inheritDoc} + */ + public override void visit_package (Package item) { + item.accept_all_children (this, false); + } + + /** + * {@inheritDoc} + */ + public override void visit_namespace (Namespace item) { + item.accept_all_children (this, false); + } + + /** + * {@inheritDoc} + */ + public override void visit_interface (Interface item) { - Collection interfaces = item.get_implemented_interface_list (); ++ Vala.Collection interfaces = item.get_implemented_interface_list (); + foreach (var type_ref in interfaces) { + ((Interface) type_ref.data_type).register_related_interface (item); + } + + if (item.base_type != null) { + ((Class) item.base_type.data_type).register_derived_interface (item); + } + + item.accept_all_children (this, false); + } + + /** + * {@inheritDoc} + */ + public override void visit_class (Class item) { - Collection interfaces = item.get_implemented_interface_list (); ++ Vala.Collection interfaces = item.get_implemented_interface_list (); + foreach (TypeReference type_ref in interfaces) { + ((Interface) type_ref.data_type).register_implementation (item); + } + + if (item.base_type != null) { + ((Class) item.base_type.data_type).register_child_class (item); + } + + item.accept_all_children (this, false); + } + + /** + * {@inheritDoc} + */ + public override void visit_struct (Struct item) { + if (item.base_type != null) { + ((Struct) item.base_type.data_type).register_child_struct (item); + } + + item.accept_all_children (this, false); + } + + /** + * {@inheritDoc} + */ + public override void visit_property (Property item) { + item.accept_all_children (this, false); + } + } + diff --cc libvaladoc/api/class.vala index 000000000,8d792a75a..4ef99ea14 mode 000000,100644..100644 --- a/libvaladoc/api/class.vala +++ b/libvaladoc/api/class.vala @@@ -1,0 -1,361 +1,360 @@@ + /* class.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents a class declaration. + */ + public class Valadoc.Api.Class : TypeSymbol { - private ArrayList interfaces; ++ private Vala.ArrayList interfaces; + + private string? dbus_name; + private string? take_value_function_cname; + private string? get_value_function_cname; + private string? set_value_function_cname; + private string? unref_function_name; + private string? ref_function_name; + private string? free_function_name; + private string? finalize_function_name; + private string? param_spec_function_name; + private string? type_id; + private string? is_class_type_macro_name; + private string? class_type_macro_name; + private string? class_macro_name; + private string? private_cname; + private string? cname; + + public Class (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, string? cname, string? private_cname, string? class_macro_name, + string? type_macro_name, string? is_type_macro_name, string? type_cast_macro_name, + string? type_function_name, string? class_type_macro_name, string? is_class_type_macro_name, + string? dbus_name, string? type_id, string? param_spec_function_name, string? ref_function_name, + string? unref_function_name, string? free_function_name, string? finalize_function_name, + string? take_value_function_cname, string? get_value_function_cname, string? set_value_function_cname, + bool is_fundamental, bool is_abstract, bool is_basic_type, void* data) + { + base (parent, file, name, accessibility, comment, type_macro_name, + is_type_macro_name, type_cast_macro_name, type_function_name, is_basic_type, data); + - this.interfaces = new ArrayList (); ++ this.interfaces = new Vala.ArrayList (); + + this.is_class_type_macro_name = is_class_type_macro_name; + this.class_type_macro_name = class_type_macro_name; + this.class_macro_name = class_macro_name; + this.private_cname = private_cname; + this.dbus_name = dbus_name; + this.type_id = type_id; + this.cname = cname; + + this.param_spec_function_name = param_spec_function_name; + + this.unref_function_name = unref_function_name; + this.ref_function_name = ref_function_name; + this.finalize_function_name = finalize_function_name; + this.free_function_name = free_function_name; + + this.take_value_function_cname = take_value_function_cname; + this.get_value_function_cname = get_value_function_cname; + this.set_value_function_cname = set_value_function_cname; + + this.is_fundamental = is_fundamental; + this.is_abstract = is_abstract; + } + + /** + * Specifies the base class. + */ + public TypeReference? base_type { + set; + get; + } + + /** + * Returns the name of this class as it is used in C. + */ + public string? get_cname () { + return cname; + } + + /** + * Returns the name of this class' private data structure as it is used in C. + */ + public string? get_private_cname () { + return private_cname; + } + + /** + * Returns the C symbol representing the runtime type id for this data type. + */ + public string? get_type_id () { + return type_id; + } + + /** + * Returns the C function name that increments the reference count of + * instances of this data type. + * + * @return the name of the C function or null if this data type does not + * support reference counting + */ + public string? get_ref_function_cname () { + return ref_function_name; + } + + /** + * Returns the C function name that decrements the reference count of + * instances of this data type. + * + * @return the name of the C function or null if this data type does not + * support reference counting + */ + public string? get_unref_function_cname () { + return unref_function_name; + } + + /** + * Returns the C function name that frees the + * instances of this data type. + * + * @return the name of the C function or null + */ + public string? get_free_function_name () { + return free_function_name; + } + + /** + * Returns the C function name that finalizes the + * instances of this data type. + * + * @return the name of the C function or null + */ + public string? get_finalize_function_name () { + return finalize_function_name; + } + + /** + * Returns the cname of the GValue parameter spec function. + */ + public string? get_param_spec_function_cname () { + return param_spec_function_name; + } + + /** + * Returns the cname of the GValue setter function. + */ + public string? get_set_value_function_cname () { + return set_value_function_cname; + } + + /** + * Returns the cname of the GValue getter function. + */ + public string? get_get_value_function_cname () { + return get_value_function_cname; + } + + /** + * Returns the cname of the GValue taker function. + */ + public string? get_take_value_function_cname () { + return take_value_function_cname; + } + + /** + * Returns the dbus-name. + */ + public string? get_dbus_name () { + return dbus_name; + } + + /** + * Gets the name of the GType macro which returns the class struct. + */ + public string get_class_macro_name () { + return class_macro_name; + } + + /** + * Gets the name of the GType macro which returns the type of the class. + */ + public string get_class_type_macro_name () { + return class_type_macro_name; + } + + /** + * Gets the name of the GType macro which returns whether a class instance is of a given type. + */ + public string get_is_class_type_macro_name () { + return is_class_type_macro_name; + } + + /** + * Returns a list of all newly implemented interfaces. + * + * @see get_full_implemented_interface_list + */ - public Collection get_implemented_interface_list () { ++ public Vala.Collection get_implemented_interface_list () { + return this.interfaces; + } + - private Collection _full_implemented_interfaces = null; ++ private Vala.Collection _full_implemented_interfaces = null; + + /** + * Returns a list of all implemented interfaces. + * + * @see get_implemented_interface_list + */ - public Collection get_full_implemented_interface_list () { ++ public Vala.Collection get_full_implemented_interface_list () { + if (_full_implemented_interfaces == null) { - _full_implemented_interfaces = new LinkedList (); ++ _full_implemented_interfaces = new Vala.ArrayList (); + _full_implemented_interfaces.add_all (this.interfaces); + + if (base_type != null) { + _full_implemented_interfaces.add_all (((Class) base_type.data_type).get_full_implemented_interface_list ()); + } + } + + return _full_implemented_interfaces; + } + + public void add_interface (TypeReference iface) { + interfaces.add (iface); + } + + /** + * Specifies whether this class is abstract. + */ + public bool is_abstract { + private set; + get; + } + + /** + * Specifies whether this class is fundamental. + */ + public bool is_fundamental { + private set; + get; + } + + public bool is_compact { + get { + return base_type == null && get_attribute ("Compact") != null; + } + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { get { return NodeType.CLASS; } } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_class (this); + } + - private Set _known_derived_interfaces = new TreeSet (); - private Set _known_child_classes = new TreeSet (); ++ private Vala.Set _known_derived_interfaces = new Vala.HashSet (); ++ private Vala.Set _known_child_classes = new Vala.HashSet (); + + /** + * Returns a list of all known classes based on this class + */ - public Collection get_known_child_classes () { - return _known_child_classes.read_only_view; ++ public Vala.Collection get_known_child_classes () { ++ return _known_child_classes; + } + + /** + * Returns a list of all known interfaces based on this class + */ - public Collection get_known_derived_interfaces () { - return _known_derived_interfaces.read_only_view; ++ public Vala.Collection get_known_derived_interfaces () { ++ return _known_derived_interfaces; + } + + public void register_derived_interface (Interface iface) { + _known_derived_interfaces.add (iface); + } + + public void register_child_class (Class cl) { + if (this.base_type != null) { + ((Class) this.base_type.data_type).register_child_class (cl); + } + + _known_child_classes.add (cl); + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + var signature = new SignatureBuilder (); + + signature.append_keyword (accessibility.to_string ()); + if (is_abstract) { + signature.append_keyword ("abstract"); + } + signature.append_keyword ("class"); + signature.append_symbol (this); + + var type_parameters = get_children_by_type (NodeType.TYPE_PARAMETER, false); + if (type_parameters.size > 0) { + signature.append ("<", false); + bool first = true; + foreach (Item param in type_parameters) { + if (!first) { + signature.append (",", false); + } + signature.append_content (param.signature, false); + first = false; + } + signature.append (">", false); + } + + bool first = true; + if (base_type != null) { + signature.append (":"); + + signature.append_content (base_type.signature); + first = false; + } + + if (interfaces.size > 0) { + if (first) { + signature.append (":"); + } + + foreach (Item implemented_interface in interfaces) { + if (!first) { + signature.append (",", false); + } + signature.append_content (implemented_interface.signature); + first = false; + } + } + + return signature.get (); + } + } + diff --cc libvaladoc/api/constant.vala index 000000000,351584be4..0ff79f261 mode 000000,100644..100644 --- a/libvaladoc/api/constant.vala +++ b/libvaladoc/api/constant.vala @@@ -1,0 -1,81 +1,81 @@@ + /* constant.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; ++ + using Valadoc.Content; + + /** + * Represents a type member with a constant value. + */ + public class Valadoc.Api.Constant : Member { + private string? cname; + + /** + * The data type of this constant. + */ + public TypeReference constant_type { + set; + get; + } + + public Constant (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, string? cname, void* data) + { + base (parent, file, name, accessibility, comment, data); + + this.cname = cname; + } + + /** + * Returns the name of this constant as it is used in C. + */ + public string get_cname () { + return cname; + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + return new SignatureBuilder () + .append_keyword (accessibility.to_string ()) + .append_keyword ("const") + .append_content (constant_type.signature) + .append_symbol (this) + .get (); + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { return NodeType.CONSTANT; } + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_constant (this); + } + } + diff --cc libvaladoc/api/delegate.vala index 000000000,cd7e7c552..9db4d9f10 mode 000000,100644..100644 --- a/libvaladoc/api/delegate.vala +++ b/libvaladoc/api/delegate.vala @@@ -1,0 -1,142 +1,142 @@@ + /* delegate.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; ++ + using Valadoc.Content; + + + /** + * Represents a Delegate. + */ + public class Valadoc.Api.Delegate : TypeSymbol, Callable { + private string? cname; + + /** + * {@inheritDoc} + */ + internal string? implicit_array_length_cparameter_name { + get; + set; + } + + + public Delegate (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, string? cname, bool is_static, void* data) + { + base (parent, file, name, accessibility, comment, null, null, null, null, false, data); + + this.is_static = is_static; + this.cname = cname; + } + + /** + * Returns the name of this delegate as it is used in C. + */ + public string? get_cname () { + return cname; + } + + /** + * {@inheritDoc} + */ + public TypeReference? return_type { + set; + get; + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { return NodeType.DELEGATE; } + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_delegate (this); + } + + /** + * Specifies whether this delegate is static + */ + public bool is_static { + private set; + get; + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + var signature = new SignatureBuilder (); + + signature.append_keyword (accessibility.to_string ()); + signature.append_keyword ("delegate"); + signature.append_content (return_type.signature); + signature.append_symbol (this); + + var type_parameters = get_children_by_type (NodeType.TYPE_PARAMETER); + if (type_parameters.size > 0) { + signature.append ("<", false); + bool first = true; + foreach (Item param in type_parameters) { + if (!first) { + signature.append (",", false); + } + signature.append_content (param.signature, false); + first = false; + } + signature.append (">", false); + } + + signature.append ("("); + + bool first = true; + foreach (Node param in get_children_by_type (NodeType.FORMAL_PARAMETER, false)) { + if (!first) { + signature.append (",", false); + } + signature.append_content (param.signature, !first); + first = false; + } + + signature.append (")", false); + + var exceptions = get_children_by_types ({NodeType.ERROR_DOMAIN, NodeType.CLASS}); + if (exceptions.size > 0) { + signature.append_keyword ("throws"); + first = true; + foreach (Node param in exceptions) { + if (!first) { + signature.append (",", false); + } + signature.append_type (param); + first = false; + } + } + + return signature.get (); + } + } + diff --cc libvaladoc/api/driver.vala index 000000000,a43abcff0..dd09ed388 mode 000000,100644..100644 --- a/libvaladoc/api/driver.vala +++ b/libvaladoc/api/driver.vala @@@ -1,0 -1,43 +1,42 @@@ + /* driver.vala + * + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Valadoc.Api; -using Gee; + ++using Valadoc.Api; + + /** + * A plugin register function for drivers + * + * @see ModuleLoader + */ + [CCode (has_target = false)] + public delegate Type Valadoc.DriverRegisterFunction (ModuleLoader module_loader); + + + + public interface Valadoc.Driver : Object { + public abstract void write_gir (Settings settings, ErrorReporter reporter); + + public abstract Api.Tree? build (Settings settings, ErrorReporter reporter); + } + + diff --cc libvaladoc/api/enum.vala index 000000000,230c0bb64..cbadb1971 mode 000000,100644..100644 --- a/libvaladoc/api/enum.vala +++ b/libvaladoc/api/enum.vala @@@ -1,0 -1,72 +1,71 @@@ + /* enum.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents an enum declaration. + */ + public class Valadoc.Api.Enum : TypeSymbol { + private string cname; + + public Enum (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, string? cname, string? type_macro_name, + string? type_function_name, void* data) + { + base (parent, file, name, accessibility, comment, type_macro_name, null, null, + type_function_name, false, data); + this.cname = cname; + } + + /** + * Returns the name of this enum as it is used in C. + */ + public string? get_cname () { + return cname; + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { get { return NodeType.ENUM; } } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_enum (this); + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + return new SignatureBuilder () + .append_keyword (accessibility.to_string ()) + .append_keyword ("enum") + .append_symbol (this) + .get (); + } + } + diff --cc libvaladoc/api/enumvalue.vala index 000000000,34804ff55..e3ec568b9 mode 000000,100644..100644 --- a/libvaladoc/api/enumvalue.vala +++ b/libvaladoc/api/enumvalue.vala @@@ -1,0 -1,115 +1,114 @@@ + /* enumvalue.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents an enum member. + */ + public class Valadoc.Api.EnumValue: Symbol { + private SourceComment? source_comment; + private string? cname; + + public Content.Run default_value { + get; + set; + } + + /** + * Specifies whether the parameter has a default value + */ + public bool has_default_value { + get { + return default_value != null; + } + } + + public EnumValue (Enum parent, SourceFile file, string name, SourceComment? comment, string? cname, void* data) { + base (parent, file, name, parent.accessibility, data); + + this.source_comment = comment; + this.cname = cname; + } + + /** + * {@inheritDoc} + */ + internal override void parse_comments (Settings settings, DocumentationParser parser) { + if (documentation != null) { + return ; + } + + if (source_comment != null) { + documentation = parser.parse (this, source_comment); + } + + base.parse_comments (settings, parser); + } + + /** + * {@inheritDoc} + */ + internal override void check_comments (Settings settings, DocumentationParser parser) { + if (documentation != null) { + parser.check (this, documentation); + } + + base.check_comments (settings, parser); + } + + /** + * Returns the name of this enum value as it is used in C. + */ + public string get_cname () { + return cname; + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { get { return NodeType.ENUM_VALUE; } } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_enum_value (this); + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + var builder = new SignatureBuilder () + .append_symbol (this); + + if (has_default_value) { + builder.append ("="); + builder.append_content (default_value); + } + + return builder.get (); + } + } + diff --cc libvaladoc/api/errorcode.vala index 000000000,d7cf55128..2d10fb6a1 mode 000000,100644..100644 --- a/libvaladoc/api/errorcode.vala +++ b/libvaladoc/api/errorcode.vala @@@ -1,0 -1,108 +1,107 @@@ + /* errorcode.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents an errordomain member in the source code. + */ + public class Valadoc.Api.ErrorCode : Symbol { + private SourceComment? source_comment; + private string? dbus_name; + private string? cname; + + public ErrorCode (ErrorDomain parent, SourceFile file, string name, SourceComment? comment, + string? cname, string? dbus_name, void* data) + { + base (parent, file, name, parent.accessibility, data); + + this.source_comment = comment; + this.dbus_name = dbus_name; + this.cname = cname; + } + + /** + * {@inheritDoc} + */ + internal override void parse_comments (Settings settings, DocumentationParser parser) { + if (documentation != null) { + return ; + } + + if (source_comment != null) { + documentation = parser.parse (this, source_comment); + } + + base.parse_comments (settings, parser); + } + + /** + * {@inheritDoc} + */ + internal override void check_comments (Settings settings, DocumentationParser parser) { + if (documentation != null) { + parser.check (this, documentation); + } + + base.check_comments (settings, parser); + } + + /** + * Returns the name of this class as it is used in C. + */ + public string get_cname () { + return cname; + } + + /** + * Returns the dbus-name. + */ + public string get_dbus_name () { + return dbus_name; + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { return NodeType.ERROR_CODE; } + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_error_code (this); + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + return new SignatureBuilder () + .append_symbol (this) + .get (); + } + } + diff --cc libvaladoc/api/errordomain.vala index 000000000,969f294a3..c469bf3a8 mode 000000,100644..100644 --- a/libvaladoc/api/errordomain.vala +++ b/libvaladoc/api/errordomain.vala @@@ -1,0 -1,101 +1,100 @@@ + /* errordomain.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents an error domain declaration. + */ + public class Valadoc.Api.ErrorDomain : TypeSymbol { + private string? quark_function_name; + private string? quark_macro_name; + private string? dbus_name; + private string? cname; + + public ErrorDomain (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, string? cname, string? quark_macro_name, + string? quark_function_name, string? dbus_name, void* data) + { + base (parent, file, name, accessibility, comment, null, null, null, null, false, data); + + this.quark_function_name = quark_function_name; + this.quark_macro_name = quark_macro_name; + this.dbus_name = dbus_name; + this.cname = cname; + } + + /** + * Returns the name of this errordomain as it is used in C. + */ + public string? get_cname () { + return this.cname; + } + + /** + * Returns the dbus-name. + */ + public string? get_dbus_name () { + return dbus_name; + } + + /** + * Gets the name of the quark() function which represents the error domain + */ + public string get_quark_function_name () { + return quark_function_name; + } + + /** + * Gets the name of the quark macro which represents the error domain + */ + public string get_quark_macro_name () { + return quark_macro_name; + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { return NodeType.ERROR_DOMAIN; } + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_error_domain (this); + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + return new SignatureBuilder () + .append_keyword (accessibility.to_string ()) + .append_keyword ("errordomain") + .append_symbol (this) + .get (); + } + } + diff --cc libvaladoc/api/field.vala index 000000000,a167c35b8..d7a87a24d mode 000000,100644..100644 --- a/libvaladoc/api/field.vala +++ b/libvaladoc/api/field.vala @@@ -1,0 -1,111 +1,110 @@@ + /* field.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents a field. + */ + public class Valadoc.Api.Field : Member { + private string? cname; + + public Field (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, string? cname, bool is_static, bool is_volatile, + void* data) + { + base (parent, file, name, accessibility, comment, data); + + this.is_static = !(parent is Namespace) && is_static; + this.is_volatile = is_volatile; + + this.cname = cname; + } + + /** + * Returns the name of this field as it is used in C. + */ + public string? get_cname () { + return cname; + } + + /** + * The field type. + * + * @return The field type or null for void + */ + public TypeReference? field_type { + set; + get; + } + + /** + * Specifies whether the field is static. + */ + public bool is_static { + private set; + get; + } + + /** + * Specifies whether the field is volatile. + */ + public bool is_volatile { + private set; + get; + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + var signature = new SignatureBuilder (); + + signature.append_keyword (accessibility.to_string ()); + if (is_static) { + signature.append_keyword ("static"); + } + if (is_volatile) { + signature.append_keyword ("volatile"); + } + + signature.append_content (field_type.signature); + signature.append_symbol (this); + return signature.get (); + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { return NodeType.FIELD; } + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_field (this); + } + } + diff --cc libvaladoc/api/formalparameter.vala index 000000000,82ed872a2..58c4c42cd mode 000000,100644..100644 --- a/libvaladoc/api/formalparameter.vala +++ b/libvaladoc/api/formalparameter.vala @@@ -1,0 -1,155 +1,155 @@@ + /* formalparameter.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; ++ + using Valadoc.Content; + + /** + * Represents a formal parameter in method, signal and delegate signatures. + */ + public class Valadoc.Api.FormalParameter : Symbol { + public Content.Run default_value { + get; + set; + } + + /** + * Used to translate imported C-documentation + */ + internal string? implicit_array_length_cparameter_name { + get; + set; + } + + /** + * Used to translate imported C-documentation + */ + internal string? implicit_closure_cparameter_name { + get; + set; + } + + /** + * Used to translate imported C-documentation + */ + internal string? implicit_destroy_cparameter_name { + get; + set; + } + + private FormalParameterType type; + + public FormalParameter (Node parent, SourceFile file, string? name, SymbolAccessibility accessibility, FormalParameterType type, bool ellipsis, void* data) { + base (parent, file, name, accessibility, data); + assert ((name == null && ellipsis) || (name != null && !ellipsis)); + + this.ellipsis = ellipsis; + this.type = type; + } + + /** + * Specifies whether the parameter direction is out + */ + public bool is_out { + get { + return type == FormalParameterType.OUT; + } + } + + /** + * Specifies whether the parameter direction is ref + */ + public bool is_ref { + get { + return type == FormalParameterType.REF; + } + } + + /** + * Specifies whether the parameter has a default value + */ + public bool has_default_value { + get { + return default_value != null; + } + } + + /** + * The parameter type. + * + * @return The parameter type or null for void + */ + public TypeReference? parameter_type { + set; + get; + } + + /** + * Specifies whether the methods accepts a variable number of arguments + */ + public bool ellipsis { + private set; + get; + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { return NodeType.FORMAL_PARAMETER; } + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_formal_parameter (this); + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + var signature = new SignatureBuilder (); + + if (ellipsis) { + signature.append ("..."); + } else { + if (is_out) { + signature.append_keyword ("out"); + } else if (is_ref) { + signature.append_keyword ("ref"); + } + + signature.append_content (parameter_type.signature); + signature.append (name); + + if (has_default_value) { + signature.append ("="); + signature.append_content (default_value); + } + } + + return signature.get (); + } + } + diff --cc libvaladoc/api/girsourcecomment.vala index 000000000,c935ba39e..d6ffa5ae6 mode 000000,100644..100644 --- a/libvaladoc/api/girsourcecomment.vala +++ b/libvaladoc/api/girsourcecomment.vala @@@ -1,0 -1,60 +1,57 @@@ + /* sourcecomment.vala + * + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + + -using Gee; - - + /** + * A documentation comment used by valadoc + */ + public class Valadoc.Api.GirSourceComment : SourceComment { - private Map parameters = new HashMap (); ++ private Vala.Map parameters = new Vala.HashMap (str_hash, str_equal); + + public string? instance_param_name { set; get; } + public SourceComment? return_comment { set; get; } + public SourceComment? deprecated_comment { set; get; } + public SourceComment? version_comment { get; set; } + public SourceComment? stability_comment { get; set; } + + - public MapIterator parameter_iterator () { ++ public Vala.MapIterator parameter_iterator () { + return parameters.map_iterator (); + } + + public void add_parameter_content (string param_name, SourceComment comment) { + this.parameters.set (param_name, comment); + } + + public SourceComment? get_parameter_comment (string param_name) { + if (parameters == null) { + return null; + } + + return parameters.get (param_name); + } + + public GirSourceComment (string content, SourceFile file, int first_line, int first_column, int last_line, int last_column) { + base (content, file, first_line, first_column, last_line, last_column); + } + } + diff --cc libvaladoc/api/interface.vala index 000000000,c75846ed8..ede696cf9 mode 000000,100644..100644 --- a/libvaladoc/api/interface.vala +++ b/libvaladoc/api/interface.vala @@@ -1,0 -1,215 +1,213 @@@ + /* interface.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; - + ++using Valadoc.Content; + + /** + * Represents a interface declaration in the source code. + */ + public class Valadoc.Api.Interface : TypeSymbol { + private string? interface_macro_name; + private string? dbus_name; + private string? cname; + + + public Interface (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, string? cname, string? type_macro_name, string? is_type_macro_name, + string? type_cast_macro_name, string? type_function_name, string interface_macro_name, + string? dbus_name, void* data) + { + base (parent, file, name, accessibility, comment, type_macro_name, is_type_macro_name, + type_cast_macro_name, type_function_name, false, data); + + this.interface_macro_name = interface_macro_name; + this.dbus_name = dbus_name; + this.cname = cname; + } + + /** + * A list of preconditioned interfaces + */ - private ArrayList interfaces = new ArrayList (); ++ private Vala.ArrayList interfaces = new Vala.ArrayList (); + + /** + * Add a newpreconditioned interface to the list + */ + public void add_interface (TypeReference iface) { + interfaces.add (iface); + } + + /** + * Returns a list of newly preconditioned interfaces + */ - public Collection get_implemented_interface_list () { ++ public Vala.Collection get_implemented_interface_list () { + return this.interfaces; + } + + + /** + * A list of all preconditioned interfaces + */ - private Collection _full_implemented_interfaces = null; ++ private Vala.Collection _full_implemented_interfaces = null; + + /** + * Returns a list of all preconditioned interfaces + */ - public Collection get_full_implemented_interface_list () { ++ public Vala.Collection get_full_implemented_interface_list () { + if (_full_implemented_interfaces == null) { - _full_implemented_interfaces = new LinkedList (); ++ _full_implemented_interfaces = new Vala.ArrayList (); + _full_implemented_interfaces.add_all (this.interfaces); + + if (base_type != null) { + _full_implemented_interfaces.add_all (((Class) base_type.data_type).get_full_implemented_interface_list ()); + } + } + + return _full_implemented_interfaces; + } + + /** + * Returns the name of this interface as it is used in C. + */ + public string? get_cname () { + return cname; + } + + /** + * Returns the dbus-name. + */ + public string? get_dbus_name () { + return dbus_name; + } + + /** + * Gets the name of the GType macro which returns the interface struct. + */ + public string get_interface_macro_name () { + return interface_macro_name; + } + + /** + * A preconditioned class or null + */ + public TypeReference? base_type { + set; + get; + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { return NodeType.INTERFACE; } + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_interface (this); + } + + /** + * A list of all known related (sub-)interfaces + */ - private Set _known_related_interfaces = new TreeSet (); ++ private Vala.Set _known_related_interfaces = new Vala.HashSet (); + + /** + * A list of all known implementations of this interface + */ - private Set _known_implementations = new TreeSet (); ++ private Vala.Set _known_implementations = new Vala.HashSet (); + + /** + * Returns a list of all known implementations of this interface + */ - public Collection get_known_implementations () { ++ public Vala.Collection get_known_implementations () { + return _known_implementations; + } + + /** + * Returns a list of all known related (sub-)interfaces + */ - public Collection get_known_related_interfaces () { ++ public Vala.Collection get_known_related_interfaces () { + return _known_related_interfaces; + } + + public void register_related_interface (Interface iface) { + _known_related_interfaces.add (iface); + } + + public void register_implementation (Class cl) { + _known_implementations.add (cl); + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + var signature = new SignatureBuilder (); + + signature.append_keyword (accessibility.to_string ()); + signature.append_keyword ("interface"); + signature.append_symbol (this); + + var type_parameters = get_children_by_type (NodeType.TYPE_PARAMETER, false); + if (type_parameters.size > 0) { + signature.append ("<", false); + bool first = true; + foreach (Item param in type_parameters) { + if (!first) { + signature.append (",", false); + } + signature.append_content (param.signature, false); + first = false; + } + signature.append (">", false); + } + + bool first = true; + if (base_type != null) { + signature.append (":"); + + signature.append_content (base_type.signature); + first = false; + } + + if (interfaces.size > 0) { + if (first) { + signature.append (":"); + } + + foreach (Item implemented_interface in interfaces) { + if (!first) { + signature.append (",", false); + } + signature.append_content (implemented_interface.signature); + first = false; + } + } + + return signature.get (); + } + } + diff --cc libvaladoc/api/item.vala index 000000000,63b994736..60967a7c1 mode 000000,100644..100644 --- a/libvaladoc/api/item.vala +++ b/libvaladoc/api/item.vala @@@ -1,0 -1,71 +1,70 @@@ + /* item.vala + * + * Copyright (C) 2008 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Valadoc.Content; -using Gee; + ++using Valadoc.Content; + + /** + * Represents a node in the api tree. + */ + public abstract class Valadoc.Api.Item : Object { + private Inline _signature; + + public void* data { + private set; + get; + } + + /** + * The parent of this item. + */ + public Item parent { + protected set; + get; + } + + public Item (void* data) { + this.data = data; + } + + internal virtual void parse_comments (Settings settings, DocumentationParser parser) { + } + + internal virtual void check_comments (Settings settings, DocumentationParser parser) { + } + + + /** + * The signature of this item. + */ + public Inline signature { + get { + if (_signature == null) { + _signature = build_signature (); + } + return _signature; + } + } + + protected abstract Inline build_signature (); + } + diff --cc libvaladoc/api/member.vala index 000000000,b8271c37b..fcabbea6b mode 000000,100644..100644 --- a/libvaladoc/api/member.vala +++ b/libvaladoc/api/member.vala @@@ -1,0 -1,63 +1,62 @@@ + /* member.vala + * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; + + public abstract class Valadoc.Api.Member : Symbol { + private SourceComment? source_comment; + + public Member (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, void* data) + { + base (parent, file, name, accessibility, data); + + this.source_comment = comment; + } + + + /** + * {@inheritDoc} + */ + internal override void parse_comments (Settings settings, DocumentationParser parser) { + if (documentation != null) { + return ; + } + + if (source_comment != null) { + documentation = parser.parse (this, source_comment); + } + + base.parse_comments (settings, parser); + } + + /** + * {@inheritDoc} + */ + internal override void check_comments (Settings settings, DocumentationParser parser) { + if (documentation != null) { + parser.check (this, documentation); + } + + base.check_comments (settings, parser); + } + } diff --cc libvaladoc/api/method.vala index 000000000,ce891e112..bccbac5fb mode 000000,100644..100644 --- a/libvaladoc/api/method.vala +++ b/libvaladoc/api/method.vala @@@ -1,0 -1,266 +1,265 @@@ + /* method.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Valadoc.Content; -using Gee; + ++using Valadoc.Content; + + /** + * Represents a function or a method. + */ + public class Valadoc.Api.Method : Member, Callable { + private string? finish_function_cname; + private string? dbus_result_name; + private string? dbus_name; + private string? cname; + + private MethodBindingType binding_type; + + /** + * {@inheritDoc} + */ + internal string? implicit_array_length_cparameter_name { + get; + set; + } + + + public Method (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, string? cname, string? dbus_name, string? dbus_result_name, + string? finish_function_cname, MethodBindingType binding_type, bool is_yields, + bool is_dbus_visible, bool is_constructor, void* data) + { + base (parent, file, name, accessibility, comment, data); + + this.finish_function_cname = finish_function_cname; + this.dbus_result_name = dbus_result_name; + this.dbus_name = dbus_name; + this.cname = cname; + + this.binding_type = binding_type; + this.is_dbus_visible = is_dbus_visible; + this.is_constructor = is_constructor; + this.is_yields = is_yields; + } + + /** + * Returns the name of this method as it is used in C. + */ + public string? get_cname () { + return cname; + } + + /** + * Returns the name of the finish function as it is used in C. + */ + public string? get_finish_function_cname () { + return finish_function_cname; + } + + /** + * Returns the dbus-name. + */ + public string get_dbus_name () { + return dbus_name; + } + + public string get_dbus_result_name () { + return dbus_result_name; + } + + /** + * Specifies the virtual or abstract method this method overrides. + */ + public weak Method? base_method { + set; + get; + } + + /** + * {@inheritDoc} + */ + public TypeReference? return_type { + set; + get; + } + + /** + * Specifies whether this method is asynchronous + */ + public bool is_yields { + private set; + get; + } + + /** + * Specifies whether this method is abstract + */ + public bool is_abstract { + get { + return binding_type == MethodBindingType.ABSTRACT; + } + } + + /** + * Specifies whether this method is virtual + */ + public bool is_virtual { + get { + return binding_type == MethodBindingType.VIRTUAL; + } + } + + /** + * Specifies whether this method overrides another one + */ + public bool is_override { + get { + return binding_type == MethodBindingType.OVERRIDE; + } + } + + /** + * Specifies whether this method is static + */ + public bool is_static { + get { + return !is_constructor && binding_type == MethodBindingType.STATIC + && parent is Namespace == false; + } + } + + /** + * Specifies whether this method is a creation method + */ + public bool is_constructor { + private set; + get; + } + + /** + * Specifies whether this method is inline + */ + public bool is_inline { + get { + return binding_type == MethodBindingType.INLINE; + } + } + + /** + * Specifies whether this method is visible for dbus + */ + public bool is_dbus_visible { + private set; + get; + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + var signature = new SignatureBuilder (); + + signature.append_keyword (accessibility.to_string ()); + + if (!is_constructor) { + if (is_static) { + signature.append_keyword ("static"); + } else if (is_abstract) { + signature.append_keyword ("abstract"); + } else if (is_override) { + signature.append_keyword ("override"); + } else if (is_virtual) { + signature.append_keyword ("virtual"); + } + if (is_inline) { + signature.append_keyword ("inline"); + } + if (is_yields) { + signature.append_keyword ("async"); + } + + signature.append_content (return_type.signature); + } + + signature.append_symbol (this); + + var type_parameters = get_children_by_type (NodeType.TYPE_PARAMETER, false); + if (type_parameters.size > 0) { + signature.append ("<", false); + bool first = true; + foreach (Item param in type_parameters) { + if (!first) { + signature.append (",", false); + } + signature.append_content (param.signature, false); + first = false; + } + signature.append (">", false); + } + + signature.append ("("); + + bool first = true; + foreach (Node param in get_children_by_type (NodeType.FORMAL_PARAMETER, false)) { + if (!first) { + signature.append (",", false); + } + signature.append_content (param.signature, !first); + first = false; + } + + signature.append (")", false); + + var exceptions = get_children_by_types ({NodeType.ERROR_DOMAIN, NodeType.CLASS}); + if (exceptions.size > 0) { + signature.append_keyword ("throws"); + first = true; + foreach (Node param in exceptions) { + if (!first) { + signature.append (",", false); + } + signature.append_type (param); + first = false; + } + } + + return signature.get (); + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { + return is_constructor ? NodeType.CREATION_METHOD : + is_static ? NodeType.STATIC_METHOD : NodeType.METHOD; + } + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_method (this); + } + } + diff --cc libvaladoc/api/namespace.vala index 000000000,c2cba30d4..7e3516605 mode 000000,100644..100644 --- a/libvaladoc/api/namespace.vala +++ b/libvaladoc/api/namespace.vala @@@ -1,0 -1,97 +1,96 @@@ + /* namespace.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents a namespace declaration. + */ + public class Valadoc.Api.Namespace : Symbol { + private SourceComment? source_comment; + + public Namespace (Api.Node parent, SourceFile file, string? name, SourceComment? comment, void* data) { + base (parent, file, name, SymbolAccessibility.PUBLIC, data); + + this.source_comment = comment; + } + + + /** + * {@inheritDoc} + */ + internal override void parse_comments (Settings settings, DocumentationParser parser) { + if (documentation != null) { + return ; + } + + if (source_comment != null) { + documentation = parser.parse (this, source_comment); + } + + base.parse_comments (settings, parser); + } + + /** + * {@inheritDoc} + */ + internal override void check_comments (Settings settings, DocumentationParser parser) { + if (documentation != null) { + parser.check (this, documentation); + } + + base.check_comments (settings, parser); + } + + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + return new SignatureBuilder () + .append_keyword (accessibility.to_string ()) + .append_keyword ("namespace") + .append_symbol (this) + .get (); + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { get { return NodeType.NAMESPACE; } } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_namespace (this); + } + + /** + * {@inheritDoc} + */ + public override bool is_browsable (Settings settings) { + return has_visible_children (settings); + } + } + diff --cc libvaladoc/api/node.vala index 000000000,580828ff6..f1bbd2c62 mode 000000,100644..100644 --- a/libvaladoc/api/node.vala +++ b/libvaladoc/api/node.vala @@@ -1,0 -1,725 +1,723 @@@ + /* node.vala + * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * Copyright (C) 20011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + /** + * Represents a node in the api tree. + */ -public abstract class Valadoc.Api.Node : Item, Browsable, Documentation, Comparable { ++public abstract class Valadoc.Api.Node : Item, Browsable, Documentation { + protected bool do_document = false; + private SourceFile file; + + /** + * The name of the node + */ + public string? name { + private set; + get; + } + + public SourceFile get_source_file () { + return file; + } + + /** + * Returns the type of this node + */ + public abstract NodeType node_type { get; } + - private Map per_name_children; - private Map> per_type_children; ++ private Vala.Map per_name_children; ++ private Vala.Map> per_type_children; + + + public Node (Node? parent, SourceFile? file, string? name, void* data) { + base (data); + - per_name_children = new HashMap (); - per_type_children = new HashMap> (); ++ per_name_children = new Vala.HashMap (str_hash, str_equal); ++ per_type_children = new Vala.HashMap> (); + + if (name != null && (is_keyword (name) || name[0].isdigit ())) { + this.name = "@" + name; + } else { + this.name = name; + } + + this.parent = parent; + this.file = file; + } + + /** + * Visits this node with the specified Visitor. + * + * @param visitor the visitor to be called while traversing + */ + public abstract void accept (Visitor visitor); + + /** + * {@inheritDoc} + */ + // TODO: rename to is_visible + public abstract bool is_browsable (Settings settings); + + /** + * {@inheritDoc} + */ + public string? get_filename () { + if (file == null) { + return null; + } + + return file.relative_path; + } + + public void add_child (Symbol child) { + if (child.name != null) { + if (child.name[0] == '@') { + per_name_children.set (child.name.next_char (), child); + } else { + per_name_children.set (child.name, child); + } + } else { + // Special case for the root namespace + per_name_children.set ("", child); + } + - Gee.List children = per_type_children.get (child.node_type); ++ Vala.List children = per_type_children.get (child.node_type); + if (children == null) { - children = new ArrayList (); ++ children = new Vala.ArrayList (); + per_type_children.set (child.node_type, children); + } + + children.add (child); + } + + /** + * {@inheritDoc} + */ + internal override void parse_comments (Settings settings, DocumentationParser parser) { + do_document = true; + - foreach (Node node in per_name_children.values) { ++ foreach (Node node in per_name_children.get_values ()) { + if (node.is_browsable (settings)) { + node.parse_comments (settings, parser); + } + } + } + + /** + * {@inheritDoc} + */ + internal override void check_comments (Settings settings, DocumentationParser parser) { + - foreach (Node node in per_name_children.values) { ++ foreach (Node node in per_name_children.get_values ()) { + if (node.is_browsable (settings)) { + node.check_comments (settings, parser); + } + } + } + + + /** + * Specifies whether this node has at least one visible child with the given type + * + * @param type a node type + */ + public bool has_visible_children_by_type (NodeType type, Settings settings) { - Gee.List? all_children = per_type_children.get (type); ++ Vala.List? all_children = per_type_children.get (type); + if (all_children != null) { + foreach (Node node in all_children) { + if (node.is_browsable (settings)) { + return true; + } + } + } + + return false; + } + + /** + * Specifies whether this node has at least one visible child with the given types + * + * @param types a list of node types + */ + public bool has_visible_children_by_types (NodeType[] types, Settings settings) { + foreach (NodeType type in types) { + if (has_visible_children_by_type (type, settings)) { + return true; + } + } + + return false; + } + + /** + * Specifies whether this node has at least one visible child + */ + public bool has_visible_children (Settings settings) { - return has_visible_children_by_types (per_type_children.keys.to_array (), settings); ++ return has_visible_children_by_types (per_type_children.get_keys ().to_array (), settings); + } + + /** + * Specifies whether this node has at least one child with the given type + * + * @param type a node type + */ + public bool has_children_by_type (NodeType type) { - Gee.List? all_children = per_type_children.get (type); ++ Vala.List? all_children = per_type_children.get (type); + return all_children != null && !all_children.is_empty; + } + + /** + * Specifies whether this node has at least one child with the given types + * + * @param types a list of node types + */ + public bool has_children (NodeType[] types) { + foreach (NodeType type in types) { + if (has_children_by_type (type)) { + return true; + } + } + return false; + } + + /** + * Returns a list of all children with the given type. + * + * @param type a node type + * @param filtered specifies whether nodes which are not browsable should appear in the list + */ - public Gee.List get_children_by_type (NodeType type, bool filtered = true) { - var children = new ArrayList (); ++ public Vala.List get_children_by_type (NodeType type, bool filtered = true) { ++ var children = new Vala.ArrayList (); + - Gee.List all_children = per_type_children.get (type); ++ Vala.List all_children = per_type_children.get (type); + if (all_children != null) { + foreach (Node node in all_children) { + if (node.do_document || !filtered) { + children.add (node); + } + } + } + + return children; + } + + /** + * Returns a list of all children with the given types. + * + * @param types a list of node types + * @param filtered specifies whether nodes which are not browsable should appear in the list + */ - public Gee.List get_children_by_types (NodeType[] types, bool filtered = true) { - var children = new ArrayList (); ++ public Vala.List get_children_by_types (NodeType[] types, bool filtered = true) { ++ var children = new Vala.ArrayList (); + + foreach (NodeType type in types) { + children.add_all (get_children_by_type (type, filtered)); + } + + return children; + } + + /** + * Visits all children of this node with the given type with the specified Visitor. + * + * @param type a node type + * @param visitor the visitor to be called while traversing + * @param filtered specifies whether nodes which are not browsable should appear in the list + */ + public void accept_children_by_type (NodeType type, Visitor visitor, bool filtered = true) { - Gee.List all_children = per_type_children.get (type); ++ Vala.List all_children = per_type_children.get (type); + if (all_children != null) { + foreach (Node node in all_children) { + if (node.do_document || !filtered) { + node.accept (visitor); + } + } + } + } + + /** + * Visits all children of this node with the given types with the specified Visitor. + * + * @param types a list of node types + * @param visitor the visitor to be called while traversing + * @param filtered specifies whether nodes which are not browsable should appear in the list + */ + public void accept_children (NodeType[] types, Visitor visitor, bool filtered = true) { + foreach (NodeType type in types) { + accept_children_by_type (type, visitor, filtered); + } + } + + /** + * Visits all children of this node with the specified Visitor. + * + * @param visitor the visitor to be called while traversing + * @param filtered specifies whether nodes which are not browsable should appear in the list + */ + public void accept_all_children (Visitor visitor, bool filtered = true) { - foreach (Gee.List children in per_type_children.values) { ++ foreach (Vala.List children in per_type_children.get_values ()) { + foreach (Node node in children) { + if (node.do_document || !filtered) { + node.accept (visitor); + } + } + } + } + + public Node? find_by_name (string name) { + if (name[0] == '@') { + return per_name_children.get (name.next_char ()); + } else { + return per_name_children.get (name); + } + } + + private Namespace? _nspace = null; + private Package? _package = null; + private string _full_name = null; + + /** + * The corresponding namespace + */ + public Namespace? nspace { + get { + if (this._nspace == null) { + Api.Item ast = this; + while (ast is Valadoc.Api.Namespace == false) { + ast = ast.parent; + if (ast == null) { + return null; + } + } + this._nspace = (Valadoc.Api.Namespace)ast; + } + return this._nspace; + } + } + + /** + * The corresponding package such as a vapi or gir file + */ + public Package? package { + get { + if (this._package == null) { + Api.Item ast = this; + while (ast is Valadoc.Api.Package == false) { + ast = ast.parent; + if (ast == null) { + return null; + } + } + this._package = (Valadoc.Api.Package)ast; + } + return this._package; + } + } + + public Content.Comment? documentation { + internal set; + get; + } + + /** + * Returns canonicalized absolute name (GLib.FileStream for instance) + */ + public string? get_full_name () { + if (this._full_name == null) { + if (this.name == null) { + return null; + } + + GLib.StringBuilder full_name = new GLib.StringBuilder (this.name); + + if (this.parent != null) { + for (Item pos = this.parent; pos is Package == false ; pos = pos.parent) { + string name = ((Node)pos).name; + if (name != null) { + full_name.prepend_unichar ('.'); + full_name.prepend (name); + } + } + } + this._full_name = full_name.str; + } + return this._full_name; + } + + /** + * A comparison function used to sort nodes in alphabetical order + */ + public int compare_to (Node node) { + return strcmp (name, node.name); + } + + private bool is_keyword (string name) { + switch (name[0]) { + case 'a': + switch (name[1]) { + case 'b': + return name == "abstract"; + + case 's': + if (name[2] == '\0') { + return true; + } + + return name == "async"; + } + break; + + case 'b': + switch (name[1]) { + case 'a': + return name == "base"; + + case 'r': + return name == "break"; + } + break; + + case 'c': + switch (name[1]) { + case 'a': + switch (name[2]) { + case 's': + return name == "case"; + + case 't': + return name == "catch"; + } + break; + + case 'l': + return name == "class"; + + case 'o': + if (name[2] != 'n') { + return false; + } + + switch (name[3]) { + case 's': + if (name[4] == 't') { + switch (name[5]) { + case '\0': + return true; + + case 'r': + return name == "construct"; + } + } + break; + + case 't': + return name == "continue"; + } + break; + } + break; + + case 'd': + switch (name[1]) { + case 'e': + switch (name[2]) { + case 'f': + return name == "default"; + + case 'l': + if (name[3] != 'e') { + return false; + } + + switch (name[4]) { + case 'g': + return name == "delegate"; + + case 't': + return name == "delete"; + } + break; + } + break; + + case 'o': + return name[2] == '\0'; + + case 'y': + return name == "dynamic"; + } + break; + + case 'e': + switch (name[1]) { + case 'l': + return name == "else"; + + case 'n': + switch (name[2]) { + case 's': + return name == "ensures"; + + case 'u': + return name == "enum"; + } + break; + + case 'r': + return name == "errordomain"; + + case 'x': + return name == "extern"; + } + break; + + case 'f': + switch (name[1]) { + case 'a': + return name == "false"; + + case 'i': + return name == "finally"; + + case 'o': + if (name[2] != 'r') { + return false; + } + + switch (name[3]) { + case '\0': + return true; + + case 'e': + return name == "foreach"; + } + break; + } + break; + + case 'g': + return name == "get"; + + case 'i': + switch (name[1]) { + case 'f': + return name[2] == '\0'; + + case 'n': + switch (name[2]) { + case '\0': + return true; + + case 'l': + return name == "inline"; + + case 't': + return name == "interface" || name == "internal"; + } + break; + + case 's': + return name[2] == '\0'; + } + break; + + case 'l': + return name == "lock"; + + case 'n': + switch (name[1]) { + case 'a': + return name == "namespace"; + + case 'e': + return name == "new"; + + case 'u': + return name == "null"; + } + break; + + case 'o': + switch (name[1]) { + case 'u': + return name == "out"; + + case 'v': + return name == "override"; + + case 'w': + return name == "owned"; + } + break; + + case 'p': + switch (name[1]) { + case 'a': + return name == "params"; + + case 'r': + switch (name[2]) { + case 'i': + return name == "private"; + + case 'o': + return name == "protected"; + } + break; + case 'u': + return name == "public"; + } + break; + + case 'r': + if (name[1] != 'e') { + return false; + } + + switch (name[2]) { + case 'f': + return name[3] == '\0'; + + case 'q': + return name == "requires"; + + case 't': + return name == "return"; + } + break; + + case 's': + switch (name[1]) { + case 'e': + switch (name[2]) { + case 'a': + return name == "sealed"; + + case 't': + return name[3] == '\0'; + } + break; + + case 'i': + switch (name[2]) { + case 'g': + return name == "signal"; + case 'z': + return name == "sizeof"; + } + break; + + case 't': + switch (name[2]) { + case 'a': + return name == "static"; + + case 'r': + return name == "struct"; + } + break; + + case 'w': + return name == "switch"; + } + break; + + case 't': + switch (name[1]) { + case 'h': + switch (name[2]) { + case 'i': + return name == "this"; + + case 'r': + if (name[3] == 'o' && name[4] == 'w') { + return name[5] == '\0' || (name[5] == 's' && name[6] == '\0'); + } + break; + } + break; + + case 'r': + switch (name[2]) { + case 'u': + return name == "true"; + + case 'y': + return name[3] == '\0'; + } + break; + + case 'y': + return name == "typeof"; + } + break; + + case 'u': + switch (name[1]) { + case 'n': + return name == "unowned"; + + case 's': + return name == "using"; + } + break; + + case 'v': + switch (name[1]) { + case 'a': + return name == "var"; + + case 'i': + return name == "virtual"; + + case 'o': + switch (name[2]) { + case 'i': + return name == "void"; + + case 'l': + return name == "volatile"; + } + break; + } + break; + + case 'w': + switch (name[1]) { + case 'e': + return name == "weak"; + + case 'h': + return name == "while"; + } + break; + + case 'y': + return name == "yield"; + } + + return false; + } + } + diff --cc libvaladoc/api/nodetype.vala index 000000000,1fbc22e66..dc515fa25 mode 000000,100644..100644 --- a/libvaladoc/api/nodetype.vala +++ b/libvaladoc/api/nodetype.vala @@@ -1,0 -1,119 +1,117 @@@ + /* node.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2007-20012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + /** + * Specifies the context of a node. + */ + public enum Valadoc.Api.NodeType { + CLASS, + CONSTANT, + CREATION_METHOD, + DELEGATE, + ENUM, + ENUM_VALUE, + ERROR_CODE, + ERROR_DOMAIN, + FIELD, + FORMAL_PARAMETER, + INTERFACE, + METHOD, + NAMESPACE, + PACKAGE, + PROPERTY, + PROPERTY_ACCESSOR, + SIGNAL, + STATIC_METHOD, + STRUCT, + TYPE_PARAMETER; + + public string to_string () { + switch (this) { + case CLASS: + return "CLASS"; + + case CONSTANT: + return "CONSTANT"; + + case CREATION_METHOD: + return "CREATION_METHOD"; + + case DELEGATE: + return "DELEGATE"; + + case ENUM: + return "ENUM"; + + case ENUM_VALUE: + return "ENUM_VALUE"; + + case ERROR_CODE: + return "ERROR_CODE"; + + case ERROR_DOMAIN: + return "ERROR_DOMAIN"; + + case FIELD: + return "FIELD"; + + case FORMAL_PARAMETER: + return "FORMAL_PARAMETER"; + + case INTERFACE: + return "INTERFACE"; + + case METHOD: + return "METHOD"; + + case NAMESPACE: + return "NAMESPACE"; + + case PACKAGE: + return "PACKAGE"; + + case PROPERTY: + return "PROPERTY"; + + case PROPERTY_ACCESSOR: + return "PROPERTY_ACCESSOR"; + + case SIGNAL: + return "SIGNAL"; + + case STATIC_METHOD: + return "STATIC_METHOD"; + + case STRUCT: + return "STRUCT"; + + case TYPE_PARAMETER: + return "TYPE_PARAMETER"; + + default: + assert_not_reached (); + } + } + } + diff --cc libvaladoc/api/package.vala index 000000000,8c2cad184..821230ecf mode 000000,100644..100644 --- a/libvaladoc/api/package.vala +++ b/libvaladoc/api/package.vala @@@ -1,0 -1,139 +1,143 @@@ + /* package.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; ++ + using Valadoc.Content; + using Valadoc.Importer; + + public class Valadoc.Api.Package : Node { + + /** + * Specifies whether this package is a dependency + */ + public bool is_package { + private set; + get; + } + - internal void set_dependency_list (ArrayList list) { ++ internal void set_dependency_list (Vala.ArrayList list) { + this._dependencies = list; + } + - private ArrayList _dependencies; ++ private Vala.ArrayList _dependencies; + + /** + * Returns a list with all dependencies + */ - public Collection get_full_dependency_list () { - ArrayList list = new ArrayList (); ++ public Vala.Collection get_full_dependency_list () { ++ Vala.ArrayList list = new Vala.ArrayList (); + + if (this._dependencies == null) { - return list.read_only_view; ++ return list; + } + + foreach (Package pkg in this._dependencies) { + if (list.contains ( pkg ) == false) { + list.add (pkg); + } + + var pkg_list = pkg.get_full_dependency_list (); + foreach (Package pkg2 in pkg_list) { + if (list.contains (pkg2) == false) { + list.add (pkg2); + } + } + } - return list.read_only_view; ++ return list; + } + - public Collection get_dependency_list () { ++ public Vala.Collection get_dependency_list () { + if (this._dependencies == null) { - return Collection.empty (); ++ return new Vala.ArrayList (); + } + - return this._dependencies.read_only_view; ++ return this._dependencies; + } + + public Package (string name, bool is_package, void* data) { + base (null, null, name, data); + + this.is_package = is_package; + this.parent = null; + } + + // - private HashMap> deprecated; ++ private Vala.HashMap> deprecated; + + internal void register_deprecated_symbol (Symbol symbol, string? version) { + if (deprecated == null) { - deprecated = new HashMap> (); ++ deprecated = new Vala.HashMap> (str_hash, str_equal); ++ } ++ ++ if (version == null) { ++ version = "0xdeadbeef"; + } + - ArrayList list = deprecated.get (version); ++ Vala.ArrayList list = deprecated.get (version); + if (list == null) { - list = new ArrayList (); ++ list = new Vala.ArrayList (); + deprecated.set (version, list); + } + + list.add (symbol); + } + - public Map> get_deprecated_symbols () { ++ public Vala.Map> get_deprecated_symbols () { + if (deprecated == null) { - return Map>.empty> (); ++ return new Vala.HashMap> (str_hash, str_equal); + } + + return deprecated; + } + + /** + * {@inheritDoc} + */ + public override bool is_browsable (Settings settings) { + return !(this.is_package && settings.with_deps == false); + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { return NodeType.PACKAGE; } + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_package (this); + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + return new SignatureBuilder () + .append_keyword ("package") + .append (name) + .get (); + } + } + diff --cc libvaladoc/api/pointer.vala index 000000000,aec541bb8..954acd949 mode 000000,100644..100644 --- a/libvaladoc/api/pointer.vala +++ b/libvaladoc/api/pointer.vala @@@ -1,0 -1,55 +1,54 @@@ + /* pointer.vala + * + * Copyright (C) 2008 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents a pointer declaration. + */ + public class Valadoc.Api.Pointer : Item { + + /** + * The type the pointer is referring to. + */ + public Item data_type { + set; + get; + } + + public Pointer (Item parent, void* data) { + base (data); + + this.parent = parent; + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + return new SignatureBuilder () + .append_content (data_type.signature) + .append ("*", false) + .get (); + } + } diff --cc libvaladoc/api/property.vala index 000000000,556c7c9bf..235292f20 mode 000000,100644..100644 --- a/libvaladoc/api/property.vala +++ b/libvaladoc/api/property.vala @@@ -1,0 -1,202 +1,201 @@@ + /* property.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents a property declaration. + */ + public class Valadoc.Api.Property : Member { + private PropertyBindingType binding_type; + private string? dbus_name; + private string? cname; + + public Property (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, string? cname, string? dbus_name, bool is_dbus_visible, + PropertyBindingType binding_type, void* data) + { + base (parent, file, name, accessibility, comment, data); + + this.is_dbus_visible = is_dbus_visible; + this.binding_type = binding_type; + + this.dbus_name = dbus_name; + this.cname = cname; + } + + /** + * Returns the name of this method as it is used in C. + */ + public string? get_cname () { + return cname; + } + + /** + * Returns the dbus-name. + */ + public string get_dbus_name () { + return dbus_name; + } + + /** + * The property type. + * + * @return The property type or null for void + */ + public TypeReference? property_type { + set; + get; + } + + /** + * Specifies whether the property is virtual. + */ + public bool is_virtual { + get { + return binding_type == PropertyBindingType.VIRTUAL; + } + } + + /** + * Specifies whether the property is abstract. + */ + public bool is_abstract { + get { + return binding_type == PropertyBindingType.ABSTRACT; + } + } + + /** + * Specifies whether the property is override. + */ + public bool is_override { + get { + return binding_type == PropertyBindingType.OVERRIDE; + } + } + + /** + * Specifies whether the property is visible. + */ + public bool is_dbus_visible { + private set; + get; + } + + public PropertyAccessor? setter { - internal set; ++ set; + get; + } + + public PropertyAccessor? getter { - internal set; ++ set; + get; + } + + /** + * Specifies the virtual or abstract property this property overrides. + */ + public Property base_property { + set; + get; + } + + /** + * {@inheritDoc} + */ + internal override void parse_comments (Settings settings, DocumentationParser parser) { + if (getter != null && getter.is_browsable (settings)) { + getter.parse_comments (settings, parser); + } + + if (setter != null && setter.is_browsable (settings)) { + setter.parse_comments (settings, parser); + } + + base.parse_comments (settings, parser); + } + + /** + * {@inheritDoc} + */ + internal override void check_comments (Settings settings, DocumentationParser parser) { + if (getter != null && getter.is_browsable (settings)) { + getter.check_comments (settings, parser); + } + + if (setter != null && setter.is_browsable (settings)) { + setter.check_comments (settings, parser); + } + + base.check_comments (settings, parser); + } + + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + var signature = new SignatureBuilder (); + + signature.append_keyword (accessibility.to_string ()); + if (is_abstract) { + signature.append_keyword ("abstract"); + } else if (is_override) { + signature.append_keyword ("override"); + } else if (is_virtual) { + signature.append_keyword ("virtual"); + } + + signature.append_content (property_type.signature); + signature.append_symbol (this); + signature.append ("{"); + + if (setter != null && setter.do_document) { + signature.append_content (setter.signature); + } + + if (getter != null && getter.do_document) { + signature.append_content (getter.signature); + } + + signature.append ("}"); + + return signature.get (); + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { return NodeType.PROPERTY; } + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_property (this); + } + } + diff --cc libvaladoc/api/propertyaccessor.vala index 000000000,0a79dd3fc..173edd89d mode 000000,100644..100644 --- a/libvaladoc/api/propertyaccessor.vala +++ b/libvaladoc/api/propertyaccessor.vala @@@ -1,0 -1,134 +1,133 @@@ + /* propertyaccessor.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents a get or set accessor of a property. + */ + public class Valadoc.Api.PropertyAccessor : Symbol { + private PropertyAccessorType type; + private Ownership ownership; + private string? cname; + + public PropertyAccessor (Property parent, SourceFile file, string name, SymbolAccessibility accessibility, + string? cname, PropertyAccessorType type, Ownership ownership, void* data) + { + base (parent, file, name, accessibility, data); + + this.ownership = ownership; + this.cname = cname; + this.type = type; + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { return NodeType.PROPERTY_ACCESSOR; } + } + + /** + * Returns the name of this property accessor as it is used in C. + */ + public string? get_cname () { + return cname; + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + } + + /** + * Specifies whether this accessor may be used to construct the property. + */ + public bool is_construct { + get { + return (type & PropertyAccessorType.CONSTRUCT) != 0; + } + } + + /** + * Specifies whether this accessor is a setter. + */ + public bool is_set { + get { + return (type & PropertyAccessorType.SET) != 0; + } + } + + /** + * Specifies whether this accessor is a getter. + */ + public bool is_get { + get { + return (type & PropertyAccessorType.GET) != 0; + } + } + + /** + * Specifies whether the property is owned. + */ + public bool is_owned { + get { + return ownership == Ownership.OWNED; + } + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + var signature = new SignatureBuilder (); + + // FIXME + if (!do_document) { + return signature.get (); + } + + if (((Property) parent).accessibility != accessibility) { + signature.append_keyword (accessibility.to_string ()); + } + + if (is_set || is_construct) { + if (is_construct) { + signature.append_keyword ("construct"); + } + if (is_set) { + signature.append_keyword ("set"); + } + } else if (is_get) { + if (is_owned) { + signature.append_keyword ("owned"); + } + signature.append_keyword ("get"); + } + signature.append (";", false); + + return signature.get (); + } + } + diff --cc libvaladoc/api/propertyaccessortype.vala index 000000000,609815ae0..8453ca502 mode 000000,100644..100644 --- a/libvaladoc/api/propertyaccessortype.vala +++ b/libvaladoc/api/propertyaccessortype.vala @@@ -1,0 -1,42 +1,43 @@@ + /* propertyaccessor.vala + * + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + ++ + public enum Valadoc.Api.PropertyAccessorType { + CONSTRUCT = 1 << 0, + SET = 1 << 1, + GET = 1 << 2; + + public string to_string () { + if ((this & PropertyAccessorType.CONSTRUCT) != 0) { + if ((this & PropertyAccessorType.SET) != 0) { + return "construct set"; + } + return "construct"; + } else if ((this & PropertyAccessorType.SET) != 0) { + return "set"; + } else if ((this & PropertyAccessorType.GET) != 0) { + return "get"; + } + + assert_not_reached (); + } + } diff --cc libvaladoc/api/signal.vala index 000000000,4bbbb2320..6e6f8855f mode 000000,100644..100644 --- a/libvaladoc/api/signal.vala +++ b/libvaladoc/api/signal.vala @@@ -1,0 -1,146 +1,145 @@@ + /* signal.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents an signal. + */ + public class Valadoc.Api.Signal : Member, Callable { + private string? default_impl_cname; + private string? dbus_name; + private string? cname; + + + /** + * {@inheritDoc} + */ + internal string? implicit_array_length_cparameter_name { + get; + set; + } + + + public Signal (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, string? cname, string? default_impl_cname, string? dbus_name, bool is_dbus_visible, + bool is_virtual, void* data) + { + base (parent, file, name, accessibility, comment, data); + + this.default_impl_cname = default_impl_cname; + this.dbus_name = dbus_name; + this.cname = cname; + + this.is_dbus_visible = is_dbus_visible; + this.is_virtual = is_virtual; + } + + /** + * Returns the name of this signal as it is used in C. + */ + public string? get_cname () { + return cname; + } + + public string? get_default_impl_cname () { + return default_impl_cname; + } + + /** + * Returns the dbus-name. + */ + public string get_dbus_name () { + return dbus_name; + } + + /** + * {@inheritDoc} + */ + public TypeReference? return_type { + set; + get; + } + + /** + * Specifies whether this signal is virtual + */ + public bool is_virtual { + private set; + get; + } + + /** + * Specifies whether this signal is visible for dbus + */ + public bool is_dbus_visible { + private set; + get; + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + var signature = new SignatureBuilder (); + + signature.append_keyword (accessibility.to_string ()); + if (is_virtual) { + signature.append_keyword ("virtual"); + } + + signature.append_keyword ("signal"); + + signature.append_content (return_type.signature); + signature.append_symbol (this); + signature.append ("("); + + bool first = true; + foreach (Node param in get_children_by_type (NodeType.FORMAL_PARAMETER, false)) { + if (!first) { + signature.append (",", false); + } + signature.append_content (param.signature, !first); + first = false; + } + + signature.append (")", false); + + return signature.get (); + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { return NodeType.SIGNAL; } + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_signal (this); + } + } + diff --cc libvaladoc/api/signaturebuilder.vala index 000000000,158bd6e41..a897dae6b mode 000000,100644..100644 --- a/libvaladoc/api/signaturebuilder.vala +++ b/libvaladoc/api/signaturebuilder.vala @@@ -1,0 -1,180 +1,180 @@@ + /* signaturebuilder.vala + * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Builds up a signature from the given items. + */ + public class Valadoc.Api.SignatureBuilder { + private Run run; + private Inline last_appended; + + /** + * Creates a new SignatureBuilder + */ + public SignatureBuilder () { + run = new Run (Run.Style.NONE); + } + + private void append_text (string text) { + if (last_appended is Text) { + ((Text) last_appended).content += text; + } else { + run.content.add (last_appended = new Text (text)); + } + } + + /** + * Adds text onto the end of the builder. + * + * @param text a string + * @param spaced add a space at the front of the string if necessary + * @return this + */ + public SignatureBuilder append (string text, bool spaced = true) { + string content = (last_appended != null && spaced ? " " : "") + text; + append_text (content); + return this; + } + + /** + * Adds text onto the end of the builder. + * + * @param text a string + * @param spaced add a space at the front of the string if necessary + * @return this + */ + public SignatureBuilder append_attribute (string text, bool spaced = true) { + string content = (last_appended != null && spaced ? " " : "") + text; + append_text (content); + return this; + } + + /** + * Adds highlighted text onto the end of the builder. + * + * @param text a string + * @param spaced add a space at the front of the string if necessary + * @return this + */ + public SignatureBuilder append_highlighted (string text, bool spaced = true) { + string content = (last_appended != null && spaced ? " " : "") + text; + Run inner = new Run (Run.Style.ITALIC); + inner.content.add (new Text (content)); + return append_content (inner, spaced); + } + + /** + * Adds a Inline onto the end of the builder. + * + * @param content a content + * @param spaced add a space at the front of the inline if necessary + * @return this + */ + public SignatureBuilder append_content (Inline content, bool spaced = true) { + if (last_appended != null && spaced) { + append_text (" "); + } + run.content.add (last_appended = content); + return this; + } + + /** + * Adds a keyword onto the end of the builder. + * + * @param keyword a keyword + * @param spaced add a space at the front of the keyword if necessary + * @return this + */ + public SignatureBuilder append_keyword (string keyword, bool spaced = true) { + Run inner = new Run (Run.Style.LANG_KEYWORD); + inner.content.add (new Text (keyword)); + return append_content (inner, spaced); + } + + /** + * Adds a symbol onto the end of the builder. + * + * @param node a node + * @param spaced add a space at the front of the node if necessary + * @return this + */ + public SignatureBuilder append_symbol (Node node, bool spaced = true) { + Run inner = new Run (Run.Style.BOLD); + inner.content.add (new SymbolLink (node, node.name)); + return append_content (inner, spaced); + } + + /** + * Adds a type onto the end of the builder. + * + * @param node a node + * @param spaced add a space at the front of the node if necessary + * @return this + */ + public SignatureBuilder append_type (Node node, bool spaced = true) { + Run.Style style = Run.Style.LANG_TYPE; + if (node is TypeSymbol && ((TypeSymbol)node).is_basic_type) { + style = Run.Style.LANG_BASIC_TYPE; + } + + Run inner = new Run (style); + inner.content.add (new SymbolLink (node, node.name)); + return append_content (inner, spaced); + } + + /** + * Adds a type name onto the end of the builder. + * + * @param name a type name + * @param spaced add a space at the front of the type name if necessary + * @return this + */ + public SignatureBuilder append_type_name (string name, bool spaced = true) { + Run inner = new Run (Run.Style.LANG_TYPE); + inner.content.add (new Text (name)); + return append_content (inner, spaced); + } + + /** + * Adds a literal onto the end of the builder. + * + * @param literal a literal + * @param spaced add a space at the front of the literal if necessary + * @return this + */ + public SignatureBuilder append_literal (string literal, bool spaced = true) { + Run inner = new Run (Run.Style.LANG_LITERAL); + inner.content.add (new Text (literal)); + return append_content (inner, spaced); + } + + /** + * The content + */ + public new Run get () { + return run; + } + } + diff --cc libvaladoc/api/sourcecomment.vala index 000000000,df6d1e1da..2d8eb1485 mode 000000,100644..100644 --- a/libvaladoc/api/sourcecomment.vala +++ b/libvaladoc/api/sourcecomment.vala @@@ -1,0 -1,86 +1,85 @@@ + /* sourcecomment.vala + * + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + + - + /** + * A documentation comment used by valadoc + */ + public class Valadoc.Api.SourceComment { + public SourceFile file { + private set; + get; + } + + /** + * The text describing the referenced source code. + */ + public string content { + private set; + get; + } + + /** + * The first line number of the referenced source code. + */ + public int first_line { + private set; + get; + } + + /** + * The first column number of the referenced source code. + */ + public int first_column { + private set; + get; + } + + /** + * The last line number of the referenced source code. + */ + public int last_line { + private set; + get; + } + + /** + * The last column number of the referenced source code. + */ + public int last_column { + private set; + get; + } + + public SourceComment (string content, SourceFile file, int first_line, int first_column, + int last_line, int last_column) + { + this.first_column = first_column; + this.last_column = last_column; + this.first_line = first_line; + this.last_line = last_line; + this.content = content; + this.file = file; + } + } + + diff --cc libvaladoc/api/sourcefile.vala index 000000000,46d1801be..9c3401145 mode 000000,100644..100644 --- a/libvaladoc/api/sourcefile.vala +++ b/libvaladoc/api/sourcefile.vala @@@ -1,0 -1,60 +1,61 @@@ + /* sourcefile.vala + * + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Brosch Florian + */ + ++ + /** + * Represents a source file + */ + public class Valadoc.Api.SourceFile : Object { + + public Package package { + private set; + get; + } + + public string relative_path { + private set; + get; + } + + public string? relative_c_path { + private set; + get; + } + + public string get_name () { + return Path.get_basename (relative_path); + } + + public void* data { + private set; + get; + } + + public SourceFile (Package package, string relative_path, string? relative_c_path, void* data) { + this.relative_c_path = relative_c_path; + this.relative_path = relative_path; + this.package = package; + this.data = data; + } + } + + diff --cc libvaladoc/api/struct.vala index 000000000,e1df479c3..93bbce778 mode 000000,100644..100644 --- a/libvaladoc/api/struct.vala +++ b/libvaladoc/api/struct.vala @@@ -1,0 -1,174 +1,173 @@@ + /* struct.vala + * + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents a struct declaration. + */ + public class Valadoc.Api.Struct : TypeSymbol { + private string? dup_function_cname; + private string? copy_function_cname; + private string? free_function_cname; + private string? destroy_function_cname; + private string? type_id; + private string? cname; + + public Struct (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, string? cname, string? type_macro_name, + string? type_function_name, string? type_id, string? dup_function_cname, + string? copy_function_cname, string? destroy_function_cname, + string? free_function_cname, bool is_basic_type, void* data) + { + base (parent, file, name, accessibility, comment, type_macro_name, null, null, + type_function_name, is_basic_type, data); + + this.dup_function_cname = dup_function_cname; + this.copy_function_cname = copy_function_cname; + this.free_function_cname = free_function_cname; + this.destroy_function_cname = destroy_function_cname; + + this.cname = cname; + } + + /** + * Specifies the base struct. + */ + public TypeReference? base_type { + set; + get; + } + + + /** + * Returns the name of this struct as it is used in C. + */ + public string? get_cname () { + return cname; + } + + /** + * Returns the C symbol representing the runtime type id for this data type. + */ + public string? get_type_id () { + return type_id; + } + + /** + * Returns the C function name that duplicates instances of this data + * type. + */ + public string? get_dup_function_cname () { + return dup_function_cname; + } + + /** + * Returns the C function name that copies instances of this data + * type. + */ + public string? get_copy_function_cname () { + return copy_function_cname; + } + + /** + * Returns the C function name that frees instances of this data type. + */ + public string? get_free_function_cname () { + return free_function_cname; + } + + /** + * Returns the C function name that destroys instances of this data type. + */ + public string? get_destroy_function_cname () { + return destroy_function_cname; + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { + get { return NodeType.STRUCT; } + } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_struct (this); + } + + - private Set _known_child_structs = new TreeSet (); ++ private Vala.Set _known_child_structs = new Vala.HashSet (); + + /** + * Returns a list of all known structs based on this struct + */ - public Collection get_known_child_structs () { - return _known_child_structs.read_only_view; ++ public Vala.Collection get_known_child_structs () { ++ return _known_child_structs; + } + + public void register_child_struct (Struct stru) { + if (this.base_type != null) { + ((Struct) this.base_type.data_type).register_child_struct (stru); + } + + _known_child_structs.add (stru); + } + + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + var signature = new SignatureBuilder (); + + signature.append_keyword (accessibility.to_string ()); + signature.append_keyword ("struct"); + signature.append_symbol (this); + + var type_parameters = get_children_by_type (NodeType.TYPE_PARAMETER, false); + if (type_parameters.size > 0) { + signature.append ("<", false); + bool first = true; + foreach (Item param in type_parameters) { + if (!first) { + signature.append (",", false); + } + signature.append_content (param.signature, false); + first = false; + } + signature.append (">", false); + } + + if (base_type != null) { + signature.append (":"); + + signature.append_content (base_type.signature); + } + + return signature.get (); + } + } + diff --cc libvaladoc/api/symbol.vala index 000000000,aec2bdd75..020c28ab1 mode 000000,100644..100644 --- a/libvaladoc/api/symbol.vala +++ b/libvaladoc/api/symbol.vala @@@ -1,0 -1,158 +1,157 @@@ + /* symbol.vala + * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; + + /** + * Represents a node in the symbol tree. + */ + public abstract class Valadoc.Api.Symbol : Node { - private ArrayList attributes; ++ private Vala.ArrayList attributes; + + public bool is_deprecated { + default = false; + private set; + get; + } + + public Symbol (Node parent, SourceFile file, string? name, SymbolAccessibility accessibility, + void* data) + { + base (parent, file, name, data); + + this.accessibility = accessibility; + } + + public void add_attribute (Attribute att) { + if (attributes == null) { - attributes = new ArrayList (); ++ attributes = new Vala.ArrayList (); + } + + // register deprecated symbols: + if (att.name == "Version") { + AttributeArgument? deprecated = att.get_argument ("deprecated"); + AttributeArgument? version = att.get_argument ("deprecated_since"); + if ((deprecated != null && deprecated.get_value_as_boolean ()) || version != null) { + string? version_str = (version != null) ? version.get_value_as_string () : null; + + package.register_deprecated_symbol (this, version_str); + is_deprecated = true; + } + } else if (att.name == "Deprecated") { + AttributeArgument? version = att.get_argument ("version"); + string? version_str = (version != null) ? version.get_value_as_string () : null; + + package.register_deprecated_symbol (this, version_str); + is_deprecated = true; + } + + attributes.add (att); + } + - public Collection get_attributes () { ++ public Vala.Collection get_attributes () { + if (attributes == null) { - return Collection.empty (); ++ return new Vala.ArrayList (); + } else { + return attributes; + } + } + + public Attribute? get_attribute (string name) { + if (attributes != null) { + foreach (Attribute att in attributes) { + if (att.name == name) { + return att; + } + } + } + + return null; + } + + /** + * {@inheritDoc} + */ + public override bool is_browsable (Settings settings) { + if (!settings._private && this.is_private) { + return false; + } + if (!settings._internal && this.is_internal) { + return false; + } + if (!settings._protected && this.is_protected) { + return false; + } + + Item? pos = parent; + while (pos != null && pos is Symbol && pos is Namespace == false) { + if (((Symbol) pos).is_browsable (settings) == false) { + return false; + } + pos = pos.parent; + } + + return true; + } + + public SymbolAccessibility accessibility { + private set; + get; + } + + /** + * Specifies whether this symbol is public. + */ + public bool is_public { + get { + return accessibility == SymbolAccessibility.PUBLIC; + } + } + + /** + * Specifies whether this symbol is protected. + */ + public bool is_protected { + get { + return accessibility == SymbolAccessibility.PROTECTED; + } + } + + /** + * Specifies whether this symbol is internal. + */ + public bool is_internal { + get { + return accessibility == SymbolAccessibility.INTERNAL; + } + } + + /** + * Specifies whether this symbol is private. + */ + public bool is_private { + get { + return accessibility == SymbolAccessibility.PRIVATE; + } + } + } + diff --cc libvaladoc/api/tree.vala index 000000000,a5ae3c54b..4344c2e46 mode 000000,100644..100644 --- a/libvaladoc/api/tree.vala +++ b/libvaladoc/api/tree.vala @@@ -1,0 -1,352 +1,350 @@@ + /* tree.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Valadoc.Importer; -using Gee; - + ++using Valadoc.Importer; + + /** + * The root of the code tree. + */ + public class Valadoc.Api.Tree { - private Deque inheritdocs = new LinkedList (); - private ArrayList external_c_files = new ArrayList(); - private ArrayList packages = new ArrayList(); ++ private Vala.List inheritdocs = new Vala.ArrayList (); ++ private Vala.ArrayList external_c_files = new Vala.ArrayList(str_equal); ++ private Vala.ArrayList packages = new Vala.ArrayList(); + private Package source_package = null; + private Settings settings; + private ErrorReporter reporter; + private Highlighter.Highlighter _highlighter; + private CTypeResolver _cresolver = null; + private Package _source_package; + + + private class InheritDocContainer { + public unowned Taglets.InheritDoc taglet; + public unowned Api.Node taglet_container; + + public InheritDocContainer (Api.Node taglet_container, Taglets.InheritDoc taglet) { + this.taglet_container = taglet_container; + this.taglet = taglet; + } + } + + + public void add_package(Package package) { + this.packages.add (package); + } + + public void* data { + set; + get; + } + + public Highlighter.Highlighter highlighter { + get { + if (_highlighter == null) { + _highlighter = new Highlighter.Highlighter (); + } + + return _highlighter; + } + } + + /** + * The root of the wiki tree. + */ + public WikiPageTree? wikitree { + private set; + get; + } + + /** + * Returns a list of C source files. + * + * @return list of C source files + */ - public Collection get_external_c_files () { - return external_c_files.read_only_view; ++ public Vala.Collection get_external_c_files () { ++ return external_c_files; + } + + public void add_external_c_files (string name) { + external_c_files.add (name); + } + + + /** + * Returns a list of all packages in the tree + * + * @return list of all packages + */ - public Collection get_package_list () { - return this.packages.read_only_view; ++ public Vala.Collection get_package_list () { ++ return this.packages; + } + + private void add_dependencies_to_source_package () { + if ( this.source_package != null ) { - ArrayList deplst = new ArrayList (); ++ Vala.ArrayList deplst = new Vala.ArrayList (); + foreach (Package pkg in this.packages) { + if (pkg != this.source_package) { + deplst.add (pkg); + } + } + this.source_package.set_dependency_list (deplst); + } + } + + /** + * Visits this node with the specified Visitor. + * + * @param visitor the visitor to be called while traversing + */ + public void accept (Visitor visitor) { + visitor.visit_tree (this); + } + + /** + * Visits all children of this node with the given types with the specified Visitor. + * + * @param visitor the visitor to be called while traversing + */ + public void accept_children (Visitor visitor) { + foreach (Node node in packages) { + node.accept (visitor); + } + } + + private Node? search_relative_to (Node element, string[] path) { + Api.Node? node = element; + + foreach (string name in path) { + node = node.find_by_name (name); + if (node == null) { + break; + } + } + + if (node == null && element.parent != null) { + node = search_relative_to ((Node) element.parent, path); + } + + return node; + } + + public Node? search_symbol_path (Node? element, string[] path) { + Api.Node? node = null; + + // relative to element + if (element != null) { + node = search_relative_to (element, path); + if (node != null) { + return node; + } + } + + + // absolute + foreach (Package package in packages) { + // search in root namespace + + Node? global = package.find_by_name (""); + if (global != null) { + node = search_relative_to (global, path); + if (node != null) { + return node; + } + } + } + + return null; + } + + public TypeSymbol? search_symbol_type_cstr (string cname) { + if (_cresolver == null) { + _cresolver = new CTypeResolver (this); + } + + return _cresolver.resolve_symbol_type (cname); + } + + public Node? search_symbol_cstr (Node? element, string cname) { + if (_cresolver == null) { + _cresolver = new CTypeResolver (this); + } + + return _cresolver.resolve_symbol (element, cname); + } + + public Node? search_symbol_str (Node? element, string symname) { + string[] path = split_name (symname); + + var node = search_symbol_path (element, path); + if (node != null) { + return node; + } + + if (path.length >= 2 && path[path.length-2] == path[path.length-2]) { + path[path.length-2] = path[path.length-2]+"."+path[path.length-1]; + path.resize (path.length-1); + return search_symbol_path (element, path); + } + + return null; + } + + private string[] split_name (string full_name) { + string[] params = (full_name).split (".", -1); + int i = 0; while (params[i] != null) i++; + params.length = i; + return params; + } + + public Tree (ErrorReporter reporter, Settings settings, void* data = null) { + this.settings = settings; + this.reporter = reporter; + this.data = data; + } + + // copied from valacodecontext.vala + private string? get_file_path (string basename, string[] directories) { + string filename = null; + + if (directories != null) { + foreach (string dir in directories) { + filename = Path.build_filename (dir, basename); + if (FileUtils.test (filename, FileTest.EXISTS)) { + return filename; + } + } + } + + foreach (string dir in Environment.get_system_data_dirs ()) { + filename = Path.build_filename (dir, basename); + if (FileUtils.test (filename, FileTest.EXISTS)) { + return filename; + } + } + + return null; + } + + public bool create_tree ( ) { + this.add_dependencies_to_source_package (); + return true; + } + + private Package? get_source_package () { + if (_source_package == null) { + foreach (Package pkg in packages) { + if (!pkg.is_package) { + _source_package = pkg; + break; + } + } + } + + return _source_package; + } + + private void parse_wiki (DocumentationParser docparser) { + this.wikitree = new WikiPageTree (); + var pkg = get_source_package (); + if (pkg != null) { + wikitree.parse (settings, docparser, pkg, reporter); + } + } + + private void check_wiki (DocumentationParser docparser) { + Package pkg = get_source_package (); + if (pkg != null) { + wikitree.check (settings, docparser, pkg); + } + } + + public void parse_comments (DocumentationParser docparser) { + parse_wiki (docparser); + + foreach (Package pkg in this.packages) { + if (pkg.is_browsable (settings)) { + pkg.parse_comments (settings, docparser); + } + } + } + + public void check_comments (DocumentationParser docparser) { + check_wiki (docparser); + + foreach (Package pkg in this.packages) { + if (pkg.is_browsable (settings)) { + pkg.check_comments (settings, docparser); + postprocess_inheritdoc (docparser); + } + } + } + + internal void register_inheritdoc (Api.Node container, Taglets.InheritDoc taglet) { + inheritdocs.add (new InheritDocContainer (container, taglet)); + } + + private void postprocess_inheritdoc (DocumentationParser docparser) { + while (!this.inheritdocs.is_empty) { - InheritDocContainer container = this.inheritdocs.poll_head (); ++ InheritDocContainer container = this.inheritdocs.remove_at (0); + + docparser.transform_inheritdoc (container.taglet_container, container.taglet); + } + } + + + /** + * Import documentation from various sources + * + * @param importers a list of importers + * @param packages sources + * @param import_directories List of directories where to find the files + */ + public void import_comments (DocumentationImporter[] importers, string[] packages, + string[] import_directories) + { - HashSet processed = new HashSet (); ++ Vala.HashSet processed = new Vala.HashSet (); + foreach (string pkg_name in packages) { + bool imported = false; + foreach (DocumentationImporter importer in importers) { + string? path = get_file_path ("%s.%s".printf (pkg_name, importer.file_extension), + import_directories); + if (path == null) { + continue; + } + + path = realpath (path); + imported = true; + + if (!processed.contains (path)) { + importer.process (path); + processed.add (path); + } + } + + if (imported == false) { + reporter.simple_error (null, "'%s' not found in specified import directories", pkg_name); + } + } + } + } + diff --cc libvaladoc/api/typeparameter.vala index 000000000,b5f33b860..9cfe86482 mode 000000,100644..100644 --- a/libvaladoc/api/typeparameter.vala +++ b/libvaladoc/api/typeparameter.vala @@@ -1,0 -1,62 +1,61 @@@ + /* typeparameter.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * Represents a generic type parameter in the source code. + */ + public class Valadoc.Api.TypeParameter : Symbol { + + public TypeParameter (Node parent, SourceFile file, string name, void* data) { + base (parent, file, name, SymbolAccessibility.PUBLIC, data); + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + return new SignatureBuilder () + .append_symbol (this) + .get (); + } + + /** + * {@inheritDoc} + */ + public override NodeType node_type { get { return NodeType.TYPE_PARAMETER; } } + + /** + * {@inheritDoc} + */ + public override void accept (Visitor visitor) { + visitor.visit_type_parameter (this); + } + + public override bool is_browsable (Settings settings) { + return false; + } + + } + diff --cc libvaladoc/api/typereference.vala index 000000000,0d5bffc1f..3fd975c4b mode 000000,100644..100644 --- a/libvaladoc/api/typereference.vala +++ b/libvaladoc/api/typereference.vala @@@ -1,0 -1,168 +1,167 @@@ + /* typereference.vala + * + * Copyright (C) 2008-2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; -using Valadoc.Content; + ++using Valadoc.Content; + + /** + * A reference to a data type. + */ + public class Valadoc.Api.TypeReference : Item { - private ArrayList type_arguments = new ArrayList (); ++ private Vala.ArrayList type_arguments = new Vala.ArrayList (); + private string? dbus_type_signature; + private Ownership ownership; + + public TypeReference (Item parent, Ownership ownership, bool pass_ownership, bool is_dynamic, + bool is_nullable, string? dbus_type_signature, void* data) + { + base (data); + + this.dbus_type_signature = dbus_type_signature; + this.pass_ownership = pass_ownership; + this.is_nullable = is_nullable; + this.is_dynamic = is_dynamic; + this.ownership = ownership; + this.parent = parent; + } + + /** + * Returns a copy of the list of generic type arguments. + * + * @return type argument list + */ - public Gee.Collection get_type_arguments () { - return this.type_arguments.read_only_view; ++ public Vala.Collection get_type_arguments () { ++ return this.type_arguments; + } + + public void add_type_argument (TypeReference type_ref) { + type_arguments.add (type_ref); + } + + /** + * The referred data type. + */ + public Item? data_type { + set; + get; + } + + public bool pass_ownership { + private set; + get; + } + + /** + * Specifies that the expression is owned. + */ + public bool is_owned { + get { + return ownership == Ownership.OWNED; + } + } + + /** + * Specifies that the expression is weak. + */ + public bool is_weak { + get { + return ownership == Ownership.WEAK; + } + } + + /** + * Specifies that the expression is unwoned. + */ + public bool is_unowned { + get { + return ownership == Ownership.UNOWNED; + } + } + + + /** + * Specifies that the expression is dynamic. + */ + public bool is_dynamic { + private set; + get; + } + + /** + * Specifies that the expression may be null. + */ + public bool is_nullable { + private set; + get; + } + + public string? get_dbus_type_signature () { + return dbus_type_signature; + } + + /** + * {@inheritDoc} + */ + protected override Inline build_signature () { + var signature = new SignatureBuilder (); + + if (is_dynamic) { + signature.append_keyword ("dynamic"); + } + + if (is_weak) { + signature.append_keyword ("weak"); + } else if (is_owned) { + signature.append_keyword ("owned"); + } else if (is_unowned) { + signature.append_keyword ("unowned"); + } + + if (data_type == null) { + signature.append_keyword ("void"); + } else if (data_type is Symbol) { + signature.append_type ((Symbol) data_type); + } else { + signature.append_content (data_type.signature); + } + + if (type_arguments.size > 0) { + signature.append ("<", false); + bool first = true; + foreach (Item param in type_arguments) { + if (!first) { + signature.append (",", false); + } + signature.append_content (param.signature, false); + first = false; + } + signature.append (">", false); + } + + if (is_nullable) { + signature.append ("?", false); + } + + return signature.get (); + } + } + diff --cc libvaladoc/api/typesymbol.vala index 000000000,3574688e6..c7274ba01 mode 000000,100644..100644 --- a/libvaladoc/api/typesymbol.vala +++ b/libvaladoc/api/typesymbol.vala @@@ -1,0 -1,114 +1,112 @@@ + /* typesymbol.vala + * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + /** + * Represents a runtime data type. + */ + public abstract class Valadoc.Api.TypeSymbol : Symbol { + private SourceComment? source_comment; + private string? type_macro_name; + private string? is_type_macro_name; + private string? type_cast_macro_name; + private string? type_function_name; + + public TypeSymbol (Node parent, SourceFile file, string name, SymbolAccessibility accessibility, + SourceComment? comment, string? type_macro_name, string? is_type_macro_name, + string? type_cast_macro_name, string? type_function_name, bool is_basic_type, + void* data) + { + base (parent, file, name, accessibility, data); + + this.type_cast_macro_name = type_cast_macro_name; + this.is_type_macro_name = is_type_macro_name; + this.type_function_name = type_function_name; + this.type_macro_name = type_macro_name; + + this.is_basic_type = is_basic_type; + this.source_comment = comment; + } + + /** + * Specifies whether this symbol is a basic type (string, int, char, etc) + */ + public bool is_basic_type { + private set; + get; + } + + /** + * Gets the name of the GType macro which represents the type symbol + */ + public string get_type_macro_name () { + return type_macro_name; + } + + /** + * Gets the name of the GType macro which casts a type instance to the given type. + */ + public string get_type_cast_macro_name () { + return type_cast_macro_name; + } + + /** + * Gets the name of the GType macro which determines whether a type instance is of a given type. + */ + public string get_is_type_macro_name () { + return is_type_macro_name; + } + + /** + * Gets the name of the get_type() function which represents the type symbol + */ + public string get_type_function_name () { + return type_function_name; + } + + /** + * {@inheritDoc} + */ + internal override void parse_comments (Settings settings, DocumentationParser parser) { + if (documentation != null) { + return ; + } + + if (source_comment != null) { + documentation = parser.parse (this, source_comment); + } + + base.parse_comments (settings, parser); + } + + /** + * {@inheritDoc} + */ + internal override void check_comments (Settings settings, DocumentationParser parser) { + if (documentation != null) { + parser.check (this, documentation); + } + + base.check_comments (settings, parser); + } + } diff --cc libvaladoc/charts/chartfactory.vala index 000000000,c2582ab9f..ab1ea7364 mode 000000,100644..100644 --- a/libvaladoc/charts/chartfactory.vala +++ b/libvaladoc/charts/chartfactory.vala @@@ -1,0 -1,53 +1,53 @@@ + /* chartfactory.vala + * + * Copyright (C) 2008 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + + + public abstract class Valadoc.Charts.Factory : Object { + protected Gvc.Node create_type (Gvc.Graph graph, Api.Node item) { - #if WITH_CGRAPH ++#if WITH_CGRAPH + return graph.create_node (item.get_full_name (), 1); - #else ++#else + return graph.create_node (item.get_full_name ()); - #endif ++#endif + } + + public abstract Gvc.Graph create_graph (Api.Node item); + + public abstract Gvc.Context create_context (Gvc.Graph graph); + + public abstract Gvc.Node create_class (Gvc.Graph graph, Api.Class item); + + public abstract Gvc.Node create_struct (Gvc.Graph graph, Api.Struct item); + + public abstract Gvc.Node create_interface (Gvc.Graph graph, Api.Interface item); + + public abstract Gvc.Node create_enum (Gvc.Graph graph, Api.Enum item); + + public abstract Gvc.Node create_delegate (Gvc.Graph graph, Api.Delegate item); + + public abstract Gvc.Node create_errordomain (Gvc.Graph graph, Api.ErrorDomain item); + + public abstract Gvc.Node create_namespace (Gvc.Graph graph, Api.Namespace item); + + public abstract Gvc.Edge add_children (Gvc.Graph graph, Gvc.Node parent, Gvc.Node child); + } + diff --cc libvaladoc/charts/hierarchychart.vala index 000000000,ce3613488..c60882cb4 mode 000000,100644..100644 --- a/libvaladoc/charts/hierarchychart.vala +++ b/libvaladoc/charts/hierarchychart.vala @@@ -1,0 -1,82 +1,80 @@@ + /* hierarchychart.vala + * + * Copyright (C) 2008 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; - + + public class Valadoc.Charts.Hierarchy : Charts.Chart { + public Hierarchy (Factory factory, Api.Node node) { + base (factory, node); + } + - private void draw_implemented_interfaces (Gvc.Node child, Collection interfaces) { ++ private void draw_implemented_interfaces (Gvc.Node child, Vala.Collection interfaces) { + foreach (Api.TypeReference typeref in interfaces) { + var parent = factory.create_interface (graph, (Api.Interface) typeref.data_type); + factory.add_children (graph, parent, child); + } + } + + private void draw_parent_classes (Api.Class item, Gvc.Node? child = null) { + var parent = factory.create_class (graph, item); + + if (child != null) { + factory.add_children (graph, parent, child); + } + + if (item.base_type != null) { + draw_parent_classes ((Api.Class) item.base_type.data_type, parent); + } + + draw_implemented_interfaces (parent, item.get_implemented_interface_list ()); + } + + private void draw_parent_structs (Api.Struct item, Gvc.Node? child = null) { + var parent = factory.create_struct (graph, item); + + if (child != null) { + factory.add_children (graph, parent, child); + } + + if (item.base_type != null) { + draw_parent_structs ((Api.Struct) item.base_type.data_type, parent); + } + } + + public override void visit_interface (Api.Interface item) { + var iface = factory.create_interface (graph, item); + + if (item.base_type != null) { + draw_parent_classes ((Api.Class) item.base_type.data_type, iface); + } + + draw_implemented_interfaces (iface, item.get_implemented_interface_list ()); + } + + public override void visit_class (Api.Class item) { + draw_parent_classes (item); + } + + public override void visit_struct (Api.Struct item) { + draw_parent_structs (item); + } + } + diff --cc libvaladoc/charts/simplechartfactory.vala index 000000000,06da97e13..a1d080fdd mode 000000,100644..100644 --- a/libvaladoc/charts/simplechartfactory.vala +++ b/libvaladoc/charts/simplechartfactory.vala @@@ -1,0 -1,87 +1,87 @@@ + /* simplechartfactory.vala + * + * Copyright (C) 2008 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + + + + public class Valadoc.Charts.SimpleFactory : Charts.Factory { + protected virtual Gvc.Node configure_type (Gvc.Node node, Api.Node item) { + node.safe_set ("shape", "box", ""); + node.safe_set ("fontname", "Times", ""); + node.safe_set ("label", item.get_full_name (), ""); + return node; + } + + public override Gvc.Graph create_graph (Api.Node item) { - #if WITH_CGRAPH ++#if WITH_CGRAPH + var graph = new Gvc.Graph (item.get_full_name (), Gvc.Agdirected, 0); - #else ++#else + var graph = new Gvc.Graph (item.get_full_name (), Gvc.GraphKind.AGDIGRAPH); - #endif ++#endif + return graph; + } + + public override Gvc.Context create_context (Gvc.Graph graph) { + var context = new Gvc.Context (); + context.layout_jobs (graph); + context.layout (graph, "dot"); + return context; + } + + public override Gvc.Node create_class (Gvc.Graph graph, Api.Class item) { + var node = configure_type (create_type (graph, item), item); + node.safe_set ("style", "bold", ""); + return node; + } + + public override Gvc.Node create_struct (Gvc.Graph graph, Api.Struct item) { + var node = configure_type (create_type (graph, item), item); + node.safe_set ("style", "bold", ""); + return node; + } + + public override Gvc.Node create_interface (Gvc.Graph graph, Api.Interface item) { + return configure_type (create_type (graph, item), item); + } + + public override Gvc.Node create_enum (Gvc.Graph graph, Api.Enum item) { + return configure_type (create_type (graph, item), item); + } + + public override Gvc.Node create_delegate (Gvc.Graph graph, Api.Delegate item) { + return configure_type (create_type (graph, item), item); + } + + public override Gvc.Node create_errordomain (Gvc.Graph graph, Api.ErrorDomain item) { + return configure_type (create_type (graph, item), item); + } + + public override Gvc.Node create_namespace (Gvc.Graph graph, Api.Namespace item) { + return configure_type (create_type (graph, item), item); + } + + public override Gvc.Edge add_children (Gvc.Graph graph, Gvc.Node parent, Gvc.Node child) { + var edge = graph.create_edge (parent, child); + edge.safe_set ("dir", "back", ""); + return edge; + } + } + diff --cc libvaladoc/content/blockcontent.vala index 000000000,47e99a217..06e3d0594 mode 000000,100644..100644 --- a/libvaladoc/content/blockcontent.vala +++ b/libvaladoc/content/blockcontent.vala @@@ -1,0 -1,66 +1,65 @@@ + /* blockcontent.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; + + public abstract class Valadoc.Content.BlockContent : ContentElement { - public Gee.List content { get { return _content; } } ++ public Vala.List content { get { return _content; } } + - private Gee.List _content; ++ private Vala.List _content; + + construct { - _content = new ArrayList (); ++ _content = new Vala.ArrayList (); + } + + internal BlockContent () { + } + + public override void configure (Settings settings, ResourceLocator locator) { + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + foreach (Block element in _content) { + element.parent = this; + element.check (api_root, container, file_path, reporter, settings); + } + } + + public override void accept_children (ContentVisitor visitor) { + foreach (Block element in _content) { + element.accept (visitor); + } + } + + public override bool is_empty () { + foreach (Block item in content) { + if (!item.is_empty ()) { + return false; + } + } + + return true; + } + } + diff --cc libvaladoc/content/comment.vala index 000000000,f4ba4a09f..79362f5a1 mode 000000,100644..100644 --- a/libvaladoc/content/comment.vala +++ b/libvaladoc/content/comment.vala @@@ -1,0 -1,106 +1,105 @@@ + /* comment.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Valadoc.Taglets; -using Gee; + ++using Valadoc.Taglets; + + public class Valadoc.Content.Comment : BlockContent { - public Gee.List taglets { get { return _taglets; } } - private Gee.List _taglets; ++ public Vala.List taglets { get { return _taglets; } } ++ private Vala.List _taglets; + + private bool checked = false; + + + internal Comment () { + base (); - _taglets = new ArrayList (); ++ _taglets = new Vala.ArrayList (); + } + + public override void configure (Settings settings, ResourceLocator locator) { + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + if (checked == true) { + return ; + } + + checked = true; + + + base.check (api_root, container, file_path, reporter, settings); + + foreach (Taglet element in _taglets) { + element.parent = this; + element.check (api_root, container, file_path, reporter, settings); + } + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_comment (this); + } + + public override void accept_children (ContentVisitor visitor) { + base.accept_children (visitor); + + foreach (Taglet element in _taglets) { + element.accept (visitor); + } + } + - public Gee.List find_taglets (Api.Node? container, Type taglet_type) { - Gee.List selected_taglets = new ArrayList (); ++ public Vala.List find_taglets (Api.Node? container, Type taglet_type) { ++ Vala.List selected_taglets = new Vala.ArrayList (); + + // TODO inherit stuff if needed + + foreach (Taglet taglet in _taglets) { + if (taglet.get_type () == taglet_type) { + selected_taglets.add (taglet); + } + } + + return selected_taglets; + } + + public override ContentElement copy (ContentElement? new_parent = null) { + assert (new_parent == null); + + Comment comment = new Comment (); + comment.parent = new_parent; + + foreach (Block element in content) { + Block copy = element.copy (comment) as Block; + comment.content.add (copy); + } + + foreach (Taglet taglet in _taglets) { + Taglet copy = taglet.copy (comment) as Taglet; + comment.taglets.add (copy); + } + + return comment; + } + } + diff --cc libvaladoc/content/contentelement.vala index 000000000,6e2c65934..13e99e3dd mode 000000,100644..100644 --- a/libvaladoc/content/contentelement.vala +++ b/libvaladoc/content/contentelement.vala @@@ -1,0 -1,46 +1,44 @@@ + /* contentelement.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using GLib; - + + public abstract class Valadoc.Content.ContentElement : Object { + public ContentElement parent { get; internal set; } + + public abstract ContentElement copy (ContentElement? new_parent = null); + + + public virtual void configure (Settings settings, ResourceLocator locator) { + } + + public abstract void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings); + + public abstract void accept (ContentVisitor visitor); + + public abstract bool is_empty (); + + public virtual void accept_children (ContentVisitor visitor) { + } + } + diff --cc libvaladoc/content/contentfactory.vala index 000000000,dda8a8763..fc14fe479 mode 000000,100644..100644 --- a/libvaladoc/content/contentfactory.vala +++ b/libvaladoc/content/contentfactory.vala @@@ -1,0 -1,124 +1,122 @@@ + /* contentfactory.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.ContentFactory : Object { + + public ContentFactory (Settings settings, ResourceLocator locator, ModuleLoader modules) { + _settings = settings; + _locator = locator; + _modules = modules; + } + + private Settings _settings; + private ResourceLocator _locator; + private ModuleLoader _modules; + + private inline ContentElement configure (ContentElement element) { + element.configure (_settings, _locator); + return element; + } + + public Comment create_comment () { + return (Comment) configure (new Comment ()); + } + + public Embedded create_embedded () { + return (Embedded) configure (new Embedded ()); + } + + public Headline create_headline () { + return (Headline) configure (new Headline ()); + } + + public Link create_link () { + return (Link) configure (new Link ()); + } + + public WikiLink create_wiki_link () { + return (WikiLink) configure (new WikiLink ()); + } + + public List create_list () { + return (List) configure (new List ()); + } + + public ListItem create_list_item () { + return (ListItem) configure (new ListItem ()); + } + + public Page create_page () { + return (Page) configure (new Page ()); + } + + public Paragraph create_paragraph () { + return (Paragraph) configure (new Paragraph ()); + } + + public Warning create_warning () { + return (Warning) configure (new Warning ()); + } + public Note create_note () { + return (Note) configure (new Note ()); + } + + public Run create_run (Run.Style style) { + return (Run) configure (new Run (style)); + } + + public SourceCode create_source_code () { + return (SourceCode) configure (new SourceCode ()); + } + + public Table create_table () { + return (Table) configure (new Table ()); + } + + public TableCell create_table_cell () { + return (TableCell) configure (new TableCell ()); + } + + public TableRow create_table_row () { + return (TableRow) configure (new TableRow ()); + } + + public Taglet? create_taglet (string name) { + return _modules.create_taglet (name); + } + + public Text create_text (string? text = null) { + return (Text) configure (new Text (text)); + } + + public ContentElement set_style_attributes (StyleAttributes element, + VerticalAlign? valign, + HorizontalAlign? halign, + string? style) { + element.vertical_align = valign; + element.horizontal_align = halign; + element.style = style; + return element; + } + } diff --cc libvaladoc/content/contentrenderer.vala index 000000000,153e35deb..bad2beecc mode 000000,100644..100644 --- a/libvaladoc/content/contentrenderer.vala +++ b/libvaladoc/content/contentrenderer.vala @@@ -1,0 -1,32 +1,30 @@@ + /* contentrenderer.vala + * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using GLib; - + + public abstract class Valadoc.Content.ContentRenderer : ContentVisitor { + + public abstract void render (ContentElement element); + + public abstract void render_children (ContentElement element); + } + diff --cc libvaladoc/content/contentvisitor.vala index 000000000,d1b14c453..8ff33d6c1 mode 000000,100644..100644 --- a/libvaladoc/content/contentvisitor.vala +++ b/libvaladoc/content/contentvisitor.vala @@@ -1,0 -1,86 +1,84 @@@ + /* contentvisitor.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using GLib; - + + public abstract class Valadoc.Content.ContentVisitor : Object { + + public virtual void visit_comment (Comment element) { + } + + public virtual void visit_embedded (Embedded element) { + } + + public virtual void visit_headline (Headline element) { + } + + public virtual void visit_link (Link element) { + } + + public virtual void visit_wiki_link (WikiLink element) { + } + + public virtual void visit_symbol_link (SymbolLink element) { + } + + public virtual void visit_list (List element) { + } + + public virtual void visit_list_item (ListItem element) { + } + + public virtual void visit_paragraph (Paragraph element) { + } + + public virtual void visit_warning (Warning element) { + } + + public virtual void visit_note (Note element) { + } + + public virtual void visit_page (Page element) { + } + + public virtual void visit_run (Run element) { + } + + public virtual void visit_source_code (SourceCode element) { + } + + public virtual void visit_table (Table element) { + } + + public virtual void visit_table_cell (TableCell element) { + } + + public virtual void visit_table_row (TableRow element) { + } + + public virtual void visit_taglet (Taglet element) { + } + + public virtual void visit_text (Text element) { + } + } + diff --cc libvaladoc/content/embedded.vala index 000000000,b1d7d9525..2666cd8e9 mode 000000,100644..100644 --- a/libvaladoc/content/embedded.vala +++ b/libvaladoc/content/embedded.vala @@@ -1,0 -1,125 +1,123 @@@ + /* embedded.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.Embedded : ContentElement, Inline, StyleAttributes { + public string url { + get; + set; + } + + public string? caption { + get; + set; + } + + public HorizontalAlign? horizontal_align { + get; + set; + } + + public VerticalAlign? vertical_align { + get; + set; + } + + public string? style { + get; + set; + } + + public Api.Package package; + + private ResourceLocator _locator; + + internal Embedded () { + base (); + } + + public override void configure (Settings settings, ResourceLocator locator) { + _locator = locator; + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + // search relative to our file + if (!Path.is_absolute (url)) { + string relative_to_file = Path.build_path (Path.DIR_SEPARATOR_S, + Path.get_dirname (file_path), + url); + if (FileUtils.test (relative_to_file, FileTest.EXISTS | FileTest.IS_REGULAR)) { + url = (owned) relative_to_file; + package = container.package; + return ; + } + } + + // search relative to the current directory / absoulte path + if (!FileUtils.test (url, FileTest.EXISTS | FileTest.IS_REGULAR)) { + string base_name = Path.get_basename (url); + + foreach (unowned string dir in settings.alternative_resource_dirs) { + string alternative_path = Path.build_path (Path.DIR_SEPARATOR_S, + dir, + base_name); + if (FileUtils.test (alternative_path, FileTest.EXISTS | FileTest.IS_REGULAR)) { + url = (owned) alternative_path; + package = container.package; + return ; + } + } + + string node_segment = (container is Api.Package)? "" : container.get_full_name () + ": "; + reporter.simple_error ("%s: %s{{".printf (file_path, node_segment), + "'%s' does not exist", url); + } else { + package = container.package; + } + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_embedded (this); + } + + public override bool is_empty () { + return false; + } + + public override ContentElement copy (ContentElement? new_parent = null) { + Embedded embedded = new Embedded (); + embedded.parent = new_parent; + + embedded.horizontal_align = horizontal_align; + embedded.vertical_align = vertical_align; + embedded._locator = _locator; + embedded.caption = caption; + embedded.package = package; + embedded.style = style; + embedded.url = url; + + return embedded; + } + } diff --cc libvaladoc/content/headline.vala index 000000000,56a4a443e..dcf2e6f47 mode 000000,100644..100644 --- a/libvaladoc/content/headline.vala +++ b/libvaladoc/content/headline.vala @@@ -1,0 -1,66 +1,64 @@@ + /* headline.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.Headline : InlineContent, Block { + public int level { get; set; } + + internal Headline () { + base (); + _level = 0; + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + // TODO report error if level == 0 ? + // TODO: content.size == 0? + + // Check inline content + base.check (api_root, container, file_path, reporter, settings); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_headline (this); + } + + public override bool is_empty () { + return false; + } + + public override ContentElement copy (ContentElement? new_parent = null) { + Headline headline = new Headline (); + headline.parent = new_parent; + headline.level = level; + + foreach (Inline element in content) { + Inline copy = element.copy (headline) as Inline; + headline.content.add (copy); + } + + return headline; + } + } + diff --cc libvaladoc/content/inlinecontent.vala index 000000000,f67ee4e1a..8fdb82d92 mode 000000,100644..100644 --- a/libvaladoc/content/inlinecontent.vala +++ b/libvaladoc/content/inlinecontent.vala @@@ -1,0 -1,75 +1,73 @@@ + /* inlinecontent.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public abstract class Valadoc.Content.InlineContent : ContentElement { - public Gee.List content { ++ public Vala.List content { + get { + return _content; + } + } + - private Gee.List _content; ++ private Vala.List _content; + + construct { - _content = new ArrayList (); ++ _content = new Vala.ArrayList (); + } + + internal InlineContent () { + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + foreach (Inline element in _content) { + element.parent = this; + element.check (api_root, container, file_path, reporter, settings); + } + } + + public override void accept_children (ContentVisitor visitor) { + foreach (Inline element in _content) { + element.accept (visitor); + } + } + + public override bool is_empty () { + foreach (Inline item in content) { + if (!item.is_empty ()) { + return false; + } + } + + return true; + } + + internal void replace_node (Inline old, Inline replacement) { + int index = _content.index_of (old); + assert (index >= 0); + + _content.set (index, replacement); + } + } + diff --cc libvaladoc/content/inlinetaglet.vala index 000000000,812eab39a..ad6c7a719 mode 000000,100644..100644 --- a/libvaladoc/content/inlinetaglet.vala +++ b/libvaladoc/content/inlinetaglet.vala @@@ -1,0 -1,71 +1,69 @@@ + /* taglet.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public abstract class Valadoc.Content.InlineTaglet : ContentElement, Taglet, Inline { + protected Settings settings; + protected ResourceLocator locator; + private ContentElement _content; + + public InlineTaglet () { + base (); + } + + public abstract Rule? get_parser_rule (Rule run_rule); + + public abstract ContentElement produce_content (); + + private ContentElement get_content () { + if (_content == null) { + _content = produce_content (); + } + return _content; + } + + public override void configure (Settings settings, ResourceLocator locator) { + this.settings = settings; + this.locator = locator; + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + ContentElement element = get_content (); + element.parent = this; + + element.check (api_root, container, file_path, reporter, settings); + } + + public override void accept (ContentVisitor visitor) { + ContentElement element = get_content (); + element.accept (visitor); + } + + public override bool is_empty () { + // taglets are not empty by default + return false; + } + } + diff --cc libvaladoc/content/link.vala index 000000000,ba641e7e5..4e91aabe2 mode 000000,100644..100644 --- a/libvaladoc/content/link.vala +++ b/libvaladoc/content/link.vala @@@ -1,0 -1,115 +1,113 @@@ + /* link.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2014 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.Link : InlineContent, Inline { + public string url { + set; + get; + } + + /** + * Used by importers to transform internal URLs + */ + public Importer.InternalIdRegistrar id_registrar { + internal set; + get; + } + + + internal Link () { + base (); + } + + public override void configure (Settings settings, ResourceLocator locator) { + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + + // Internal gktdoc-id? (gir-importer) + if (id_registrar != null) { + Api.Node? node = id_registrar.map_symbol_id (url); + if (node != null) { + InlineContent _parent = parent as InlineContent; + assert (_parent != null); + + SymbolLink replacement = new SymbolLink (node); + replacement.content.add_all (content); + + replacement.check (api_root, container, file_path, reporter, settings); + _parent.replace_node (this, replacement); + return ; + } + + + string _url = id_registrar.map_url_id (url); + if (_url == null) { + string node_segment = (container is Api.Package)? "" : container.get_full_name () + ": "; + reporter.simple_warning ("%s: %s[[".printf (file_path, node_segment), + "unknown imported internal id '%s'", url); + + InlineContent _parent = parent as InlineContent; + assert (_parent != null); + + Run replacement = new Run (Run.Style.ITALIC); + replacement.content.add_all (content); + replacement.check (api_root, container, file_path, reporter, settings); + + _parent.replace_node (this, replacement); + return ; + } + + url = _url; + } + + + //TODO: check url + base.check (api_root, container, file_path, reporter, settings); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_link (this); + } + + public override bool is_empty () { + return false; + } + + public override ContentElement copy (ContentElement? new_parent = null) { + Link link = new Link (); + link.id_registrar = id_registrar; + link.parent = new_parent; + link.url = url; + + foreach (Inline element in content) { + Inline copy = element.copy (link) as Inline; + link.content.add (copy); + } + + return link; + } + } diff --cc libvaladoc/content/list.vala index 000000000,b23452648..e47ed0b63 mode 000000,100644..100644 --- a/libvaladoc/content/list.vala +++ b/libvaladoc/content/list.vala @@@ -1,0 -1,156 +1,154 @@@ + /* list.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.List : ContentElement, Block { + public enum Bullet { + NONE, + UNORDERED, + ORDERED, + ORDERED_NUMBER, + ORDERED_LOWER_CASE_ALPHA, + ORDERED_UPPER_CASE_ALPHA, + ORDERED_LOWER_CASE_ROMAN, + ORDERED_UPPER_CASE_ROMAN; + + public static Bullet? from_string (string? str) { + switch (str) { + case "none": + return Bullet.NONE; + + case "unordered": + return Bullet.UNORDERED; + + case "ordered": + return Bullet.ORDERED; + + case "ordered-number": + return Bullet.ORDERED_NUMBER; + + case "ordered-lower-case-alpa": + return Bullet.ORDERED_LOWER_CASE_ALPHA; + + case "ordered-upper-case-alpha": + return Bullet.ORDERED_UPPER_CASE_ALPHA; + + case "ordered-lower-case-roman": + return Bullet.ORDERED_LOWER_CASE_ROMAN; + + case "ordered-upper-case-roman": + return Bullet.ORDERED_UPPER_CASE_ROMAN; + } + + return null; + } + + public unowned string to_string () { + switch (this) { + case Bullet.NONE: + return "none"; + + case Bullet.UNORDERED: + return "unordered"; + + case Bullet.ORDERED: + return "ordered"; + + case Bullet.ORDERED_NUMBER: + return "ordered-number"; + + case Bullet.ORDERED_LOWER_CASE_ALPHA: + return "ordered-lower-case-alpa"; + + case Bullet.ORDERED_UPPER_CASE_ALPHA: + return "ordered-upper-case-alpha"; + + case Bullet.ORDERED_LOWER_CASE_ROMAN: + return "ordered-lower-case-roman"; + + case Bullet.ORDERED_UPPER_CASE_ROMAN: + return "ordered-upper-case-roman"; + } + + assert (true); + return ""; + } + } + + public Bullet bullet { + get; + set; + } + + // TODO add initial value (either a number or some letters) - public Gee.List items { ++ public Vala.List items { + get { + return _items; + } + } + - private Gee.List _items; ++ private Vala.List _items; + + internal List () { + base (); + _bullet = Bullet.NONE; - _items = new ArrayList (); ++ _items = new Vala.ArrayList (); + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + // Check individual list items + foreach (ListItem element in _items) { + element.parent = this; + element.check (api_root, container, file_path, reporter, settings); + } + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_list (this); + } + + public override void accept_children (ContentVisitor visitor) { + foreach (ListItem element in _items) { + element.accept (visitor); + } + } + + public override bool is_empty () { + return _items.size == 0; + } + + public override ContentElement copy (ContentElement? new_parent = null) { + Content.List list = new Content.List (); + list.parent = new_parent; + list.bullet = bullet; + + foreach (ListItem item in items) { + ListItem copy = item.copy (list) as ListItem; + list.items.add (copy); + } + + return list; + } + } diff --cc libvaladoc/content/listitem.vala index 000000000,299ce4e4e..ee3aa45ec mode 000000,100644..100644 --- a/libvaladoc/content/listitem.vala +++ b/libvaladoc/content/listitem.vala @@@ -1,0 -1,59 +1,57 @@@ + /* listitem.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.ListItem : BlockContent { + + internal ListItem () { + base (); + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + // Check block content + base.check (api_root, container, file_path, reporter, settings); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_list_item (this); + } + + public override void accept_children (ContentVisitor visitor) { + base.accept_children (visitor); + } + + public override ContentElement copy (ContentElement? new_parent = null) { + ListItem item = new ListItem (); + item.parent = new_parent; + + foreach (Block block in content) { + Block copy = block.copy (item) as Block; + item.content.add (copy); + } + + return item; + } + } diff --cc libvaladoc/content/note.vala index 000000000,d35347e05..49b81786c mode 000000,100644..100644 --- a/libvaladoc/content/note.vala +++ b/libvaladoc/content/note.vala @@@ -1,0 -1,55 +1,53 @@@ + /* note.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.Note : BlockContent, Block { + internal Note () { + base (); + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + // Check inline content + base.check (api_root, container, file_path, reporter, settings); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_note (this); + } + + public override ContentElement copy (ContentElement? new_parent = null) { + Note note = new Note (); + note.parent = new_parent; + + foreach (Block block in content) { + Block copy = block.copy (note) as Block; + note.content.add (copy); + } + + return note; + } + } + diff --cc libvaladoc/content/page.vala index 000000000,f180be84f..caaa7d93c mode 000000,100644..100644 --- a/libvaladoc/content/page.vala +++ b/libvaladoc/content/page.vala @@@ -1,0 -1,65 +1,63 @@@ + /* page.vala + * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.Page : BlockContent { + private bool checked = false; + + + internal Page () { + base (); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_page (this); + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + if (checked == true) { + return ; + } + + checked = true; + + + base.check (api_root, container, file_path, reporter, settings); + } + + public override ContentElement copy (ContentElement? new_parent = null) { + assert (new_parent == null); + + Content.Page page = new Content.Page (); + page.parent = new_parent; + + foreach (Block block in content) { + Block copy = block.copy (page) as Block; + page.content.add (copy); + } + + return page; + } + } + diff --cc libvaladoc/content/paragraph.vala index 000000000,6d474b940..548c03f0d mode 000000,100644..100644 --- a/libvaladoc/content/paragraph.vala +++ b/libvaladoc/content/paragraph.vala @@@ -1,0 -1,74 +1,72 @@@ + /* paragraph.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.Paragraph : InlineContent, Block, StyleAttributes { + public HorizontalAlign? horizontal_align { + get; + set; + } + + public VerticalAlign? vertical_align { + get; + set; + } + + public string? style { + get; + set; + } + + internal Paragraph () { + base (); + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + // Check inline content + base.check (api_root, container, file_path, reporter, settings); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_paragraph (this); + } + + public override ContentElement copy (ContentElement? new_parent = null) { + Paragraph p = new Paragraph (); + p.parent = new_parent; + + p.horizontal_align = horizontal_align; + p.vertical_align = vertical_align; + p.style = style; + + foreach (Inline element in content) { + Inline copy = element.copy (p) as Inline; + p.content.add (copy); + } + + return p; + } + } + diff --cc libvaladoc/content/resourcelocator.vala index 000000000,beffdfd0e..e6f278502 mode 000000,100644..100644 --- a/libvaladoc/content/resourcelocator.vala +++ b/libvaladoc/content/resourcelocator.vala @@@ -1,0 -1,29 +1,27 @@@ + /* resourcelocator.vala + * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using GLib; - + + public interface Valadoc.ResourceLocator : Object { + public abstract string resolve (string path); + } + diff --cc libvaladoc/content/run.vala index 000000000,01eace6b2..c2228b76a mode 000000,100644..100644 --- a/libvaladoc/content/run.vala +++ b/libvaladoc/content/run.vala @@@ -1,0 -1,208 +1,206 @@@ + /* run.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.Run : InlineContent, Inline { + public enum Style { + NONE, + BOLD, + ITALIC, + UNDERLINED, + MONOSPACED, + STROKE, + LANG_KEYWORD, + LANG_LITERAL, + LANG_BASIC_TYPE, + LANG_TYPE, + LANG_PREPROCESSOR, + LANG_COMMENT, + LANG_ESCAPE, + + XML_ESCAPE, + XML_ELEMENT, + XML_ATTRIBUTE, + XML_ATTRIBUTE_VALUE, + XML_COMMENT, + XML_CDATA; + + public static Style? from_string (string str) { + switch (str) { + case "none": + return Style.NONE; + + case "bold": + return Style.BOLD; + + case "italic": + return Style.ITALIC; + + case "underlined": + return Style.UNDERLINED; + + case "monospaced": + return Style.MONOSPACED; + + case "stroke": + return Style.STROKE; + + case "lang-escape": + return Style.LANG_ESCAPE; + + case "lang-keyword": + return Style.LANG_KEYWORD; + + case "lang-literal": + return Style.LANG_LITERAL; + + case "lang-basic-type": + return Style.LANG_BASIC_TYPE; + + case "lang-type": + return Style.LANG_TYPE; + + case "lang-preprocessor": + return Style.LANG_PREPROCESSOR; + + case "lang-comment": + return Style.LANG_COMMENT; + + case "xml-escape": + return Style.XML_ESCAPE; + + case "xml-element": + return Style.XML_ELEMENT; + + case "xml-attribute": + return Style.XML_ATTRIBUTE; + + case "xml-attribute-value": + return Style.XML_ATTRIBUTE_VALUE; + + case "xml-comment": + return Style.XML_COMMENT; + + case "xml-cdata": + return Style.XML_CDATA; + } + + return null; + } + + public unowned string to_string () { + switch (this) { + case Style.NONE: + return "none"; + + case Style.BOLD: + return "bold"; + + case Style.ITALIC: + return "italic"; + + case Style.UNDERLINED: + return "underlined"; + + case Style.MONOSPACED: + return "monospaced"; + + case Style.STROKE: + return "stroke"; + + case Style.LANG_ESCAPE: + return "lang-escape"; + + case Style.LANG_KEYWORD: + return "lang-keyword"; + + case Style.LANG_LITERAL: + return "lang-literal"; + + case Style.LANG_BASIC_TYPE: + return "lang-basic-type"; + + case Style.LANG_TYPE: + return "lang-type"; + + case Style.LANG_PREPROCESSOR: + return "lang-preprocessor"; + + case Style.LANG_COMMENT: + return "lang-comment"; + + case Style.XML_ESCAPE: + return "xml-escape"; + + case Style.XML_ELEMENT: + return "xml-element"; + + case Style.XML_ATTRIBUTE: + return "xml-attribute"; + + case Style.XML_ATTRIBUTE_VALUE: + return "xml-attribute-value"; + + case Style.XML_COMMENT: + return "xml-comment"; + + case Style.XML_CDATA: + return "xml-cdata"; + } + + assert (true); + return ""; + } + } + + public Style style { get; set; } + + internal Run (Style style) { + base (); + _style = style; + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + // Check inline content + base.check (api_root, container, file_path, reporter, settings); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_run (this); + } + + public override ContentElement copy (ContentElement? new_parent = null) { + Run run = new Run (style); + run.parent = new_parent; + + foreach (Inline element in content) { + Inline copy = element.copy (run) as Inline; + run.content.add (copy); + } + + return run; + } + } + diff --cc libvaladoc/content/sourcecode.vala index 000000000,31803f026..a9c4935f4 mode 000000,100644..100644 --- a/libvaladoc/content/sourcecode.vala +++ b/libvaladoc/content/sourcecode.vala @@@ -1,0 -1,240 +1,239 @@@ + /* sourcecode.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; + + public class Valadoc.Content.SourceCode : ContentElement, Inline { + public enum Language { + GENIE, + VALA, + XML, + C; + + public static Language? from_path (string path) { + int pos = path.last_index_of ("."); + if (pos < 0) { + return null; + } + + string ext = path.substring (pos + 1); + return from_string (ext, true); + } + + public static Language? from_string (string str, bool is_extension = false) { + switch (str) { + case "genie": + if (is_extension) { + return null; + } + return Language.GENIE; + + case "gs": + return Language.GENIE; + + case "xml": + return Language.XML; + + case "vala": + return Language.VALA; + + case "c": + case "h": + return Language.C; + } + + return null; + } + + public unowned string to_string () { + switch (this) { + case Language.GENIE: + return "genie"; + + case Language.VALA: + return "vala"; + + case Language.XML: + return "xml"; + + case Language.C: + return "c"; + } + + assert (true); + return ""; + } + } + + + public string code { + get; + set; + } + + public Run? highlighted_code { + get; + private set; + } + + public Language? language { + get; + set; + } + + internal SourceCode () { + base (); + _language = Language.VALA; + } + + private string? get_path (string path, Api.Node container, string source_file_path, + ErrorReporter reporter) + { + // search relative to our file + if (!Path.is_absolute (path)) { + string relative_to_file = Path.build_path (Path.DIR_SEPARATOR_S, + Path.get_dirname (source_file_path), + path); + if (FileUtils.test (relative_to_file, FileTest.EXISTS | FileTest.IS_REGULAR)) { + return (owned) relative_to_file; + } + } + + // search relative to the current directory / absoulte path + if (!FileUtils.test (path, FileTest.EXISTS | FileTest.IS_REGULAR)) { + string node_segment = (container is Api.Package)? "" : container.get_full_name () + ": "; + code = "File '%s' does not exist".printf (path); + reporter.simple_warning ("%s: %s{{{".printf (source_file_path, node_segment), + "%s", code); + return null; + } + + return path; + } + + private void load_source_code (string _path, Api.Node container, string source_file_path, + ErrorReporter reporter) + { + string? path = get_path (_path, container, source_file_path, reporter); + if (path == null) { + return ; + } + + try { + string content = null; + FileUtils.get_contents (path, out content); + _language = Language.from_path (path); + code = (owned) content; + } catch (FileError err) { + string node_segment = (container is Api.Package)? "" : container.get_full_name () + ": "; + reporter.simple_error ("%s: %s{{{".printf (source_file_path, node_segment), + "Can't read file '%s': %s", path, err.message); + } + } + + private inline bool is_empty_string (string line) { + for (int i = 0; line[i] != '\0'; i++) { + if (line[i].isspace () == false) { + return false; + } + } + + return true; + } + + private string strip_code (string code) { + string[] lines = code.split ("\n"); + for (int i = lines.length - 1; i >= 0 && is_empty_string (lines[i]); i--) { + lines[i] = null; + } + + string** _lines = lines; + for (int i = 0; lines[i] != null && is_empty_string (lines[i]); i++) { + _lines = &lines[i + 1]; + } + + return string.joinv ("\n", (string[]) _lines); + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + string[] splitted = code.split ("\n", 2); + if (splitted[0].strip () == "") { + code = splitted[1] ?? ""; + } else if (splitted[0].has_prefix ("#!")) { + unowned string start = (string) (((char*) splitted[0]) + 2); + if (start.has_prefix ("include:")) { + start = (string) (((char*) start) + 8); + string path = start.strip (); + load_source_code (path, container, file_path, reporter); + } else { + string name = start._strip ().down (); + _language = Language.from_string (name); + code = splitted[1] ?? ""; + if (_language == null && name != "none") { + string node_segment = (container is Api.Package)? "" : container.get_full_name () + ": "; + reporter.simple_warning ("%s: %s{{{".printf (file_path, node_segment), + "Unsupported programming language '%s'", name); + } + } + } + + code = strip_code (code); + + if (_language == Language.VALA) { + highlighted_code = api_root.highlighter.highlight_vala (code); + } else if (_language == Language.XML) { + highlighted_code = api_root.highlighter.highlight_xml (code); + } else if (_language == Language.C) { + highlighted_code = api_root.highlighter.highlight_c (code); + } else { + highlighted_code = new Run (Run.Style.MONOSPACED); + highlighted_code.content.add (new Text (code)); + } + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_source_code (this); + } + + public override void accept_children (ContentVisitor visitor) { + if (highlighted_code != null) { + highlighted_code.accept (visitor); + } + } + + public override bool is_empty () { + // empty source blocks are visible as well + return false; + } + + public override ContentElement copy (ContentElement? new_parent = null) { + SourceCode source_code = new SourceCode (); + source_code.parent = new_parent; + + source_code.language = language; + source_code.code = code; + + return source_code; + } + } diff --cc libvaladoc/content/styleattributes.vala index 000000000,c24893aaf..69fdb83e4 mode 000000,100644..100644 --- a/libvaladoc/content/styleattributes.vala +++ b/libvaladoc/content/styleattributes.vala @@@ -1,0 -1,116 +1,114 @@@ + /* styleattributes.vala + * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public enum Valadoc.Content.HorizontalAlign { + LEFT, + RIGHT, + CENTER; + + public static HorizontalAlign? from_string (string str) { + switch (str) { + case "left": + return HorizontalAlign.LEFT; + + case "right": + return HorizontalAlign.RIGHT; + + case "center": + return HorizontalAlign.CENTER; + } + + return null; + } + + public unowned string to_string () { + switch (this) { + case HorizontalAlign.LEFT: + return "left"; + + case HorizontalAlign.RIGHT: + return "right"; + + case HorizontalAlign.CENTER: + return "center"; + } + + assert (true); + return ""; + } + } + + public enum Valadoc.Content.VerticalAlign { + TOP, + MIDDLE, + BOTTOM; + + public static VerticalAlign? from_string (string str) { + switch (str) { + case "top": + return VerticalAlign.TOP; + + case "middle": + return VerticalAlign.MIDDLE; + + case "bottom": + return VerticalAlign.BOTTOM; + } + + return null; + } + + public unowned string to_string () { + switch (this) { + case VerticalAlign.TOP: + return "top"; + + case VerticalAlign.MIDDLE: + return "middle"; + + case VerticalAlign.BOTTOM: + return "bottom"; + } + + assert (true); + return ""; + } + } + + public interface Valadoc.Content.StyleAttributes : ContentElement { + public abstract HorizontalAlign? horizontal_align { + get; + set; + } + + public abstract VerticalAlign? vertical_align { + get; + set; + } + + public abstract string? style { + get; + set; + } + } + diff --cc libvaladoc/content/symbollink.vala index 000000000,70e528495..7ea01b837 mode 000000,100644..100644 --- a/libvaladoc/content/symbollink.vala +++ b/libvaladoc/content/symbollink.vala @@@ -1,0 -1,72 +1,70 @@@ + /* symbollink.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2014 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.SymbolLink : InlineContent, Inline { + public Api.Node symbol { + get; + set; + } + + public string given_symbol_name { + get; + set; + } + + internal SymbolLink (Api.Node? symbol = null, string? given_symbol_name = null) { + base (); + _symbol = symbol; + _given_symbol_name = given_symbol_name; + } + + public override void configure (Settings settings, ResourceLocator locator) { + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_symbol_link (this); + } + + public override bool is_empty () { + return false; + } + + public override ContentElement copy (ContentElement? new_parent = null) { + SymbolLink link = new SymbolLink (symbol, _given_symbol_name); + link.parent = new_parent; + + foreach (Inline element in content) { + Inline copy = element.copy (link) as Inline; + link.content.add (copy); + } + + return link; + } + } + diff --cc libvaladoc/content/table.vala index 000000000,0a7941a04..baae1a039 mode 000000,100644..100644 --- a/libvaladoc/content/table.vala +++ b/libvaladoc/content/table.vala @@@ -1,0 -1,79 +1,77 @@@ + /* table.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.Table : ContentElement, Block { - public Gee.List rows { ++ public Vala.List rows { + get { + return _rows; + } + } + - private Gee.List _rows; ++ private Vala.List _rows; + + internal Table () { + base (); - _rows = new ArrayList (); ++ _rows = new Vala.ArrayList (); + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + // Check the table consistency in term of row/column number + + // Check individual rows + foreach (var row in _rows) { + row.parent = this; + row.check (api_root, container, file_path, reporter, settings); + } + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_table (this); + } + + public override void accept_children (ContentVisitor visitor) { + foreach (TableRow element in _rows) { + element.accept (visitor); + } + } + + public override bool is_empty () { + return false; + } + + public override ContentElement copy (ContentElement? new_parent = null) { + Table table = new Table (); + table.parent = new_parent; + + foreach (var row in _rows) { + TableRow copy = row.copy (table) as TableRow; + table.rows.add (copy); + } + + return table; + } + } + diff --cc libvaladoc/content/tablecell.vala index 000000000,50c7fd4ba..9bc120888 mode 000000,100644..100644 --- a/libvaladoc/content/tablecell.vala +++ b/libvaladoc/content/tablecell.vala @@@ -1,0 -1,93 +1,91 @@@ + /* tablecell.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.TableCell : InlineContent, StyleAttributes { + public HorizontalAlign? horizontal_align { + get; + set; + } + + public VerticalAlign? vertical_align { + get; + set; + } + + public string? style { + get; + set; + } + + public int colspan { + get; + set; + } + + public int rowspan { + get; + set; + } + + internal TableCell () { + base (); + _colspan = 1; + _rowspan = 1; + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + // Check inline content + base.check (api_root, container, file_path, reporter, settings); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_table_cell (this); + } + + public override bool is_empty () { + // empty cells are displayed as well + return false; + } + + public override ContentElement copy (ContentElement? new_parent = null) { + TableCell cell = new TableCell (); + cell.parent = new_parent; + + cell.horizontal_align = horizontal_align; + cell.vertical_align = vertical_align; + cell.colspan = colspan; + cell.rowspan = rowspan; + cell.style = style; + + foreach (Inline element in content) { + Inline copy = element.copy (cell) as Inline; + cell.content.add (copy); + } + + return cell; + } + } + diff --cc libvaladoc/content/tablerow.vala index 000000000,d8759caac..97b024b75 mode 000000,100644..100644 --- a/libvaladoc/content/tablerow.vala +++ b/libvaladoc/content/tablerow.vala @@@ -1,0 -1,77 +1,75 @@@ + /* tablerow.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.TableRow : ContentElement { - public Gee.List cells { ++ public Vala.List cells { + get { + return _cells; + } + } + - private Gee.List _cells; ++ private Vala.List _cells; + + internal TableRow () { + base (); - _cells = new ArrayList (); ++ _cells = new Vala.ArrayList (); + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + // Check individual cells + foreach (var cell in _cells) { + cell.parent = this; + cell.check (api_root, container, file_path, reporter, settings); + } + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_table_row (this); + } + + public override void accept_children (ContentVisitor visitor) { + foreach (TableCell element in _cells) { + element.accept (visitor); + } + } + + public override bool is_empty () { + return false; + } + + public override ContentElement copy (ContentElement? new_parent = null) { + TableRow row = new TableRow (); + row.parent = new_parent; + + foreach (TableCell cell in _cells) { + TableCell copy = cell.copy (row) as TableCell; + row.cells.add (copy); + } + + return row; + } + } + diff --cc libvaladoc/content/taglet.vala index 000000000,c492621a1..d2efb4300 mode 000000,100644..100644 --- a/libvaladoc/content/taglet.vala +++ b/libvaladoc/content/taglet.vala @@@ -1,0 -1,38 +1,36 @@@ + /* taglet.vala + * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public interface Valadoc.Content.Taglet : ContentElement { + + public abstract Rule? get_parser_rule (Rule run_rule); + - public virtual Gee.List? get_inheritable_documentation () { ++ public virtual Vala.List? get_inheritable_documentation () { + return null; + } + + public virtual bool inheritable (Taglet taglet) { + return false; + } + } + diff --cc libvaladoc/content/text.vala index 000000000,42ce1e15f..ab42864db mode 000000,100644..100644 --- a/libvaladoc/content/text.vala +++ b/libvaladoc/content/text.vala @@@ -1,0 -1,63 +1,61 @@@ + /* text.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.Text : ContentElement, Inline { + public string content { + get; + set; + } + + construct { + _content = ""; + } + + internal Text (string? text = null) { + if (text != null) { + _content = text; + } + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_text (this); + } + + + public override bool is_empty () { + return content == ""; + } + + public override ContentElement copy (ContentElement? new_parent = null) { + Text text = new Text (content); + text.parent = new_parent; + return text; + } + } + diff --cc libvaladoc/content/warning.vala index 000000000,445a447f8..e44173269 mode 000000,100644..100644 --- a/libvaladoc/content/warning.vala +++ b/libvaladoc/content/warning.vala @@@ -1,0 -1,55 +1,53 @@@ + /* warning.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.Warning : BlockContent, Block { + internal Warning () { + base (); + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + // Check inline content + base.check (api_root, container, file_path, reporter, settings); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_warning (this); + } + + public override ContentElement copy (ContentElement? new_parent = null) { + Warning warning = new Warning (); + warning.parent = new_parent; + + foreach (Block block in content) { + Block copy = block.copy (warning) as Block; + warning.content.add (copy); + } + + return warning; + } + } + diff --cc libvaladoc/content/wikilink.vala index 000000000,1c180316b..cb62887a5 mode 000000,100644..100644 --- a/libvaladoc/content/wikilink.vala +++ b/libvaladoc/content/wikilink.vala @@@ -1,0 -1,78 +1,76 @@@ + /* link.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + -using Gee; - + + public class Valadoc.Content.WikiLink : InlineContent, Inline { + public WikiPage page { + internal set; + get; + } + + public string name { + get; + set; + } + + internal WikiLink () { + base (); + } + + public override void check (Api.Tree api_root, Api.Node container, string file_path, + ErrorReporter reporter, Settings settings) + { + base.check (api_root, container, file_path, reporter, settings); + + page = api_root.wikitree.search (name); + if (page == null) { + string node_segment = (container is Api.Package)? "" : container.get_full_name () + ": "; + reporter.simple_warning ("%s: %s[[".printf (file_path, node_segment), + "'%s' does not exist", name); + return ; + } + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_wiki_link (this); + } + + public override bool is_empty () { + return false; + } + + public override ContentElement copy (ContentElement? new_parent = null) { + WikiLink link = new WikiLink (); + link.parent = new_parent; + + link.page = page; + link.name = name; + + foreach (Inline element in content) { + Inline copy = element.copy (link) as Inline; + link.content.add (copy); + } + + return link; + } + } diff --cc libvaladoc/ctyperesolver.vala index 000000000,6901d960e..2909df682 mode 000000,100644..100644 --- a/libvaladoc/ctyperesolver.vala +++ b/libvaladoc/ctyperesolver.vala @@@ -1,0 -1,402 +1,401 @@@ + /* ctyperesolver.vala + * + * Copyright (C) 2010 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Valadoc.Api; -using Gee; + ++using Valadoc.Api; + + /** + * Resolves symbols by C-names + */ + public class Valadoc.CTypeResolver : Visitor { - private Map types = new HashMap (); - private Map nodes = new HashMap (); ++ private Vala.Map types = new Vala.HashMap (str_hash, str_equal); ++ private Vala.Map nodes = new Vala.HashMap (str_hash, str_equal); + private Api.Tree tree; + + public CTypeResolver (Api.Tree tree) { + tree.accept (this); + this.tree = tree; + } + + private string convert_array_to_camelcase (string[] elements) { + StringBuilder builder = new StringBuilder (); + + foreach (string element in elements) { + builder.append_c (((char[])element)[0].toupper ()); + builder.append (element.next_char ().down ()); + } + + return (owned) builder.str; + } + + private bool is_capitalized_and_underscored (string name) { + unowned string pos; + + unichar c = name.get_char (); + + + if (c < 'A' || c > 'Z') { + return false; + } + + bool last_was_underscore = false; + for (c = (pos = name).get_char (); c != '\0' ; c = (pos = pos.next_char ()).get_char ()) { + if ((c != '_' && !(c >= 'A' && c <= 'Z')) || (last_was_underscore && c == '_')) { + return false; + } + + last_was_underscore = (c == '_'); + } + + return !last_was_underscore; + } + + private string? translate_cname_to_g (string name) { + if (is_capitalized_and_underscored (name)) { + string[] segments = name.split ("_"); + unowned string last_segment = segments[segments.length - 1]; + if (last_segment != "ERROR") { + return null; + } + + return convert_array_to_camelcase (segments); + } + + int length = name.length; + if (length > 5 && name.has_suffix ("Iface")) { + return name.substring (0, length - 5); + } else if (length > 5 && name.has_suffix ("Class")) { + return name.substring (0, length - 5); + } + + return null; + } + + public Api.TypeSymbol? resolve_symbol_type (string name) { + TypeSymbol? symbol = types.get (name); + if (symbol != null) { + return symbol; + } + + if (is_capitalized_and_underscored (name)) { + string[] segments = name.split ("_"); + + if (segments[segments.length - 1] == "TYPE") { + segments.resize (segments.length - 1); + return types.get (convert_array_to_camelcase (segments)); + } else if (segments.length > 2 && segments[1] == "TYPE") { + string[] _segments = segments[1:segments.length]; + _segments[0] = segments[0]; + return types.get (convert_array_to_camelcase (_segments)); + } + } + + return null; + } + + /** + * Resolves symbols by C-names + * + * @param _name a C-name + * @return the resolved node or null + */ + public Api.Node? resolve_symbol (Api.Node? element, string _name) { + string name = _name.replace ("->", ".").replace ("-", "_"); + + if (element != null && name.has_prefix (":")) { + Item parent = element; + while (parent != null && !(parent is Class || parent is Interface)) { + parent = parent.parent; + } + + if (parent is Class && ((Class) parent).get_cname () != null) { + name = ((Class) parent).get_cname () + name; + } else if (parent is Interface && ((Interface) parent).get_cname () != null) { + name = ((Interface) parent).get_cname () + name; + } else { + return null; + } + + } + + Api.Node? node = nodes.get (name); + if (node != null) { + return node; + } + + string? alternative = translate_cname_to_g (name); + if (alternative != null) { + return nodes.get (alternative); + } + + if (element != null && name.has_prefix (":")) { + if (element is Class && ((Class) element).get_cname () != null) { + return nodes.get (((Class) element).get_cname () + "." + name); + } else if (element is Struct && ((Struct) element).get_cname () != null) { + return nodes.get (((Struct) element).get_cname () + "." + name); + } + } + + if (name == "dgettext") { + return nodes.get ("g_dgettext"); + } else if (name == "printf") { + return this.tree.search_symbol_str (null, "GLib.FileStream.printf"); + } + + int dotpos = name.index_of_char ('.'); + if (dotpos > 0) { + string fst = name.substring (0, dotpos); + string snd = name.substring (dotpos + 1); + return nodes.get (fst + ":" + snd); + } + + return null; + } + + private void register_symbol_type (string? name, Api.TypeSymbol symbol) { + if (name != null) { + types.set (name, symbol); + } + } + + private void register_symbol (string? name, Api.Node node) { + if (name != null) { + nodes.set (name.replace ("-", "_"), node); + } + } + + private string? get_parent_type_cname (Item item) { + string parent_cname = null; + if (item.parent is Class) { + parent_cname = ((Class) item.parent).get_cname (); + } else if (item.parent is Interface) { + parent_cname = ((Interface) item.parent).get_cname (); + } else if (item.parent is Struct) { + parent_cname = ((Struct) item.parent).get_cname (); + } else if (item.parent is ErrorDomain) { + parent_cname = ((ErrorDomain) item.parent).get_cname (); + } else if (item.parent is Api.Enum) { + parent_cname = ((Api.Enum) item.parent).get_cname (); + } else { + assert (true); + } + return parent_cname; + } + + /** + * {@inheritDoc} + */ + public override void visit_tree (Api.Tree item) { + item.accept_children (this); + } + + /** + * {@inheritDoc} + */ + public override void visit_package (Package item) { + item.accept_all_children (this, false); + } + + /** + * {@inheritDoc} + */ + public override void visit_namespace (Namespace item) { + item.accept_all_children (this, false); + } + + /** + * {@inheritDoc} + */ + public override void visit_interface (Interface item) { + register_symbol (item.get_cname (), item); + item.accept_all_children (this, false); + } + + /** + * {@inheritDoc} + */ + public override void visit_class (Class item) { + register_symbol_type (item.get_type_id (), item); + register_symbol (item.get_cname (), item); + item.accept_all_children (this, false); + } + + /** + * {@inheritDoc} + */ + public override void visit_struct (Struct item) { + register_symbol_type (item.get_type_id (), item); + register_symbol (item.get_cname (), item); + item.accept_all_children (this, false); + } + + /** + * {@inheritDoc} + */ + public override void visit_property (Property item) { + string parent_cname = get_parent_type_cname (item); + assert (parent_cname != null); + + string cname = item.get_cname (); + register_symbol (parent_cname+":"+cname, item); + + - Collection interfaces = null; - Collection classes = null; ++ Vala.Collection interfaces = null; ++ Vala.Collection classes = null; + + if (item.parent is Interface) { + interfaces = ((Api.Interface) item.parent).get_known_related_interfaces (); + classes = ((Api.Interface) item.parent).get_known_implementations (); + } else if (item.parent is Class) { + interfaces = ((Api.Class) item.parent).get_known_derived_interfaces (); + classes = ((Api.Class) item.parent).get_known_child_classes (); + } + + foreach (Interface iface in interfaces) { + register_symbol (iface.get_cname () + ":" + cname, item); + } + + foreach (Class cl in classes) { + register_symbol (cl.get_cname () + ":" + cname, item); + } + } + + /** + * {@inheritDoc} + */ + public override void visit_field (Field item) { + if (item.parent is Namespace || item.is_static) { + register_symbol (item.get_cname (), item); + } else { + string parent_cname = get_parent_type_cname (item); + if (parent_cname != null) { + register_symbol (parent_cname + "." + item.get_cname (), item); + } + } + } + + /** + * {@inheritDoc} + */ + public override void visit_constant (Constant item) { + register_symbol (item.get_cname (), item); + } + + /** + * {@inheritDoc} + */ + public override void visit_delegate (Delegate item) { + register_symbol (item.get_cname (), item); + } + + /** + * {@inheritDoc} + */ + public override void visit_signal (Api.Signal item) { + string parent_cname = get_parent_type_cname (item); + assert (parent_cname != null); + + string? default_impl_cname = item.get_default_impl_cname (); + string cname = item.get_cname (); + register_symbol (parent_cname+"::"+cname, item); + + if (item.is_virtual) { + // only supported by classes + register_symbol (parent_cname + "Class." + item.name, item); + } + - Collection interfaces = null; - Collection classes = null; ++ Vala.Collection interfaces = null; ++ Vala.Collection classes = null; + + if (item.parent is Interface) { + interfaces = ((Api.Interface) item.parent).get_known_related_interfaces (); + classes = ((Api.Interface) item.parent).get_known_implementations (); + } else if (item.parent is Class) { + interfaces = ((Api.Class) item.parent).get_known_derived_interfaces (); + classes = ((Api.Class) item.parent).get_known_child_classes (); + } + + foreach (Interface iface in interfaces) { + register_symbol (iface.get_cname () + "::" + cname, item); + } + + foreach (Class cl in classes) { + register_symbol (cl.get_cname () + "::" + cname, item); + } + + if (default_impl_cname != null) { + register_symbol (default_impl_cname, item); + } + } + + /** + * {@inheritDoc} + */ + public override void visit_method (Method item) { + if (item.is_abstract || item.is_virtual || item.is_override) { + string parent_cname = get_parent_type_cname (item); + + if (item.parent is Class) { + register_symbol (parent_cname + "Class." + item.name, item); + } else { + register_symbol (parent_cname + "Iface." + item.name, item); + } + + // Allow to resolve invalid links: + register_symbol (parent_cname + "." + item.name, item); + } + + register_symbol (item.get_cname (), item); + } + + /** + * {@inheritDoc} + */ + public override void visit_error_domain (ErrorDomain item) { + register_symbol (item.get_cname (), item); + item.accept_all_children (this, false); + } + + /** + * {@inheritDoc} + */ + public override void visit_error_code (ErrorCode item) { + register_symbol (item.get_cname (), item); + } + + /** + * {@inheritDoc} + */ + public override void visit_enum (Api.Enum item) { + register_symbol (item.get_cname (), item); + item.accept_all_children (this, false); + } + + /** + * {@inheritDoc} + */ + public override void visit_enum_value (Api.EnumValue item) { + register_symbol (item.get_cname (), item); + } + } + + diff --cc libvaladoc/devhelp-markupwriter.vala index 000000000,ae524384c..d86808026 mode 000000,100644..100644 --- a/libvaladoc/devhelp-markupwriter.vala +++ b/libvaladoc/devhelp-markupwriter.vala @@@ -1,0 -1,93 +1,94 @@@ + /* devhelp-markupwriter.vala + * + * Copyright (C) 2008-2009 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + ++ + public class Valadoc.Devhelp.MarkupWriter : Valadoc.MarkupWriter { + + public MarkupWriter (FileStream stream, bool xml_declaration = true) { + // avoid broken implicit copy + unowned FileStream _stream = stream; + + base ((str) => { _stream.printf (str); }, xml_declaration); + } + + protected override bool inline_element (string name) { + return name != "book"; + } + + protected override bool content_inline_element (string name) { + return name == "keyword" + || name == "sub"; + } + + public MarkupWriter start_book (string title, string lang, string link, string name, string version, string author) { + this.start_tag ("book", {"xmlns", "http://www.devhelp.net/book", + "title", title, + "language", lang, + "name", name, + "version", version, + "author", author, + "link", link}); + return this; + } + + public MarkupWriter end_book () { + this.end_tag ("book"); + return this; + } + + public MarkupWriter start_functions () { + this.start_tag ("functions"); + return this; + } + + public MarkupWriter end_functions () { + this.end_tag ("functions"); + return this; + } + + public MarkupWriter start_chapters () { + this.start_tag ("chapters"); + return this; + } + + public MarkupWriter end_chapters () { + this.end_tag ("chapters"); + return this; + } + + public MarkupWriter start_sub (string name, string link) { + this.start_tag ("sub", {"name", name, "link", link}); + return this; + } + + public MarkupWriter end_sub () { + this.end_tag ("sub"); + return this; + } + + public MarkupWriter keyword (string name, string type, string link) { + this.start_tag ("keyword", {"type", type, "name", name, "link", link}); + this.end_tag ("keyword"); + return this; + } + } + diff --cc libvaladoc/doclet.vala index 000000000,c8c580444..d099bf5d4 mode 000000,100644..100644 --- a/libvaladoc/doclet.vala +++ b/libvaladoc/doclet.vala @@@ -1,0 -1,52 +1,51 @@@ + /* doclet.vala + * + * Copyright (C) 2008-2009 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Brosch Florian + */ + -using Gee; + + /** + * A plugin register function for doclets + * + * @see ModuleLoader + */ + [CCode (has_target = false)] + public delegate Type Valadoc.DocletRegisterFunction (ModuleLoader module_loader); + + + + /** + * Provides a mechanism to inspect the API & documentation of programs and libraries + */ + public interface Valadoc.Doclet : GLib.Object { + + /** + * Allows the doclet to inspect the given {@link Api.Tree} + * + * @param settings various configurations + * @param tree the tree to inspect + * @param reporter the reporter to use + * @see Content.ContentVisitor + * @see Api.Visitor + */ + public abstract void process (Settings settings, Api.Tree tree, ErrorReporter reporter); + } + + diff --cc libvaladoc/documentation/documentation.vala index 000000000,6df57eaa4..da366840e mode 000000,100644..100644 --- a/libvaladoc/documentation/documentation.vala +++ b/libvaladoc/documentation/documentation.vala @@@ -1,0 -1,39 +1,38 @@@ + /* documentation.vala + * + * Copyright (C) 2008-2009 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using Gee; + + public interface Valadoc.Documentation : Object { + + /** + * The corresponding package + */ + public abstract Api.Package? package { + get; + } + + /** + * The corresponding file name + */ + public abstract string? get_filename (); + } + diff --cc libvaladoc/documentation/documentationparser.vala index 000000000,fe6d68505..878f8a180 mode 000000,100644..100644 --- a/libvaladoc/documentation/documentationparser.vala +++ b/libvaladoc/documentation/documentationparser.vala @@@ -1,0 -1,897 +1,896 @@@ + /* documentationparser.vala + * + * Copyright (C) 2008-2009 Didier Villevalois + * Copyright (C) 2008-2012 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Didier 'Ptitjes Villevalois + */ + ++ + using Valadoc.Content; + using Valadoc.Importer; -using Gee; - + + public class Valadoc.DocumentationParser : Object, ResourceLocator { - private HashMap metadata; ++ private Vala.HashMap metadata; + private Importer.InternalIdRegistrar id_registrar; + + + public DocumentationParser (Settings settings, ErrorReporter reporter, + Api.Tree tree, ModuleLoader modules) + { + _settings = settings; + _reporter = reporter; + _tree = tree; + _modules = modules; + + _factory = new ContentFactory (_settings, this, _modules); + + _wiki_scanner = new WikiScanner (_settings); + _wiki_parser = new Parser (_settings, _wiki_scanner, _reporter); + _wiki_scanner.set_parser (_wiki_parser); + + _comment_scanner = new CommentScanner (_settings); + _comment_parser = new Parser (_settings, _comment_scanner, _reporter); + _comment_scanner.set_parser (_comment_parser); + + gtkdoc_parser = new Gtkdoc.Parser (settings, reporter, tree, modules); + gtkdoc_markdown_parser = new Gtkdoc.MarkdownParser (settings, reporter, tree, modules); + + - metadata = new HashMap (); ++ metadata = new Vala.HashMap (); + id_registrar = new Importer.InternalIdRegistrar (); + + init_valadoc_rules (); + } + + private Gtkdoc.Parser gtkdoc_parser; + private Gtkdoc.MarkdownParser gtkdoc_markdown_parser; + + private Settings _settings; + private ErrorReporter _reporter; + private Api.Tree _tree; + private ModuleLoader _modules; + + private ContentFactory _factory; + private WikiScanner _wiki_scanner; + private CommentScanner _comment_scanner; + private Parser _wiki_parser; + private Parser _comment_parser; + + private Parser _parser; + private Scanner _scanner; + + public Comment? parse (Api.Node element, Api.SourceComment comment) { + if (comment is Api.GirSourceComment) { + Api.GirSourceComment gir_comment = (Api.GirSourceComment) comment; + GirMetaData metadata = get_metadata_for_comment (gir_comment); + + if (metadata.is_docbook) { + Comment doc_comment = gtkdoc_parser.parse (element, gir_comment, metadata, id_registrar); + return doc_comment; + } else { + Comment doc_comment = gtkdoc_markdown_parser.parse (element, gir_comment, metadata, id_registrar); + return doc_comment; + } + } else { + return parse_comment_str (element, comment.content, comment.file.get_name (), + comment.first_line, comment.first_column); + } + } + + public Comment? parse_comment_str (Api.Node element, string content, string filename, + int first_line, int first_column) + { + try { + Comment doc_comment = parse_comment (content, filename, first_line, first_column); + return doc_comment; + } catch (ParserError error) { + return null; + } + } + + public Page? parse_wikipage (Api.Package pkg, WikiPage page) { + if (page.documentation != null) { + return page.documentation; + } + + if (page.documentation_str == null) { + return null; + } + + try { + Page documentation = parse_wiki (page.documentation_str, page.get_filename ()); + return documentation; + } catch (ParserError error) { + return null; + } + } + + private Comment parse_comment (string content, string filename, int first_line, int first_column) + throws ParserError + { + _parser = _comment_parser; + _scanner = _comment_scanner; + _stack.clear (); + _comment_parser.parse (content, filename, first_line, first_column); + return (Comment) pop (); + } + + private Page parse_wiki (string content, string filename) throws ParserError { + _parser = _wiki_parser; + _scanner = _wiki_scanner; + _stack.clear (); + _wiki_parser.parse (content, filename, 0, 0); + return (Page) pop (); + } + + public void check (Api.Node element, Comment comment) { + comment.check (_tree, element, element.get_source_file ().relative_path, _reporter, _settings); + } + + public void check_wikipage (Api.Package package, WikiPage page) { + page.documentation.check (_tree, package, page.path, _reporter, _settings); + } + + public void transform_inheritdoc (Api.Node taglet_owner, Taglets.InheritDoc taglet) { + if (taglet.inherited == null) { + return ; + } + + + taglet.inherited.parse_comments (_settings, this); + if (taglet.inherited.documentation == null) { + return ; + } + + + taglet.inherited.check_comments (_settings, this); + + taglet.transform (_tree, taglet_owner, taglet_owner.get_source_file ().get_name (), _reporter, _settings); + } + + private GirMetaData get_metadata_for_comment (Api.GirSourceComment gir_comment) { + GirMetaData metadata = metadata.get (gir_comment.file); + if (metadata != null) { + return metadata; + } + + metadata = new GirMetaData (gir_comment.file.relative_path, _settings.metadata_directories, _reporter); + if (metadata.index_sgml != null) { + id_registrar.read_index_sgml_file (metadata.index_sgml, metadata.index_sgml_online, _reporter); + } + + this.metadata.set (gir_comment.file, metadata); + return metadata; + } + + public string resolve (string path) { + return path; + } + - private ArrayList _stack = new ArrayList (); ++ private Vala.ArrayList _stack = new Vala.ArrayList (); + + private void push (Object element) { + _stack.add (element); + } + + private Object peek (int offset = -1) { + assert (_stack.size >= - offset); + return _stack.get (_stack.size + offset); + } + + private Object pop () { + Object node = peek (); + _stack.remove_at (_stack.size - 1); + return node; + } + + private Rule multiline_block_run; + private Rule multiline_run; + private int current_level = 0; + private int[] levels = new int[0]; + + private void new_list_item (Content.List.Bullet bullet) throws ParserError { + var new_item = _factory.create_list_item (); + + Content.List list = null; + if (levels.length >= 1) { + if (current_level > levels[levels.length - 1]) { + list = _factory.create_list (); + list.bullet = bullet; + + var current_item = peek () as ListItem; + current_item.content.add (list); + push (list); + + levels += current_level; + } else { + bool poped_some_lists = false; + while (current_level < levels[levels.length - 1]) { + // Pop current item and list + pop (); + pop (); + levels.resize (levels.length - 1); + poped_some_lists = true; + } + list = peek (-2) as Content.List; + + if (!poped_some_lists && bullet == Content.List.Bullet.NONE) { + ((Paragraph) ((ListItem) peek ()).content[0]).content.add (_factory.create_text (" ")); + return; + } else if (list.bullet != bullet) { + _parser.error (null, "Invalid bullet type '%s': expected '%s'" + .printf (bullet_type_string (bullet), bullet_type_string (list.bullet))); + return; + } + + pop (); + } + } else { + list = _factory.create_list (); + list.bullet = bullet; + + ((BlockContent) peek ()).content.add (list); + push (list); + + levels = new int[0]; + levels += current_level; + } + + list.items.add (new_item); + push (new_item); + } + + private string bullet_type_string (Content.List.Bullet bullet) { + switch (bullet) { + case Content.List.Bullet.NONE: + return "."; + case Content.List.Bullet.UNORDERED: + return "*"; + case Content.List.Bullet.ORDERED_NUMBER: + return "1."; + case Content.List.Bullet.ORDERED_LOWER_CASE_ALPHA: + return "a."; + case Content.List.Bullet.ORDERED_UPPER_CASE_ALPHA: + return "A."; + case Content.List.Bullet.ORDERED_LOWER_CASE_ROMAN: + return "i."; + case Content.List.Bullet.ORDERED_UPPER_CASE_ROMAN: + return "I."; + } + return ""; + } + + private void finish_list () { + while (peek () is ListItem) { + pop (); + pop (); + levels.resize (levels.length - 1); + } + } + + private void add_content_string (string str) { + var text = peek () as Text; + if (text == null) { + push (text = _factory.create_text ()); + } + text.content += str; + } + + private void add_content_space () { + // avoid double spaces + var head = peek (); + Text text_node = null; + + if (head is Text) { + text_node = (Text) head; + } else if (head is InlineContent && ((InlineContent) head).content.size > 0 + && ((InlineContent) head).content.last () is Text) + { + text_node = (Text) ((InlineContent) head).content.last (); + } else { + text_node = _factory.create_text (); + ((InlineContent) peek ()).content.add (text_node); + } + + if (!text_node.content.has_suffix (" ")) { + text_node.content += " "; + } + } + + private void init_valadoc_rules () { + // Inline rules + + StubRule run = new StubRule (); + run.set_name ("Run"); + + TokenType.Action add_text = (token) => { + add_content_string (token.to_string ()); + }; + + TokenType space = TokenType.SPACE.action ((token) => { add_content_space (); }); + TokenType word = TokenType.any_word ().action (add_text); + + Rule optional_invisible_spaces = + Rule.option ({ + Rule.many ({ TokenType.SPACE }) + }); + + Rule optional_spaces = + Rule.option ({ + Rule.many ({ + TokenType.SPACE.action ((token) => { add_content_space (); }) + }) + }); + + + Rule text = + Rule.many ({ + Rule.one_of ({ + TokenType.BREAK.action ((token) => { add_content_string ("\n"); }), + TokenType.CLOSED_BRACE.action (add_text), + TokenType.MINUS.action (add_text), + TokenType.ALIGN_BOTTOM.action (add_text), + TokenType.ALIGN_TOP.action (add_text), + TokenType.GREATER_THAN.action (add_text), + TokenType.LESS_THAN.action (add_text), + TokenType.DOUBLE_PIPE.action (add_text), + TokenType.PIPE.action (add_text), + TokenType.ALIGN_RIGHT.action (add_text), + TokenType.ALIGN_CENTER.action (add_text), + TokenType.EQUAL_1.action (add_text), + TokenType.EQUAL_2.action (add_text), + TokenType.EQUAL_3.action (add_text), + TokenType.EQUAL_4.action (add_text), + TokenType.EQUAL_5.action (add_text), + word + }), + Rule.option ({ space }) + }) + .set_name ("Text") + .set_start (() => { push (_factory.create_text ()); }); + + Rule run_with_spaces = + Rule.seq ({ + Rule.many ({ + Rule.one_of ({ + optional_invisible_spaces, + run + }) + }) + }) + .set_name ("RunWithSpaces"); + + multiline_run = Rule.many ({ + run_with_spaces, + TokenType.EOL.action (() => { add_content_space (); }) + }) + .set_name ("MultiLineRun"); + + Rule inline_taglet = + Rule.seq ({ + TokenType.OPEN_BRACE, + Rule.option ({ + TokenType.AROBASE, + TokenType.any_word ().action ((token) => { + var taglet = _factory.create_taglet (token.to_string ()); + if (!(taglet is Inline)) { + _parser.error (null, "Invalid taglet in this context: %s".printf (token.to_string ())); + } + push (taglet); + Rule? taglet_rule = taglet.get_parser_rule (multiline_run); + if (taglet_rule != null) { + _parser.push_rule (Rule.seq ({ TokenType.SPACE, taglet_rule })); + } + }), + TokenType.CLOSED_BRACE + }) + .set_skip (() => { add_content_string ("{"); }) + }) + .set_name ("InlineTaglet"); + + //TODO: Find a nicer way to allow empty tags (''run?'' won't work) + Rule bold = + Rule.seq ({ + TokenType.SINGLE_QUOTE_2, + Rule.one_of ({ + TokenType.SINGLE_QUOTE_2, + Rule.seq ({ optional_spaces, run, TokenType.SINGLE_QUOTE_2 }) + }) + }) + .set_name ("Bold") + .set_start (() => { push (_factory.create_run (Run.Style.BOLD)); }); + + Rule italic = + Rule.seq ({ + TokenType.SLASH_2, + Rule.one_of ({ + TokenType.SLASH_2, + Rule.seq ({ optional_spaces, run, TokenType.SLASH_2 }) + }) + }) + .set_name ("Italic") + .set_start (() => { push (_factory.create_run (Run.Style.ITALIC)); }); + + Rule underlined = + Rule.seq ({ + TokenType.UNDERSCORE_2, + Rule.one_of ({ + TokenType.UNDERSCORE_2, + Rule.seq ({ optional_spaces, run, TokenType.UNDERSCORE_2 }) + }) + }) + .set_name ("Underlined") + .set_start (() => { push (_factory.create_run (Run.Style.UNDERLINED)); }); + + Rule monospace = + Rule.seq ({ + TokenType.BACK_QUOTE_2, + Rule.one_of ({ + TokenType.BACK_QUOTE_2, + Rule.seq ({ optional_spaces, run, TokenType.BACK_QUOTE_2 }) + }) + }) + .set_name ("Monospace") + .set_start (() => { push (_factory.create_run (Run.Style.MONOSPACED)); }); + + Rule embedded = + Rule.seq ({ + TokenType.DOUBLE_OPEN_BRACE.action (() => { ((WikiScanner) _scanner).set_url_escape_mode (true); }), + TokenType.any_word ().action ((token) => { ((Embedded) peek ()).url = token.to_string (); }), + Rule.option ({ + TokenType.PIPE.action (() => { ((WikiScanner) _scanner).set_url_escape_mode (false); }), + text + }) + .set_reduce (() => { var caption = pop () as Text; ((Embedded) peek ()).caption = caption.content; }), + TokenType.DOUBLE_CLOSED_BRACE.action (() => { ((WikiScanner) _scanner).set_url_escape_mode (false); }) + }) + .set_name ("Embedded") + .set_start (() => { push (_factory.create_embedded ()); }); + + Rule link = + Rule.seq ({ + TokenType.DOUBLE_OPEN_BRACKET.action (() => { ((WikiScanner) _scanner).set_url_escape_mode (true); }), + TokenType.any_word ().action ((token) => { + var url = token.to_string (); + if (url.has_suffix (".valadoc")) { + var link = _factory.create_wiki_link (); + link.name = url; + push (link); + } else { + var link = _factory.create_link (); + link.url = url; + push (link); + } + }), + Rule.option ({ + TokenType.PIPE.action (() => { ((WikiScanner) _scanner).set_url_escape_mode (false); }), + run + }), + TokenType.DOUBLE_CLOSED_BRACKET.action (() => { ((WikiScanner) _scanner).set_url_escape_mode (false); }) + }) + .set_name ("Link"); + Rule source_code = + Rule.seq ({ + TokenType.TRIPLE_OPEN_BRACE.action ((token) => { ((WikiScanner) _scanner).set_code_escape_mode (true); }), + TokenType.any_word ().action ((token) => { ((SourceCode) peek ()).code = token.to_string (); }), + TokenType.TRIPLE_CLOSED_BRACE.action ((token) => { ((WikiScanner) _scanner).set_code_escape_mode (false); }) + }) + .set_name ("SourceCode") + .set_start (() => { push (_factory.create_source_code ()); }); + + Rule.Action append_head_to_head2 = () => { + var head = (Inline) pop (); + ((InlineContent) peek ()).content.add (head); + }; + + Rule run_subrules = + Rule.one_of ({ + Rule.seq ({ + text + }) + .set_reduce (append_head_to_head2), + Rule.seq ({ + Rule.one_of ({ + inline_taglet, bold, italic, underlined, monospace, embedded, link, source_code + }) + .set_reduce (append_head_to_head2), + optional_spaces + }) + }); + + Rule run_arobase = + Rule.seq ({ + TokenType.AROBASE.action (add_text) + }) + .set_reduce (append_head_to_head2); + + run.set_rule ( + Rule.seq ({ + run_subrules, + optional_spaces, + Rule.option ({ + Rule.many ({ + Rule.one_of ({ + run_arobase, + run_subrules, + optional_spaces + }) + }) + }) + }) + .set_name ("Run") + ); + + + // Block rules + + Rule paragraph = + Rule.seq ({ + Rule.option ({ + Rule.one_of ({ + TokenType.ALIGN_CENTER.action (() => { ((Paragraph) peek ()).horizontal_align = HorizontalAlign.CENTER; }), + TokenType.ALIGN_RIGHT.action (() => { ((Paragraph) peek ()).horizontal_align = HorizontalAlign.RIGHT; }) + }) + }), + Rule.many ({ + run, + TokenType.EOL.action (() => { add_content_space (); }) + }) + }) + .set_name ("Paragraph") + .set_start (() => { push (_factory.create_paragraph ()); }) + .set_reduce (() => { + var head = (Paragraph) pop (); + ((BlockContent) peek ()).content.add (head); + + Text last_element = head.content.last () as Text; + if (last_element != null) { + last_element.content._chomp (); + } + }); + + Rule warning = + Rule.seq ({ + TokenType.str ("Warning:"), + optional_invisible_spaces, + Rule.many ({ + Rule.seq({optional_invisible_spaces, run}), + TokenType.EOL.action (() => { add_content_space (); }) + }) + }) + .set_name ("Warning") + .set_start (() => { push (_factory.create_paragraph ()); }) + .set_reduce (() => { + var head = _factory.create_warning (); + head.content.add ((Paragraph) pop ()); + ((BlockContent) peek ()).content.add (head); + + Text last_element = head.content.last () as Text; + if (last_element != null) { + last_element.content._chomp (); + } + }); + + Rule note = + Rule.seq ({ + TokenType.str ("Note:"), + optional_invisible_spaces, + Rule.many ({ + Rule.seq({optional_invisible_spaces, run}), + TokenType.EOL.action (() => { add_content_space (); }) + }) + }) + .set_name ("Note") + .set_start (() => { push (_factory.create_paragraph ()); }) + .set_reduce (() => { + var head = _factory.create_note (); + head.content.add ((Paragraph) pop ()); + ((BlockContent) peek ()).content.add (head); + + Text last_element = head.content.last () as Text; + if (last_element != null) { + last_element.content._chomp (); + } + }); + + Rule indented_item = + Rule.seq ({ + Rule.many ({ + TokenType.SPACE.action ((token) => { current_level++; }) + }), + Rule.option ({ + Rule.one_of ({ + TokenType.str (".").action ((token) => { new_list_item (Content.List.Bullet.NONE); }), + TokenType.str ("*").action ((token) => { new_list_item (Content.List.Bullet.UNORDERED); }), + TokenType.str ("#").action ((token) => { new_list_item (Content.List.Bullet.ORDERED); }), + TokenType.str ("1.").action ((token) => { new_list_item (Content.List.Bullet.ORDERED_NUMBER); }), + TokenType.str ("a.").action ((token) => { new_list_item (Content.List.Bullet.ORDERED_LOWER_CASE_ALPHA); }), + TokenType.str ("A.").action ((token) => { new_list_item (Content.List.Bullet.ORDERED_UPPER_CASE_ALPHA); }), + TokenType.str ("i.").action ((token) => { new_list_item (Content.List.Bullet.ORDERED_LOWER_CASE_ROMAN); }), + TokenType.str ("I.").action ((token) => { new_list_item (Content.List.Bullet.ORDERED_UPPER_CASE_ROMAN); }) + }), + optional_invisible_spaces + }) + .set_skip (() => { new_list_item (Content.List.Bullet.NONE); }), + Rule.seq ({ run }) + .set_start (() => { + var content = _factory.create_paragraph (); + ((ListItem) peek ()).content.add (content); + push (content); + }) + .set_reduce (() => { pop (); }), + TokenType.EOL + }) + .set_name ("IndentedItem") + .set_start (() => { current_level = 0; }) + .set_reduce (() => { + var content_list = ((ListItem) peek ()).content; + if (content_list.size > 0 && content_list.last () is Text) { + ((Text) content_list.last ()).content._chomp (); + } + }); + + Rule indented_blocks = + Rule.many ({ + indented_item + }) + .set_name ("IndentedBlocks") + .set_reduce (() => { finish_list (); }); + + Rule table_cell_attributes = + Rule.seq ({ + TokenType.LESS_THAN, + Rule.option ({ + Rule.one_of ({ + Rule.seq ({ + Rule.option ({ + Rule.one_of ({ + TokenType.ALIGN_RIGHT.action ((token) => { ((TableCell) peek ()).horizontal_align = HorizontalAlign.RIGHT; }), + TokenType.ALIGN_CENTER.action ((token) => { ((TableCell) peek ()).horizontal_align = HorizontalAlign.CENTER; }) + }) + }), + Rule.option ({ + Rule.one_of ({ + TokenType.ALIGN_TOP.action ((token) => { ((TableCell) peek ()).vertical_align = VerticalAlign.TOP; }), + TokenType.ALIGN_BOTTOM.action ((token) => { ((TableCell) peek ()).vertical_align = VerticalAlign.BOTTOM; }) + }) + }) + }), + TokenType.any_word ().action ((token) => { ((TableCell) peek ()).style = token.to_string (); }) + }) + }), + Rule.option ({ + Rule.one_of ({ + Rule.seq ({ + TokenType.PIPE, + TokenType.any_number ().action ((token) => { ((TableCell) peek ()).rowspan = token.to_int (); }) + }), + Rule.seq ({ + TokenType.MINUS, + TokenType.any_number ().action ((token) => { ((TableCell) peek ()).colspan = token.to_int (); }) + }) + }) + }), + TokenType.GREATER_THAN + }) + .set_name ("CellAttributes"); + Rule table_cell = + Rule.seq ({ + Rule.seq ({ + Rule.option ({ + table_cell_attributes + }), + optional_invisible_spaces, + run + }), + TokenType.DOUBLE_PIPE + }) + .set_name ("Cell") + .set_start (() => { push (_factory.create_table_cell ()); }) + .set_reduce (() => { + var head = (TableCell) pop (); + ((TableRow) peek ()).cells.add (head); + + if (head.content.size > 0 && head.content.last () is Text) { + ((Text) head.content.last ()).content._chomp (); + } + }); + Rule table_row = + Rule.seq ({ + TokenType.DOUBLE_PIPE, + Rule.many ({ + table_cell + }), + TokenType.EOL + }) + .set_name ("Row") + .set_start (() => { push (_factory.create_table_row ()); }) + .set_reduce (() => { + var head = (TableRow) pop (); + ((Table) peek ()).rows.add (head); + }); + Rule table = + Rule.seq ({ + Rule.many ({ + table_row + }) + }) + .set_name ("Table") + .set_start (() => { push (_factory.create_table ()); }) + .set_reduce (() => { + var head = (Block) pop (); + ((BlockContent) peek ()).content.add (head); + }); + + Rule headline = + Rule.one_of ({ + Rule.seq ({ + TokenType.EQUAL_1.action ((token) => { ((Headline) peek ()).level = 1; }), + optional_invisible_spaces, + run, + optional_invisible_spaces, + TokenType.EQUAL_1, + TokenType.EOL + }), + Rule.seq ({ + TokenType.EQUAL_2.action ((token) => { ((Headline) peek ()).level = 2; }), + optional_invisible_spaces, + run, + optional_invisible_spaces, + TokenType.EQUAL_2, + TokenType.EOL + }), + Rule.seq ({ + TokenType.EQUAL_3.action ((token) => { ((Headline) peek ()).level = 3; }), + optional_invisible_spaces, + run, + optional_invisible_spaces, + TokenType.EQUAL_3, + TokenType.EOL + }), + Rule.seq ({ + TokenType.EQUAL_4.action ((token) => { ((Headline) peek ()).level = 4; }), + optional_invisible_spaces, + run, + optional_invisible_spaces, + TokenType.EQUAL_4, + TokenType.EOL + }), + Rule.seq ({ + TokenType.EQUAL_5.action ((token) => { ((Headline) peek ()).level = 5; }), + optional_invisible_spaces, + run, + optional_invisible_spaces, + TokenType.EQUAL_5, + TokenType.EOL + }) + }) + .set_name ("Headline") + .set_start (() => { push (_factory.create_headline ()); }) + .set_reduce (() => { + var head = (Block) pop (); + ((BlockContent) peek ()).content.add (head); + }); + + Rule blocks = + Rule.one_of ({ + indented_blocks, + table, + headline, + warning, + note, + paragraph + }) + .set_name ("Blocks"); + + Rule page = + Rule.seq ({ + blocks, + Rule.option ({ + Rule.many ({ + TokenType.EOL, + Rule.option ({ blocks }) + }) + }) + }) + .set_name ("Page") + .set_start (() => { push (_factory.create_page ()); }); + + Rule description = + Rule.seq ({ + blocks, + Rule.option ({ + Rule.many ({ + TokenType.EOL, + Rule.option ({ blocks }) + }) + }) + }) + .set_name ("Description"); + + multiline_block_run = + Rule.seq ({ + multiline_run + }) + .set_start (() => { push (_factory.create_paragraph ()); }) + .set_reduce (() => { + Paragraph p = (Paragraph) pop (); + ((BlockContent) peek ()).content.add (p); + }) + .set_name ("BlockMultilineRun"); + + Rule taglet = + Rule.seq ({ + TokenType.AROBASE, + TokenType.any_word ().action ((token) => { + + string tag_name = token.to_string (); + var taglet = _factory.create_taglet (tag_name); + if (!(taglet is Block)) { + _parser.error (token, "Invalid taglet in this context"); + } + push (taglet); + + Rule? taglet_rule; + if (taglet is BlockContent) { + taglet_rule = taglet.get_parser_rule (multiline_block_run); + } else { + taglet_rule = taglet.get_parser_rule (multiline_run); + } + + if (taglet_rule != null) { + _parser.push_rule (Rule.seq ({ TokenType.SPACE, taglet_rule })); + } + }), + Rule.option ({ + Rule.many ({ TokenType.EOL }) + }) + }) + .set_name ("Taglet") + .set_reduce (() => { + var head = (Taglet) pop (); + ((Comment) peek ()).taglets.add (head); + }); + + Rule comment = + Rule.seq ({ + TokenType.EOL, + Rule.option ({ + description + }), + Rule.option ({ + Rule.many ({ taglet }) + }) + }) + .set_name ("Comment") + .set_start (() => { push (_factory.create_comment ()); }); + + _comment_parser.set_root_rule (comment); + _wiki_parser.set_root_rule (page); + } + + #if DEBUG + private void dump_stack (string title) { + message ("=== Dumping stack: %s ===", title); + foreach (Object object in _stack) { + message ("%s", object.get_type ().name ()); + } + } + #endif + } diff --cc libvaladoc/documentation/girmetadata.vala index 000000000,2dbae65e4..7d1b78ee9 mode 000000,100644..100644 --- a/libvaladoc/documentation/girmetadata.vala +++ b/libvaladoc/documentation/girmetadata.vala @@@ -1,0 -1,156 +1,154 @@@ + /* girmetadata.vala + * + * Copyright (C) 2012-2014 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Brosch Florian + */ + -using Gee; - + + /** + * Metadata reader for GIR files + */ + public class Valadoc.GirMetaData : Object { + private string? metadata_path = null; + private string? resource_dir = null; + + + public bool is_docbook { private set; get; default = false; } + public string index_sgml { private set; get; default = null; } + public string index_sgml_online { private set; get; default = null; } + + /** + * Used to manipulate paths to resources inside gir-files + */ + public string get_resource_path (string resource) { + if (resource_dir == null || metadata_path == null) { + return resource; + } + + if (Path.is_absolute (resource_dir)) { + return Path.build_filename (resource_dir, resource); + } + + return Path.build_filename (Path.get_dirname (metadata_path), resource_dir, resource); + } + + private string? get_metadata_file_name (string gir_file_path) { + string metadata_file_name = Path.get_basename (gir_file_path); + int last_dot_pos = metadata_file_name.last_index_of ("."); + if (last_dot_pos < 0) { + return null; + } + + metadata_file_name = metadata_file_name.substring (0, last_dot_pos); + return metadata_file_name + ".valadoc.metadata"; + } + + private string? get_metadata_path (string gir_file_path, string[] metadata_dirs) { + string? metadata_file_name = get_metadata_file_name (gir_file_path); + if (metadata_file_name == null) { + return null; + } + + // search for metatada at the same location as the gir file + string metadata_path = Path.build_filename (Path.get_dirname (gir_file_path), metadata_file_name); + if (FileUtils.test (metadata_path, FileTest.IS_REGULAR)) { + return metadata_path; + } + + foreach (string metadata_dir in metadata_dirs) { + metadata_path = Path.build_filename (metadata_dir, metadata_file_name); + if (FileUtils.test (metadata_path, FileTest.IS_REGULAR)) { + return metadata_path; + } + } + + return null; + } + + private void load_general_metadata (KeyFile key_file, ErrorReporter reporter) throws KeyFileError { + foreach (string key in key_file.get_keys ("General")) { + switch (key) { + case "resources": + this.resource_dir = key_file.get_string ("General", "resources"); + break; + + case "is_docbook": + this.is_docbook = key_file.get_boolean ("General", "is_docbook"); + break; + + case "index_sgml": + string tmp = key_file.get_string ("General", "index_sgml"); + this.index_sgml = Path.build_filename (Path.get_dirname (metadata_path), tmp); + break; + + case "index_sgml_online": + this.index_sgml_online = key_file.get_string ("General", "index_sgml_online"); + break; + + default: + reporter.simple_warning (metadata_path, "Unknown key 'General.%s'", key); + break; + } + } + } + + public GirMetaData (string gir_file_path, string[] metadata_dirs, ErrorReporter reporter) { + if (!FileUtils.test (gir_file_path, FileTest.IS_REGULAR)) { + return ; + } + + metadata_path = get_metadata_path (gir_file_path, metadata_dirs); + if (metadata_path == null) { + return ; + } + + KeyFile key_file; + + try { + key_file = new KeyFile (); + key_file.load_from_file (metadata_path, KeyFileFlags.NONE); + } catch (KeyFileError e) { + reporter.simple_error (metadata_path, "%s", e.message); + return ; + } catch (FileError e) { + reporter.simple_error (metadata_path, "%s", e.message); + return ; + } + + try { + foreach (string group in key_file.get_groups ()) { + switch (group) { + case "General": + load_general_metadata (key_file, reporter); + break; + + default: + reporter.simple_warning (metadata_path, "Unknown group '%s'", group); + break; + } + } + } catch (KeyFileError e) { + reporter.simple_error (null, "Unable to read file '%s': %s", metadata_path, e.message); + } + + + // Load internal link lut: + } + } + diff --cc libvaladoc/documentation/gtkdoccommentparser.vala index 000000000,81dc52a8f..ede991ce8 mode 000000,100644..100644 --- a/libvaladoc/documentation/gtkdoccommentparser.vala +++ b/libvaladoc/documentation/gtkdoccommentparser.vala @@@ -1,0 -1,1668 +1,1663 @@@ + /* gtkcommentparser.vala + * + * Copyright (C) 2011-2014 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + + + using Valadoc.Content; + using Valadoc.Gtkdoc; -using Gee; - - + + public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator { + private Scanner scanner = new Scanner (); + private Token current; + - private LinkedList stack = new LinkedList (); - private LinkedList> footnotes = new LinkedList> (); ++ private Vala.List stack = new Vala.ArrayList (str_equal); ++ private Vala.List> footnotes = new Vala.ArrayList> (); + + private ContentFactory factory; + private ErrorReporter reporter; + private Settings settings; + private Api.Tree tree; + private Api.Node? element; + + private bool show_warnings; + private Api.SourceComment comment; + private unowned string instance_param_name; + + private string[]? comment_lines; + + private Regex? is_numeric_regex = null; + private Regex? normalize_regex = null; + private Regex regex_source_lang = null; + + private Importer.InternalIdRegistrar id_registrar = null; + private GirMetaData? current_metadata = null; + + private inline string fix_resource_path (string path) { + return this.current_metadata.get_resource_path (path); + } + + private void reset (Api.SourceComment comment) { + this.scanner.reset (comment.content); + this.show_warnings = !comment.file.package.is_package; + this.comment_lines = null; + this.footnotes.clear (); + this.comment = comment; + this.current = null; + this.stack.clear (); + } + + private string normalize (string text) { + try { + return normalize_regex.replace (text, -1, 0, " "); + } catch (RegexError e) { + assert_not_reached (); + } + } + + private bool is_numeric (string str) { + return is_numeric_regex.match (str); + } + + private void report_unexpected_token (Token got, string expected) { + report_warning (got, "Unexpected Token: %s (Expected: %s)".printf (got.to_string (), expected)); + } + + private void report_warning (Token got, string message) { + if (!this.show_warnings) { + return ; + } + + int startpos = (got.line == 0)? comment.first_column + got.first_column : got.first_column; + int endpos = (got.line == 0)? comment.first_column + got.last_column : got.last_column; + + if (this.comment_lines == null) { + this.comment_lines = this.comment.content.split ("\n"); + } + + this.reporter.warning (this.comment.file.get_name (), + comment.first_line + got.line, + startpos + 1, + endpos + 1, + this.comment_lines[got.line], + message); + } + + public Parser (Settings settings, ErrorReporter reporter, Api.Tree tree, ModuleLoader modules) { + this.factory = new ContentFactory (settings, this, modules); + this.reporter = reporter; + this.settings = settings; + this.tree = tree; + + try { + is_numeric_regex = new Regex ("^[+-]?([0-9]*\\.?[0-9]+|[0-9]+\\.?[0-9]*)([eE][+-]?[0-9]+)?$", + RegexCompileFlags.OPTIMIZE); + normalize_regex = new Regex ("( |\n|\t)+", RegexCompileFlags.OPTIMIZE); + regex_source_lang = new Regex ("^"); + } catch (RegexError e) { + assert_not_reached (); + } + } + + private Note? _parse_note (Api.SourceComment comment) { + Comment? cmnt = parse_root_content (comment); + if (cmnt == null) { + return null; + } + + Note note = factory.create_note (); + note.content.add_all (cmnt.content); + + return note; + } + + private void add_note (ref Comment? comment, Note? note) { + if (note == null) { + return ; + } + + if (comment == null) { + comment = factory.create_comment (); + } + + if (comment.content.size == 0) { + comment.content.add (factory.create_paragraph ()); + } + + comment.content.insert (1, note); + } + + private void add_taglet (ref Comment? comment, Taglet? taglet) { + if (taglet == null) { + return ; + } + + if (comment == null) { + comment = factory.create_comment (); + } + + comment.taglets.add (taglet); + } + + public Comment? parse (Api.Node element, Api.GirSourceComment gir_comment, GirMetaData gir_metadata, Importer.InternalIdRegistrar id_registrar) { + this.instance_param_name = gir_comment.instance_param_name; + this.current_metadata = gir_metadata; + this.id_registrar = id_registrar; + this.element = element; + + + Comment? cmnt = parse_root_content (gir_comment); + if (cmnt != null) { + ImporterHelper.extract_short_desc (cmnt, factory); + } + + + // deprecated: + if (gir_comment.deprecated_comment != null) { + Note? note = _parse_note (gir_comment.deprecated_comment); + add_note (ref cmnt, note); + } + + + // version: + if (gir_comment.version_comment != null) { + Note? note = _parse_note (gir_comment.version_comment); + add_note (ref cmnt, note); + } + + // stability: + if (gir_comment.stability_comment != null) { + Note? note = _parse_note (gir_comment.stability_comment); + add_note (ref cmnt, note); + } + + + // return: + if (gir_comment.return_comment != null) { + Taglet? taglet = parse_block_taglet (gir_comment.return_comment, "return"); + add_taglet (ref cmnt, taglet); + } + + + // parameters: - MapIterator iter = gir_comment.parameter_iterator (); ++ Vala.MapIterator iter = gir_comment.parameter_iterator (); + for (bool has_next = iter.next (); has_next; has_next = iter.next ()) { + Taglets.Param? taglet = parse_block_taglet (iter.get_value (), "param") as Taglets.Param; + string param_name = iter.get_key (); + + taglet.is_c_self_param = (param_name == gir_comment.instance_param_name); + taglet.parameter_name = param_name; + add_taglet (ref cmnt, taglet); + } + + + bool first = true; - foreach (LinkedList note in this.footnotes) { ++ foreach (Vala.List note in this.footnotes) { + if (first == true && note.size > 0) { + Paragraph p = note.first () as Paragraph; + if (p == null) { + p = factory.create_paragraph (); + cmnt.content.add (p); + } + + p.content.insert (0, factory.create_text ("\n")); + } + cmnt.content.add_all (note); + first = false; + } + + return cmnt; + } + + private Taglet? parse_block_taglet (Api.SourceComment gir_comment, string taglet_name) { + this.reset (gir_comment); + current = null; + next (); + + parse_docbook_spaces (false); + var ic = parse_inline_content (); + parse_docbook_spaces (false); + + if (current.type != TokenType.EOF) { + this.report_unexpected_token (current, ""); + return null; + } + + BlockContent? taglet = factory.create_taglet (taglet_name) as BlockContent; + assert (taglet != null); + Paragraph paragraph = factory.create_paragraph (); + paragraph.content.add (ic); + taglet.content.add (paragraph); + return taglet as Taglet; + } + + private Comment? parse_root_content (Api.SourceComment gir_comment) { + this.reset (gir_comment); + current = null; + + next (); + + Token tmp = null; + parse_docbook_spaces (false); + + Comment comment = factory.create_comment (); + while (current.type != TokenType.EOF && tmp != current) { + tmp = current; + var ic = parse_inline_content (); + if (ic != null && ic.content.size > 0) { + Paragraph p = factory.create_paragraph (); + p.content.add (ic); + comment.content.add (p); + } + + var bc = parse_block_content (); + if (bc != null && bc.size > 0) { + comment.content.add_all (bc); + } + } + + if (current.type != TokenType.EOF) { + this.report_unexpected_token (current, ""); + return null; + } + + ImporterHelper.extract_short_desc (comment, factory); + + return comment; + } + + + + // + // Common: + // + + private Token next () { + current = scanner.next (); + return current; + } + + private bool ignore_current_xml_close () { + if (current.type != TokenType.XML_CLOSE) { + return false; + } + + string name = current.content; + if ((name in stack) == false) { + return true; + } + + return false; + } + + private bool check_xml_open_tag (string tagname) { + if ((current.type == TokenType.XML_OPEN && current.content != tagname) + || current.type != TokenType.XML_OPEN) + { + return false; + } + - stack.offer_head (tagname); ++ stack.insert (0, tagname); + return true; + } + + private bool check_xml_close_tag (string tagname) { + if ((current.type == TokenType.XML_CLOSE && current.content != tagname) + || current.type != TokenType.XML_CLOSE) + { + return false; + } + - if (stack.poll_head () == tagname) { - stack.peek_head (); - } ++ assert (stack.remove_at (0) == tagname); + + return true; + } + + + private void parse_docbook_spaces (bool accept_paragraphs = true) { + while (true) { + if (current.type == TokenType.SPACE) { + next (); + } else if (current.type == TokenType.NEWLINE) { + next (); + } else if (accept_paragraphs && current.type == TokenType.GTKDOC_PARAGRAPH) { + next (); + } else { + break; + } + } + } + + + + // + // Rules, Ground: + // + + private Inline? parse_docbook_link_tempalte (string tagname, bool is_internal) { + if (!check_xml_open_tag (tagname)) { + this.report_unexpected_token (current, "<%s>".printf (tagname)); + return null; + } + + StringBuilder builder = new StringBuilder (); + string url = current.attributes.get ("linkend"); + next (); + + // TODO: check xml + while (!(current.type == TokenType.XML_CLOSE && current.content == tagname) + && current.type != TokenType.EOF) + { + if (current.type == TokenType.XML_OPEN) { + } else if (current.type == TokenType.XML_CLOSE) { + } else if (current.type == TokenType.XML_COMMENT) { + } else { + builder.append (current.content); + } + + next (); + } + + var link = factory.create_link (); + if (is_internal) { + link.id_registrar = id_registrar; + } + link.url = url; + + if (builder.len == 0) { + link.content.add (factory.create_text (url)); + } else { + link.content.add (factory.create_text (normalize (builder.str))); + } + + if (!check_xml_close_tag (tagname)) { + this.report_unexpected_token (current, "".printf (tagname)); + return link; + } + + next (); + return link; + } + + private InlineTaglet? parse_symbol_link (string tagname) { + if (!check_xml_open_tag (tagname)) { + this.report_unexpected_token (current, "<%s>".printf (tagname)); + return null; + } + + if (next ().type == TokenType.SPACE) { + next (); + } + + InlineTaglet? taglet = null; + + if (current.type == TokenType.WORD && current.content == "struct") { + next (); + + if (next ().type == TokenType.SPACE) { + next (); + } + } + + + if (current.type == TokenType.GTKDOC_FUNCTION || current.type == TokenType.GTKDOC_CONST + || current.type == TokenType.GTKDOC_TYPE || current.type == TokenType.WORD + || current.type == TokenType.GTKDOC_PROPERTY || current.type == TokenType.GTKDOC_SIGNAL) + { + taglet = this.create_type_link (current.content) as InlineTaglet; + assert (taglet != null); + } + + if (next ().type == TokenType.SPACE) { + next (); + } + + if (!check_xml_close_tag (tagname)) { + this.report_unexpected_token (current, "".printf (tagname)); + return taglet; + } + + next (); + return taglet; + } + + private void parse_anchor () { + if (!check_xml_open_tag ("anchor")) { + this.report_unexpected_token (current, ""); + return; + } + + string id = current.attributes.get ("id"); + if (id != null) { + id_registrar.register_symbol (id, element); + } + next (); + + if (!check_xml_close_tag ("anchor")) { + this.report_unexpected_token (current, ""); + return; + } + + next (); + } + + private Link? parse_xref () { + if (!check_xml_open_tag ("xref")) { + this.report_unexpected_token (current, ""); + return null; + } + + string linkend = current.attributes.get ("linkend"); + next (); + + Link link = factory.create_link (); + link.content.add (factory.create_text (linkend)); + link.id_registrar = id_registrar; + link.url = linkend; + + if (!check_xml_close_tag ("xref")) { + this.report_unexpected_token (current, ""); + return link; + } + + next (); + return link; + } + + private Run? parse_highlighted_template (string tag_name, Run.Style style) { + if (!check_xml_open_tag (tag_name)) { + this.report_unexpected_token (current, "<%s>".printf (tag_name)); + return null; + } + + next (); + Run run = parse_inline_content (); + if (run.style != Run.Style.NONE && run.style != style) { + Run tmp = factory.create_run (style); + tmp.content.add (run); + run = tmp; + } else { + run.style = style; + } + + if (!check_xml_close_tag (tag_name)) { + this.report_unexpected_token (current, "".printf (tag_name)); + return run; + } + + next (); + return run; + } + + private ListItem? parse_docbook_listitem () { + if (!check_xml_open_tag ("listitem")) { + this.report_unexpected_token (current, ""); + return null; + } + + next (); + + ListItem item = factory.create_list_item (); + + item.content.add_all (parse_mixed_content ()); + + if (!check_xml_close_tag ("listitem")) { + this.report_unexpected_token (current, ""); + return item; + } + + next (); + return item; + } + + private BlockContent? parse_docbook_information_box_template (string tagname, BlockContent container) { + if (!check_xml_open_tag (tagname)) { + this.report_unexpected_token (current, "<%s>".printf (tagname)); + return null; + } + + next (); + parse_docbook_spaces (); + + Token tmp = null; + while (current.type != TokenType.XML_CLOSE && current.type != TokenType.EOF) { + tmp = current; + var ic = parse_inline_content (); + if (ic != null && ic.content.size > 0) { + Paragraph p = factory.create_paragraph (); + p.content.add (ic); + container.content.add (p); + } + + var bc = parse_block_content (); + if (bc != null && bc.size > 0) { + container.content.add_all (bc); + } + } + + parse_docbook_spaces (); + + if (!check_xml_close_tag (tagname)) { + this.report_unexpected_token (current, "".printf (tagname)); + return container; + } + + next (); + return container; + } + + private Note? parse_docbook_important () { + return (Note?) parse_docbook_information_box_template ("important", factory.create_note ()); + } + + private Note? parse_docbook_note () { + return (Note?) parse_docbook_information_box_template ("note", factory.create_note ()); + } + + private Warning? parse_docbook_warning () { + return (Warning?) parse_docbook_information_box_template ("warning", factory.create_warning ()); + } + - private inline LinkedList? parse_docbook_orderedlist () { ++ private inline Vala.Collection? parse_docbook_orderedlist () { + return parse_docbook_itemizedlist ("orderedlist", Content.List.Bullet.ORDERED); + } + - private LinkedList? parse_docbook_itemizedlist (string tag_name = "itemizedlist", ++ private Vala.Collection? parse_docbook_itemizedlist (string tag_name = "itemizedlist", + Content.List.Bullet bullet_type = Content.List.Bullet.UNORDERED) + { + if (!check_xml_open_tag (tag_name)) { + this.report_unexpected_token (current, "<%s>".printf (tag_name)); + return null; + } + next (); + + - LinkedList content = new LinkedList (); ++ Vala.Collection content = new Vala.ArrayList (); + parse_docbook_spaces (); + + if (current.type == TokenType.XML_OPEN && current.content == "title") { + append_block_content_not_null (content, parse_docbook_title ()); + parse_docbook_spaces (); + } + + Content.List list = factory.create_list (); + list.bullet = bullet_type; + content.add (list); + + while (current.type == TokenType.XML_OPEN) { + if (current.content == "listitem") { + list.items.add (parse_docbook_listitem ()); + } else { + break; + } + + parse_docbook_spaces (); + } + + if (!check_xml_close_tag (tag_name)) { + this.report_unexpected_token (current, "".printf (tag_name)); + return content; + } + + next (); + return content; + } + + private Paragraph? parse_gtkdoc_paragraph () { + if (current.type != TokenType.GTKDOC_PARAGRAPH) { + this.report_unexpected_token (current, ""); + return null; + } + + next (); + + Paragraph p = factory.create_paragraph (); + + Run? run = parse_inline_content (); + p.content.add (run); + return p; + } + - private LinkedList parse_mixed_content () { - LinkedList content = new LinkedList (); ++ private Vala.Collection parse_mixed_content () { ++ Vala.Collection content = new Vala.ArrayList (); + Token tmp = null; + + while (tmp != current) { + tmp = current; + parse_docbook_spaces (); + + Run? run = parse_inline_content (); + if (run != null && run.content.size > 0) { + Paragraph p = factory.create_paragraph (); + p.content.add (run); + content.add (p); + continue; + } + - LinkedList lst = parse_block_content (); ++ Vala.Collection lst = parse_block_content (); + if (lst != null && lst.size > 0) { + content.add_all (lst); + continue; + } + } + + return content; + } + - private inline LinkedList? parse_docbook_simpara () { ++ private inline Vala.Collection? parse_docbook_simpara () { + return parse_docbook_para ("simpara"); + } + - private LinkedList? parse_docbook_para (string tag_name = "para") { ++ private Vala.Collection? parse_docbook_para (string tag_name = "para") { + if (!check_xml_open_tag (tag_name)) { + this.report_unexpected_token (current, "<%s>".printf (tag_name)); + return null; + } + + next (); + - LinkedList content = parse_mixed_content (); ++ Vala.Collection content = parse_mixed_content (); + + // ignore missing to match gtkdocs behaviour + if (!check_xml_close_tag (tag_name) && current.type != TokenType.EOF) { + this.report_unexpected_token (current, "".printf (tag_name)); + return content; + } + + next (); + return content; + } + + private Paragraph? parse_gtkdoc_source () { + if (current.type != TokenType.GTKDOC_SOURCE_OPEN) { + this.report_unexpected_token (current, "|["); + return null; + } + + StringBuilder builder = new StringBuilder (); + Token source_token = current; + + for (next (); current.type != TokenType.EOF && current.type != TokenType.GTKDOC_SOURCE_CLOSE; next ()) { + if (current.type == TokenType.WORD) { + builder.append (current.content); + } else if (current.type != TokenType.XML_COMMENT) { + builder.append_len (current.start, current.length); + } + } + + SourceCode code = factory.create_source_code (); + MatchInfo info; + + unowned string source = builder.str; + if (regex_source_lang.match (source, 0, out info)) { + string lang_name = info.fetch (1).down (); + SourceCode.Language? lang = SourceCode.Language.from_string (lang_name); + code.language = lang; + + if (lang == null) { + report_warning (source_token, "Unknown language `%s' in source code block |[")) { + next_char (); + next_char (); + next_char (); + return new Token (TokenType.XML_COMMENT, + "", + null, + start, + offset (this.pos, start), + this.line, + column_start, + this.column); + } + } + } else if (this.pos.has_prefix ("[CDATA[")) { + next_char (); + next_char (); + next_char (); + next_char (); + next_char (); + next_char (); + + for (unichar c = next_char (); c != '\0'; c = next_char ()) { + if (c == '\n') { + this.line++; + this.column = 0; + } else if (this.pos.has_prefix ("]]>")) { + string content = start.substring (9, offset (this.pos, start) - 9); + next_char (); + next_char (); + next_char (); + return new Token (TokenType.WORD, + unescape (content), + null, + start, + offset (this.pos, start), + this.line, + column_start, + this.column); + } + } + } + + this.pos = start; + this.column = column_start; + this.line = line_start; + return null; + } + + bool close = false; + if (get () == '/') { + next_char (); + close = true; + } + + unowned string id_start = this.pos; + + int id_len = 0; + if ((id_len = id_prefix ()) == 0) { + this.column = column_start; + this.pos = start; + return null; + } + - HashMap map = new HashMap (); ++ Vala.HashMap map = new Vala.HashMap (str_hash, str_equal); + + while (close == false && skip_spaces_and_newlines () > 0) { + string name; + string val; + + unowned string att_pos = this.pos; + int att_id_len = 0; + if ((att_id_len = id_prefix ()) == 0) { + break; + } + + name = att_pos.substring (0, att_id_len); + + if (get() != '=') { + break; + } + + next_char (); + skip_spaces_and_newlines (); + + if (get() != '"') { + break; + } + + unichar c = next_char (); + att_pos = this.pos; + for (; c != '\0' && c != '\n' && c != '"' ; c = next_char ()); + + val = att_pos.substring (0, offset (this.pos, att_pos)); + + if (get() != '"') { + break; + } + + next_char (); + + map.set (name, val); + } + + skip_spaces_and_newlines (); + + bool open_and_close = false; + + if (!close && get () == '/') { + open_and_close = true; + next_char (); + } + + if (get () != '>') { + this.line = line_start; + this.column = column_start; + this.pos = start; + return null; + } + + next_char (); + + if (open_and_close) { + this.tmp_token = new Token (TokenType.XML_CLOSE, + id_start.substring (0, id_len), + null, + start, + offset (this.pos, start), + this.line, + column_start, + this.column); + } + + if (close) { + return new Token (TokenType.XML_CLOSE, + id_start.substring (0, id_len), + null, + start, + offset (this.pos, start), + this.line, + column_start, + this.column); + } else { + return new Token (TokenType.XML_OPEN, + id_start.substring (0, id_len), + map, + start, + offset (this.pos, start), + this.line, + column_start, + this.column); + } + } + + private Token? newline_prefix () { + if (get () != '\n') { + return null; + } + + unowned string start = this.pos; + this.line++; + this.column = 0; + + for (unichar c = next_char (); c == ' ' || c == '\t' ; c = next_char ()); + + if (get () == '\n') { + next_char (); + this.line++; + this.column = 0; + return new Token (TokenType.GTKDOC_PARAGRAPH, + "\n\n", + null, + start, + offset (this.pos, start), + this.line, + this.column, + this.column); + } else { + return new Token (TokenType.NEWLINE, + "\n", + null, + start, + offset (this.pos, start), + this.line, + this.column, + this.column); + } + } + + private Token? eof_prefix () { + if (get () != '\0') { + return null; + } + + return new Token (TokenType.EOF, + "", + null, + this.pos, + 1, + this.line, + this.column, + this.column); + } + + private Token? space_prefix () { + unowned string start = this.pos; + int column_start = this.column; + for (unichar c = get (); c == ' ' || c == '\t'; c = next_char ()); + int len = offset (this.pos, start); + if (len == 0) { + this.column = column_start; + this.pos = start; + return null; + } + + return new Token (TokenType.SPACE, + start.substring (0, len), + null, + start, + offset (this.pos, start), + this.line, + column_start, + this.column); + } + + private Token? word_prefix () { + unowned string start = this.pos; + int column_start = this.column; + unichar c = get (); + if (c == '<' || c == '@') { + next_char (); + } + + for (c = get (); c != ' ' && c != '\t' && c != '\n' && c != '\0' && c != '<' && c != '@'; c = next_char ()); + int len = offset (this.pos, start); + if (len == 0) { + this.column = column_start; + this.pos = start; + return null; + } + + return new Token (TokenType.WORD, + unescape (start.substring (0, len)), + null, + start, + offset (this.pos, start), + this.line, + column_start, + this.column); + } + + private Token? gtkdoc_source_open_prefix () { + if (!this.pos.has_prefix ("|[")) { + return null; + } + + unowned string start = this.pos; + int column_start = this.column; + next_char (); + next_char (); + + return new Token (TokenType.GTKDOC_SOURCE_OPEN, + "|[", + null, + start, + offset (this.pos, start), + this.line, + column_start, + this.column); + } + + private Token? gtkdoc_source_close_prefix () { + if (!this.pos.has_prefix ("]|")) { + return null; + } + + unowned string start = this.pos; + int column_start = this.column; + next_char (); + next_char (); + + return new Token (TokenType.GTKDOC_SOURCE_CLOSE, "]|", + null, + start, + offset (this.pos, start), + this.line, + column_start, + this.column); + } + + public Token next () { + if (tmp_token != null) { + var tmp = tmp_token; + tmp_token = null; + return tmp; + } + + Token? token = function_prefix (); + if (token != null) { + return token; + } + + token = xml_prefix (); + if (token != null) { + return token; + } + + token = gtkdoc_param_prefix (); + if (token != null) { + return token; + } + + token = gtkdoc_const_prefix (); + if (token != null) { + return token; + } + + token = gtkdoc_type_prefix (); + if (token != null) { + return token; + } + + token = space_prefix (); + if (token != null) { + return token; + } + + token = newline_prefix (); + if (token != null) { + return token; + } + + token = gtkdoc_signal_prefix (); + if (token != null) { + return token; + } + + token = gtkdoc_property_prefix (); + if (token != null) { + return token; + } + + token = gtkdoc_source_open_prefix (); + if (token != null) { + return token; + } + + token = gtkdoc_source_close_prefix (); + if (token != null) { + return token; + } + + token = eof_prefix (); + if (token != null) { + return token; + } + + token = word_prefix (); + if (token != null) { + return token; + } + + assert_not_reached (); + } + } + diff --cc libvaladoc/documentation/gtkdocmarkdownparser.vala index 000000000,ff52e9542..66218e16c mode 000000,100644..100644 --- a/libvaladoc/documentation/gtkdocmarkdownparser.vala +++ b/libvaladoc/documentation/gtkdocmarkdownparser.vala @@@ -1,0 -1,840 +1,837 @@@ + /* gtkdocmarkdownparser.vala + * + * Copyright (C) 2014 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + + + using Valadoc.Content; + using Valadoc; -using Gee; - - + + public class Valadoc.Gtkdoc.MarkdownParser : Object, ResourceLocator { + private Valadoc.Parser parser; + private Content.ContentFactory _factory; + + private Settings _settings; + private ErrorReporter _reporter; + private Api.Tree _tree; + - private ArrayList _stack = new ArrayList (); ++ private Vala.ArrayList _stack = new Vala.ArrayList (); + + private Valadoc.Token preserved_token = null; + private Regex regex_source_lang; + + private Importer.InternalIdRegistrar id_registrar; + private GirMetaData metadata; + private Api.GirSourceComment gir_comment; + private Api.Node element; + + + public MarkdownParser (Settings settings, ErrorReporter reporter, Api.Tree? tree, ModuleLoader _modules) { + MarkdownScanner scanner = new MarkdownScanner (settings); + parser = new Valadoc.Parser (settings, scanner, reporter); + scanner.set_parser (parser); + + + _factory = new Content.ContentFactory (settings, this, _modules); + _settings = settings; + _reporter = reporter; + _tree = tree; + + init_rules (); + + try { + regex_source_lang = new Regex ("^"); + } catch (Error e) { + assert_not_reached (); + } + } + + public void init_rules () { + Valadoc.TokenType word = Valadoc.TokenType.any_word ().action (add_text); + + StubRule content = new StubRule (); + content.set_name ("Content"); + + StubRule run = new StubRule (); + run.set_name ("Run"); + + + Rule param = Rule.seq ({ + Valadoc.TokenType.MARKDOWN_PARAMETER.action ((token) => { + Run _run = null; + + if (token.value == gir_comment.instance_param_name) { + _run = _factory.create_run (Run.Style.LANG_KEYWORD); + _run.content.add (_factory.create_text ("this")); + } else if (is_error_parameter (token.value)) { + _run = _factory.create_run (Run.Style.LANG_KEYWORD); + _run.content.add (_factory.create_text ("throws")); + } else { + string? param_name; + string? param_array_name; + bool is_return_type_len; + + ImporterHelper.resolve_parameter_ctype ( + this._tree, + this.element, + token.value, + out param_name, + out param_array_name, + out is_return_type_len); + + _run = _factory.create_run (Run.Style.MONOSPACED); + + if (is_return_type_len) { + Run keyword_run = _factory.create_run (Run.Style.LANG_KEYWORD); + keyword_run.content.add (_factory.create_text ("return")); + _run.content.add (keyword_run); + + _run.content.add (_factory.create_text (".length")); + } else if (param_array_name != null) { + _run.content.add (_factory.create_text (param_array_name + ".length")); + } else { + _run.content.add (_factory.create_text (param_name)); + } + + + } + + push (_run); + }) + }) + .set_name ("Parameter"); + + + Rule constant = Rule.seq ({ + Valadoc.TokenType.MARKDOWN_CONSTANT.action ((token) => { + if (is_literal (token.value)) { + var _run = _factory.create_run (Run.Style.LANG_LITERAL); + _run.content.add (_factory.create_text (token.value.down ())); + push (_run); + } else { + add_symbol_link ("c::" + token.value, true); + } + }) + }) + .set_name ("Constant"); + + + Rule gmember = Rule.seq ({ + Valadoc.TokenType.MARKDOWN_LOCAL_GMEMBER.action ((token) => { + Api.Item gtype = element; + while (gtype is Api.Class == false && gtype is Api.Interface == false && gtype != null) { + gtype = gtype.parent; + } + + string parent_cname; + if (gtype is Api.Class) { + parent_cname = ((Api.Class) gtype).get_cname (); + } else if (gtype is Api.Interface) { + parent_cname = ((Api.Interface) gtype).get_cname (); + } else { + parent_cname = ""; + } + + add_symbol_link ("c::" + parent_cname + token.value, true); + }) + }) + .set_name ("GLocalMember"); + + + Rule symbol = Rule.seq ({ + Valadoc.TokenType.MARKDOWN_SYMBOL.action ((token) => { + add_symbol_link ("c::" + token.value, true); + }) + }) + .set_name ("Symbol"); + + + Rule function = Rule.seq ({ + Valadoc.TokenType.MARKDOWN_FUNCTION.action ((token) => { + add_symbol_link ("c::" + token.value, false); + }) + }) + .set_name ("Function"); + + + Rule link_short = Rule.seq ({ + Valadoc.TokenType.MARKDOWN_LESS_THAN, + Rule.option ({ + Rule.one_of ({ + Valadoc.TokenType.MARKDOWN_MAIL.action (preserve_token), + Valadoc.TokenType.MARKDOWN_LINK.action (preserve_token) + }), + Rule.option ({ + Valadoc.TokenType.MARKDOWN_GREATER_THAN, + }) + .set_reduce (() => { + Link url = _factory.create_link (); + url.url = pop_preserved_link (); + push (url); + }) + .set_skip (() => { + add_content_string ("<"); + add_value (preserved_token); + preserved_token = null; + }) + }) + .set_skip (() => { + add_content_string ("<"); + }) + }) + .set_name ("Link"); + + + Rule link = Rule.seq ({ + Valadoc.TokenType.MARKDOWN_OPEN_BRACKET, + Rule.option ({ + Rule.option ({ + run + }), + Valadoc.TokenType.MARKDOWN_CLOSE_BRACKET, + Rule.option ({ + Rule.one_of ({ + // External link: + Rule.seq ({ + Valadoc.TokenType.MARKDOWN_OPEN_PARENS, + Rule.option ({ + Rule.one_of ({ + Valadoc.TokenType.MARKDOWN_LINK.action (preserve_token), + Valadoc.TokenType.MARKDOWN_MAIL.action (preserve_token) + }), + Rule.option ({ + Valadoc.TokenType.MARKDOWN_CLOSE_PARENS + }) + .set_reduce (() => { + Link url = _factory.create_link (); + url.url = pop_preserved_link (); + + Run label = (Run) peek (); + url.content.add_all (label.content); + label.content.clear (); + label.content.add (url); + }) + .set_skip (() => { + Run _run = (Run) peek (); + _run.content.insert (0, _factory.create_text ("[")); + _run.content.add (_factory.create_text ("](" + pop_preserved_link ())); + }) + }) + .set_skip (() => { + Run _run = (Run) peek (); + _run.content.insert (0, _factory.create_text ("[")); + _run.content.add (_factory.create_text ("](")); + }) + }), + // Internal link: + Rule.seq ({ + Valadoc.TokenType.MARKDOWN_OPEN_BRACKET, + Rule.option ({ + Valadoc.TokenType.any_word ().action (preserve_token), + Rule.option ({ + Valadoc.TokenType.MARKDOWN_CLOSE_BRACKET + }) + .set_reduce (() => { + Link url = _factory.create_link (); + url.url = pop_preserved_link (); + url.id_registrar = id_registrar; + + Run label = (Run) peek (); + url.content.add_all (label.content); + label.content.clear (); + label.content.add (url); + }) + .set_skip (() => { + Run _run = (Run) peek (); + _run.content.insert (0, _factory.create_text ("[")); + + _run.content.add (_factory.create_text ("][" + pop_preserved_link ())); + }) + }) + .set_skip (() => { + Run _run = (Run) peek (); + _run.content.insert (0, _factory.create_text ("[")); + _run.content.add (_factory.create_text ("][")); + }) + }) + }) + }) + .set_skip (() => { + Run _run = (Run) peek (); + _run.content.insert (0, _factory.create_text ("[")); + _run.content.add (_factory.create_text ("]")); + }) + }) + .set_skip (() => { + Run _run = (Run) peek (); + _run.content.insert (0, _factory.create_text ("[")); + }) + }) + .set_start (() => { push (_factory.create_run (Run.Style.NONE)); }) + .set_name ("Link"); + + + Rule image = Rule.seq ({ + Valadoc.TokenType.MARKDOWN_EXCLAMATION_MARK, + Rule.option ({ + Valadoc.TokenType.MARKDOWN_OPEN_BRACKET, + Rule.option ({ + run + }), + Valadoc.TokenType.MARKDOWN_CLOSE_BRACKET, + Rule.option ({ + Valadoc.TokenType.MARKDOWN_OPEN_BRACKET, + Rule.option ({ + Rule.one_of ({ + Valadoc.TokenType.any_word ().action (preserve_token), + Valadoc.TokenType.MARKDOWN_LINK.action (preserve_token), + Valadoc.TokenType.MARKDOWN_MAIL.action (preserve_token) + }), + Rule.option ({ + Valadoc.TokenType.MARKDOWN_CLOSE_BRACKET, + }) + .set_reduce (() => { + Run label = (Run) peek (); + + string label_str; + try { + label_str = run_to_string (label, ""); + } catch (Error e) { + parser.warning (preserved_token, e.message); + label_str = null; + } + + Embedded embedded = _factory.create_embedded (); + embedded.url = fix_resource_path (pop_preserved_path ()); + embedded.caption = label_str; + + label.content.clear (); + label.content.add (embedded); + }) + .set_skip (() => { + Run _run = (Run) peek (); + _run.content.insert (0, _factory.create_text ("![")); + _run.content.add (_factory.create_text ("][" + pop_preserved_link ())); + }) + }) + .set_skip (() => { + Run _run = (Run) peek (); + _run.content.insert (0, _factory.create_text ("![")); + _run.content.add (_factory.create_text ("][")); + }) + }) + .set_skip (() => { + Run _run = (Run) peek (); + _run.content.insert (0, _factory.create_text ("![")); + _run.content.add (_factory.create_text ("]")); + }) + }) + .set_skip (() => { + Run _run = (Run) peek (); + _run.content.insert (0, _factory.create_text ("!")); + }) + }) + .set_start (() => { push (_factory.create_run (Run.Style.NONE)); }) + .set_name ("Image"); + + + Rule source = Rule.seq ({ + Valadoc.TokenType.MARKDOWN_SOURCE.action ((token) => { + SourceCode code = _factory.create_source_code (); + MatchInfo info; + + unowned string source = token.value; + if (regex_source_lang.match (source, 0, out info)) { + string lang_name = info.fetch (1).down (); + SourceCode.Language? lang = SourceCode.Language.from_string (lang_name); + code.language = lang; + + if (lang == null) { + parser.warning (token, "Unknown language `%s' in source code block |[ + + foo_bar () + %aaa + @param + #TypeName + myword + + |[]| + ::my-signal + :my-property + """); + + var token = scanner.next (); + + assert (token.type == Gtkdoc.TokenType.XML_OPEN); + assert (token.content == "element1"); - assert (((Gee.Map) token.attributes).size == 0); ++ assert (((Vala.Map) token.attributes).size == 0); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.XML_OPEN); + assert (token.content == "element2"); + assert (token.attributes.get ("a") == "a-val"); + assert (token.attributes.get ("b") == "b-val"); - assert (((Gee.Map) token.attributes).size == 2); ++ assert (((Vala.Map) token.attributes).size == 2); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.XML_CLOSE); + assert (token.content == "element3"); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.XML_OPEN); + assert (token.content == "element4"); - assert (((Gee.Map) token.attributes).size == 0); ++ assert (((Vala.Map) token.attributes).size == 0); + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.XML_CLOSE); + assert (token.content == "element4"); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.XML_OPEN); + assert (token.content == "element5"); + assert (token.attributes.get ("a") == "a-val"); + assert (token.attributes.get ("b") == "b-val"); - assert (((Gee.Map) token.attributes).size == 2); ++ assert (((Vala.Map) token.attributes).size == 2); + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.XML_CLOSE); + assert (token.content == "element5"); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.XML_COMMENT); + assert (token.content == ""); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.XML_COMMENT); + assert (token.content == ""); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.GTKDOC_FUNCTION); + assert (token.content == "foo_bar"); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.GTKDOC_CONST); + assert (token.content == "aaa"); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.GTKDOC_PARAM); + assert (token.content == "param"); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.GTKDOC_TYPE); + assert (token.content == "TypeName"); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.WORD); + assert (token.content == "myword"); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.SPACE); + assert (token.content == " "); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.GTKDOC_PARAGRAPH); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.GTKDOC_SOURCE_OPEN); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.GTKDOC_SOURCE_CLOSE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.GTKDOC_SIGNAL); + assert (token.content == "my-signal"); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.GTKDOC_PROPERTY); + assert (token.content == "my-property"); + assert (token.attributes == null); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.NEWLINE); + + + token = scanner.next (); + assert (token.type == Gtkdoc.TokenType.EOF); + + } diff --cc valadoc/tests/testrunner.sh index 000000000,79f29788e..59302ffe7 mode 000000,100755..100755 --- a/valadoc/tests/testrunner.sh +++ b/valadoc/tests/testrunner.sh @@@ -1,0 -1,123 +1,130 @@@ + #!/usr/bin/env bash + # testrunner.sh + # + # Copyright (C) 2006-2008 Jürg Billeter + # + # This library is free software; you can redistribute it and/or + # modify it under the terms of the GNU Lesser General Public + # License as published by the Free Software Foundation; either + # version 2.1 of the License, or (at your option) any later version. + # + # This library is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + # Lesser General Public License for more details. + # + # You should have received a copy of the GNU Lesser General Public + # License along with this library; if not, write to the Free Software + # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + # + # Author: + # Jürg Billeter + + builddir=$PWD + topbuilddir=$TOPBUILDDIR + topsrcdir=$TOPSRCDIR + vapidir=$topsrcdir/vapi + + export G_DEBUG=fatal_warnings -export PKG_CONFIG_PATH=$topbuilddir/src/libvaladoc -export LD_LIBRARY_PATH=$topbuilddir/src/libvaladoc/.libs ++export PKG_CONFIG_PATH=$topbuilddir/libvaladoc ++export LD_LIBRARY_PATH=$topbuilddir/gee/.libs:$topbuilddir/libvaladoc/.libs + -VALAC=valac -VALAFLAGS="-X -D -X TOP_SRC_DIR=\"$topsrcdir\" --vapidir $topbuilddir/src/libvaladoc --pkg valadoc-1.0 --pkg gee-0.8 --disable-warnings --main main --save-temps -X -g -X -O0 -X -pipe -X -lm -X -Werror=return-type -X -Werror=init-self -X -Werror=implicit -X -Werror=sequence-point -X -Werror=return-type -X -Werror=uninitialized -X -Werror=pointer-arith -X -Werror=int-to-pointer-cast -X -Werror=pointer-to-int-cast -X -Wformat -X -Werror=format-security -X -Werror=format-nonliteral -X -L$topbuilddir/src/libvaladoc/.libs -X -I$topbuilddir/src/libvaladoc $topsrcdir/tests/libvaladoc/parser/generic-scanner.vala $topsrcdir/tests/drivers/generic-api-test.vala" ++VALAC=$topbuilddir/compiler/valac$EXEEXT ++VALAFLAGS="-X -D -X TOP_SRC_DIR=\"$topsrcdir\" --vapidir $vapidir --pkg libgvc --vapidir $topsrcdir/vala --pkg libvala$PACKAGE_SUFFIX --vapidir $topsrcdir/libvaladoc --pkg valadoc$PACKAGE_SUFFIX --disable-warnings --main main --save-temps -X -g -X -O0 -X -pipe -X -lm -X -Werror=return-type -X -Werror=init-self -X -Werror=implicit -X -Werror=sequence-point -X -Werror=return-type -X -Werror=uninitialized -X -Werror=pointer-arith -X -Werror=int-to-pointer-cast -X -Werror=pointer-to-int-cast -X -Wformat -X -Werror=format-security -X -Werror=format-nonliteral -X -Werror=redundant-decls -X -Werror=int-conversion -X -L$topbuilddir/gee/.libs -X -lgee -X -L$topbuilddir/libvaladoc/.libs -X -lvaladoc$PACKAGE_SUFFIX -X -I$topsrcdir/gee -X -I$topsrcdir/libvaladoc $topsrcdir/valadoc/tests/libvaladoc/parser/generic-scanner.vala" ++ ++ ++# Incorporate the user's CFLAGS. Matters if the user decided to insert ++# -m32 in CFLAGS, for example. ++for cflag in ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}; do ++ VALAFLAGS="${VALAFLAGS} -X ${cflag}" ++done + + testdir=_test + rm -rf $testdir + mkdir $testdir + cd $testdir + + echo -n -e "TEST: Building...\033[72G" + + cat << "EOF" > checkall + all=0 + fail=0 + EOF + + cat << "EOF" > main.vala + void main (string[] args) { + switch (args[1]) { + EOF + + PACKAGES=gio-2.0 + SOURCEFILES= + for testfile in "$@"; do + rm -f prepare check + echo 'set -e' >> prepare + + case "$testfile" in + *.vala) + testpath=${testfile/.vala/} + ns=${testpath//\//.} + ns=${ns//-/_} + SOURCEFILE=$ns.vala + SOURCEFILES="$SOURCEFILES $SOURCEFILE" + + echo " case \"/$testpath\": $ns.main (); break;" >> main.vala + echo "namespace $ns {" > $SOURCEFILE - cat "$topsrcdir/tests/$testfile" >> $SOURCEFILE ++ cat "$topsrcdir/valadoc/tests/$testfile" >> $SOURCEFILE + echo "}" >> $SOURCEFILE + + echo "./test$EXEEXT /$testpath" > check + ;; + esac + + cat prepare check > $ns.check + cat << EOF >> checkall + echo -n -e " /$testpath: \033[72G" + ((all++)) + if bash $ns.check &>log; then + echo -e "\033[0;32mOK\033[m" + else + ((fail++)) + echo -e "\033[0;31mFAIL\033[m" + cat log + fi + EOF + done + + cat << "EOF" >> checkall + if [ $fail -eq 0 ]; then + echo "All $all tests passed" + else + echo "$fail of $all tests failed" + exit 1 + fi + EOF + + cat << "EOF" >> main.vala + default: assert_not_reached (); + } + } + EOF + + cat $SOURCEFILES >> main.vala + + if $VALAC $VALAFLAGS -o test$EXEEXT $([ -z "$PACKAGES" ] || echo $PACKAGES | xargs -n 1 echo -n " --pkg") main.vala &>log; then + echo -e "\033[0;32mOK\033[m" + else + echo -e "\033[0;31mFAIL\033[m" + cat log + + cd $builddir + exit 1 + fi + + if bash checkall; then + cd $builddir + rm -rf $testdir + else + cd $builddir + exit 1 + fi + diff --cc valadoc/treebuilder.vala index 000000000,aebf2726e..7615eb80a mode 000000,100644..100644 --- a/valadoc/treebuilder.vala +++ b/valadoc/treebuilder.vala @@@ -1,0 -1,1537 +1,1535 @@@ + /* treebuilder.vala + * + * Copyright (C) 2011 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + + + using Valadoc.Api; -using Gee; - + + /** + * Creates an simpler, minimized, more abstract AST for valacs AST. + */ + public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor { - private ArrayList packages = new ArrayList (); ++ private Vala.ArrayList packages = new Vala.ArrayList (); + private PackageMetaData source_package; + - private HashMap files = new HashMap (); - private HashMap symbol_map = new HashMap (); ++ private Vala.HashMap files = new Vala.HashMap (); ++ private Vala.HashMap symbol_map = new Vala.HashMap (); + + private ErrorReporter reporter; + private Settings settings; + + private Api.Node current_node; + private Api.Tree tree; + + private Valadoc.Api.Class glib_error = null; + + + // + // Accessors + // + + public Api.Class get_glib_error () { + return glib_error; + } + - public HashMap get_symbol_map () { ++ public Vala.HashMap get_symbol_map () { + return symbol_map; + } + + + // + // + // + + private class PackageMetaData { + public Package package; - public HashMap namespaces = new HashMap (); - public ArrayList files = new ArrayList (); ++ public Vala.HashMap namespaces = new Vala.HashMap (); ++ public Vala.ArrayList files = new Vala.ArrayList (); + + public PackageMetaData (Package package) { + this.package = package; + } + + public Namespace get_namespace (Vala.Namespace vns, SourceFile file) { + Namespace? ns = namespaces.get (vns); + if (ns != null) { + return ns; + } + + // find documentation comment if existing: + SourceComment? comment = null; + if (vns.source_reference != null) { + foreach (Vala.Comment c in vns.get_comments()) { + if (c.source_reference.file == file.data || + (c.source_reference.file.file_type == Vala.SourceFileType.SOURCE + && ((Vala.SourceFile) file.data).file_type == Vala.SourceFileType.SOURCE) + ) { + Vala.SourceReference pos = c.source_reference; + if (c is Vala.GirComment) { + comment = new GirSourceComment (c.content, + file, + pos.begin.line, + pos.begin.column, + pos.end.line, + pos.end.column); + } else { + comment = new SourceComment (c.content, + file, + pos.begin.line, + pos.begin.column, + pos.end.line, + pos.end.column); + } + break; + } + } + } + + // find parent if existing + var parent_vns = vns.parent_symbol; + + if (parent_vns == null) { + ns = new Namespace (package, file, vns.name, comment, vns); + package.add_child (ns); + } else { + Namespace parent_ns = get_namespace ((Vala.Namespace) parent_vns, file); + ns = new Namespace (parent_ns, file, vns.name, comment, vns); + parent_ns.add_child (ns); + } + + namespaces.set (vns, ns); + return ns; + } + + public void register_source_file (Vala.SourceFile file) { + files.add (file); + } + + public bool is_package_for_file (Vala.SourceFile source_file) { + if (source_file.file_type == Vala.SourceFileType.SOURCE && !package.is_package) { + return true; + } + + return files.contains (source_file); + } + } + + + // + // Type constructor translation helpers: + // + + private Pointer create_pointer (Vala.PointerType vtyperef, Item parent, Api.Node caller) { + Pointer ptr = new Pointer (parent, vtyperef); + + Vala.DataType vntype = vtyperef.base_type; + if (vntype is Vala.PointerType) { + ptr.data_type = create_pointer ((Vala.PointerType) vntype, ptr, caller); + } else if (vntype is Vala.ArrayType) { + ptr.data_type = create_array ((Vala.ArrayType) vntype, ptr, caller); + } else { + ptr.data_type = create_type_reference (vntype, ptr, caller); + } + + return ptr; + } + + private Api.Array create_array (Vala.ArrayType vtyperef, Item parent, Api.Node caller) { + Api.Array arr = new Api.Array (parent, vtyperef); + + Vala.DataType vntype = vtyperef.element_type; + if (vntype is Vala.ArrayType) { + arr.data_type = create_type_reference (vntype, arr, caller); + } else { + arr.data_type = create_type_reference (vntype, arr, caller); + } + + return arr; + } + + private TypeReference create_type_reference (Vala.DataType? vtyperef, Item parent, Api.Node caller) { + bool is_nullable = vtyperef != null + && vtyperef.nullable + && !(vtyperef is Vala.GenericType) + && !(vtyperef is Vala.PointerType); + string? signature = (vtyperef != null + && vtyperef.data_type != null)? Vala.GVariantModule.get_dbus_signature (vtyperef.data_type) : null; + bool pass_ownership = type_reference_pass_ownership (vtyperef); + Ownership ownership = get_type_reference_ownership (vtyperef); + bool is_dynamic = vtyperef != null && vtyperef.is_dynamic; + + TypeReference type_ref = new TypeReference (parent, + ownership, + pass_ownership, + is_dynamic, + is_nullable, + signature, + vtyperef); + + if (vtyperef is Vala.PointerType) { + type_ref.data_type = create_pointer ((Vala.PointerType) vtyperef, type_ref, caller); + } else if (vtyperef is Vala.ArrayType) { + type_ref.data_type = create_array ((Vala.ArrayType) vtyperef, type_ref, caller); + //} else if (vtyperef is Vala.GenericType) { + // type_ref.data_type = new TypeParameter (caller, + // caller.get_source_file (), + // ((Vala.GenericType) vtyperef).type_parameter.name, + // vtyperef); + } + + // type parameters: + if (vtyperef != null) { + foreach (Vala.DataType vdtype in vtyperef.get_type_arguments ()) { + var type_param = create_type_reference (vdtype, type_ref, caller); + type_ref.add_type_argument (type_param); + } + } + + return type_ref; + } + + + + // + // Translation helpers: + // + + private void process_attributes (Api.Symbol parent, GLib.List lst) { + // attributes without arguments: + string[] attributes = { + "ReturnsModifiedPointer", + "DestroysInstance", + "GenericAccessors", + "NoAccessorMethod", + "NoArrayLength", + "Experimental", + "Diagnostics", + "PrintfFormat", + "PointerType", + "ScanfFormat", + "ThreadLocal", + "SimpleType", + "HasEmitter", + "ModuleInit", + "NoWrapper", + "Immutable", + "ErrorBase", + "NoReturn", + "NoThrow", + "Compact", + "Assert", + "Flags" + }; + + string? tmp = ""; + + foreach (Vala.Attribute att in lst) { + if (att.name == "CCode" && (tmp = att.args.get ("has_target")) != null && tmp == "false") { + Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att); + new_attribute.add_boolean ("has_target", false, att); + parent.add_attribute (new_attribute); + } else if (att.name == "Version") { + Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att); + if ((tmp = att.args.get ("deprecated")) != null) { + new_attribute.add_boolean ("deprecated", bool.parse (tmp), att); + } + if ((tmp = att.args.get ("since")) != null) { + new_attribute.add_string ("since", tmp, att); + } + if ((tmp = att.args.get ("deprecated_since")) != null) { + new_attribute.add_string ("deprecated_since", tmp, att); + if (att.args.get ("deprecated") == null) { + new_attribute.add_boolean ("deprecated", true, att); + } + } + if ((tmp = att.args.get ("replacement")) != null) { + new_attribute.add_string ("replacement", tmp, att); + } + parent.add_attribute (new_attribute); + } else if (att.name == "Deprecated") { + Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att); + if ((tmp = att.args.get ("since")) != null) { + new_attribute.add_string ("since", tmp, att); + } + if ((tmp = att.args.get ("replacement")) != null) { + new_attribute.add_string ("replacement", tmp, att); + } + parent.add_attribute (new_attribute); + } else if (att.name in attributes) { + Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att); + parent.add_attribute (new_attribute); + } + } + } + + private string? get_ccode_type_id (Vala.CodeNode node) { + return Vala.CCodeBaseModule.get_ccode_type_id (node); + } + + private bool is_reference_counting (Vala.TypeSymbol sym) { + return Vala.CCodeBaseModule.is_reference_counting (sym); + } + + private string? get_ref_function (Vala.Class sym) { + return Vala.CCodeBaseModule.get_ccode_ref_function (sym); + } + + private string? get_unref_function (Vala.Class sym) { + return Vala.CCodeBaseModule.get_ccode_unref_function (sym); + } + + private string? get_finalize_function_name (Vala.Class element) { + if (!element.is_fundamental ()) { + return null; + } + + return "%s_finalize".printf (Vala.CCodeBaseModule.get_ccode_lower_case_name (element, null)); + } + + private string? get_free_function_name (Vala.Class element) { + if (!element.is_compact) { + return null; + } + + return Vala.CCodeBaseModule.get_ccode_free_function (element); + } + + private string? get_finish_name (Vala.Method m) { + return Vala.CCodeBaseModule.get_ccode_finish_name (m); + } + + private string? get_take_value_function (Vala.Class sym) { + return Vala.CCodeBaseModule.get_ccode_take_value_function (sym); + } + + private string? get_get_value_function (Vala.Class sym) { + return Vala.CCodeBaseModule.get_ccode_get_value_function (sym); + } + + private string? get_set_value_function (Vala.Class sym) { + return Vala.CCodeBaseModule.get_ccode_set_value_function (sym); + } + + + private string? get_param_spec_function (Vala.CodeNode sym) { + return Vala.CCodeBaseModule.get_ccode_param_spec_function (sym); + } + + private string? get_dup_function (Vala.TypeSymbol sym) { + return Vala.CCodeBaseModule.get_ccode_dup_function (sym); + } + + private string? get_copy_function (Vala.TypeSymbol sym) { + return Vala.CCodeBaseModule.get_ccode_copy_function (sym); + } + + private string? get_destroy_function (Vala.TypeSymbol sym) { + return Vala.CCodeBaseModule.get_ccode_destroy_function (sym); + } + + private string? get_free_function (Vala.TypeSymbol sym) { + return Vala.CCodeBaseModule.get_ccode_free_function (sym); + } + + private string? get_cname (Vala.Symbol symbol) { + return Vala.CCodeBaseModule.get_ccode_name (symbol); + } + + private SourceComment? create_comment (Vala.Comment? comment) { + if (comment != null) { + Vala.SourceReference pos = comment.source_reference; + SourceFile file = files.get (pos.file); + if (comment is Vala.GirComment) { + var tmp = new GirSourceComment (comment.content, + file, + pos.begin.line, + pos.begin.column, + pos.end.line, + pos.end.column); + if (((Vala.GirComment) comment).return_content != null) { + Vala.SourceReference return_pos = ((Vala.GirComment) comment).return_content.source_reference; + tmp.return_comment = new SourceComment (((Vala.GirComment) comment).return_content.content, + file, + return_pos.begin.line, + return_pos.begin.column, + return_pos.end.line, + return_pos.end.column); + } + + Vala.MapIterator it = ((Vala.GirComment) comment).parameter_iterator (); + while (it.next ()) { + Vala.Comment vala_param = it.get_value (); + Vala.SourceReference param_pos = vala_param.source_reference; + var param_comment = new SourceComment (vala_param.content, + file, + param_pos.begin.line, + param_pos.begin.column, + param_pos.end.line, + param_pos.end.column); + tmp.add_parameter_content (it.get_key (), param_comment); + } + return tmp; + } else { + return new SourceComment (comment.content, + file, + pos.begin.line, + pos.begin.column, + pos.end.line, + pos.end.column); + } + } + + return null; + } + + private string get_method_name (Vala.Method element) { + if (element is Vala.CreationMethod) { + if (element.name == ".new") { + return element.parent_symbol.name; + } else { + return element.parent_symbol.name + "." + element.name; + } + } + + return element.name; + } + + private string? get_quark_macro_name (Vala.ErrorDomain element) { + return Vala.CCodeBaseModule.get_ccode_upper_case_name (element, null); + } + + private string? get_private_cname (Vala.Class element) { + if (element.is_compact) { + return null; + } + + string? cname = get_cname (element); + return (cname != null)? cname + "Private" : null; + } + + private string? get_class_macro_name (Vala.Class element) { + if (element.is_compact) { + return null; + } + + return "%s_GET_CLASS".printf (Vala.CCodeBaseModule.get_ccode_upper_case_name (element, null)); + } + + private string? get_class_type_macro_name (Vala.Class element) { + if (element.is_compact) { + return null; + } + + return "%s_CLASS".printf (Vala.CCodeBaseModule.get_ccode_upper_case_name (element, null)); + } + + private string? get_is_type_macro_name (Vala.TypeSymbol element) { + string? name = Vala.CCodeBaseModule.get_ccode_type_check_function (element); + return (name != null && name != "")? name : null; + } + + private string? get_is_class_type_macro_name (Vala.TypeSymbol element) { + string? name = get_is_type_macro_name (element); + return (name != null)? name + "_CLASS" : null; + } + + private string? get_type_function_name (Vala.TypeSymbol element) { + if ((element is Vala.Class + && ((Vala.Class) element).is_compact) + || element is Vala.ErrorDomain + || element is Vala.Delegate) + { + return null; + } + + return "%s_get_type".printf (Vala.CCodeBaseModule.get_ccode_lower_case_name (element, null)); + } + + private string? get_type_macro_name (Vala.TypeSymbol element) { + if ((element is Vala.Class + && ((Vala.Class) element).is_compact) + || element is Vala.ErrorDomain + || element is Vala.Delegate) + { + return null; + } + + return Vala.CCodeBaseModule.get_ccode_type_id (element); + } + + private string? get_type_cast_macro_name (Vala.TypeSymbol element) { + if ((element is Vala.Class + && !((Vala.Class) element).is_compact) + || element is Vala.Interface) + { + return Vala.CCodeBaseModule.get_ccode_upper_case_name (element, null); + } else { + return null; + } + } + + private string? get_interface_macro_name (Vala.Interface element) { + return "%s_GET_INTERFACE".printf (Vala.CCodeBaseModule.get_ccode_upper_case_name (element, null)); + } + + private string get_quark_function_name (Vala.ErrorDomain element) { + return Vala.CCodeBaseModule.get_ccode_lower_case_prefix (element) + "quark"; + } + + private PackageMetaData? get_package_meta_data (Package pkg) { + foreach (PackageMetaData data in packages) { + if (data.package == pkg) { + return data; + } + } + + return null; + } + + private PackageMetaData register_package (Package package) { + PackageMetaData meta_data = new PackageMetaData (package); + tree.add_package (package); + packages.add (meta_data); + return meta_data; + } + + private SourceFile register_source_file (PackageMetaData meta_data, Vala.SourceFile source_file) { + SourceFile file = new SourceFile (meta_data.package, + source_file.get_relative_filename (), + source_file.get_csource_filename (), + source_file); + files.set (source_file, file); + + meta_data.register_source_file (source_file); + return file; + } + + private SourceFile? get_source_file (Vala.Symbol symbol) { + Vala.SourceReference source_ref = symbol.source_reference; + if (source_ref == null) { + return null; + } + + SourceFile? file = files.get (source_ref.file); + assert (file != null); + return file; + } + + private Package? find_package_for_file (Vala.SourceFile source_file) { + foreach (PackageMetaData pkg in this.packages) { + if (pkg.is_package_for_file (source_file)) { + return pkg.package; + } + } + + return null; + } + + + private Namespace get_namespace (Package pkg, Vala.Symbol symbol, SourceFile? file) { + // Find the closest namespace in our vala-tree + Vala.Symbol namespace_symbol = symbol; + while (!(namespace_symbol is Vala.Namespace)) { + namespace_symbol = namespace_symbol.parent_symbol; + } + + PackageMetaData? meta_data = get_package_meta_data (pkg); + assert (meta_data != null); + + return meta_data.get_namespace ((Vala.Namespace) namespace_symbol, file); + } + + private MethodBindingType get_method_binding_type (Vala.Method element) { + if (element.is_inline) { + return MethodBindingType.INLINE; + } else if (element.is_abstract) { + return MethodBindingType.ABSTRACT; + } else if (element.is_virtual) { + return MethodBindingType.VIRTUAL; + } else if (element.overrides) { + return MethodBindingType.OVERRIDE; + } else if (element.is_inline) { + return MethodBindingType.INLINE; + } else if (element.binding != Vala.MemberBinding.INSTANCE) { + return MethodBindingType.STATIC; + } + return MethodBindingType.UNMODIFIED; + } + + + private SymbolAccessibility get_access_modifier(Vala.Symbol symbol) { + switch (symbol.access) { + case Vala.SymbolAccessibility.PROTECTED: + return SymbolAccessibility.PROTECTED; + + case Vala.SymbolAccessibility.INTERNAL: + return SymbolAccessibility.INTERNAL; + + case Vala.SymbolAccessibility.PRIVATE: + return SymbolAccessibility.PRIVATE; + + case Vala.SymbolAccessibility.PUBLIC: + return SymbolAccessibility.PUBLIC; + + default: + error ("Unknown symbol accessibility modifier found"); + } + } + + private PropertyAccessorType get_property_accessor_type (Vala.PropertyAccessor element) { + if (element.construction) { + if (element.writable) { + return (PropertyAccessorType.CONSTRUCT | PropertyAccessorType.SET); + } + return PropertyAccessorType.CONSTRUCT; + } else if (element.writable) { + return PropertyAccessorType.SET; + } else if (element.readable) { + return PropertyAccessorType.GET; + } + + error ("Unknown symbol accessibility type"); + } + + private bool type_reference_pass_ownership (Vala.DataType? element) { + if (element == null) { + return false; + } + + weak Vala.CodeNode? node = element.parent_node; + if (node == null) { + return false; + } + if (node is Vala.Parameter) { + return (((Vala.Parameter)node).direction == Vala.ParameterDirection.IN && + ((Vala.Parameter)node).variable_type.value_owned); + } + if (node is Vala.Property) { + return ((Vala.Property)node).property_type.value_owned; + } + + return false; + } + + private bool is_type_reference_unowned (Vala.DataType? element) { + if (element == null) { + return false; + } + + // non ref counted types are weak, not unowned + if (element.data_type is Vala.TypeSymbol + && is_reference_counting ((Vala.TypeSymbol) element.data_type) == true) + { + return false; + } + + // FormalParameters are weak by default + return (element.parent_node is Vala.Parameter == false) + ? element.is_weak () + : false; + } + + private bool is_type_reference_owned (Vala.DataType? element) { + if (element == null) { + return false; + } + + weak Vala.CodeNode parent = element.parent_node; + + // parameter: + if (parent is Vala.Parameter) { + if (((Vala.Parameter)parent).direction != Vala.ParameterDirection.IN) { + return false; + } + return ((Vala.Parameter)parent).variable_type.value_owned; + } + + return false; + } + + private bool is_type_reference_weak (Vala.DataType? element) { + if (element == null) { + return false; + } + + // non ref counted types are unowned, not weak + if (element.data_type is Vala.TypeSymbol + && is_reference_counting ((Vala.TypeSymbol) element.data_type) == false) + { + return false; + } + + // arrays are unowned, not weak + if (element is Vala.ArrayType) { + return false; + } + + // FormalParameters are weak by default + return (element.parent_node is Vala.Parameter == false)? element.is_weak () : false; + } + + private Ownership get_type_reference_ownership (Vala.DataType? element) { + if (is_type_reference_owned (element)) { + return Ownership.OWNED; + } else if (is_type_reference_weak (element)) { + return Ownership.WEAK; + } else if (is_type_reference_unowned (element)) { + return Ownership.UNOWNED; + } + + return Ownership.DEFAULT; + } + + private Ownership get_property_ownership (Vala.PropertyAccessor element) { + if (element.value_type.value_owned) { + return Ownership.OWNED; + } + + // the exact type (weak, unowned) does not matter + return Ownership.UNOWNED; + } + + private PropertyBindingType get_property_binding_type (Vala.Property element) { + if (element.is_abstract) { + return PropertyBindingType.ABSTRACT; + } else if (element.is_virtual) { + return PropertyBindingType.VIRTUAL; + } else if (element.overrides) { + return PropertyBindingType.OVERRIDE; + } + + return PropertyBindingType.UNMODIFIED; + } + + private FormalParameterType get_formal_parameter_type (Vala.Parameter element) { + if (element.direction == Vala.ParameterDirection.OUT) { + return FormalParameterType.OUT; + } else if (element.direction == Vala.ParameterDirection.REF) { + return FormalParameterType.REF; + } else if (element.direction == Vala.ParameterDirection.IN) { + return FormalParameterType.IN; + } + + error ("Unknown formal parameter type"); + } + + + // + // Vala tree creation: + // + + private string get_package_name (string path) { + string file_name = Path.get_basename (path); + return file_name.substring (0, file_name.last_index_of_char ('.')); + } + + private bool add_package (Vala.CodeContext context, string pkg) { + // ignore multiple occurences of the same package + if (context.has_package (pkg)) { + return true; + } + + string vapi_name = pkg + ".vapi"; + string gir_name = pkg + ".gir"; + foreach (string source_file in settings.source_files) { + string basename = Path.get_basename (source_file); + if (basename == vapi_name || basename == gir_name) { + return true; + } + } + + + var package_path = context.get_vapi_path (pkg) ?? context.get_gir_path (pkg); + if (package_path == null) { + Vala.Report.error (null, "Package `%s' not found in specified Vala API directories or GObject-Introspection GIR directories".printf (pkg)); + return false; + } + + context.add_package (pkg); + + var vfile = new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, package_path); + context.add_source_file (vfile); + Package vdpkg = new Package (pkg, true, null); + register_source_file (register_package (vdpkg), vfile); + + add_deps (context, Path.build_filename (Path.get_dirname (package_path), "%s.deps".printf (pkg)), pkg); + return true; + } + + private void add_deps (Vala.CodeContext context, string file_path, string pkg_name) { + if (FileUtils.test (file_path, FileTest.EXISTS)) { + try { + string deps_content; + ulong deps_len; + FileUtils.get_contents (file_path, out deps_content, out deps_len); + foreach (string dep in deps_content.split ("\n")) { + dep = dep.strip (); + if (dep != "") { + if (!add_package (context, dep)) { + Vala.Report.error (null, "%s, dependency of %s, not found in specified Vala API directories".printf (dep, pkg_name)); + } + } + } + } catch (FileError e) { + Vala.Report.error (null, "Unable to read dependency file: %s".printf (e.message)); + } + } + } + + /** + * Adds the specified packages to the list of used packages. + * + * @param context The code context + * @param packages a list of package names + */ + private void add_depencies (Vala.CodeContext context, string[] packages) { + foreach (string package in packages) { + if (!add_package (context, package)) { + Vala.Report.error (null, "Package `%s' not found in specified Vala API directories or GObject-Introspection GIR directories".printf (package)); + } + } + } + + /** + * Add the specified source file to the context. Only .vala, .vapi, .gs, + * and .c files are supported. + */ + private void add_documented_files (Vala.CodeContext context, string[] sources) { + if (sources == null) { + return; + } + + foreach (string source in sources) { + if (FileUtils.test (source, FileTest.EXISTS)) { + var rpath = realpath (source); + if (source.has_suffix (".vala") || source.has_suffix (".gs")) { + var source_file = new Vala.SourceFile (context, Vala.SourceFileType.SOURCE, rpath); + + if (source_package == null) { + source_package = register_package (new Package (settings.pkg_name, false, null)); + } + + register_source_file (source_package, source_file); + + if (context.profile == Vala.Profile.GOBJECT) { + // import the GLib namespace by default (namespace of backend-specific standard library) + var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null)); + source_file.add_using_directive (ns_ref); + context.root.add_using_directive (ns_ref); + } + + context.add_source_file (source_file); + } else if (source.has_suffix (".vapi") || source.has_suffix (".gir")) { + string file_name = get_package_name (source); + + var vfile = new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, rpath); + context.add_source_file (vfile); + + if (source_package == null) { + source_package = register_package (new Package (settings.pkg_name, false, null)); + } + + register_source_file (source_package, vfile); + + add_deps (context, Path.build_filename (Path.get_dirname (source), "%s.deps".printf (file_name)), file_name); + } else if (source.has_suffix (".c")) { + context.add_c_source_file (rpath); + tree.add_external_c_files (rpath); + } else { + Vala.Report.error (null, "%s is not a supported source file type. Only .vala, .vapi, .gs, and .c files are supported.".printf (source)); + } + } else { + Vala.Report.error (null, "%s not found".printf (source)); + } + } + } + + private Vala.CodeContext create_valac_tree (Settings settings) { + // init context: + var context = new Vala.CodeContext (); + Vala.CodeContext.push (context); + + + // settings: + context.experimental = settings.experimental; + context.experimental_non_null = settings.experimental || settings.experimental_non_null; + context.vapi_directories = settings.vapi_directories; + context.report.enable_warnings = settings.verbose; + context.metadata_directories = settings.metadata_directories; + context.gir_directories = settings.gir_directories; + + if (settings.basedir == null) { + context.basedir = realpath ("."); + } else { + context.basedir = realpath (settings.basedir); + } + + if (settings.directory != null) { + context.directory = realpath (settings.directory); + } else { + context.directory = context.basedir; + } + + + // add default packages: + if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) { + context.profile = Vala.Profile.GOBJECT; + context.add_define ("GOBJECT"); + } + + + if (settings.defines != null) { + foreach (string define in settings.defines) { + context.add_define (define); + } + } + - for (int i = 2; i <= 36; i += 2) { ++ for (int i = 2; i <= 38; i += 2) { + context.add_define ("VALA_0_%d".printf (i)); + } + + if (context.profile == Vala.Profile.GOBJECT) { + int glib_major = 2; + int glib_minor = 24; + + context.target_glib_major = glib_major; + context.target_glib_minor = glib_minor; + if (context.target_glib_major != 2) { + Vala.Report.error (null, "This version of valac only supports GLib 2"); + } + + if (settings.target_glib != null && settings.target_glib.scanf ("%d.%d", out glib_major, out glib_minor) != 2) { + Vala.Report.error (null, "Invalid format for --target-glib"); + } + + context.target_glib_major = glib_major; + context.target_glib_minor = glib_minor; + if (context.target_glib_major != 2) { + Vala.Report.error (null, "This version of valac only supports GLib 2"); + } + + for (int i = 16; i <= glib_minor; i += 2) { + context.add_define ("GLIB_2_%d".printf (i)); + } + + // default packages + if (!this.add_package (context, "glib-2.0")) { // + Vala.Report.error (null, "glib-2.0 not found in specified Vala API directories"); + } + + if (!this.add_package (context, "gobject-2.0")) { // + Vala.Report.error (null, "gobject-2.0 not found in specified Vala API directories"); + } + } + + // add user defined files: + add_depencies (context, settings.packages); + if (reporter.errors > 0) { + return context; + } + + add_documented_files (context, settings.source_files); + if (reporter.errors > 0) { + return context; + } + + + // parse vala-code: + Vala.Parser parser = new Vala.Parser (); + + parser.parse (context); + if (context.report.get_errors () > 0) { + return context; + } + + // parse gir: + Vala.GirParser gir_parser = new Vala.GirParser (); + + gir_parser.parse (context); + if (context.report.get_errors () > 0) { + return context; + } + + + + // check context: + context.check (); + if (context.report.get_errors () > 0) { + return context; + } + + return context; + } + + + + // + // Valadoc tree creation: + // + + private void process_children (Api.Node node, Vala.CodeNode element) { + Api.Node old_node = current_node; + current_node = node; + element.accept_children (this); + current_node = old_node; + } + + private Api.Node get_parent_node_for (Vala.Symbol element) { + if (current_node != null) { + return current_node; + } + + Vala.SourceFile vala_source_file = element.source_reference.file; + Package package = find_package_for_file (vala_source_file); + SourceFile? source_file = get_source_file (element); + + return get_namespace (package, element, source_file); + } + + /** + * {@inheritDoc} + */ + public override void visit_namespace (Vala.Namespace element) { + element.accept_children (this); + } + + /** + * {@inheritDoc} + */ + public override void visit_class (Vala.Class element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + bool is_basic_type = element.base_class == null && element.name == "string"; + + Class node = new Class (parent, + file, + element.name, + get_access_modifier (element), + comment, + get_cname (element), + get_private_cname (element), + get_class_macro_name (element), + get_type_macro_name (element), + get_is_type_macro_name (element), + get_type_cast_macro_name (element), + get_type_function_name (element), + get_class_type_macro_name (element), + get_is_class_type_macro_name (element), + Vala.GDBusModule.get_dbus_name (element), + get_ccode_type_id (element), + get_param_spec_function (element), + get_ref_function (element), + get_unref_function (element), + get_free_function_name (element), + get_finalize_function_name (element), + get_take_value_function (element), + get_get_value_function (element), + get_set_value_function (element), + element.is_fundamental (), + element.is_abstract, + is_basic_type, + element); + symbol_map.set (element, node); + parent.add_child (node); + + // relations + foreach (Vala.DataType vala_type_ref in element.get_base_types ()) { + var type_ref = create_type_reference (vala_type_ref, node, node); + + if (vala_type_ref.data_type is Vala.Interface) { + node.add_interface (type_ref); + } else if (vala_type_ref.data_type is Vala.Class) { + node.base_type = type_ref; + } + } + + process_attributes (node, element.attributes); + process_children (node, element); + + // save GLib.Error + if (glib_error == null && node.get_full_name () == "GLib.Error") { + glib_error = node; + } + } + + /** + * {@inheritDoc} + */ + public override void visit_interface (Vala.Interface element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + Interface node = new Interface (parent, + file, + element.name, + get_access_modifier (element), + comment, + get_cname (element), + get_type_macro_name (element), + get_is_type_macro_name (element), + get_type_cast_macro_name (element), + get_type_function_name (element), + get_interface_macro_name (element), + Vala.GDBusModule.get_dbus_name (element), + element); + symbol_map.set (element, node); + parent.add_child (node); + + // prerequisites: + foreach (Vala.DataType vala_type_ref in element.get_prerequisites ()) { + TypeReference type_ref = create_type_reference (vala_type_ref, node, node); + if (vala_type_ref.data_type is Vala.Interface) { + node.add_interface (type_ref); + } else { + node.base_type = type_ref; + } + } + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_struct (Vala.Struct element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + bool is_basic_type = element.base_type == null + && (element.is_boolean_type () + || element.is_floating_type () + || element.is_integer_type ()); + + Struct node = new Struct (parent, + file, + element.name, + get_access_modifier (element), + comment, + get_cname (element), + get_type_macro_name (element), + get_type_function_name (element), + get_ccode_type_id (element), + get_dup_function (element), + get_copy_function (element), + get_destroy_function (element), + get_free_function (element), + is_basic_type, + element); + symbol_map.set (element, node); + parent.add_child (node); + + // parent type: + Vala.ValueType? basetype = element.base_type as Vala.ValueType; + if (basetype != null) { + node.base_type = create_type_reference (basetype, node, node); + } + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_field (Vala.Field element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + Field node = new Field (parent, + file, + element.name, + get_access_modifier (element), + comment, + get_cname (element), + element.binding == Vala.MemberBinding.STATIC, + element.is_volatile, + element); + node.field_type = create_type_reference (element.variable_type, node, node); + symbol_map.set (element, node); + parent.add_child (node); + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_property (Vala.Property element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + Property node = new Property (parent, + file, + element.name, + get_access_modifier (element), + comment, + element.nick, + Vala.GDBusModule.get_dbus_name_for_member (element), + Vala.GDBusModule.is_dbus_visible (element), + get_property_binding_type (element), + element); + node.property_type = create_type_reference (element.property_type, node, node); + symbol_map.set (element, node); + parent.add_child (node); + + // Process property type + if (element.get_accessor != null) { + var accessor = element.get_accessor; + node.getter = new PropertyAccessor (node, + file, + element.name, + get_access_modifier (accessor), + get_cname (accessor), + get_property_accessor_type (accessor), + get_property_ownership (accessor), + accessor); + } + + if (element.set_accessor != null) { + var accessor = element.set_accessor; + node.setter = new PropertyAccessor (node, + file, + element.name, + get_access_modifier (accessor), + get_cname (accessor), + get_property_accessor_type (accessor), + get_property_ownership (accessor), + accessor); + } + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_creation_method (Vala.CreationMethod element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + Method node = new Method (parent, + file, + get_method_name (element), + get_access_modifier (element), + comment, + get_cname (element), + Vala.GDBusModule.get_dbus_name_for_member (element), + Vala.GDBusModule.dbus_result_name (element), + (element.coroutine)? get_finish_name (element) : null, + get_method_binding_type (element), + element.coroutine, + Vala.GDBusModule.is_dbus_visible (element), + element is Vala.CreationMethod, + element); + node.return_type = create_type_reference (element.return_type, node, node); + symbol_map.set (element, node); + parent.add_child (node); + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_method (Vala.Method element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + Method node = new Method (parent, + file, + get_method_name (element), + get_access_modifier (element), + comment, + get_cname (element), + Vala.GDBusModule.get_dbus_name_for_member (element), + Vala.GDBusModule.dbus_result_name (element), + (element.coroutine)? get_finish_name (element) : null, + get_method_binding_type (element), + element.coroutine, + Vala.GDBusModule.is_dbus_visible (element), + element is Vala.CreationMethod, + element); + node.return_type = create_type_reference (element.return_type, node, node); + symbol_map.set (element, node); + parent.add_child (node); + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_signal (Vala.Signal element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + Api.Signal node = new Api.Signal (parent, + file, + element.name, + get_access_modifier (element), + comment, + get_cname (element), + (element.default_handler != null)? get_cname (element.default_handler) : null, + Vala.GDBusModule.get_dbus_name_for_member (element), + Vala.GDBusModule.is_dbus_visible (element), + element.is_virtual, + element); + node.return_type = create_type_reference (element.return_type, node, node); + symbol_map.set (element, node); + parent.add_child (node); + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_delegate (Vala.Delegate element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + Delegate node = new Delegate (parent, + file, + element.name, + get_access_modifier (element), + comment, + get_cname (element), + !element.has_target, + element); + node.return_type = create_type_reference (element.return_type, node, node); + symbol_map.set (element, node); + parent.add_child (node); + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_enum (Vala.Enum element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + Symbol node = new Enum (parent, + file, + element.name, + get_access_modifier (element), + comment, + get_cname (element), + get_type_macro_name (element), + get_type_function_name (element), + element); + symbol_map.set (element, node); + parent.add_child (node); + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_enum_value (Vala.EnumValue element) { + Api.Enum parent = (Enum) get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + Symbol node = new Api.EnumValue (parent, + file, + element.name, + comment, + get_cname (element), + element); + symbol_map.set (element, node); + parent.add_child (node); + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_constant (Vala.Constant element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + Constant node = new Constant (parent, + file, + element.name, + get_access_modifier (element), + comment, + get_cname (element), + element); + node.constant_type = create_type_reference (element.type_reference, node, node); + symbol_map.set (element, node); + parent.add_child (node); + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_error_domain (Vala.ErrorDomain element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + SourceComment? comment = create_comment (element.comment); + + Symbol node = new ErrorDomain (parent, + file, + element.name, + get_access_modifier (element), + comment, + get_cname (element), + get_quark_macro_name (element), + get_quark_function_name (element), + Vala.GDBusModule.get_dbus_name (element), + element); + symbol_map.set (element, node); + parent.add_child (node); + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_error_code (Vala.ErrorCode element) { + Api.ErrorDomain parent = (ErrorDomain) get_parent_node_for (element); + SourceFile? file = get_source_file (element); + if (file == null) { + file = parent.get_source_file (); + } + + SourceComment? comment = create_comment (element.comment); + + Symbol node = new Api.ErrorCode (parent, + file, + element.name, + comment, + get_cname (element), + Vala.GDBusModule.get_dbus_name_for_member (element), + element); + symbol_map.set (element, node); + parent.add_child (node); + + process_attributes (node, element.attributes); + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_type_parameter (Vala.TypeParameter element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + + Symbol node = new TypeParameter (parent, + file, + element.name, + element); + symbol_map.set (element, node); + parent.add_child (node); + + process_children (node, element); + } + + /** + * {@inheritDoc} + */ + public override void visit_formal_parameter (Vala.Parameter element) { + Api.Node parent = get_parent_node_for (element); + SourceFile? file = get_source_file (element); + + FormalParameter node = new FormalParameter (parent, + file, + element.name, + get_access_modifier(element), + get_formal_parameter_type (element), + element.ellipsis, + element); + node.parameter_type = create_type_reference (element.variable_type, node, node); + parent.add_child (node); + + process_children (node, element); + } + + + // + // startpoint: + // + + public Api.Tree? build (Settings settings, ErrorReporter reporter) { + this.settings = settings; + this.reporter = reporter; + + this.tree = new Api.Tree (reporter, settings); + var context = create_valac_tree (settings); + this.tree.data = context; + + reporter.warnings_offset = context.report.get_warnings (); + reporter.errors_offset = context.report.get_errors (); + + if (context == null) { + return null; + } + + // TODO: Register all packages here + // register packages included by gir-files + foreach (Vala.SourceFile vfile in context.get_source_files ()) { + if (vfile.file_type == Vala.SourceFileType.PACKAGE + && vfile.get_nodes ().size > 0 - && files.has_key (vfile) == false) ++ && files.contains (vfile) == false) + { + Package vdpkg = new Package (get_package_name (vfile.filename), true, null); + register_source_file (register_package (vdpkg), vfile); + } + } + + context.accept(this); + + return (reporter.errors == 0)? tree : null; + } + } + + diff --cc valadoc/valadoc.vala index 000000000,a4aa3277f..d1727c8e8 mode 000000,100644..100644 --- a/valadoc/valadoc.vala +++ b/valadoc/valadoc.vala @@@ -1,0 -1,418 +1,403 @@@ + /* valadoc.vala + * + * Copyright (C) 2008-2014 Florian Brosch + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Florian Brosch + */ + -using GLib.Path; + using Valadoc.Importer; + using Valadoc; -using Config; -using Gee; - - + + public class ValaDoc : Object { + private const string DEFAULT_COLORS = "error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01"; + + private static string wikidirectory = null; + private static string pkg_version = null; + private static string docletpath = null; + [CCode (array_length = false, array_null_terminated = true)] + private static string[] pluginargs; - private static string gir_directory = null; + private static string directory = null; + private static string pkg_name = null; + private static string gir_name = null; + private static string gir_namespace = null; + private static string gir_version = null; + private static string driverpath = null; + + private static bool add_inherited = false; + private static bool _protected = true; + private static bool _internal = false; + private static bool with_deps = false; + private static bool _private = false; + private static bool version = false; + private static bool use_svg_images = false; + + private static bool disable_diagnostic_colors = false; + private static bool verbose = false; + private static bool force = false; + + private static string basedir = null; + [CCode (array_length = false, array_null_terminated = true)] + private static string[] defines; + private static bool experimental; + private static bool experimental_non_null = false; + private static string profile; + [CCode (array_length = false, array_null_terminated = true)] + private static string[] import_packages; + [CCode (array_length = false, array_null_terminated = true)] + private static string[] import_directories; + [CCode (array_length = false, array_null_terminated = true)] + private static string[] vapi_directories; + [CCode (array_length = false, array_null_terminated = true)] + private static string[] metadata_directories; + [CCode (array_length = false, array_null_terminated = true)] + private static string[] gir_directories; + [CCode (array_length = false, array_null_terminated = true)] + private static string[] tsources; + [CCode (array_length = false, array_null_terminated = true)] + private static string[] packages; + [CCode (array_length = false, array_null_terminated = true)] + private static string[] alternative_resource_dirs; + static string target_glib; + + private const GLib.OptionEntry[] options = { + { "directory", 'o', 0, OptionArg.FILENAME, ref directory, "Output directory", "DIRECTORY" }, + + { "basedir", 'b', 0, OptionArg.FILENAME, ref basedir, "Base source directory", "DIRECTORY" }, + { "define", 'D', 0, OptionArg.STRING_ARRAY, ref defines, "Define SYMBOL", "SYMBOL..." }, + { "profile", 0, 0, OptionArg.STRING, ref profile, "Use the given profile instead of the default", "PROFILE" }, + + { "enable-experimental", 0, 0, OptionArg.NONE, ref experimental, "Enable experimental features", null }, + { "enable-experimental-non-null", 0, 0, OptionArg.NONE, ref experimental_non_null, "Enable experimental enhancements for non-null types", null }, + + { "metadatadir", 0, 0, OptionArg.FILENAME_ARRAY, ref metadata_directories, "Look for GIR .metadata files in DIRECTORY", "DIRECTORY..." }, + { "girdir", 0, 0, OptionArg.FILENAME_ARRAY, ref gir_directories, "Look for .gir files in DIRECTORY", "DIRECTORY..." }, + { "vapidir", 0, 0, OptionArg.FILENAME_ARRAY, ref vapi_directories, "Look for package bindings in DIRECTORY", "DIRECTORY..." }, + { "pkg", 0, 0, OptionArg.STRING_ARRAY, ref packages, "Include binding for PACKAGE", "PACKAGE..." }, + + { "driver", 0, 0, OptionArg.STRING, ref driverpath, "Name of an driver or path to a custom driver", null }, + + { "importdir", 0, 0, OptionArg.FILENAME_ARRAY, ref import_directories, "Look for external documentation in DIRECTORY", "DIRECTORY..." }, + { "import", 0, 0, OptionArg.STRING_ARRAY, ref import_packages, "Include binding for PACKAGE", "PACKAGE..." }, + { "alternative-resource-dir", 0, 0, OptionArg.STRING_ARRAY, ref alternative_resource_dirs, "Alternative resource directories", "DIRECTORY..." }, + + { "wiki", 0, 0, OptionArg.FILENAME, ref wikidirectory, "Wiki directory", "DIRECTORY" }, + + { "deps", 0, 0, OptionArg.NONE, ref with_deps, "Adds packages to the documentation", null }, + + { "doclet", 0, 0, OptionArg.STRING, ref docletpath, "Name of an included doclet or path to custom doclet", "PLUGIN"}, + { "doclet-arg", 'X', 0, OptionArg.STRING_ARRAY, ref pluginargs, "Pass arguments to the doclet", "ARG" }, + + { "no-protected", 0, OptionFlags.REVERSE, OptionArg.NONE, ref _protected, "Removes protected elements from documentation", null }, + { "internal", 0, 0, OptionArg.NONE, ref _internal, "Adds internal elements to documentation", null }, + { "private", 0, 0, OptionArg.NONE, ref _private, "Adds private elements to documentation", null }, + { "use-svg-images", 0, 0, OptionArg.NONE, ref use_svg_images, "Generate SVG image charts instead of PNG", null }, + + { "package-name", 0, 0, OptionArg.STRING, ref pkg_name, "package name", "NAME" }, + { "package-version", 0, 0, OptionArg.STRING, ref pkg_version, "package version", "VERSION" }, + { "gir", 0, 0, OptionArg.STRING, ref gir_name, "GObject-Introspection repository file name", "NAME-VERSION.gir" }, + + { "version", 0, 0, OptionArg.NONE, ref version, "Display version number", null }, + + { "force", 0, 0, OptionArg.NONE, ref force, "force", null }, + { "verbose", 0, 0, OptionArg.NONE, ref verbose, "Show all warnings", null }, + { "no-color", 0, 0, OptionArg.NONE, ref disable_diagnostic_colors, "Disable colored output", null }, + { "target-glib", 0, 0, OptionArg.STRING, ref target_glib, "Target version of glib for code generation", "MAJOR.MINOR" }, + { "", 0, 0, OptionArg.FILENAME_ARRAY, ref tsources, null, "FILE..." }, + + { null } + }; + + private static int quit (ErrorReporter reporter) { + if (reporter.errors == 0) { + stdout.printf ("Succeeded - %d warning(s)\n", reporter.warnings); + return 0; + } else { + stdout.printf ("Failed: %d error(s), %d warning(s)\n", reporter.errors, reporter.warnings); + return 1; + } + } + + private static bool check_pkg_name () { + if (pkg_name == null) { + return true; + } + + if (pkg_name == "glib-2.0" || pkg_name == "gobject-2.0") { + return false; + } + + foreach (string package in tsources) { + if (pkg_name == package) { + return false; + } + } + return true; + } + + private string get_pkg_name () { + if (ValaDoc.pkg_name == null) { + if (ValaDoc.directory.has_suffix ("/")) { + ValaDoc.pkg_name = GLib.Path.get_dirname (ValaDoc.directory); + } else { + ValaDoc.pkg_name = GLib.Path.get_basename (ValaDoc.directory); + } + } + + return ValaDoc.pkg_name; + } + + private ModuleLoader? create_module_loader (ErrorReporter reporter, out Doclet? doclet, out Driver? driver) { + ModuleLoader modules = ModuleLoader.get_instance (); + + doclet = null; + driver = null; + + // doclet: + string? pluginpath = ModuleLoader.get_doclet_path (docletpath, reporter); + if (pluginpath == null) { + return null; + } + + doclet = modules.create_doclet (pluginpath); + if (doclet == null) { + reporter.simple_error (null, "failed to load doclet"); + return null; + } + + + // driver: - pluginpath = ModuleLoader.get_driver_path (driverpath, reporter); - if (pluginpath == null) { - return null; - } - - driver = modules.create_driver (pluginpath); - if (driver == null) { - reporter.simple_error (null, "failed to load driver"); - return null; - } ++ driver = new Valadoc.Drivers.Driver (); + + assert (driver != null && doclet != null); + + return modules; + } + + private int run (ErrorReporter reporter) { + // settings: + var settings = new Valadoc.Settings (); + reporter.settings = settings; + + settings.pkg_name = this.get_pkg_name (); + settings.gir_namespace = ValaDoc.gir_namespace; + settings.gir_version = ValaDoc.gir_version; + if (ValaDoc.gir_name != null) { + settings.gir_name = GLib.Path.get_basename (ValaDoc.gir_name); + settings.gir_directory = GLib.Path.get_dirname (ValaDoc.gir_name); + if (settings.gir_directory == "") { + settings.gir_directory = GLib.Path.get_dirname (ValaDoc.directory); + } + } + settings.pkg_version = ValaDoc.pkg_version; + settings.add_inherited = ValaDoc.add_inherited; + settings._protected = ValaDoc._protected; + settings._internal = ValaDoc._internal; + settings.with_deps = ValaDoc.with_deps; + settings._private = ValaDoc._private; + settings.path = realpath (ValaDoc.directory); + settings.verbose = ValaDoc.verbose; + settings.wiki_directory = ValaDoc.wikidirectory; + settings.pluginargs = ValaDoc.pluginargs; + + settings.experimental = experimental; + settings.experimental_non_null = experimental_non_null; + settings.basedir = basedir; + settings.directory = directory; + settings.vapi_directories = vapi_directories; + settings.metadata_directories = metadata_directories; + settings.gir_directories = gir_directories; + settings.target_glib = target_glib; + settings.use_svg_images = use_svg_images; + + settings.source_files = tsources; + settings.packages = packages; + + settings.profile = profile; + settings.defines = defines; + + settings.alternative_resource_dirs = alternative_resource_dirs; + + + // load plugins: + Doclet? doclet = null; + Driver? driver = null; + + ModuleLoader? modules = create_module_loader (reporter, out doclet, out driver); + if (reporter.errors > 0 || modules == null) { + return quit (reporter); + } + + + // Create tree: + Valadoc.Api.Tree doctree = driver.build (settings, reporter); + if (reporter.errors > 0) { + driver = null; + doclet = null; + return quit (reporter); + } + + // register child symbols: + Valadoc.Api.ChildSymbolRegistrar registrar = new Valadoc.Api.ChildSymbolRegistrar (); + doctree.accept (registrar); + + // process documentation + Valadoc.DocumentationParser docparser = new Valadoc.DocumentationParser (settings, reporter, doctree, modules); + if (!doctree.create_tree()) { + return quit (reporter); + } + + DocumentationImporter[] importers = { + new ValadocDocumentationImporter (doctree, docparser, modules, settings, reporter), + new GirDocumentationImporter (doctree, docparser, modules, settings, reporter) + }; + + doctree.parse_comments (docparser); + if (reporter.errors > 0) { + return quit (reporter); + } + + doctree.import_comments (importers, import_packages, import_directories); + if (reporter.errors > 0) { + return quit (reporter); + } + + doctree.check_comments (docparser); + if (reporter.errors > 0) { + return quit (reporter); + } + + if (ValaDoc.gir_name != null) { + driver.write_gir (settings, reporter); + if (reporter.errors > 0) { + return quit (reporter); + } + } + + doclet.process (settings, doctree, reporter); + return quit (reporter); + } + + static int main (string[] args) { + Intl.setlocale (LocaleCategory.ALL, ""); + ErrorReporter reporter = new ErrorReporter(); + + try { + var opt_context = new OptionContext ("- Vala Documentation Tool"); + opt_context.set_help_enabled (true); + opt_context.add_main_entries (options, null); + opt_context.parse (ref args); + } catch (OptionError e) { + reporter.simple_error (null, "%s", e.message); + stdout.printf ("Run '%s --help' to see a full list of available command line options.\n", args[0]); + return quit (reporter); + } + + if (disable_diagnostic_colors == false) { + unowned string env_colors = Environment.get_variable ("VALA_COLORS"); + if (env_colors != null) { + reporter.set_colors (env_colors); + } else { + reporter.set_colors (DEFAULT_COLORS); + } + } + + if (version) { - stdout.printf ("Valadoc %s\n", Config.version); ++ stdout.printf ("Valadoc %s\n", Config.BUILD_VERSION); + return 0; + } + + if (directory == null) { + reporter.simple_error (null, "No output directory specified."); + return quit (reporter); + } + + if (!check_pkg_name ()) { + reporter.simple_error (null, "File already exists"); + return quit (reporter); + } + + if (FileUtils.test (directory, FileTest.EXISTS)) { + if (force == true) { + bool tmp = remove_directory (directory); + if (tmp == false) { + reporter.simple_error (null, "Can't remove directory."); + return quit (reporter); + } + } else { + reporter.simple_error (null, "File already exists"); + return quit (reporter); + } + } + + if (wikidirectory != null) { + if (!FileUtils.test(wikidirectory, FileTest.IS_DIR)) { + reporter.simple_error (null, "Wiki-directory does not exist."); + return quit (reporter); + } + } + + foreach (unowned string dir in alternative_resource_dirs) { + if (!FileUtils.test(dir, FileTest.IS_DIR)) { + reporter.simple_error (null, "alternative resource directory '%s' does not exist.".printf (dir)); + return quit (reporter); + } + } + if (reporter.errors > 0) { + return quit (reporter); + } + + if (gir_name != null) { + long gir_len = gir_name.length; + int last_hyphen = gir_name.last_index_of_char ('-'); + + if (last_hyphen == -1 || !gir_name.has_suffix (".gir")) { + reporter.simple_error (null, "GIR file name '%s' is not well-formed, expected NAME-VERSION.gir", gir_name); + return quit (reporter); + } + + gir_namespace = gir_name.substring (0, last_hyphen); + gir_version = gir_name.substring (last_hyphen + 1, gir_len - last_hyphen - 5); + gir_version.canon ("0123456789.", '?'); + + if (gir_namespace == "" || gir_version == "" || !gir_version[0].isdigit () || gir_version.contains ("?")) { + reporter.simple_error (null, "GIR file name '%s' is not well-formed, expected NAME-VERSION.gir", gir_name); + return quit (reporter); + } + + + bool report_warning = true; + foreach (string source in tsources) { + if (source.has_suffix (".vala") || source.has_suffix (".gs")) { + report_warning = false; + break; + } + } + + if (report_warning == true) { + reporter.simple_error (null, "No source file specified to be compiled to gir."); + return quit (reporter); + } + } + + + var valadoc = new ValaDoc( ); + return valadoc.run (reporter); + } + } + +