Mercurial > ~dholland > hg > ag > index.cgi
diff tests/agcl/bugs/wraperror.syn @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/agcl/bugs/wraperror.syn Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,86 @@ +{ +/* + * 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; +} + +}