Skip to content
Snippets Groups Projects
Commit 2ac90788 authored by Rico Tzschichholz's avatar Rico Tzschichholz
Browse files

vala: Correctly replace "in" expression in pre-/postconditions of method

parent f9098a27
No related branches found
No related tags found
No related merge requests found
......@@ -188,6 +188,7 @@ TESTS = \
methods/preconditions-temp-variables.vala \
methods/prepostconditions.vala \
methods/prepostconditions-captured.vala \
methods/prepostconditions-contains.vala \
methods/postconditions.vala \
methods/postconditions-temp-variables.vala \
methods/return-unowned-delegate.vala \
......
/* methods_prepostconditions_contains.c generated by valac, the Vala compiler
* generated from methods_prepostconditions_contains.vala, do not modify */
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif
#define _g_free0(var) (var = (g_free (var), NULL))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
VALA_EXTERN void foo (const gchar* s);
static gboolean _vala_string_array_contains (const gchar* * stack,
gssize stack_length,
const const gchar* needle);
VALA_EXTERN gchar* bar (void);
static void _vala_main (void);
const gchar* array[3] = {"foo", "bar", "manam"};
static gboolean
_vala_string_array_contains (const gchar* * stack,
gssize stack_length,
const const gchar* needle)
{
gssize i;
for (i = 0; i < stack_length; i++) {
if (g_strcmp0 (stack[i], needle) == 0) {
return TRUE;
}
}
return FALSE;
}
void
foo (const gchar* s)
{
g_return_if_fail (s != NULL);
_vala_return_if_fail (_vala_string_array_contains (array, G_N_ELEMENTS (array), s), "s in array");
}
gchar*
bar (void)
{
gchar* _tmp0_;
gchar* result = NULL;
_tmp0_ = g_strdup ("manam");
result = _tmp0_;
_vala_warn_if_fail (_vala_string_array_contains (array, G_N_ELEMENTS (array), result), "result in array");
return result;
}
static void
_vala_main (void)
{
gchar* _tmp0_;
gchar* _tmp1_;
foo ("bar");
_tmp0_ = bar ();
_tmp1_ = _tmp0_;
_g_free0 (_tmp1_);
}
int
main (int argc,
char ** argv)
{
_vala_main ();
return 0;
}
const string[] array = { "foo", "bar", "manam" };
void foo (string s) requires (s in array) {
}
string bar () ensures (result in array) {
return "manam";
}
void main () {
foo ("bar");
bar ();
}
......@@ -577,6 +577,23 @@ public class Vala.Method : Subroutine, Callable {
}
}
public override void replace_expression (Expression old_node, Expression new_node) {
if (preconditions != null) {
var index = preconditions.index_of (old_node);
if (index >= 0) {
preconditions[index] = new_node;
new_node.parent_node = this;
}
}
if (postconditions != null) {
var index = postconditions.index_of (old_node);
if (index >= 0) {
postconditions[index] = new_node;
new_node.parent_node = this;
}
}
}
public override void replace_type (DataType old_type, DataType new_type) {
if (base_interface_type == old_type) {
base_interface_type = new_type;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment