+2006-08-05 Jürg Billeter <j@bitron.ch>
+
+ * vala/valaparser.vala: only parse .vala source files
+ * vala/valasymbolbuilder.vala, vala/valaproperty.vala: support disabling
+ automatic property accessor generation
+ * vala/valasemanticanalyzer.vala: fix typo
+ * vala/valacodegenerator.vala, vala/valainterfacewriter.vala,
+ vala/valacodecontext.vala: use correct includes for libraries
+ * vala/valacodegenerator.vala: use get_canonical_cconstant method for
+ signals
+ * vala/valainterfacewriter.vala: support interfaces, non-null types,
+ callbacks, and construction methods
+ * vala/valasignal.vala: add get_canonical_cconstant method
+ * vala/valaenum.vala, vala/valainterface.vala, vala/valanamespace.vala,
+ vala/valastruct: add default arguments
+ * vala/Makefile.am: install libvala.so and header files
+ * ccode/Makefile.am: install header files
+ * compiler/valacompiler.vala: set library name in code context
+ * compiler/Makefile.am: adapt to build system changes
+ * vapi/glib-2.0.vala: add skeletons for Callback, Closure, IOChannel,
+ TimeVal, Scanner, SpawnFlags, OptionGroup, MarkupParser, and Quark
+ * vapi/Makefile.am: add vala-1.0.vala
+ * vala-1.0.pc.in
+ * configure.ac: disable static library by default, add vala-1.0.pc
+ * Makefile.am: add vala-1.0.pc
+
2006-08-02 Jürg Billeter <j@bitron.ch>
* configure.ac: Post-release version bump.
vapi \
tests \
$(NULL)
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = vala-1.0.pc
+
+EXTRA_DIST = vala-1.0.pc.in
$(GLIB_CFLAGS) \
$(NULL)
-BUILT_SOURCES = valaccode.vala.stamp
+BUILT_SOURCES = ccode.vala.stamp
noinst_LTLIBRARIES = \
libvalaccode.la
$(NULL)
libvalaccode_la_SOURCES = \
- valaccode.vala.stamp \
+ ccode.vala.stamp \
valaccodeassignment.c \
valaccodeassignment.h \
valaccodeassignment.vala \
valaccodeelementaccess.vala \
$(NULL)
-valaccode.vala valaccode.vala.stamp: $(filter %.vala,$(libvalaccode_la_SOURCES))
- $(VALAC) --vapidir $(srcdir)/../vapi --library valaccode $^
+ccodeincludedir = $(includedir)/vala-1.0/ccode
+
+ccodeinclude_HEADERS = \
+ valaccodeassignment.h \
+ valaccodebinaryexpression.h \
+ valaccodeblock.h \
+ valaccodebreakstatement.h \
+ valaccodecasestatement.h \
+ valaccodecastexpression.h \
+ valaccodecommaexpression.h \
+ valaccodecomment.h \
+ valaccodeconditionalexpression.h \
+ valaccodeconstant.h \
+ valaccodecontinuestatement.h \
+ valaccodedeclaration.h \
+ valaccodedeclarator.h \
+ valaccodeemptystatement.h \
+ valaccodeenum.h \
+ valaccodeexpression.h \
+ valaccodeexpressionstatement.h \
+ valaccodeformalparameter.h \
+ valaccodeforstatement.h \
+ valaccodefragment.h \
+ valaccodefunction.h \
+ valaccodefunctioncall.h \
+ valaccodefunctiondeclarator.h \
+ valaccodeidentifier.h \
+ valaccodeifstatement.h \
+ valaccodeincludedirective.h \
+ valaccodeinitializerlist.h \
+ valaccodelinedirective.h \
+ valaccodemacroreplacement.h \
+ valaccodememberaccess.h \
+ valaccodemodifiers.h \
+ valaccodenewline.h \
+ valaccodenode.h \
+ valaccodeoncesection.h \
+ valaccodeparenthesizedexpression.h \
+ valaccodereturnstatement.h \
+ valaccodestatement.h \
+ valaccodestruct.h \
+ valaccodeswitchstatement.h \
+ valaccodetypedefinition.h \
+ valaccodeunaryexpression.h \
+ valaccodevariabledeclarator.h \
+ valaccodewhilestatement.h \
+ valaccodewriter.h \
+ valaccodeelementaccess.h \
+ $(NULL)
+
+ccode.vala ccode.vala.stamp: $(filter %.vala,$(libvalaccode_la_SOURCES))
+ $(VALAC) --vapidir $(srcdir)/../vapi --library ccode $^
touch $@
libvalaccode_la_LIBADD = \
$(GLIB_LIBS) \
$(NULL)
-EXTRA_DIST = valaccode.vala valaccode.vala.stamp
+EXTRA_DIST = ccode.vala ccode.vala.stamp
INCLUDES = \
$(GLIB_CFLAGS) \
- -I../ccode \
- -I../vala \
$(NULL)
BUILT_SOURCES = valac.vala.stamp
$(NULL)
valac.vala.stamp: $(filter %.vala,$(valac_SOURCES))
- $(VALAC) --vapidir $(srcdir)/../vapi --vapidir ../ccode --pkg valaccode --vapidir ../vala --pkg vala $^
+ $(VALAC) --vapidir $(srcdir)/../vapi --vapidir ../ccode --pkg ccode --vapidir ../vala --pkg vala $^
touch $@
valac_LDADD = \
$(GLIB_LIBS) \
- ../ccode/libvalaccode.la \
../vala/libvala.la \
$(NULL)
private int run () {
context = new CodeContext ();
+ context.library = library;
+
/* default package */
if (!add_package ("glib-2.0")) {
Report.error (null, "glib-2.0 not found in specified Vala API directories");
# Checks for programs.
AC_PROG_CC
+AC_DISABLE_STATIC
AC_PROG_LIBTOOL
AM_PROG_LEX
AC_PROG_YACC
AC_SUBST(GLIB_LIBS)
AC_CONFIG_FILES([Makefile
+ vala-1.0.pc
ccode/Makefile
vala/Makefile
compiler/Makefile
--- /dev/null
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+datarootdir=@datarootdir@
+datadir=@datadir@
+
+Name: Vala
+Description: The Vala compiler library
+Version: @VERSION@
+Requires: glib-2.0 gobject-2.0
+Libs: -L${libdir} -lvala
+Cflags: -I${includedir}/vala-1.0
INCLUDES = \
$(GLIB_CFLAGS) \
- -I ../ccode \
$(NULL)
BUILT_SOURCES = parser.h vala.vala.stamp
AM_YFLAGS = -d
-noinst_LTLIBRARIES = \
+lib_LTLIBRARIES = \
libvala.la
$(NULL)
scanner.l \
vala.h \
vala.vala.stamp \
+ valaarray.c \
+ valaarray.h \
+ valaarray.vala \
valaassignment.c \
valaassignment.h \
valaassignment.vala \
valawhilestatement.c \
valawhilestatement.h \
valawhilestatement.vala \
- valaarray.c \
+ $(NULL)
+
+valaincludedir = $(includedir)/vala-1.0/vala
+
+valainclude_HEADERS = \
+ vala.h \
valaarray.h \
- valaarray.vala \
+ valaassignment.h \
+ valaattribute.h \
+ valaattributeprocessor.h \
+ valabinaryexpression.h \
+ valablock.h \
+ valabooleanliteral.h \
+ valabreakstatement.h \
+ valacallback.h \
+ valacastexpression.h \
+ valacharacterliteral.h \
+ valaclass.h \
+ valaclassregisterfunction.h \
+ valacodecontext.h \
+ valacodegenerator.h \
+ valacodenode.h \
+ valacodevisitor.h \
+ valaconditionalexpression.h \
+ valaconstant.h \
+ valaconstructor.h \
+ valacontinuestatement.h \
+ valadatatype.h \
+ valadeclarationstatement.h \
+ valadestructor.h \
+ valadostatement.h \
+ valaelementaccess.h \
+ valaemptystatement.h \
+ valaenum.h \
+ valaenumvalue.h \
+ valaexpression.h \
+ valaexpressionstatement.h \
+ valafield.h \
+ valaflags.h \
+ valaflagsvalue.h \
+ valaforeachstatement.h \
+ valaformalparameter.h \
+ valaforstatement.h \
+ valaifstatement.h \
+ valainitializerlist.h \
+ valainstancecast.h \
+ valaintegerliteral.h \
+ valainterface.h \
+ valainterfaceregisterfunction.h \
+ valainterfacewriter.h \
+ valainvocationexpression.h \
+ valalambdaexpression.h \
+ valaliteral.h \
+ valaliteralexpression.h \
+ valalocalvariabledeclaration.h \
+ valamemberaccess.h \
+ valamemberaccessibility.h \
+ valamemorymanager.h \
+ valamethod.h \
+ valanamedargument.h \
+ valanamespace.h \
+ valanamespacereference.h \
+ valanullliteral.h \
+ valaobjectcreationexpression.h \
+ valaparenthesizedexpression.h \
+ valaparser.h \
+ valapostfixexpression.h \
+ valapropertyaccessor.h \
+ valaproperty.h \
+ valarealliteral.h \
+ valareport.h \
+ valareturnstatement.h \
+ valasemanticanalyzer.h \
+ valasignal.h \
+ valasourcefile.h \
+ valasourcefilecycle.h \
+ valasourcereference.h \
+ valastatement.h \
+ valastringliteral.h \
+ valastruct.h \
+ valaswitchlabel.h \
+ valaswitchsection.h \
+ valaswitchstatement.h \
+ valasymbolbuilder.h \
+ valasymbol.h \
+ valasymbolresolver.h \
+ valatypecheck.h \
+ valatypeofexpression.h \
+ valatypeparameter.h \
+ valatypereference.h \
+ valatyperegisterfunction.h \
+ valaunaryexpression.h \
+ valavariabledeclarator.h \
+ valawhilestatement.h \
$(NULL)
vala.vala vala.vala.stamp: $(filter %.vala,$(libvala_la_SOURCES))
- $(VALAC) --vapidir $(srcdir)/../vapi --vapidir ../ccode --pkg valaccode --library vala $^
+ $(VALAC) --vapidir $(srcdir)/../vapi --vapidir ../ccode --pkg ccode --library vala $^
touch $@
libvala_la_LIBADD = \
* @param source reference to source code
* @return newly created class
*/
- public construct (string! _name, SourceReference source) {
+ public construct (string! _name, SourceReference source = null) {
name = _name;
source_reference = source;
}
* The root of the code tree.
*/
public class Vala.CodeContext {
+ /**
+ * Specifies the name of the library to be built.
+ *
+ * Public header files of a library will be assumed to be installed in
+ * a subdirectory named like the library.
+ */
+ public string library { get; set; }
+
List<SourceFile> source_files;
private Symbol! root = new Symbol ();
*/
public bool memory_management { get; set; }
+ private CodeContext context;
+
Symbol root_symbol;
Symbol current_symbol;
Symbol current_type_symbol;
* @param context a code context
*/
public void emit (CodeContext! context) {
+ this.context = context;
+
context.find_header_cycles ();
root_symbol = context.get_root ();
}
}
}
+
+ private ref CCodeIncludeDirective get_internal_include (string! filename) {
+ if (context.library != null) {
+ return new CCodeIncludeDirective ("%s/%s".printf (context.library, filename));
+ } else {
+ return new CCodeIncludeDirective (filename, true);
+ }
+ }
public override void visit_begin_source_file (SourceFile! source_file) {
header_begin = new CCodeFragment ();
}
foreach (string filename2 in source_file.get_header_internal_includes ()) {
if (used_includes.find_custom (filename2, strcmp) == null) {
- header_begin.append (new CCodeIncludeDirective (filename2, true));
+ header_begin.append (get_internal_include (filename2));
used_includes.append (filename2);
}
}
}
foreach (string filename4 in source_file.get_source_internal_includes ()) {
if (used_includes.find_custom (filename4, strcmp) == null) {
- source_include_directives.append (new CCodeIncludeDirective (filename4, true));
+ source_include_directives.append (get_internal_include (filename4));
used_includes.append (filename4);
}
}
ccall.add_argument (new CCodeIdentifier ("self"));
}
- ccall.add_argument (new CCodeConstant ("\"%s\"".printf (sig.name)));
+ ccall.add_argument (sig.get_canonical_cconstant ());
ccall.add_argument (new CCodeCastExpression (new CCodeIdentifier (m.get_cname ()), "GCallback"));
* @param source reference to source code
* @return newly created enum
*/
- public construct (string! _name, SourceReference source) {
+ public construct (string! _name, SourceReference source = null) {
name = _name;
source_reference = source;
}
* @param source reference to source code
* @return newly created interface
*/
- public construct (string! _name, SourceReference source) {
+ public construct (string! _name, SourceReference source = null) {
name = _name;
source_reference = source;
}
* Code visitor generating Vala API file for the public interface.
*/
public class Vala.InterfaceWriter : CodeVisitor {
+ private CodeContext context;
+
File stream;
int indent;
* @param filename a relative or absolute filename
*/
public void write_file (CodeContext! context, string! filename) {
+ this.context = context;
+
stream = File.open (filename, "w");
/* we're only interested in non-pkg source files */
public override void visit_begin_source_file (SourceFile! source_file) {
current_cheader_filename = source_file.get_cheader_filename ();
+
+ if (context.library != null) {
+ current_cheader_filename = "%s/%s".printf (context.library, current_cheader_filename);
+ }
}
public override void visit_begin_namespace (Namespace! ns) {
write_newline ();
}
+ public override void visit_begin_interface (Interface! iface) {
+ if (iface.access != MemberAccessibility.PUBLIC) {
+ internal_scope = true;
+ return;
+ }
+
+ write_indent ();
+ write_string ("public ");
+ write_string ("interface ");
+ write_identifier (iface.name);
+
+ write_begin_block ();
+ }
+
+ public override void visit_end_interface (Interface! iface) {
+ if (iface.access != MemberAccessibility.PUBLIC) {
+ internal_scope = false;
+ return;
+ }
+
+ write_end_block ();
+ write_newline ();
+ }
+
public override void visit_begin_enum (Enum! en) {
if (en.access != MemberAccessibility.PUBLIC) {
internal_scope = true;
write_string (";");
write_newline ();
}
-
- public override void visit_begin_method (Method! m) {
- if (internal_scope || m.access != MemberAccessibility.PUBLIC || m.overrides) {
- return;
- }
-
- write_indent ();
- write_string ("public ");
-
- if (m.construction) {
- write_string ("construct ");
- } else if (!m.instance) {
- write_string ("static ");
- } else if (m.is_abstract) {
- write_string ("abstract ");
- } else if (m.is_virtual) {
- write_string ("virtual ");
- }
-
- if (!m.construction) {
- var type = m.return_type.data_type;
- if (type == null) {
- write_string ("void");
- } else {
- if (m.return_type.transfers_ownership) {
- write_string ("ref ");
- }
- write_string (m.return_type.data_type.symbol.get_full_name ());
- }
- }
-
- if (m.name != null) {
- write_string (" ");
- write_identifier (m.name);
- }
-
- write_string (" (");
+
+ private void write_params (List<FormalParameter> params) {
+ write_string ("(");
bool first = true;
- foreach (FormalParameter param in m.get_parameters ()) {
+ foreach (FormalParameter param in params) {
if (!first) {
write_string (", ");
} else {
}
write_string (">");
}
+
+ if (param.type_reference.non_null) {
+ write_string ("!");
+ }
write_string (" ");
+ if (param.name == "callback" || param.name == "flags" ||
+ param.name == "out") {
+ write_string ("@");
+ }
write_identifier (param.name);
if (param.default_expression != null) {
}
}
- write_string (");");
+ write_string (")");
+ }
+
+ public override void visit_begin_callback (Callback! cb) {
+ if (internal_scope || cb.access != MemberAccessibility.PUBLIC) {
+ return;
+ }
+
+ write_indent ();
+ write_string ("public callback ");
+
+ var type = cb.return_type.data_type;
+ if (type == null) {
+ write_string ("void");
+ } else {
+ if (cb.return_type.transfers_ownership) {
+ write_string ("ref ");
+ }
+ write_string (cb.return_type.data_type.symbol.get_full_name ());
+ }
+
+ write_string (" ");
+ write_identifier (cb.name);
+
+ write_string (" ");
+
+ write_params (cb.get_parameters ());
+
+ write_string (";");
+
+ write_newline ();
+ }
+
+ public override void visit_begin_method (Method! m) {
+ if (internal_scope || m.access != MemberAccessibility.PUBLIC || m.overrides) {
+ return;
+ }
+
+ write_indent ();
+ write_string ("public");
+
+ if (m.construction) {
+ write_string (" construct");
+ } else if (!m.instance) {
+ write_string (" static");
+ } else if (m.is_abstract) {
+ write_string (" abstract");
+ } else if (m.is_virtual) {
+ write_string (" virtual");
+ }
+
+ if (!m.construction) {
+ write_string (" ");
+
+ var type = m.return_type.data_type;
+ if (type == null) {
+ write_string ("void");
+ } else {
+ if (m.return_type.transfers_ownership) {
+ write_string ("ref ");
+ }
+ write_string (m.return_type.data_type.symbol.get_full_name ());
+ if (m.return_type.non_null) {
+ write_string ("!");
+ }
+ }
+ }
+
+ if (m.name != null) {
+ write_string (" ");
+ if (m.name == "class" || m.name == "construct" ||
+ m.name == "foreach" || m.name == "get" ||
+ m.name == "ref" || m.name == "set") {
+ write_string ("@");
+ }
+ write_identifier (m.name);
+ }
+
+ write_string (" ");
+
+ write_params (m.get_parameters ());
+
+ write_string (";");
+
write_newline ();
}
* @param source reference to source code
* @return newly created namespace
*/
- public construct (string _name, SourceReference source) {
+ public construct (string _name, SourceReference source = null) {
name = _name;
source_reference = source;
}
}
public override void visit_begin_source_file (SourceFile! source_file) {
- parse_file (source_file);
- source_file.comment = _file_comment;
+ if (source_file.filename.has_suffix (".vala")) {
+ parse_file (source_file);
+ source_file.comment = _file_comment;
+ }
}
public override void visit_end_source_file (SourceFile! source_file) {
*/
public bool no_accessor_method { get; set; }
+ /**
+ * Specifies whether automatic accessor code generation should be
+ * disabled.
+ */
+ public bool interface_only { get; set; }
+
/**
* Creates a new property.
*
if (base_method.is_abstract || base_method.is_virtual) {
if (!m.equals (base_method)) {
m.error = true;
- Report.error (m.source_reference, "Return type and or parameters of overridding method `%s' do not match overridden method `%s'.".printf (m.symbol.get_full_name (), base_method.symbol.get_full_name ()));
+ Report.error (m.source_reference, "Return type and or parameters of overriding method `%s' do not match overridden method `%s'.".printf (m.symbol.get_full_name (), base_method.symbol.get_full_name ()));
return;
}
private List<FormalParameter> parameters;
private Callback generated_callback;
+ private string cname;
+
/**
* Creates a new signal.
*
return generated_callback;
}
+
+ /**
+ * Returns the name of this signal as it is used in C code.
+ *
+ * @return the name to be used in C code
+ */
+ public string! get_cname () {
+ if (cname == null) {
+ cname = name;
+ }
+ return cname;
+ }
+
+ public void set_cname (string cname) {
+ this.cname = cname;
+ }
+
+ /**
+ * Returns the string literal of this signal to be used in C code.
+ *
+ * @return string literal to be used in C code
+ */
+ public ref CCodeConstant! get_canonical_cconstant () {
+ var str = new String ("\"");
+
+ string i = name;
+
+ while (i.len () > 0) {
+ unichar c = i.get_char ();
+ if (c == '_') {
+ str.append_c ('-');
+ } else {
+ str.append_unichar (c);
+ }
+
+ i = i.next_char ();
+ }
+
+ str.append_c ('"');
+
+ return new CCodeConstant (str.str);
+ }
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_signal (this);
* @param source reference to source code
* @return newly created struct
*/
- public construct (string! _name, SourceReference source) {
+ public construct (string! _name, SourceReference source = null) {
name = _name;
source_reference = source;
}
/* no accessor body specified, insert default body */
var prop = (Property) acc.symbol.parent_symbol.node;
+
+ if (prop.interface_only) {
+ return;
+ }
var block = new Block ();
if (acc.readable) {
vapidir = $(pkgdatadir)/vapi
+vala-1.0.vala: ../ccode/ccode.vala ../vala/vala.vala
+ cat $^ > $@
+
dist_vapi_DATA = \
glib-2.0.vala \
libxml-2.0.vala \
gtk+-2.0.vala \
pango.vala \
+ vala-1.0.vala \
$(NULL)
public Object get_object ();
}
+ public callback void Callback ();
+
+ public struct Closure {
+ }
+
[ReferenceType (dup_function = "g_main_loop_ref", free_function = "g_main_loop_unref")]
public struct MainLoop {
public construct (MainContext context, bool is_running);
}
public static pointer malloc0 (ulong n_bytes);
+
+ [ReferenceType ()]
+ public struct IOChannel {
+ }
[ReferenceType ()]
public struct Error {
public static ref string decode (string! text, ref ulong out_len);
}
+ public struct TimeVal {
+ }
+
public struct Environment {
[CCode (cname = "g_get_application_name")]
public static string get_application_name ();
[CCode (cname = "g_build_filename")]
public static ref string build_filename (string first_element, ...);
}
+
+ [ReferenceType (free_function = "g_scanner_destroy")]
+ public struct Scanner {
+ }
+
+ public enum SpawnFlags {
+ }
+
+ public callback void SpawnChildSetupFunc (pointer user_data);
public enum FileTest {
IS_REGULAR,
string arg_description;
}
+ [ReferenceType ()]
+ public struct OptionGroup {
+ }
+
+ [CCode (cprefix = "G_MARKUP_")]
+ public enum MarkupParseFlags {
+ TREAT_CDATA_AS_TEXT
+ }
+
+ [ReferenceType (free_function = "g_markup_parse_context_free")]
+ public struct MarkupParseContext {
+ public construct (MarkupParser parser, MarkupParseFlags _flags, pointer user_data, DestroyNotify user_data_dnotify);
+ public bool parse (string text, long text_len, out Error error);
+ }
+
+ public callback void MarkupParserStartElementFunc (MarkupParseContext context, string element_name, string[] attribute_names, string[] attribute_values, pointer user_data, out Error error);
+
+ public callback void MarkupParserEndElementFunc (MarkupParseContext context, string element_name, pointer user_data, out Error error);
+
+ public callback void MarkupParserTextFunc (MarkupParseContext context, string text, ulong text_len, pointer user_data, out Error error);
+
+ public callback void MarkupParserPassthroughFunc (MarkupParseContext context, string passthrough_text, ulong text_len, pointer user_data, out Error error);
+
+ public callback void MarkupParserErrorFunc (MarkupParseContext context, Error error, pointer user_data);
+
+ [ReferenceType (free_function = "g_free")]
+ public struct MarkupParser {
+ public MarkupParserStartElementFunc start_element;
+ public MarkupParserEndElementFunc end_element;
+ public MarkupParserTextFunc text;
+ public MarkupParserPassthroughFunc passthrough;
+ public MarkupParserErrorFunc error;
+ }
+
[ReferenceType (dup_function = "g_list_copy", free_function = "g_list_free")]
public struct List<G> {
[ReturnsModifiedPointer ()]
public long len;
public long allocated_len;
}
+
+ public struct Quark {
+ public static Quark from_string (string string);
+ public string to_string ();
+ }
}