Skip to content

Commit

Permalink
Merge pull request vizor-games#6 from nikitamiroshnichenko/fix-null-p…
Browse files Browse the repository at this point in the history
…ackage-compile-errors-generation

null package name makes compile errors in generated code
  • Loading branch information
RChehowski committed Feb 25, 2019
2 parents 1e38e75 + 749d852 commit 792953c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
23 changes: 15 additions & 8 deletions src/main/java/com/vizor/unreal/convert/ClientWorkerGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,26 @@ private CppClass genSingle(final ServiceElement service)
final List<CppField> cppFields = extractConduits(service);
final List<CppField> fields = new ArrayList<>(cppFields);



// 0 - Request Type
// 1 - Response Type
// 2 - UE Response Generic Type
// 3 - UE Response Type
// 4 - Package Name
// 5 - Function Name
final String rpcMethodBody = join(lineSeparator(), asList(
"{4}::{0} ClientRequest(casts::Proto_Cast<{4}::{0}>(Request));",
"{4}{0} ClientRequest(casts::Proto_Cast<{4}{0}>(Request));",
"",
"grpc::ClientContext ClientContext;",
"casts::CastClientContext(Context, ClientContext);",
"",
"grpc::CompletionQueue Queue;",
"grpc::Status Status;",
"",
"std::unique_ptr<grpc::ClientAsyncResponseReader<{4}::{1}>> Rpc(Stub->Async{5}(&ClientContext, ClientRequest, &Queue));",
"std::unique_ptr<grpc::ClientAsyncResponseReader<{4}{1}>> Rpc(Stub->Async{5}(&ClientContext, ClientRequest, &Queue));",
"",
"{4}::{1} Response;",
"{4}{1} Response;",
"Rpc->Finish(&Response, &Status, (void*)1);",
"",
"void* got_tag;",
Expand All @@ -120,7 +123,6 @@ private CppClass genSingle(final ServiceElement service)
));

final List<CppFunction> methods = extractFunctions(service);

for (int i = 0; i < methods.size(); i++)
{
final RpcElement rpc = service.rpcs().get(i);
Expand All @@ -130,7 +132,7 @@ private CppClass genSingle(final ServiceElement service)
final CppType responseWithStatus = rspWithSts.makeGeneric(response);

function.setBody(format(rpcMethodBody, rpc.requestType(), rpc.responseType(), responseWithStatus.toString(),
response, parse.packageName(), function.getName()));
response, getPackageNamespaceString(), function.getName()));
}

methods.add(createStubInitializer(service, fields));
Expand All @@ -157,10 +159,10 @@ private CppFunction createStubInitializer(final ServiceElement service, final Li
sb.append("if (!Channel.get())").append(lineSeparator());
sb.append(" return false;").append(lineSeparator()).append(lineSeparator());

final String initStubPattern = "Stub = {0}::{1}::NewStub(Channel);";
final String initStubPattern = "Stub = {0}{1}::NewStub(Channel);";
final String acquireProducerPattern = "{0}->AcquireResponsesProducer();";

sb.append(format(initStubPattern, parse.packageName(), service.name()))
sb.append(format(initStubPattern, getPackageNamespaceString(), service.name()))
.append(lineSeparator()).append(lineSeparator());

// Acquire all required conduits
Expand Down Expand Up @@ -215,7 +217,7 @@ private CppFunction createUpdate(final ServiceElement service, final List<CppFie

private CppField createStub(final ServiceElement service)
{
final CppType plain = plain(parse.packageName() + "::" + service.name() + "::Stub", Struct);
final CppType plain = plain(getPackageNamespaceString() + service.name() + "::Stub", Struct);
final CppType stubPtr = wildcardUniquePtr.makeGeneric(plain);
final CppField stub = new CppField(stubPtr, "Stub");

Expand Down Expand Up @@ -262,4 +264,9 @@ private List<CppFunction> extractFunctions(final ServiceElement service)
.collect(toList());
}

private String getPackageNamespaceString()
{
return parse.packageName() != null ? parse.packageName() + "::" : "";
}

}
14 changes: 10 additions & 4 deletions src/main/java/com/vizor/unreal/convert/ProtoProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class ProtoProcessor implements Runnable

this.className = snakeCaseToCamelCase(wrapperName);

if (parse.packageName() == null)
throw new RuntimeException("package filed in proto file is required for cornerstone");
// if (parse.packageName() == null)
// throw new RuntimeException("package filed in proto file is required for cornerstone");

this.packageNamespace = new CppNamespace(parse.packageName());
}
Expand Down Expand Up @@ -342,13 +342,19 @@ private CppType cppNamedType(final TypeElement el)
if (el instanceof MessageElement)
{
final CppType mt = plain(el.name(), Struct);
mt.setNamespaces(packageNamespace);

if (packageNamespace.hasName())
mt.setNamespaces(packageNamespace);

return mt;
}
else if (el instanceof EnumElement)
{
final CppType et = plain(el.name(), Enum);
et.setNamespaces(packageNamespace);

if (packageNamespace.hasName())
et.setNamespaces(packageNamespace);

return et;
}
else
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/vizor/unreal/tree/CppNamespace.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public String getName()
return name;
}

public boolean hasName()
{
return name != null;
}

@Override
public CppPrinter accept(CppPrinter printer)
{
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/vizor/unreal/tree/CppType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vizor.unreal.tree;

import com.squareup.wire.schema.internal.parser.ProtoFileElement;
import com.vizor.unreal.writer.CppPrinter;

import java.util.ArrayList;
Expand Down Expand Up @@ -406,8 +407,13 @@ public final String toString()
{
final StringBuilder sb = new StringBuilder();

if (!namespaces.isEmpty())
namespaces.forEach(obj -> sb.append(obj.getName()).append("::"));
for (CppNamespace namespace : namespaces)
{
final String namespaceName = (namespace != null) ? namespace.getName() : null;
if (namespaceName != null)
sb.append(namespaceName).append("::");
}


sb.append(name);

Expand Down

0 comments on commit 792953c

Please sign in to comment.