Commit 35bd6909 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

support ELLIPSIS, use g_strdup instead of strdup support variable argument

2006-05-25  Jürg Billeter  <j@bitron.ch>

	* vala/scanner.l: support ELLIPSIS, use g_strdup instead of strdup
	* vala/parser.y: support variable argument lists, type access modifiers
	* vala/valareport.vala: class to handle error reporting
	* vala/valasymbolbuilder.vala: switch to new error reporting scheme
	* vala/valasymbolresolver.vala: switch to new error reporting scheme
	* vala/valasemanticanalyzer.vala: process Constant and EnumValue symbol
	  dependencies, check method argument types, find types of unary and
	  binary expressions, remove dummy field, switch to new error reporting
	  scheme
	* vala/valacodegenerator.vala: support calling functions with variable
	  argument lists, support break and continue statements, remove dummy fields,
	  switch to new error reporting scheme
	* vala/valainterfacewriter.vala: visitor to write public vala api in one
	  file
	* vala/valasourcefile.vala: support field and property symbol
	  dependencies, remove dummy field
	* vala/valaclass.vala: add is_abstract field
	* vala/valaenumvalue.vala: remove dummy field
	* vala/valaformalparameter.vala: add ellipsis property
	* vala/valamemberaccessibility.vala: add INTERNAL
	* vala/valamethod.vala: make parameters public, remove dummy field
	* vala/valaproperty.vala: remove dummy field
	* vala/valasymbol.vala: add name field and get_full_name method
	* vala/valatype.vala: add access field
	* vala/valatypereference.vala: switch to new error reporting scheme
	* ccode/valaccodeblock.vala: improve formatting
	* ccode/valaccodeifstatement.vala: improve formatting
	* ccode/valaccodewriter.vala: improve formatting
	* compiler/valacompiler.vala: add error handling, support multiple vapi
	  directories, add --library option to generate public vala api
	* vapi/glib-2.0.vala: moved from bindings, add static GLib.stdout field,
	  correctly mark functions with variable argument lists, add File.test
	  method

	* configure.ac,Makefile.am,ccode/Makefile.am,vala/Makefile.am,
	  vapi/Makefile.am,compiler/Makefile.am: add build system
	
	* remove valac subdirectory: Bootstrap compiler is now obsolete.

