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

CppHeaderParser cant distinguish two classes with the same name in different namespaces #54

Open
PBCOnGit opened this issue Nov 24, 2020 · 2 comments

Comments

@PBCOnGit
Copy link

PBCOnGit commented Nov 24, 2020

Basically what the title says, but here is an example:
CppHeaderParser will fail to parse code like below:

namespace i {
	struct Human {
		int t1;
	};
}

namespace w {
	struct Human {
		int t2;
	};
}

The issue is caused by the following code:

if not key.endswith("::") and not key.endswith(" ") and len(key) != 0:
    if key in self.classes:
        race_print("ERROR name collision:", key)
        self.classes[key].show()
        newClass.show()
        assert key not in self.classes  # namespace collision

inside _CppHeader::_evaluate_class_stack
Sadly im not sure if there is any easy way to fix this problem since it is actually caused by the fact that CppHeaderParser doesn't include normal namespaces in the name of a class.
A possible fix would be to include the namespace in the name as well which would force everyone to rewrite their code.
Another possible fix would be to distinguish between classes with a unique hash which also includes the namespace.
Edit: Add example and fix code indention

@PBCOnGit PBCOnGit changed the title C CppHeaderParser cant distinguish two classes with the same name in different namespaces Nov 24, 2020
@virtuald
Copy link
Member

There's currently a classes dict and a classes_order list, I would expect it to contain the parsed classes even if classes doesn't contain it.

Could add a classes_ns dictionary that has this modified structure and deprecate classes?

@PBCOnGit
Copy link
Author

A classes_ns dictionary sounds like a good idea.

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

2 participants