Skip to content

Commit

Permalink
refactor(codegen/plc4go): major refactoring how types are handled in …
Browse files Browse the repository at this point in the history
…plc4go

- Interfaces are now first class citizen
  • Loading branch information
sruehl committed Jun 15, 2022
1 parent 6bc2399 commit e7fb792
Show file tree
Hide file tree
Showing 1,840 changed files with 84,366 additions and 89,978 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public String getLanguageTypeNameForTypeReference(TypeReference typeReference) {
if (typeReference.isArrayTypeReference()) {
final ArrayTypeReference arrayTypeReference = (ArrayTypeReference) typeReference;
TypeReference elementTypeReference = arrayTypeReference.getElementTypeReference();
return "[]" + (elementTypeReference.isNonSimpleTypeReference() && !elementTypeReference.isEnumTypeReference() ? "*" : "") + getLanguageTypeNameForTypeReference(elementTypeReference);
return "[]" + getLanguageTypeNameForTypeReference(elementTypeReference);
}
if (typeReference.isNonSimpleTypeReference()) {
return typeReference.asNonSimpleTypeReference().orElseThrow().getName();
Expand Down Expand Up @@ -280,7 +280,14 @@ public int getNumBits(SimpleTypeReference simpleTypeReference) {
}

public boolean needsPointerAccess(PropertyField field) {
return "optional".equals(field.getTypeName()) || (field.getType().isNonSimpleTypeReference() && !isEnumField(field));
boolean isAnTypeOfOptional = "optional".equals(field.getTypeName());
return isAnTypeOfOptional && needPointerAccess(field.getType());
}

public boolean needPointerAccess(TypeReference typeReference) {
boolean isNotAnComplexTypeReference = !typeReference.isComplexTypeReference();
boolean arrayTypeIsNotAnComplexTypeReference = !(typeReference.isArrayTypeReference() && typeReference.asArrayTypeReference().orElseThrow().getElementTypeReference().isComplexTypeReference());
return isNotAnComplexTypeReference && arrayTypeIsNotAnComplexTypeReference;
}

public String getSpecialReadBufferReadMethodCall(String logicalName, SimpleTypeReference simpleTypeReference, TypedField field) {
Expand Down Expand Up @@ -742,7 +749,8 @@ else if (thisType.isComplexTypeDefinition()
.isPresent()
) {
tracer = tracer.dive("optional fields");
return tracer + "(" + (suppressPointerAccess ? "" : "*") + "m.Get" + capitalize(variableLiteral.getName()) + "())" +
OptionalField optionalField = thisType.asComplexTypeDefinition().orElseThrow().getPropertyFieldByName(variableLiteralName).orElseThrow().asOptionalField().orElseThrow();
return tracer + "(" + (suppressPointerAccess || optionalField.getType().isComplexTypeReference() ? "" : "*") + "m.Get" + capitalize(variableLiteral.getName()) + "())" +
variableLiteral.getChild().map(child -> "." + capitalize(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, false, suppressPointerAccess, true))).orElse("");
}
// If we are accessing implicit fields, we need to rely on local variable instead.
Expand Down Expand Up @@ -798,7 +806,7 @@ else if ((variableLiteral.getChild().isPresent()) && ((ComplexTypeDefinition) th
.filter(curField -> (curField instanceof DiscriminatorField) && ((DiscriminatorField) curField).getName().equals(childProperty))
.findFirst();
if (matchingDiscriminatorField.isPresent()) {
return tracer + "Cast" + getLanguageTypeNameForTypeReference(nonSimpleTypeReference) + "(" + variableLiteralName + ").Child.Get" + capitalize(childProperty) + "()";
return tracer + "Cast" + getLanguageTypeNameForTypeReference(nonSimpleTypeReference) + "(" + variableLiteralName + ").Get" + capitalize(childProperty) + "()";
}
// TODO: is this really meant to fall through?
tracer = tracer.dive("we fell through the complex complex");
Expand All @@ -813,7 +821,7 @@ else if ((variableLiteral.getChild().isPresent()) && ((ComplexTypeDefinition) th
}
}
// TODO: is this really meant to fall through?
tracer = tracer.dive("we fell through the child comple");
tracer = tracer.dive("we fell through the child complete");
} else if (isVariableLiteralImplicitField(variableLiteral)) {
tracer = tracer.dive("implicit");
if (serialize) {
Expand Down Expand Up @@ -1039,7 +1047,7 @@ private String toCastVariableExpression(Field field, TypeReference typeReference

private String toOptionalVariableExpression(Field field, TypeReference typeReference, VariableLiteral variableLiteral, List<Argument> parserArguments, List<Argument> serializerArguments, boolean suppressPointerAccess, Tracer tracer) {
tracer = tracer.dive("optional fields");
return tracer + "(" + (suppressPointerAccess ? "" : "*") + variableLiteral.getName() + ")" +
return tracer + "(" + (suppressPointerAccess || (typeReference != null && typeReference.isComplexTypeReference())? "" : "*") + variableLiteral.getName() + ")" +
variableLiteral.getChild().map(child -> "." + capitalize(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, false, suppressPointerAccess, true))).orElse("");
}

Expand Down
Loading

0 comments on commit e7fb792

Please sign in to comment.