-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make-structs cmd line option #15
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,14 +35,18 @@ class CodeGeneratorException : Exception | |
class CodeGenerator | ||
{ | ||
private enum indentSize = 4; | ||
private bool makeStructs = false; | ||
deviator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
CodeGeneratorResponse handle(CodeGeneratorRequest request) | ||
{ | ||
import std.algorithm : filter, map; | ||
import std.algorithm : filter, map, canFind, splitter; | ||
import std.array : array; | ||
import std.conv : to; | ||
import std.format : format; | ||
|
||
if (request.parameter.splitter(",").canFind("make-structs")) | ||
makeStructs = true; | ||
|
||
if (request.compilerVersion) with (request.compilerVersion) | ||
protocVersion = format!"%d%03d%03d"(major, minor, patch); | ||
|
||
|
@@ -146,9 +150,18 @@ class CodeGenerator | |
if (messageType.isMap) | ||
return ""; | ||
|
||
auto strIndent = "%*s".format(indent, ""); | ||
deviator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
auto result = appender!string; | ||
result ~= "\n%*s%sclass %s\n".format(indent, "", indent > 0 ? "static " : "", messageType.name.escapeKeywords); | ||
result ~= "%*s{\n".format(indent, ""); | ||
result ~= "\n"; | ||
result ~= strIndent; | ||
result ~= indent > 0 ? "static " : ""; | ||
result ~= makeStructs ? "struct" : "class"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check here if the protobuf message definition is recursive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What you mean by recursive messages? |
||
result ~= " "; | ||
result ~= messageType.name.escapeKeywords; | ||
result ~= "\n"; | ||
result ~= strIndent; | ||
result ~= "{\n"; | ||
|
||
int[] generatedOneofs; | ||
foreach (field; messageType.fields.sort!((a, b) => a.number < b.number)) | ||
|
@@ -173,7 +186,8 @@ class CodeGenerator | |
foreach (enumType; messageType.enumTypes) | ||
result ~= generateEnum(enumType, indent + indentSize); | ||
|
||
result ~= "%*s}\n".format(indent, ""); | ||
result ~= strIndent; | ||
result ~= "}\n"; | ||
|
||
return result.data; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Three times the same
static if/else
, maybe a small templatemake!T
.Ex.:
auto person = make!Person