From bee064ffea4a3de56259578662825b69a4a3f91e Mon Sep 17 00:00:00 2001 From: Juerg Billeter Date: Wed, 28 Nov 2007 16:28:30 +0000 Subject: [PATCH] add support for inline methods 2007-11-28 Juerg Billeter * vala/parser.y, vala/scanner.l, vala/valamethod.vala, ccode/valaccodefunction.vala, ccode/valaccodemodifiers.vala, gobject/valaccodegeneratormethod.vala: add support for inline methods svn path=/trunk/; revision=734 --- ChangeLog | 8 +++++++- ccode/valaccodefunction.vala | 5 ++++- ccode/valaccodemodifiers.vala | 3 ++- gobject/valaccodegeneratormethod.vala | 5 +++++ vala/parser.y | 11 ++++++++++- vala/scanner.l | 1 + vala/valamethod.vala | 5 +++++ 7 files changed, 34 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f5778b..13d1a91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,18 @@ 2007-11-28 Jürg Billeter + * vala/parser.y, vala/scanner.l, vala/valamethod.vala, + ccode/valaccodefunction.vala, ccode/valaccodemodifiers.vala, + gobject/valaccodegeneratormethod.vala: add support for inline methods + +2007-11-28 Jürg Billeter + * vapi/glib-2.0.vapi: bind atomic operations, fixes bug 499970 2007-11-28 Jürg Billeter * vala/parser.y, vala/scanner.l, vala/valafield.vala, gobject/valaccodegenerator.vala: add support for volatile fields, - fixes bug #499960 + fixes bug 499960 2007-11-27 Jürg Billeter diff --git a/ccode/valaccodefunction.vala b/ccode/valaccodefunction.vala index eeeccc8..e3dfcf4 100644 --- a/ccode/valaccodefunction.vala +++ b/ccode/valaccodefunction.vala @@ -83,9 +83,12 @@ public class Vala.CCodeFunction : CCodeNode { public override void write (CCodeWriter! writer) { writer.write_indent (line); - if ((modifiers & CCodeModifiers.STATIC) == CCodeModifiers.STATIC) { + if (CCodeModifiers.STATIC in modifiers) { writer.write_string ("static "); } + if (CCodeModifiers.INLINE in modifiers) { + writer.write_string ("inline "); + } writer.write_string (return_type); writer.write_string (" "); writer.write_string (name); diff --git a/ccode/valaccodemodifiers.vala b/ccode/valaccodemodifiers.vala index c34393d..d1a4a7a 100644 --- a/ccode/valaccodemodifiers.vala +++ b/ccode/valaccodemodifiers.vala @@ -28,5 +28,6 @@ public enum Vala.CCodeModifiers { NONE, STATIC, REGISTER, - EXTERN + EXTERN, + INLINE } diff --git a/gobject/valaccodegeneratormethod.vala b/gobject/valaccodegeneratormethod.vala index ed89308..ce0b830 100644 --- a/gobject/valaccodegeneratormethod.vala +++ b/gobject/valaccodegeneratormethod.vala @@ -108,6 +108,11 @@ public class Vala.CCodeGenerator { function = new CCodeFunction (m.get_real_cname (), m.return_type.get_cname ()); m.ccodenode = function; + + if (m.is_inline) { + function.modifiers |= CCodeModifiers.INLINE; + } + CCodeFunctionDeclarator vdeclarator = null; CCodeFormalParameter instance_param = null; diff --git a/vala/parser.y b/vala/parser.y index 1db5cab..f389dcc 100644 --- a/vala/parser.y +++ b/vala/parser.y @@ -46,7 +46,8 @@ typedef enum { VALA_MODIFIER_OVERRIDE = 1 << 1, VALA_MODIFIER_STATIC = 1 << 2, VALA_MODIFIER_VIRTUAL = 1 << 3, - VALA_MODIFIER_VOLATILE = 1 << 4 + VALA_MODIFIER_VOLATILE = 1 << 4, + VALA_MODIFIER_INLINE = 1 << 5 } ValaModifier; int yylex (YYSTYPE *yylval_param, YYLTYPE *yylloc_param, ValaParser *parser); @@ -173,6 +174,7 @@ static gboolean check_is_struct (ValaSymbol *symbol, ValaSourceReference *src); %token GET "get" %token IF "if" %token IN "in" +%token INLINE "inline" %token INTERFACE "interface" %token IS "is" %token LOCK "lock" @@ -2641,6 +2643,10 @@ modifier { $$ = VALA_MODIFIER_VOLATILE; } + | INLINE + { + $$ = VALA_MODIFIER_INLINE; + } ; opt_class_base @@ -2940,6 +2946,9 @@ method_header vala_report_error (vala_code_node_get_source_reference (VALA_CODE_NODE ($$)), "Only one of `abstract', `virtual', and `override' may be specified."); vala_code_node_set_error (VALA_CODE_NODE ($$), TRUE); } + if (($4 & VALA_MODIFIER_INLINE) == VALA_MODIFIER_INLINE) { + vala_method_set_is_inline ($$, TRUE); + } VALA_CODE_NODE($$)->attributes = $2; for (l = $8; l != NULL; l = l->next) { diff --git a/vala/scanner.l b/vala/scanner.l index 90febb1..fdab188 100644 --- a/vala/scanner.l +++ b/vala/scanner.l @@ -151,6 +151,7 @@ literal ({integer_literal}|{real_literal}|{character_literal}|{string_literal "get" { uploc; return GET; } "if" { uploc; return IF; } "in" { uploc; return IN; } +"inline" { uploc; return INLINE; } "interface" { uploc; return INTERFACE; } "is" { uploc; return IS; } "lock" { uploc; return LOCK; } diff --git a/vala/valamethod.vala b/vala/valamethod.vala index 2fb7346..c0eb4b4 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -100,6 +100,11 @@ public class Vala.Method : Member, Invokable { * of a base type. */ public bool overrides { get; set; } + + /** + * Specifies whether this method should be inlined. + */ + public bool is_inline { get; set; } /** * Specifies whether the C method returns a new instance pointer which -- 2.7.4