* test: test declaration override.

* test/run.sh: new option --help.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4096 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2008-12-07 07:56:00 +00:00
parent 96fb88ec26
commit 1524d3d719
8 changed files with 52 additions and 12 deletions

View File

@ -1,3 +1,9 @@
Sun Dec 7 16:55:56 2008 Minero Aoki <aamine@loveruby.net>
* test: test declaration override.
* test/run.sh: new option --help.
Mon Nov 24 18:49:27 2008 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/compiler/CodeGenerator.java: refactoring:

View File

@ -1,7 +1,4 @@
//import stdarg; // FIXME
typedef unsigned long va_arg_t;
typedef va_arg_t* va_list;
import stdarg;
va_list
va_init(void *arg)

View File

@ -26,16 +26,28 @@ public class ToplevelScope extends Scope {
return null;
}
/** Declare variable or function in this scope. */
/** Declare variable or function globally. */
// #@@range/declareEntity{
public void declareEntity(Entity ent) {
if (entities.containsKey(ent.name())) {
throw new Error("duplicated entity: " + ent.name());
throw new Error("duplicated declaration: " + ent.name());
}
entities.put(ent.name(), ent);
}
// #@@}
/** Define variable or function globally. */
// #@@range/defineEntity{
public void defineEntity(Entity entity) {
Entity ent = entities.get(entity.name());
if (ent != null && ent.isDefined()) {
throw new Error("duplicated definition: " + entity.name() + ": " +
ent.location() + " and " + entity.location());
}
entities.put(entity.name(), entity);
}
// #@@}
/** Searches and gets entity searching scopes upto ToplevelScope. */
// #@@range/get{
public Entity get(String name) throws SemanticException {

View File

@ -31,7 +31,7 @@ public class LocalReferenceResolver extends Visitor {
toplevel.declareEntity(decl);
}
for (Entity ent : ast.entities()) {
toplevel.declareEntity(ent);
toplevel.defineEntity(ent);
}
// #@@}
// #@@range/resolveRefs{

11
test/decloverride.cb Normal file
View File

@ -0,0 +1,11 @@
import stdio;
import decloverride;
int f(void) { return 77; }
int
main(void)
{
printf("%d\n", f());
return 0;
}

1
test/decloverride.hb Normal file
View File

@ -0,0 +1 @@
extern int f(void);

View File

@ -6,17 +6,25 @@ main() {
cd "$(dirname "$0")"
. ./shunit.sh
while print "$1" | grep '^-' >/dev/null 2>&1
while [ $# -gt 0 ]
do
case "$1" in
-t)
# run specified tests
shift
local pattern="$1"; shift
[ -n "$2" ] || error_exit "-t option requires argument"
local pattern="$2"
shift; shift
;;
--help)
print_usage
exit 0
;;
-*)
print_usage 1>&2
exit 1
;;
*)
echo "Usage: $0 [-t PATTERN] [<file>...]" 1>&2
exit 1
break
;;
esac
done
@ -36,6 +44,10 @@ main() {
fi
}
print_usage() {
echo "Usage: $0 [-t PATTERN] [--help] [<file>...]"
}
load_tests() {
local file
for file in "$@"

View File

@ -236,6 +236,7 @@ test_24_cast() {
test_25_block() {
assert_out "1;2;3;1;OK" ./block
assert_out "1;2;3" ./defvar
assert_out "77" ./decloverride
}
test_26_funcptr() {