Fix #101: sanitize names of namespaces/methods/signals/properties/arguments (#102)

- add a list of c++ keywords and common defines
- sanitize names so that there are no functions/args with names that are reserved in c++

Co-authored-by: Christian Schneider <cschneider@radiodata.biz>
This commit is contained in:
ChristianS99
2020-05-16 22:57:37 +02:00
committed by GitHub
parent 9af20af001
commit fb0a70a831
6 changed files with 135 additions and 13 deletions

View File

@ -135,6 +135,7 @@ std::tuple<std::string, std::string> ProxyGenerator::processMethods(const Nodes&
for (const auto& method : methods)
{
auto name = method->get("name");
auto nameSafe = mangle_name(name);
Nodes args = (*method)["arg"];
Nodes inArgs = args.select("direction" , "in");
Nodes outArgs = args.select("direction" , "out");
@ -174,7 +175,7 @@ std::tuple<std::string, std::string> ProxyGenerator::processMethods(const Nodes&
std::tie(outArgStr, outArgTypeStr, std::ignore, std::ignore) = argsToNamesAndTypes(outArgs);
const std::string realRetType = (async && !dontExpectReply ? "sdbus::PendingAsyncCall" : async ? "void" : retType);
definitionSS << tab << realRetType << " " << name << "(" << inArgTypeStr << ")" << endl
definitionSS << tab << realRetType << " " << nameSafe << "(" << inArgTypeStr << ")" << endl
<< tab << "{" << endl;
if (!timeoutValue.empty())
@ -260,6 +261,7 @@ std::string ProxyGenerator::processProperties(const Nodes& properties) const
for (const auto& property : properties)
{
auto propertyName = property->get("name");
auto propertyNameSafe = mangle_name(propertyName);
auto propertyAccess = property->get("access");
auto propertySignature = property->get("type");
@ -269,7 +271,7 @@ std::string ProxyGenerator::processProperties(const Nodes& properties) const
if (propertyAccess == "read" || propertyAccess == "readwrite")
{
propertySS << tab << propertyType << " " << propertyName << "()" << endl
propertySS << tab << propertyType << " " << propertyNameSafe << "()" << endl
<< tab << "{" << endl;
propertySS << tab << tab << "return proxy_.getProperty(\"" << propertyName << "\")"
".onInterface(INTERFACE_NAME)";
@ -278,7 +280,7 @@ std::string ProxyGenerator::processProperties(const Nodes& properties) const
if (propertyAccess == "readwrite" || propertyAccess == "write")
{
propertySS << tab << "void " << propertyName << "(" << propertyTypeArg << ")" << endl
propertySS << tab << "void " << propertyNameSafe << "(" << propertyTypeArg << ")" << endl
<< tab << "{" << endl;
propertySS << tab << tab << "proxy_.setProperty(\"" << propertyName << "\")"
".onInterface(INTERFACE_NAME)"