aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2014-10-30 15:21:42 +0100
committerDavid 'Digit' Turner <digit@google.com>2014-10-30 21:36:55 +0100
commit4631f988e530be4d11daf0fa03e8ab47e0bfbcae (patch)
treea18d7686d3172a0ac8b37e1fb07045468310f83e
parent6d4468efe84bf50fb8e43aab011059fb7d019c1b (diff)
downloadsdk-4631f988e530be4d11daf0fa03e8ab47e0bfbcae.zip
sdk-4631f988e530be4d11daf0fa03e8ab47e0bfbcae.tar.gz
sdk-4631f988e530be4d11daf0fa03e8ab47e0bfbcae.tar.bz2
emulator/opengl/emugen: Small cleanup of autogenerated sources.
This patch ensures the generated sources are cleaned up a little bit, more specifically: - Add proper end-ifdef-guard comments. - Use anonymous C++ namespaces to avoid name conflicts in the encoder. - Remove extra spaces / empty lines / indent. - Use 'const' when defining constant tables. Change-Id: Ib11fd06adb9075d472d1dd2fd6defb0760aaa2c2
-rw-r--r--emulator/opengl/host/tools/emugen/ApiGen.cpp45
-rw-r--r--emulator/opengl/host/tools/emugen/tests/t.001/expected/decoder/foo_dec.h2
-rw-r--r--emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_enc.cpp13
-rw-r--r--emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_enc.h9
-rw-r--r--emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_entry.cpp14
-rw-r--r--emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_ftable.h4
-rw-r--r--emulator/opengl/host/tools/emugen/tests/t.001/expected/wrapper/foo_wrapper_entry.cpp14
7 files changed, 49 insertions, 52 deletions
diff --git a/emulator/opengl/host/tools/emugen/ApiGen.cpp b/emulator/opengl/host/tools/emugen/ApiGen.cpp
index 71cd843..5ffe38f 100644
--- a/emulator/opengl/host/tools/emugen/ApiGen.cpp
+++ b/emulator/opengl/host/tools/emugen/ApiGen.cpp
@@ -110,7 +110,7 @@ int ApiGen::genFuncTable(const std::string &filename, SideType side)
fprintf(fp, "#ifndef __%s_%s_ftable_t_h\n", m_basename.c_str(), sideString(side));
fprintf(fp, "#define __%s_%s_ftable_t_h\n", m_basename.c_str(), sideString(side));
fprintf(fp, "\n\n");
- fprintf(fp, "static struct _%s_funcs_by_name {\n", m_basename.c_str());
+ fprintf(fp, "static const struct _%s_funcs_by_name {\n", m_basename.c_str());
fprintf(fp,
"\tconst char *name;\n" \
"\tvoid *proc;\n" \
@@ -123,7 +123,7 @@ int ApiGen::genFuncTable(const std::string &filename, SideType side)
fprintf(fp, "\t{\"%s\", (void*)%s},\n", e->name().c_str(), e->name().c_str());
}
fprintf(fp, "};\n");
- fprintf(fp, "static int %s_num_funcs = sizeof(%s_funcs_by_name) / sizeof(struct _%s_funcs_by_name);\n",
+ fprintf(fp, "static const int %s_num_funcs = sizeof(%s_funcs_by_name) / sizeof(struct _%s_funcs_by_name);\n",
m_basename.c_str(), m_basename.c_str(), m_basename.c_str());
fprintf(fp, "\n\n#endif\n");
return 0;
@@ -219,7 +219,7 @@ int ApiGen::genEntryPoints(const std::string & filename, SideType side)
fprintf(fp,
"void %s_%s_context_t::setContextAccessor(CONTEXT_ACCESSOR_TYPE *f) { getCurrentContext = f; }\n",
m_basename.c_str(), sideString(side));
- fprintf(fp, "#define GET_CONTEXT %s_%s_context_t * ctx = getCurrentContext() \n",
+ fprintf(fp, "#define GET_CONTEXT %s_%s_context_t * ctx = getCurrentContext()\n",
m_basename.c_str(), sideString(side));
fprintf(fp, "#endif\n\n");
@@ -228,7 +228,7 @@ int ApiGen::genEntryPoints(const std::string & filename, SideType side)
EntryPoint *e = &at(i);
e->print(fp);
fprintf(fp, "{\n");
- fprintf(fp, "\tGET_CONTEXT; \n");
+ fprintf(fp, "\tGET_CONTEXT;\n");
bool shouldReturn = !e->retval().isVoid();
bool shouldCallWithContext = (side == CLIENT_SIDE);
@@ -239,7 +239,7 @@ int ApiGen::genEntryPoints(const std::string & filename, SideType side)
fprintf(fp, "\t%s\n", e->vars()[j].paramCheckExpression().c_str());
}
}
- fprintf(fp, "\t %sctx->%s(%s",
+ fprintf(fp, "\t%sctx->%s(%s",
shouldReturn ? "return " : "",
e->name().c_str(),
shouldCallWithContext ? "ctx" : "");
@@ -325,18 +325,10 @@ int ApiGen::genEncoderHeader(const std::string &filename)
classname.c_str(), m_basename.c_str(), sideString(CLIENT_SIDE));
fprintf(fp, "\tIOStream *m_stream;\n\n");
- fprintf(fp, "\t%s(IOStream *stream);\n\n", classname.c_str());
- fprintf(fp, "\n};\n\n");
+ fprintf(fp, "\t%s(IOStream *stream);\n", classname.c_str());
+ fprintf(fp, "};\n\n");
- fprintf(fp,"extern \"C\" {\n");
-
- for (size_t i = 0; i < size(); i++) {
- fprintf(fp, "\t");
- at(i).print(fp, false, "_enc", /* classname + "::" */"", "void *self");
- fprintf(fp, ";\n");
- }
- fprintf(fp, "};\n");
- fprintf(fp, "#endif");
+ fprintf(fp, "#endif // GUARD_%s", classname.c_str());
fclose(fp);
return 0;
@@ -453,15 +445,20 @@ int ApiGen::genEncoderImpl(const std::string &filename)
fprintf(fp, "\n\n#include <string.h>\n");
fprintf(fp, "#include \"%s_opcodes.h\"\n\n", m_basename.c_str());
fprintf(fp, "#include \"%s_enc.h\"\n\n\n", m_basename.c_str());
- fprintf(fp, "#include <stdio.h>\n");
- std::string classname = m_basename + "_encoder_context_t";
- size_t n = size();
+ fprintf(fp, "#include <stdio.h>\n\n");
+ fprintf(fp, "namespace {\n\n");
// unsupport printout
fprintf(fp,
- "static void enc_unsupported()\n{\n\tALOGE(\"Function is unsupported\\n\");\n}\n\n");
+ "void enc_unsupported()\n"
+ "{\n"
+ "\tALOGE(\"Function is unsupported\\n\");\n"
+ "}\n\n");
// entry points;
+ std::string classname = m_basename + "_encoder_context_t";
+
+ size_t n = size();
for (size_t i = 0; i < n; i++) {
EntryPoint *e = &at(i);
@@ -646,6 +643,8 @@ int ApiGen::genEncoderImpl(const std::string &filename)
fprintf(fp, "}\n\n");
}
+ fprintf(fp, "} // namespace\n\n");
+
// constructor
fprintf(fp, "%s::%s(IOStream *stream)\n{\n", classname.c_str(), classname.c_str());
fprintf(fp, "\tm_stream = stream;\n\n");
@@ -654,13 +653,13 @@ int ApiGen::genEncoderImpl(const std::string &filename)
EntryPoint *e = &at(i);
if (e->unsupported()) {
fprintf(fp,
- "\t%s = (%s_%s_proc_t)(enc_unsupported);\n",
+ "\tthis->%s = (%s_%s_proc_t) &enc_unsupported;\n",
e->name().c_str(),
e->name().c_str(),
sideString(CLIENT_SIDE));
} else {
fprintf(fp,
- "\t%s = (%s_enc);\n",
+ "\tthis->%s = &%s_enc;\n",
e->name().c_str(),
e->name().c_str());
}
@@ -698,7 +697,7 @@ int ApiGen::genDecoderHeader(const std::string &filename)
classname.c_str(), m_basename.c_str(), sideString(SERVER_SIDE));
fprintf(fp, "\tsize_t decode(void *buf, size_t bufsize, IOStream *stream);\n");
fprintf(fp, "\n};\n\n");
- fprintf(fp, "#endif\n");
+ fprintf(fp, "#endif // GUARD_%s\n", classname.c_str());
fclose(fp);
return 0;
diff --git a/emulator/opengl/host/tools/emugen/tests/t.001/expected/decoder/foo_dec.h b/emulator/opengl/host/tools/emugen/tests/t.001/expected/decoder/foo_dec.h
index 8127237..3646de5 100644
--- a/emulator/opengl/host/tools/emugen/tests/t.001/expected/decoder/foo_dec.h
+++ b/emulator/opengl/host/tools/emugen/tests/t.001/expected/decoder/foo_dec.h
@@ -15,4 +15,4 @@ struct foo_decoder_context_t : public foo_server_context_t {
};
-#endif
+#endif // GUARD_foo_decoder_context_t
diff --git a/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_enc.cpp b/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_enc.cpp
index b1f66b7..a87c3d8 100644
--- a/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_enc.cpp
+++ b/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_enc.cpp
@@ -9,7 +9,10 @@
#include <stdio.h>
-static void enc_unsupported()
+
+namespace {
+
+void enc_unsupported()
{
ALOGE("Function is unsupported\n");
}
@@ -51,12 +54,14 @@ FooBoolean fooIsBuffer_enc(void *self , void* stuff)
return retval;
}
+} // namespace
+
foo_encoder_context_t::foo_encoder_context_t(IOStream *stream)
{
m_stream = stream;
- fooAlphaFunc = (fooAlphaFunc_enc);
- fooIsBuffer = (fooIsBuffer_enc);
- fooUnsupported = (fooUnsupported_client_proc_t)(enc_unsupported);
+ this->fooAlphaFunc = &fooAlphaFunc_enc;
+ this->fooIsBuffer = &fooIsBuffer_enc;
+ this->fooUnsupported = (fooUnsupported_client_proc_t) &enc_unsupported;
}
diff --git a/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_enc.h b/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_enc.h
index a86956f..195b37a 100644
--- a/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_enc.h
+++ b/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_enc.h
@@ -16,13 +16,6 @@ struct foo_encoder_context_t : public foo_client_context_t {
IOStream *m_stream;
foo_encoder_context_t(IOStream *stream);
-
-
};
-extern "C" {
- void fooAlphaFunc_enc(void *self , FooInt func, FooFloat ref);
- FooBoolean fooIsBuffer_enc(void *self , void* stuff);
- void fooUnsupported_enc(void *self , void* params);
-};
-#endif \ No newline at end of file
+#endif // GUARD_foo_encoder_context_t \ No newline at end of file
diff --git a/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_entry.cpp b/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_entry.cpp
index 1caacd2..78b78ba 100644
--- a/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_entry.cpp
+++ b/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_entry.cpp
@@ -15,25 +15,25 @@ extern "C" {
#ifndef GET_CONTEXT
static foo_client_context_t::CONTEXT_ACCESSOR_TYPE *getCurrentContext = NULL;
void foo_client_context_t::setContextAccessor(CONTEXT_ACCESSOR_TYPE *f) { getCurrentContext = f; }
-#define GET_CONTEXT foo_client_context_t * ctx = getCurrentContext()
+#define GET_CONTEXT foo_client_context_t * ctx = getCurrentContext()
#endif
void fooAlphaFunc(FooInt func, FooFloat ref)
{
- GET_CONTEXT;
- ctx->fooAlphaFunc(ctx, func, ref);
+ GET_CONTEXT;
+ ctx->fooAlphaFunc(ctx, func, ref);
}
FooBoolean fooIsBuffer(void* stuff)
{
- GET_CONTEXT;
+ GET_CONTEXT;
if (n == NULL) { LOG(ERROR) << "NULL stuff"; return; }
- return ctx->fooIsBuffer(ctx, stuff);
+ return ctx->fooIsBuffer(ctx, stuff);
}
void fooUnsupported(void* params)
{
- GET_CONTEXT;
- ctx->fooUnsupported(ctx, params);
+ GET_CONTEXT;
+ ctx->fooUnsupported(ctx, params);
}
diff --git a/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_ftable.h b/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_ftable.h
index 87fb3f6..abf16ad 100644
--- a/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_ftable.h
+++ b/emulator/opengl/host/tools/emugen/tests/t.001/expected/encoder/foo_ftable.h
@@ -4,7 +4,7 @@
#define __foo_client_ftable_t_h
-static struct _foo_funcs_by_name {
+static const struct _foo_funcs_by_name {
const char *name;
void *proc;
} foo_funcs_by_name[] = {
@@ -12,7 +12,7 @@ static struct _foo_funcs_by_name {
{"fooIsBuffer", (void*)fooIsBuffer},
{"fooUnsupported", (void*)fooUnsupported},
};
-static int foo_num_funcs = sizeof(foo_funcs_by_name) / sizeof(struct _foo_funcs_by_name);
+static const int foo_num_funcs = sizeof(foo_funcs_by_name) / sizeof(struct _foo_funcs_by_name);
#endif
diff --git a/emulator/opengl/host/tools/emugen/tests/t.001/expected/wrapper/foo_wrapper_entry.cpp b/emulator/opengl/host/tools/emugen/tests/t.001/expected/wrapper/foo_wrapper_entry.cpp
index 2dc18a9..8edf677 100644
--- a/emulator/opengl/host/tools/emugen/tests/t.001/expected/wrapper/foo_wrapper_entry.cpp
+++ b/emulator/opengl/host/tools/emugen/tests/t.001/expected/wrapper/foo_wrapper_entry.cpp
@@ -15,24 +15,24 @@ extern "C" {
#ifndef GET_CONTEXT
static foo_wrapper_context_t::CONTEXT_ACCESSOR_TYPE *getCurrentContext = NULL;
void foo_wrapper_context_t::setContextAccessor(CONTEXT_ACCESSOR_TYPE *f) { getCurrentContext = f; }
-#define GET_CONTEXT foo_wrapper_context_t * ctx = getCurrentContext()
+#define GET_CONTEXT foo_wrapper_context_t * ctx = getCurrentContext()
#endif
void fooAlphaFunc(FooInt func, FooFloat ref)
{
- GET_CONTEXT;
- ctx->fooAlphaFunc( func, ref);
+ GET_CONTEXT;
+ ctx->fooAlphaFunc( func, ref);
}
FooBoolean fooIsBuffer(void* stuff)
{
- GET_CONTEXT;
- return ctx->fooIsBuffer( stuff);
+ GET_CONTEXT;
+ return ctx->fooIsBuffer( stuff);
}
void fooUnsupported(void* params)
{
- GET_CONTEXT;
- ctx->fooUnsupported( params);
+ GET_CONTEXT;
+ ctx->fooUnsupported( params);
}