mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
use arg-parser in type-generator
This commit is contained in:
parent
d4d232db89
commit
13452beaab
@ -18,13 +18,16 @@ class Arg;
|
|||||||
|
|
||||||
class ArgParser {
|
class ArgParser {
|
||||||
public:
|
public:
|
||||||
Arg* first;
|
|
||||||
Arg** last;
|
|
||||||
|
|
||||||
ArgParser();
|
ArgParser();
|
||||||
|
|
||||||
bool parse(int ac, const char* const* av);
|
bool parse(int ac, const char* const* av);
|
||||||
void printUsage(const char* exe);
|
void printUsage(const char* exe);
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class Arg;
|
||||||
|
|
||||||
|
Arg* first;
|
||||||
|
Arg** last;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Arg {
|
class Arg {
|
||||||
|
5
makefile
5
makefile
@ -1268,7 +1268,8 @@ generator-sources = \
|
|||||||
$(src)/tools/type-generator/main.cpp \
|
$(src)/tools/type-generator/main.cpp \
|
||||||
$(src)/system/$(build-system).cpp \
|
$(src)/system/$(build-system).cpp \
|
||||||
$(src)/system/$(build-system)/signal.cpp \
|
$(src)/system/$(build-system)/signal.cpp \
|
||||||
$(src)/finder.cpp
|
$(src)/finder.cpp \
|
||||||
|
$(src)/util/arg-parser.cpp
|
||||||
|
|
||||||
ifneq ($(lzma),)
|
ifneq ($(lzma),)
|
||||||
common-cflags += -I$(lzma) -DAVIAN_USE_LZMA -D_7ZIP_ST
|
common-cflags += -I$(lzma) -DAVIAN_USE_LZMA -D_7ZIP_ST
|
||||||
@ -1573,7 +1574,7 @@ gen-arg = $(shell echo $(1) | sed -e 's:$(build)/type-\(.*\)\.cpp:\1:')
|
|||||||
$(generated-code): %.cpp: $(src)/types.def $(generator) $(classpath-dep)
|
$(generated-code): %.cpp: $(src)/types.def $(generator) $(classpath-dep)
|
||||||
@echo "generating $(@)"
|
@echo "generating $(@)"
|
||||||
@mkdir -p $(dir $(@))
|
@mkdir -p $(dir $(@))
|
||||||
$(generator) $(boot-classpath) $(<) $(@) $(call gen-arg,$(@))
|
$(generator) -cp $(boot-classpath) -i $(<) -o $(@) -t $(call gen-arg,$(@))
|
||||||
|
|
||||||
$(classpath-build)/%.class: $(classpath-src)/%.java
|
$(classpath-build)/%.class: $(classpath-src)/%.java
|
||||||
@echo $(<)
|
@echo $(<)
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include "avian/constants.h"
|
#include "avian/constants.h"
|
||||||
#include "avian/finder.h"
|
#include "avian/finder.h"
|
||||||
|
|
||||||
|
#include <avian/util/arg-parser.h>
|
||||||
#include <avian/util/stream.h>
|
#include <avian/util/stream.h>
|
||||||
|
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
@ -23,6 +25,8 @@
|
|||||||
|
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
|
|
||||||
|
using namespace avian::util;
|
||||||
|
|
||||||
#define UNREACHABLE abort()
|
#define UNREACHABLE abort()
|
||||||
|
|
||||||
#define UNUSED __attribute__((unused))
|
#define UNUSED __attribute__((unused))
|
||||||
@ -1903,17 +1907,6 @@ writeMaps(Output* out, Object* declarations)
|
|||||||
out->write("\n};");
|
out->write("\n};");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
usageAndExit(const char* command)
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"usage: %s <classpath> <input file> <output file> "
|
|
||||||
"{enums,declarations,constructors,initializations,"
|
|
||||||
"java-initializations,name-initializations,maps}\n",
|
|
||||||
command);
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace local
|
} // namespace local
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@ -1930,32 +1923,49 @@ vmJump(void*, void*, void*, void*, uintptr_t, uintptr_t)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int main(int ac, char** av)
|
||||||
main(int ac, char** av)
|
|
||||||
{
|
{
|
||||||
if (ac != 5
|
ArgParser parser;
|
||||||
or not (local::equal(av[4], "enums")
|
Arg classpath(parser, true, "cp", "<classpath>");
|
||||||
or local::equal(av[4], "declarations")
|
Arg input(parser, true, "i", "<input.def>");
|
||||||
or local::equal(av[4], "constructors")
|
Arg output(parser, true, "o", "<output.cpp/h>");
|
||||||
or local::equal(av[4], "initializations")
|
Arg outputType(parser,
|
||||||
or local::equal(av[4], "java-initializations")
|
true,
|
||||||
or local::equal(av[4], "name-initializations")
|
"t",
|
||||||
or local::equal(av[4], "maps")))
|
"<enums|declarations|constructors|initializations|java-"
|
||||||
{
|
"initializations|name-initializations|maps>");
|
||||||
local::usageAndExit(av[0]);
|
|
||||||
|
if (!parser.parse(ac, av)) {
|
||||||
|
parser.printUsage(av[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(local::equal(outputType.value, "enums")
|
||||||
|
|| local::equal(outputType.value, "declarations")
|
||||||
|
|| local::equal(outputType.value, "constructors")
|
||||||
|
|| local::equal(outputType.value, "initializations")
|
||||||
|
|| local::equal(outputType.value, "java-initializations")
|
||||||
|
|| local::equal(outputType.value, "name-initializations")
|
||||||
|
|| local::equal(outputType.value, "maps"))) {
|
||||||
|
parser.printUsage(av[0]);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
System* system = makeSystem();
|
System* system = makeSystem();
|
||||||
|
|
||||||
class MyAllocator : public avian::util::Allocator {
|
class MyAllocator : public avian::util::Allocator {
|
||||||
public:
|
public:
|
||||||
MyAllocator(System* s): s(s) { }
|
MyAllocator(System* s) : s(s)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
virtual void* tryAllocate(unsigned size) {
|
virtual void* tryAllocate(unsigned size)
|
||||||
|
{
|
||||||
return s->tryAllocate(size);
|
return s->tryAllocate(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* allocate(unsigned size) {
|
virtual void* allocate(unsigned size)
|
||||||
|
{
|
||||||
void* p = tryAllocate(size);
|
void* p = tryAllocate(size);
|
||||||
if (p == 0) {
|
if (p == 0) {
|
||||||
abort(s);
|
abort(s);
|
||||||
@ -1963,20 +1973,22 @@ main(int ac, char** av)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void free(const void* p, unsigned) {
|
virtual void free(const void* p, unsigned)
|
||||||
|
{
|
||||||
s->free(p);
|
s->free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
System* s;
|
System* s;
|
||||||
} allocator(system);
|
} allocator(system);
|
||||||
|
|
||||||
Finder* finder = makeFinder(system, &allocator, av[1], 0);
|
Finder* finder = makeFinder(system, &allocator, classpath.value, 0);
|
||||||
|
|
||||||
FILE* inStream = ::fopen(av[2], "rb");
|
FILE* inStream = ::fopen(input.value, "rb");
|
||||||
if (inStream == 0) {
|
if (inStream == 0) {
|
||||||
fprintf(stderr, "unable to open %s: %s\n", av[2], strerror(errno));
|
fprintf(stderr, "unable to open %s: %s\n", input.value, strerror(errno));
|
||||||
return -1;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInput in(0, inStream, false);
|
FileInput in(0, inStream, false);
|
||||||
|
|
||||||
Object* declarations = local::parse(finder, &in);
|
Object* declarations = local::parse(finder, &in);
|
||||||
@ -1984,16 +1996,16 @@ main(int ac, char** av)
|
|||||||
finder->dispose();
|
finder->dispose();
|
||||||
system->dispose();
|
system->dispose();
|
||||||
|
|
||||||
FILE* outStream = ::fopen(av[3], "wb");
|
FILE* outStream = ::fopen(output.value, "wb");
|
||||||
if (outStream == 0) {
|
if (outStream == 0) {
|
||||||
fprintf(stderr, "unable to open %s: %s\n", av[3], strerror(errno));
|
fprintf(stderr, "unable to open %s: %s\n", output.value, strerror(errno));
|
||||||
return -1;
|
exit(1);
|
||||||
}
|
}
|
||||||
FileOutput out(0, outStream, false);
|
FileOutput out(0, outStream, false);
|
||||||
|
|
||||||
if (local::equal(av[4], "enums")) {
|
if (local::equal(outputType.value, "enums")) {
|
||||||
local::writeEnums(&out, declarations);
|
local::writeEnums(&out, declarations);
|
||||||
} else if (local::equal(av[4], "declarations")) {
|
} else if (local::equal(outputType.value, "declarations")) {
|
||||||
out.write("const unsigned TypeCount = ");
|
out.write("const unsigned TypeCount = ");
|
||||||
out.Output::write(local::typeCount(declarations));
|
out.Output::write(local::typeCount(declarations));
|
||||||
out.write(";\n\n");
|
out.write(";\n\n");
|
||||||
@ -2002,20 +2014,18 @@ main(int ac, char** av)
|
|||||||
local::writeSizes(&out, declarations);
|
local::writeSizes(&out, declarations);
|
||||||
local::writeInitializerDeclarations(&out, declarations);
|
local::writeInitializerDeclarations(&out, declarations);
|
||||||
local::writeConstructorDeclarations(&out, declarations);
|
local::writeConstructorDeclarations(&out, declarations);
|
||||||
} else if (local::equal(av[4], "constructors")) {
|
} else if (local::equal(outputType.value, "constructors")) {
|
||||||
local::writeInitializers(&out, declarations);
|
local::writeInitializers(&out, declarations);
|
||||||
local::writeConstructors(&out, declarations);
|
local::writeConstructors(&out, declarations);
|
||||||
} else if (local::equal(av[4], "initializations")) {
|
} else if (local::equal(outputType.value, "initializations")) {
|
||||||
local::writeInitializations(&out, declarations);
|
local::writeInitializations(&out, declarations);
|
||||||
} else if (local::equal(av[4], "java-initializations")) {
|
} else if (local::equal(outputType.value, "java-initializations")) {
|
||||||
local::writeJavaInitializations(&out, declarations);
|
local::writeJavaInitializations(&out, declarations);
|
||||||
} else if (local::equal(av[4], "name-initializations")) {
|
} else if (local::equal(outputType.value, "name-initializations")) {
|
||||||
local::writeNameInitializations(&out, declarations);
|
local::writeNameInitializations(&out, declarations);
|
||||||
} else if (local::equal(av[4], "maps")) {
|
} else if (local::equal(outputType.value, "maps")) {
|
||||||
local::writeMaps(&out, declarations);
|
local::writeMaps(&out, declarations);
|
||||||
}
|
}
|
||||||
|
|
||||||
out.write("\n");
|
out.write("\n");
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user