+2006-08-10 Jürg Billeter <j@bitron.ch>
+
+ * vala/valasemanticanalyzer.vala, vala/valacodegenerator.vala: use
+ Invokable
+ * vala/valainvokable.vala
+ * vala/valafield.vala, vala/valaformalparameter.vala,
+ vala/valamethod.vala, valasignal.vala,
+ vala/valavariabledeclarator.vala: implement Invokable
+ * vala/Makefile.am: update
+
2006-08-10 Jürg Billeter <j@bitron.ch>
* vala/parser.y: support constants in namespaces and constants without
valainvocationexpression.c \
valainvocationexpression.h \
valainvocationexpression.vala \
+ valainvokable.c \
+ valainvokable.h \
+ valainvokable.vala \
valalambdaexpression.c \
valalambdaexpression.h \
valalambdaexpression.vala \
valainterfaceregisterfunction.h \
valainterfacewriter.h \
valainvocationexpression.h \
+ valainvokable.h \
valalambdaexpression.h \
valaliteral.h \
valaliteralexpression.h \
var ma = (MemberAccess) expr.call;
- if (expr.call.symbol_reference.node is VariableDeclarator) {
- var decl = (VariableDeclarator) expr.call.symbol_reference.node;
- var cb = (Callback) decl.type_reference.data_type;
- params = cb.get_parameters ();
- } else if (expr.call.symbol_reference.node is FormalParameter) {
- var param = (FormalParameter) expr.call.symbol_reference.node;
- var cb = (Callback) param.type_reference.data_type;
- params = cb.get_parameters ();
- } else if (expr.call.symbol_reference.node is Field) {
- var f = (Field) expr.call.symbol_reference.node;
- var cb = (Callback) f.type_reference.data_type;
- params = cb.get_parameters ();
- } else if (expr.call.symbol_reference.node is Method) {
- m = (Method) expr.call.symbol_reference.node;
- params = m.get_parameters ();
- } else if (expr.call.symbol_reference.node is Signal) {
- var sig = (Signal) expr.call.symbol_reference.node;
- params = sig.get_parameters ();
-
- ccall = (CCodeFunctionCall) expr.call.ccodenode;
+ if (expr.call.symbol_reference.node is Invokable) {
+ var i = (Invokable) expr.call.symbol_reference.node;
+ params = i.get_parameters ();
+
+ if (i is Method) {
+ m = (Method) i;
+ } else if (i is Signal) {
+ ccall = (CCodeFunctionCall) expr.call.ccodenode;
+ }
}
/* explicitly use strong reference as ccall gets unrefed
/**
* Represents a type or namespace field.
*/
-public class Vala.Field : CodeNode {
+public class Vala.Field : CodeNode, Invokable {
/**
* The symbol name of this field.
*/
}
}
}
+
+ public override ref List<FormalParameter> get_parameters () {
+ if (!is_invokable ()) {
+ return null;
+ }
+
+ var cb = (Callback) type_reference.data_type;
+ return cb.get_parameters ();
+ }
+
+ public override TypeReference get_return_type () {
+ if (!is_invokable ()) {
+ return null;
+ }
+
+ var cb = (Callback) type_reference.data_type;
+ return cb.return_type;
+ }
+
+ public override bool is_invokable () {
+ return (type_reference.data_type is Callback);
+ }
}
/**
* Represents a formal parameter in method and callback signatures.
*/
-public class Vala.FormalParameter : CodeNode {
+public class Vala.FormalParameter : CodeNode, Invokable {
/**
* The parameter name.
*/
visitor.visit_formal_parameter (this);
}
+
+ public override ref List<FormalParameter> get_parameters () {
+ if (!is_invokable ()) {
+ return null;
+ }
+
+ var cb = (Callback) type_reference.data_type;
+ return cb.get_parameters ();
+ }
+
+ public override TypeReference get_return_type () {
+ if (!is_invokable ()) {
+ return null;
+ }
+
+ var cb = (Callback) type_reference.data_type;
+ return cb.return_type;
+ }
+
+ public override bool is_invokable () {
+ return (type_reference.data_type is Callback);
+ }
}
--- /dev/null
+/* valainvokable.vala
+ *
+ * Copyright (C) 2006 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 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 <j@bitron.ch>
+ */
+
+using GLib;
+
+/**
+ * Represents a possibly invokable code object.
+ */
+public interface Vala.Invokable {
+ /**
+ * Returns whether this code object is invokable.
+ *
+ * @return true if invokable, false otherwise
+ */
+ public abstract bool is_invokable ();
+
+ /**
+ * Returns the return type of this invokable.
+ *
+ * @return return type
+ */
+ public abstract TypeReference get_return_type ();
+
+ /**
+ * Returns copy of the list of invocation parameters.
+ *
+ * @return parameter list
+ */
+ public abstract ref List<FormalParameter> get_parameters ();
+}
/**
* Represents a type or namespace method.
*/
-public class Vala.Method : CodeNode {
+public class Vala.Method : CodeNode, Invokable {
/**
* The symbol name of this method.
*/
parameters.append (param);
}
- /**
- * Returns copy of the list of method parameters.
- *
- * @return parameter list
- */
- public ref List<FormalParameter> get_parameters () {
+ public override ref List<FormalParameter> get_parameters () {
return parameters.copy ();
}
+ public override TypeReference get_return_type () {
+ return return_type;
+ }
+
+ public override bool is_invokable () {
+ return true;
+ }
+
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_method (this);
List<FormalParameter> params;
- if (msym.node is VariableDeclarator) {
- var decl = (VariableDeclarator) msym.node;
- if (decl.type_reference.data_type is Callback) {
- var cb = (Callback) decl.type_reference.data_type;
- params = cb.get_parameters ();
+ if (msym.node is Invokable) {
+ var m = (Invokable) msym.node;
+ if (m.is_invokable ()) {
+ params = m.get_parameters ();
} else {
expr.error = true;
Report.error (expr.source_reference, "invocation not supported in this context");
return;
}
- } else if (msym.node is FormalParameter) {
- var param = (FormalParameter) msym.node;
- if (param.type_reference.data_type is Callback) {
- var cb = (Callback) param.type_reference.data_type;
- params = cb.get_parameters ();
- } else {
- expr.error = true;
- Report.error (expr.source_reference, "invocation not supported in this context");
- return;
- }
- } else if (msym.node is Field) {
- var f = (Field) msym.node;
- if (f.type_reference.data_type is Callback) {
- var cb = (Callback) f.type_reference.data_type;
- params = cb.get_parameters ();
- } else {
- expr.error = true;
- Report.error (expr.source_reference, "invocation not supported in this context");
- return;
- }
- } else if (msym.node is Method) {
- var m = (Method) msym.node;
- params = m.get_parameters ();
- } else if (msym.node is Signal) {
- var sig = (Signal) msym.node;
- params = sig.get_parameters ();
} else {
expr.error = true;
Report.error (expr.source_reference, "invocation not supported in this context");
TypeReference ret_type;
List<FormalParameter> params;
- if (msym.node is VariableDeclarator) {
- var decl = (VariableDeclarator) msym.node;
- var cb = (Callback) decl.type_reference.data_type;
- ret_type = cb.return_type;
- params = cb.get_parameters ();
- } else if (msym.node is FormalParameter) {
- var param = (FormalParameter) msym.node;
- var cb = (Callback) param.type_reference.data_type;
- ret_type = cb.return_type;
- params = cb.get_parameters ();
- } else if (msym.node is Field) {
- var f = (Field) msym.node;
- var cb = (Callback) f.type_reference.data_type;
- ret_type = cb.return_type;
- params = cb.get_parameters ();
- } else if (msym.node is Method) {
- var m = (Method) msym.node;
- ret_type = m.return_type;
+ if (msym.node is Invokable) {
+ var m = (Invokable) msym.node;
+ ret_type = m.get_return_type ();
params = m.get_parameters ();
- } else if (msym.node is Signal) {
- var sig = (Signal) msym.node;
- ret_type = sig.return_type;
- params = sig.get_parameters ();
}
expr.static_type = ret_type;
/**
* Represents an object signal. Signals enable objects to provide notifications.
*/
-public class Vala.Signal : CodeNode {
+public class Vala.Signal : CodeNode, Invokable {
/**
* The symbol name of this signal.
*/
parameters.append (param);
}
- /**
- * Returns copy of list of signal handler parameters.
- *
- * @return parameter list
- */
- public ref List<FormalParameter> get_parameters () {
+ public override ref List<FormalParameter> get_parameters () {
return parameters.copy ();
}
+ public override TypeReference get_return_type () {
+ return return_type;
+ }
+
+ public override bool is_invokable () {
+ return true;
+ }
+
/**
* Returns generated callback to be used for signal handlers.
*
/**
* Represents a variable declarator in the source code.
*/
-public class Vala.VariableDeclarator : CodeNode {
+public class Vala.VariableDeclarator : CodeNode, Invokable {
/**
* The variable name.
*/
visitor.visit_variable_declarator (this);
}
+
+ public override ref List<FormalParameter> get_parameters () {
+ if (!is_invokable ()) {
+ return null;
+ }
+
+ var cb = (Callback) type_reference.data_type;
+ return cb.get_parameters ();
+ }
+
+ public override TypeReference get_return_type () {
+ if (!is_invokable ()) {
+ return null;
+ }
+
+ var cb = (Callback) type_reference.data_type;
+ return cb.return_type;
+ }
+
+ public override bool is_invokable () {
+ return (type_reference.data_type is Callback);
+ }
}