view tests/agcl/bugs/wraperror.syn @ 11:3aa0f5a02342

Remove unused variable; fix what it was supposed to be doing. (and document it a bit for the next time through here)
author David A. Holland
date Tue, 31 May 2022 00:54:12 -0400
parents 13d2b8934445
children
line wrap: on
line source

{
/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 2006 David A. Holland. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * wraperror: test for wrappers and error token together
 */

#include <stdio.h>


struct thingy {
  const char *name;
  int val;

  void g(const char *n, int v) { name = n; val = v; }
  void g(const thingy &t) { name = t.name; val = t.val; }

  void m(const char *msg) {
    printf("%s %s: %p, %d\n", msg, name, this, val);
  }

  thingy(const char *n, int v)      { g(n,v); m("Constructed new"); }
  thingy(const thingy &t)           { g(t);   m("Copied"); }
  void operator = (const thingy &t) { g(t);   m("Assigned"); }
  ~thingy()                         {         m("Destroyed"); }
};

struct foo : public thingy {
  foo(int v) : thingy("foo", v) {}
  foo(const foo &f) : thingy(f) {}
  void operator = (const foo &f) { thingy::operator = (f); }
  ~foo() {}
};

struct bar : public thingy {
  bar(int v) : thingy("bar", v) {}
  bar(const bar &f) : thingy(f) {}
  void operator = (const bar &f) { thingy::operator = (f); }
  ~bar() {}
};

void do_foo(foo &f) {
  f.m("do_foo");
}

void do_bar(bar &b) {
  b.m("do_bar");
}

}

[
  parser file name = "#.cpp"
  wrapper { foo }
]

file $
  -> declarations, eof

declarations
  -> declaration...

declaration
  -> foo decl:f, '\n' = do_foo(f);
  -> bar decl:b, '\n' = do_bar(b);
  -> '\n'
  -> error

(foo) foo decl
  -> 'f', 'o', 'o' = foo(1);

(bar) bar decl
  -> 'b', 'a', 'r' = bar(2);

eof = 0

{

int main() {
   wraperror();
   return 0;
}

}