svn path=/trunk/; revision=36
parent 29a1dec5
2006-05-25 Jürg Billeter <j@bitron.ch>
* vala/scanner.l: support ELLIPSIS, use g_strdup instead of strdup
* vala/parser.y: support variable argument lists, type access modifiers
* vala/valareport.vala: class to handle error reporting
* vala/valasymbolbuilder.vala: switch to new error reporting scheme
* vala/valasymbolresolver.vala: switch to new error reporting scheme
* vala/valasemanticanalyzer.vala: process Constant and EnumValue symbol
dependencies, check method argument types, find types of unary and
binary expressions, remove dummy field, switch to new error reporting
scheme
* vala/valacodegenerator.vala: support calling functions with variable
argument lists, support break and continue statements, remove dummy fields,
switch to new error reporting scheme
* vala/valainterfacewriter.vala: visitor to write public vala api in one
file
* vala/valasourcefile.vala: support field and property symbol
dependencies, remove dummy field
* vala/valaclass.vala: add is_abstract field
* vala/valaenumvalue.vala: remove dummy field
* vala/valaformalparameter.vala: add ellipsis property
* vala/valamemberaccessibility.vala: add INTERNAL
* vala/valamethod.vala: make parameters public, remove dummy field
* vala/valaproperty.vala: remove dummy field
* vala/valasymbol.vala: add name field and get_full_name method
* vala/valatype.vala: add access field
* vala/valatypereference.vala: switch to new error reporting scheme
* ccode/valaccodeblock.vala: improve formatting
* ccode/valaccodeifstatement.vala: improve formatting
* ccode/valaccodewriter.vala: improve formatting
* compiler/valacompiler.vala: add error handling, support multiple vapi
directories, add --library option to generate public vala api
* vapi/glib-2.0.vala: moved from bindings, add static GLib.stdout field,
correctly mark functions with variable argument lists, add File.test
method
* configure.ac,Makefile.am,ccode/Makefile.am,vala/Makefile.am,
vapi/Makefile.am,compiler/Makefile.am: add build system
* remove valac subdirectory: Bootstrap compiler is now obsolete.
2006-05-24 Jürg Billeter <j@bitron.ch>
Compiler is now self-hosting.
......
NULL =
SUBDIRS = \
valac \
ccode \
vala \
compiler \
vapi \
$(NULL)
NULL =
INCLUDES = \
$(GLIB_CFLAGS) \
$(NULL)
noinst_LTLIBRARIES = \
libvalaccode.la
$(NULL)
libvalaccode_la_VALASOURCES = \
valaccodeassignment.vala \
valaccodebinaryexpression.vala \
valaccodeblock.vala \
valaccodebreakstatement.vala \
valaccodecasestatement.vala \
valaccodecomment.vala \
valaccodeconstant.vala \
valaccodecontinuestatement.vala \
valaccodedeclaration.vala \
valaccodedeclarator.vala \
valaccodeemptystatement.vala \
valaccodeenum.vala \
valaccodeexpressionstatement.vala \
valaccodeexpression.vala \
valaccodeformalparameter.vala \
valaccodeforstatement.vala \
valaccodefragment.vala \
valaccodefunctioncall.vala \
valaccodefunctiondeclarator.vala \
valaccodefunction.vala \
valaccodeidentifier.vala \
valaccodeifstatement.vala \
valaccodeincludedirective.vala \
valaccodeinitializerlist.vala \
valaccodemacroreplacement.vala \
valaccodememberaccess.vala \
valaccodemodifiers.vala \
valaccodenewline.vala \
valaccodenode.vala \
valaccodeoncesection.vala \
valaccodeparenthesizedexpression.vala \
valaccodereturnstatement.vala \
valaccodestatement.vala \
valaccodestruct.vala \
valaccodeswitchstatement.vala \
valaccodetypedefinition.vala \
valaccodeunaryexpression.vala \
valaccodevariabledeclarator.vala \
valaccodewhilestatement.vala \
valaccodewriter.vala \
$(NULL)
libvalaccode_la_SOURCES = \
valaccodeassignment.c \
valaccodeassignment.h \
valaccodebinaryexpression.c \
valaccodebinaryexpression.h \
valaccodeblock.c \
valaccodeblock.h \
valaccodebreakstatement.c \
valaccodebreakstatement.h \
valaccodecasestatement.c \
valaccodecasestatement.h \
valaccodecomment.c \
valaccodecomment.h \
valaccodeconstant.c \
valaccodeconstant.h \
valaccodecontinuestatement.c \
valaccodecontinuestatement.h \
valaccodedeclaration.c \
valaccodedeclaration.h \
valaccodedeclarator.c \
valaccodedeclarator.h \
valaccodeemptystatement.c \
valaccodeemptystatement.h \
valaccodeenum.c \
valaccodeenum.h \
valaccodeexpression.c \
valaccodeexpression.h \
valaccodeexpressionstatement.c \
valaccodeexpressionstatement.h \
valaccodeformalparameter.c \
valaccodeformalparameter.h \
valaccodeforstatement.c \
valaccodeforstatement.h \
valaccodefragment.c \
valaccodefragment.h \
valaccodefunction.c \
valaccodefunctioncall.c \
valaccodefunctioncall.h \
valaccodefunctiondeclarator.c \
valaccodefunctiondeclarator.h \
valaccodefunction.h \
valaccodeidentifier.c \
valaccodeidentifier.h \
valaccodeifstatement.c \
valaccodeifstatement.h \
valaccodeincludedirective.c \
valaccodeincludedirective.h \
valaccodeinitializerlist.c \
valaccodeinitializerlist.h \
valaccodemacroreplacement.c \
valaccodemacroreplacement.h \
valaccodememberaccess.c \
valaccodememberaccess.h \
valaccodemodifiers.c \
valaccodemodifiers.h \
valaccodenewline.c \
valaccodenewline.h \
valaccodenode.c \
valaccodenode.h \
valaccodeoncesection.c \
valaccodeoncesection.h \
valaccodeparenthesizedexpression.c \
valaccodeparenthesizedexpression.h \
valaccodereturnstatement.c \
valaccodereturnstatement.h \
valaccodestatement.c \
valaccodestatement.h \
valaccodestruct.c \
valaccodestruct.h \
valaccodeswitchstatement.c \
valaccodeswitchstatement.h \
valaccodetypedefinition.c \
valaccodetypedefinition.h \
valaccodeunaryexpression.c \
valaccodeunaryexpression.h \
valaccodevariabledeclarator.c \
valaccodevariabledeclarator.h \
valaccodewhilestatement.c \
valaccodewhilestatement.h \
valaccodewriter.c \
valaccodewriter.h \
$(NULL)
$(subst .vala,.c,$(libvalaccode_la_VALASOURCES)) $(subst .vala,.h,$(libvalaccode_la_VALASOURCES)) valaccode.vala: $(libvalaccode_la_VALASOURCES)
$(VALAC) --vapidir $(srcdir)/../vapi --library valaccode $^
libvalaccode_la_LIBADD = \
$(GLIB_LIBS) \
$(NULL)
EXTRA_DIST = $(libvalaccode_la_VALASOURCES) valaccode.vala
......@@ -25,6 +25,7 @@ using GLib;
namespace Vala {
public class CCodeBlock : CCodeStatement {
List<CCodeNode> statements;
public bool suppress_newline;
public void add_statement (CCodeNode statement) {
/* allow generic nodes to include comments */
......@@ -34,11 +35,13 @@ namespace Vala {
public override void write (CCodeWriter writer) {
writer.write_begin_block ();
foreach (CCodeNode statement in statements) {
if (statement != null) {
statement.write (writer);
}
statement.write (writer);
}
writer.write_end_block ();
if (!suppress_newline) {
writer.write_newline ();
}
}
}
}
......@@ -27,22 +27,41 @@ namespace Vala {
public CCodeExpression condition { get; construct; }
public CCodeStatement true_statement { get; construct; }
public CCodeStatement false_statement { get; construct; }
public bool else_if;
public override void write (CCodeWriter writer) {
writer.write_indent ();
if (!else_if) {
writer.write_indent ();
} else {
writer.write_string (" ");
}
writer.write_string ("if (");
if (condition != null) {
condition.write (writer);
}
writer.write_string (")");
/* else shouldn't be on a separate line */
if (false_statement != null && true_statement is CCodeBlock) {
var cblock = (CCodeBlock) true_statement;
cblock.suppress_newline = true;
}
true_statement.write (writer);
if (false_statement != null) {
if (writer.bol) {
writer.write_indent ();
writer.write_string ("else ");
writer.write_string ("else");
} else {
writer.write_string (" else ");
writer.write_string (" else");
}
/* else if should be on one line */
if (false_statement is CCodeIfStatement) {
var cif = (CCodeIfStatement) false_statement;
cif.else_if = true;
}
false_statement.write (writer);
}
}
......
......@@ -61,6 +61,8 @@ namespace Vala {
public void write_begin_block () {
if (!bol) {
stream.putc (' ');
} else {
write_indent ();
}
stream.putc ('{');
write_newline ();
......
NULL =
INCLUDES = \
$(GLIB_CFLAGS) \
-I../ccode \
-I../vala \
$(NULL)
bin_PROGRAMS = \
valac \
$(NULL)
valac_VALASOURCES = \
valacompiler.vala \
$(NULL)
valac_SOURCES = \
valacompiler.c \
valacompiler.h \
$(NULL)
$(subst .vala,.c,$(valac_VALASOURCES)) $(subst .vala,.h,$(valac_VALASOURCES)): $(valac_VALASOURCES)
$(VALAC) --vapidir $(srcdir)/../vapi --vapidir ../ccode --pkg valaccode --vapidir ../vala --pkg vala $^
valac_LDADD = \
$(GLIB_LIBS) \
../ccode/libvalaccode.la \
../vala/libvala.la \
$(NULL)
EXTRA_DIST = $(valac_VALASOURCES)
......@@ -27,51 +27,143 @@ namespace Vala {
static string directory;
static int version;
static string[] sources;
static string package_directory = "/usr/share/vala/pkg";
static string[] vapi_directories;
static string library;
static string[] packages;
CodeContext context;
const OptionEntry[] options = {
{ "pkgdir", 0, 0, OptionArg.FILENAME, out package_directory, "Look for package bindings in DIRECTORY", "DIRECTORY" },
{ "vapidir", 0, 0, OptionArg.FILENAME_ARRAY, out vapi_directories, "Look for package bindings in DIRECTORY", "DIRECTORY..." },
{ "pkg", 0, 0, OptionArg.STRING_ARRAY, out packages, "Include binding for PACKAGE", "PACKAGE..." },
{ "library", 0, 0, OptionArg.STRING, out library, "Library name", "NAME" },
{ "directory", 'd', 0, OptionArg.FILENAME, out directory, "Output directory", "DIRECTORY" },
{ "version", 0, 0, OptionArg.NONE, ref version, "Display version number", null },
{ "", 0, 0, OptionArg.FILENAME_ARRAY, out sources, null, "FILE..." },
{ null }
};
void run () {
private int quit () {
if (Report.get_errors () == 0) {
stdout.printf ("Compilation succeeded - %d warning(s)\n", Report.get_warnings ());
return 0;
} else {
stdout.printf ("Compilation failed: %d error(s), %d warning(s)\n", Report.get_errors (), Report.get_warnings ());
return 1;
}
}
private ref string get_package_path (string pkg) {
var basename = "%s.vala".printf (pkg);
if (vapi_directories != null) {
foreach (string vapidir in vapi_directories) {
var filename = Path.build_filename (vapidir, basename, null);
if (File.test (filename, FileTest.EXISTS)) {
return filename;
}
}
}
var filename = Path.build_filename ("/usr/share/vala/vapi", basename, null);
if (File.test (filename, FileTest.EXISTS)) {
return filename;
}
return null;
}
private bool add_package (string pkg) {
var package_path = get_package_path (pkg);
if (package_path == null) {
return false;
}
context.add_source_file (new SourceFile (filename = package_path, pkg = true));
return true;
}
private int run () {
context = new CodeContext ();
context.add_source_file (new SourceFile (filename = Path.build_filename (package_directory, "glib-2.0.vala", null), pkg = true));
/* default package */
if (!add_package ("glib-2.0")) {
Report.error (null, "glib-2.0 not found in specified Vala API directories");
}
if (packages != null) {
foreach (string package in packages) {
context.add_source_file (new SourceFile (filename = Path.build_filename (package_directory, "%s.vala".printf (package), null), pkg = true));
if (!add_package (package)) {
Report.error (null, "%s not found in specified Vala API directories".printf (package));
}
}
}
if (Report.get_errors () > 0) {
return quit ();
}
foreach (string source in sources) {
context.add_source_file (new SourceFile (filename = source));
if (File.test (source, FileTest.EXISTS)) {
context.add_source_file (new SourceFile (filename = source));
} else {
Report.error (null, "%s not found".printf (source));
}
}
if (Report.get_errors () > 0) {
return quit ();
}
var parser = new Parser ();
parser.parse (context);
if (Report.get_errors () > 0) {
return quit ();
}
var builder = new SymbolBuilder ();
builder.build (context);
if (Report.get_errors () > 0) {
return quit ();
}
var resolver = new SymbolResolver ();
resolver.resolve (context);
if (Report.get_errors () > 0) {
return quit ();
}
var attributeprocessor = new AttributeProcessor ();
attributeprocessor.process (context);
if (Report.get_errors () > 0) {
return quit ();
}
var analyzer = new SemanticAnalyzer ();
analyzer.analyze (context);
if (Report.get_errors () > 0) {
return quit ();
}
var code_generator = new CodeGenerator ();
code_generator.emit (context);
if (Report.get_errors () > 0) {
return quit ();
}
if (library != null) {
var interface_writer = new InterfaceWriter ();
interface_writer.write_file (context, "%s.vala".printf (library));
}
return quit ();
}
static int main (int argc, string[] argv) {
......@@ -99,9 +191,7 @@ namespace Vala {
}
var compiler = new Compiler ();
compiler.run ();
return 0;
return compiler.run ();
}
}
}
......@@ -11,17 +11,23 @@ AC_PROG_LIBTOOL
AM_PROG_LEX
AC_PROG_YACC
AC_PATH_PROG(VALAC, valac, valac)
AC_SUBST(VALAC)
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
GLIB_REQUIRED=2.10.0
PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_REQUIRED)
PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_REQUIRED gobject-2.0 >= $GLIB_REQUIRED)
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
AC_CONFIG_FILES([Makefile
valac/Makefile])
ccode/Makefile
vala/Makefile
compiler/Makefile
vapi/Makefile])
AC_OUTPUT
NULL =
INCLUDES = \
$(GLIB_CFLAGS) \
-I ../ccode \
$(NULL)
BUILT_SOURCES = parser.h
AM_YFLAGS = -d
noinst_LTLIBRARIES = \
libvala.la
$(NULL)
libvala_la_VALASOURCES = \
valaassignment.vala \
valaattributeprocessor.vala \
valaattribute.vala \
valabinaryexpression.vala \
valablock.vala \
valabooleanliteral.vala \
valabreakstatement.vala \
valacastexpression.vala \
valacharacterliteral.vala \
valaclass.vala \
valacodecontext.vala \
valacodegenerator.vala \
valacodenode.vala \
valacodevisitor.vala \
valaconditionalexpression.vala \
valaconstant.vala \
valacontinuestatement.vala \
valadeclarationstatement.vala \
valaemptystatement.vala \
valaenum.vala \
valaenumvalue.vala \
valaexpressionstatement.vala \
valaexpression.vala \
valafield.vala \
valaforeachstatement.vala \
valaformalparameter.vala \
valaforstatement.vala \
valaifstatement.vala \
valainitializerlist.vala \
valaintegerliteral.vala \
valainterfacewriter.vala \
valainvocationexpression.vala \
valaliteralexpression.vala \
valaliteral.vala \
valalocalvariabledeclaration.vala \
valamemberaccessibility.vala \
valamemberaccess.vala \
valamethod.vala \
valanamedargument.vala \
valanamespacereference.vala \
valanamespace.vala \
valanullliteral.vala \
valaobjectcreationexpression.vala \
valaparenthesizedexpression.vala \
valaparser.vala \
valapostfixexpression.vala \
valapropertyaccessor.vala \
valaproperty.vala \
valareport.vala \
valareturnstatement.vala \
valasemanticanalyzer.vala \
valasimplename.vala \
valasourcefilecycle.vala \
valasourcefile.vala \
valasourcereference.vala \
valastatement.vala \
valastringliteral.vala \
valastruct.vala \
valasymbolbuilder.vala \
valasymbolresolver.vala \
valasymbol.vala \
valatypecheck.vala \
valatypeparameter.vala \
valatypereference.vala \
valatype.vala \
valaunaryexpression.vala \
valavariabledeclarator.vala \
valawhilestatement.vala \
$(NULL)
libvala_la_SOURCES = \
parser.y \
scanner.l \
vala.h \
valaassignment.c \
valaassignment.h \
valaattribute.c \
valaattribute.h \
valaattributeprocessor.c \
valaattributeprocessor.h \
valabinaryexpression.c \
valabinaryexpression.h \
valablock.c \
valablock.h \
valabooleanliteral.c \
valabooleanliteral.h \
valabreakstatement.c \
valabreakstatement.h \
valacastexpression.c \
valacastexpression.h \
valacharacterliteral.c \
valacharacterliteral.h \
valaclass.c \
valaclass.h \
valacodecontext.c \
valacodecontext.h \
valacodegenerator.c \
valacodegenerator.h \
valacodenode.c \
valacodenode.h \
valacodevisitor.c \
valacodevisitor.h \
valaconditionalexpression.c \
valaconditionalexpression.h \
valaconstant.c \
valaconstant.h \
valacontinuestatement.c \
valacontinuestatement.h \
valadeclarationstatement.c \
valadeclarationstatement.h \
valaemptystatement.c \
valaemptystatement.h \
valaenum.c \
valaenum.h \
valaenumvalue.c \
valaenumvalue.h \