Skip to content
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

CppGenerator: same header included multiple times #28

Open
phoppermann opened this issue Mar 16, 2021 · 1 comment
Open

CppGenerator: same header included multiple times #28

phoppermann opened this issue Mar 16, 2021 · 1 comment

Comments

@phoppermann
Copy link
Contributor

If multiple class attributes are objects of the same class, the corresponding header is included multiple times.
See

for (int idx = 0; idx < aClass.getClassAttributes().size(); idx++) {

Possible solution: store includes in Set<String>.

@phoppermann
Copy link
Contributor Author

phoppermann commented Mar 16, 2021

untested:

            // collect includes to avoid duplicates
            Set<String> includes= new HashSet<String>();
            for (int idx = 0; idx < aClass.getClassAttributes().size(); idx++) {
                ClassAttribute anAttribute = (ClassAttribute) aClass.getClassAttributes().get(idx);

                // If this attribute is a class, we need to do an import on that class
                if (anAttribute.getAttributeKind() == ClassAttribute.ClassAttributeType.CLASSREF) {
                    includes.add("#include <" + anAttribute.getType() + ".h>");
                }

                // If this attribute is a list with class type, we also need to do an import on that class
                if ((anAttribute.getAttributeKind() == ClassAttribute.ClassAttributeType.FIXED_LIST
                        || anAttribute.getAttributeKind() == ClassAttribute.ClassAttributeType.VARIABLE_LIST)
                        && !anAttribute.getUnderlyingTypeIsPrimitive()) {
                   includes.add("#include <" + anAttribute.getType() + ".h>");
                }

                // if this attribute is a variable-length list that holds a class, we need to
                // do an import on the class that is in the list.
                if (anAttribute.getAttributeKind() == ClassAttribute.ClassAttributeType.VARIABLE_LIST) {
                    hasVariableLengthList = true;
                }
            }
            // print collected includes
            for (String include : includes) {
                pw.println(include);
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant