[vala] vapigen: Support default_value for arguments



commit bcbeaad00f7482a18942f22579a4dda6b3588522
Author: Evan Nemerson <evan coeus-group com>
Date:   Sun Mar 14 13:41:02 2010 -0700

    vapigen: Support default_value for arguments

 vapigen/valagidlparser.vala |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index e255157..b686be2 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -1759,6 +1759,30 @@ public class Vala.GIdlParser : CodeVisitor {
 						foreach (string type_arg in type_args) {
 							param_type.add_type_argument (get_type_from_string (type_arg));
 						}
+					} else if (nv[0] == "default_value") {
+						var val = eval (nv[1]);
+						if (val == "null") {
+							p.default_expression = new NullLiteral (param_type.source_reference);
+						} else if (val == "true") {
+							p.default_expression = new BooleanLiteral (true, param_type.source_reference);
+						} else if (val == "false") {
+							p.default_expression = new BooleanLiteral (false, param_type.source_reference);
+						} else {
+							unowned string endptr;
+							unowned string val_end = val.offset (val.len ());
+
+							val.to_long (out endptr);
+							if ((long)endptr == (long)val_end) {
+								p.default_expression = new IntegerLiteral (val, param_type.source_reference);
+							} else {
+								val.to_double (out endptr);
+								if ((long)endptr == (long)val_end) {
+									p.default_expression = new RealLiteral (val, param_type.source_reference);
+								} else {
+									p.default_expression = new StringLiteral ("\"%s\"".printf (val), param_type.source_reference);
+								}
+							}
+						}
 					}
 				}
 			}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]