mirror of https://github.com/aamine/cbc
* 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:
parent
96fb88ec26
commit
1524d3d719
|
@ -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>
|
Mon Nov 24 18:49:27 2008 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* net/loveruby/cflat/compiler/CodeGenerator.java: refactoring:
|
* net/loveruby/cflat/compiler/CodeGenerator.java: refactoring:
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
//import stdarg; // FIXME
|
import stdarg;
|
||||||
|
|
||||||
typedef unsigned long va_arg_t;
|
|
||||||
typedef va_arg_t* va_list;
|
|
||||||
|
|
||||||
va_list
|
va_list
|
||||||
va_init(void *arg)
|
va_init(void *arg)
|
||||||
|
|
|
@ -26,16 +26,28 @@ public class ToplevelScope extends Scope {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Declare variable or function in this scope. */
|
/** Declare variable or function globally. */
|
||||||
// #@@range/declareEntity{
|
// #@@range/declareEntity{
|
||||||
public void declareEntity(Entity ent) {
|
public void declareEntity(Entity ent) {
|
||||||
if (entities.containsKey(ent.name())) {
|
if (entities.containsKey(ent.name())) {
|
||||||
throw new Error("duplicated entity: " + ent.name());
|
throw new Error("duplicated declaration: " + ent.name());
|
||||||
}
|
}
|
||||||
entities.put(ent.name(), ent);
|
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. */
|
/** Searches and gets entity searching scopes upto ToplevelScope. */
|
||||||
// #@@range/get{
|
// #@@range/get{
|
||||||
public Entity get(String name) throws SemanticException {
|
public Entity get(String name) throws SemanticException {
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class LocalReferenceResolver extends Visitor {
|
||||||
toplevel.declareEntity(decl);
|
toplevel.declareEntity(decl);
|
||||||
}
|
}
|
||||||
for (Entity ent : ast.entities()) {
|
for (Entity ent : ast.entities()) {
|
||||||
toplevel.declareEntity(ent);
|
toplevel.defineEntity(ent);
|
||||||
}
|
}
|
||||||
// #@@}
|
// #@@}
|
||||||
// #@@range/resolveRefs{
|
// #@@range/resolveRefs{
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
import stdio;
|
||||||
|
import decloverride;
|
||||||
|
|
||||||
|
int f(void) { return 77; }
|
||||||
|
|
||||||
|
int
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
printf("%d\n", f());
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
extern int f(void);
|
22
test/run.sh
22
test/run.sh
|
@ -6,17 +6,25 @@ main() {
|
||||||
cd "$(dirname "$0")"
|
cd "$(dirname "$0")"
|
||||||
. ./shunit.sh
|
. ./shunit.sh
|
||||||
|
|
||||||
while print "$1" | grep '^-' >/dev/null 2>&1
|
while [ $# -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-t)
|
-t)
|
||||||
# run specified tests
|
# run specified tests
|
||||||
shift
|
[ -n "$2" ] || error_exit "-t option requires argument"
|
||||||
local pattern="$1"; shift
|
local pattern="$2"
|
||||||
|
shift; shift
|
||||||
|
;;
|
||||||
|
--help)
|
||||||
|
print_usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
print_usage 1>&2
|
||||||
|
exit 1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: $0 [-t PATTERN] [<file>...]" 1>&2
|
break
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
@ -36,6 +44,10 @@ main() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print_usage() {
|
||||||
|
echo "Usage: $0 [-t PATTERN] [--help] [<file>...]"
|
||||||
|
}
|
||||||
|
|
||||||
load_tests() {
|
load_tests() {
|
||||||
local file
|
local file
|
||||||
for file in "$@"
|
for file in "$@"
|
||||||
|
|
|
@ -236,6 +236,7 @@ test_24_cast() {
|
||||||
test_25_block() {
|
test_25_block() {
|
||||||
assert_out "1;2;3;1;OK" ./block
|
assert_out "1;2;3;1;OK" ./block
|
||||||
assert_out "1;2;3" ./defvar
|
assert_out "1;2;3" ./defvar
|
||||||
|
assert_out "77" ./decloverride
|
||||||
}
|
}
|
||||||
|
|
||||||
test_26_funcptr() {
|
test_26_funcptr() {
|
||||||
|
|
Loading…
Reference in New Issue