+2005-08-10 Frank Ch. Eigler <fche@elastic.org>
+
+ PR translator/1186
+ * elaborate.cxx (resolve_2types): Accept a flag to tolerate unresolved
+ expression types.
+ (visit_functioncall): Call it thusly.
+ * translate.cxx (emit_function): Tolerate void functions.
+ * stap.1.in: Document possibility of void functions.
+ * tapset/builtin_{log,printk,warn}.stp: Make these void functions.
+ * testsuite/buildok/nine.stp, semok/eighteen.stp: New tests.
+
2005-08-10 Frank Ch. Eigler <fche@elastic.org>
* tapsets.cxx: Correct hex/decimal misformatting of verbose messages.
template <class Referrer, class Referent>
void resolve_2types (Referrer* referrer, Referent* referent,
- typeresolution_info* r, exp_type t)
+ typeresolution_info* r, exp_type t, bool accept_unknown = false)
{
exp_type& re_type = referrer->type;
const token* re_tok = referrer->tok;
r->resolved (te_tok, te_type);
// catch re_type/t mismatch later
}
- else
+ else if (! accept_unknown)
r->unresolved (re_tok);
}
{
assert (e->referent != 0);
- resolve_2types (e, e->referent, this, t);
+ resolve_2types (e, e->referent, this, t, true); // accept unknown type
if (e->type == pe_stats)
invalid (e->tok, e->type);
statement.
.TP
.BR return " EXP"
-Return EXP value from enclosing function. A return value is mandatory,
-since void functions are not supported.
+Return EXP value from enclosing function. If the function's value is
+not taken anywhere, then a return statement is not needed, and the
+function will have a special "unknown" type with no return value.
.TP
.BR next
Return now from enclosing probe handler.
.fi
.RE
Note the usual absence of type declarations, which are instead
-inferred by the translator. Because a return value type is required,
-each function must contain at least one
-.I return
-statement. Functions may call others or themselves recursively, up to
-a fixed nesting limit. This limit is defined by a macro in the
-translated C code and is in the neighbourhood of 30.
+inferred by the translator. Functions may call others or themselves
+recursively, up to a fixed nesting limit. This limit is defined by
+a macro in the translated C code and is in the neighbourhood of 30.
.SS EMBEDDED C
When in guru mode, the translator accepts embedded code in the
%}
function log (msg) {
- return 0 + _log (msg . "")
+ _log (msg . "")
}
%}
function printk (msg) {
- return 0 + _printk (msg . "")
+ _printk (msg . "")
}
%}
function warn (msg) {
- return 0 + _warn (msg . "")
+ _warn (msg . "")
}
--- /dev/null
+#! stap -p2
+
+function f () { }
+function g (arg) { }
+
+probe begin {
+ true ? f() : g(1);
+}
--- /dev/null
+#! stap -p2
+
+function f () { }
+function g (arg) { }
+
+probe begin {
+ f(); g(1)
+}
}
// initialize return value, if any
- var retvalue = var(true, v->type, "__retvalue");
- o->newline() << retvalue.init();
+ if (v->type != pe_unknown)
+ {
+ var retvalue = var(true, v->type, "__retvalue");
+ o->newline() << retvalue.init();
+ }
v->body->visit (this);
this->current_function = 0;