From b40d6ff5f089ad4251e771e4b5d792487868ae4d Mon Sep 17 00:00:00 2001 From: Jonathan Bendes Date: Sun, 8 Oct 2023 15:08:34 -0400 Subject: [PATCH] Added reserved keywords --- examples/cpp/FunctionNameCollision.cpp | 9 +++++ examples/cpp/wscript | 4 ++ examples/python/function_name_collision.py | 8 ++++ examples/types/function_name_collision_t.zcm | 41 ++++++++++++++++++++ gen/emit/EmitCpp.cpp | 6 ++- gen/emit/EmitJava.cpp | 6 ++- gen/emit/EmitNode.cpp | 4 +- gen/emit/EmitPython.cpp | 6 ++- 8 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 examples/cpp/FunctionNameCollision.cpp create mode 100644 examples/python/function_name_collision.py create mode 100644 examples/types/function_name_collision_t.zcm diff --git a/examples/cpp/FunctionNameCollision.cpp b/examples/cpp/FunctionNameCollision.cpp new file mode 100644 index 00000000..bb41b8b4 --- /dev/null +++ b/examples/cpp/FunctionNameCollision.cpp @@ -0,0 +1,9 @@ +#include + +#include "types/function_name_collision_t.hpp" + +int main(int argc, char *argv[]) +{ + function_name_collision_t msg; + return 0; +} diff --git a/examples/cpp/wscript b/examples/cpp/wscript index 0ba82582..a402afdf 100644 --- a/examples/cpp/wscript +++ b/examples/cpp/wscript @@ -66,4 +66,8 @@ def build(ctx): use = 'default zcm', source = 'BandwidthTest.cpp') + ctx.program(target = 'function-name-collision', + use = 'default zcm examplezcmtypes_cpp', + source = 'FunctionNameCollision.cpp') + ctx.recurse('transport') diff --git a/examples/python/function_name_collision.py b/examples/python/function_name_collision.py new file mode 100644 index 00000000..2351b630 --- /dev/null +++ b/examples/python/function_name_collision.py @@ -0,0 +1,8 @@ +#!/usr/bin/python + +blddir= os.path.dirname(os.path.realpath(__file__)) + '/../../build/examples/examples/' +sys.path.insert(0, blddir + "types/") +from function_name_collision_t import function_name_collision_t + +# declare a new msg and populate it +msg = function_name_collision_t() diff --git a/examples/types/function_name_collision_t.zcm b/examples/types/function_name_collision_t.zcm new file mode 100644 index 00000000..aacc332b --- /dev/null +++ b/examples/types/function_name_collision_t.zcm @@ -0,0 +1,41 @@ +struct function_name_collision_t +{ + boolean tmp; + + // Cpp + // boolean encode; + // boolean getEncodedSize; + // boolean decode; + // boolean getHash; + // boolean getTypeName; + // boolean _encodeNoHash; + // boolean _getEncodedSizeNoHash; + // boolean _decodeNoHash; + // boolean _computeHash; + + // Java + // boolean ZCM_FINGERPRINT; + // boolean ZCM_FINGERPRINT_BASE; + // boolean IS_LITTLE_ENDIAN; + // boolean _hashRecursive; + // boolean encode; + // boolean _encodeRecursive; + // boolean _decodeRecursiveFactory; + // boolean _decodeRecursive; + // boolean copy; + + // Node + // boolean IS_LITTLE_ENDIAN; + // boolean __hash; + + // Python + // boolean __init__; + // boolean encode; + // boolean _encode_one; + // boolean decode; + // boolean _decode_one; + // boolean _hash; + // boolean _get_hash_recursive; + // boolean _packed_fingerprint; + // boolean _get_packed_fingerprint; +} diff --git a/gen/emit/EmitCpp.cpp b/gen/emit/EmitCpp.cpp index 0bf19567..67f6d392 100644 --- a/gen/emit/EmitCpp.cpp +++ b/gen/emit/EmitCpp.cpp @@ -942,5 +942,9 @@ unordered_set getReservedKeywordsCpp() "switch", "synchronized", "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", - "while", "xor", "xor_eq" }; + "while", "xor", "xor_eq", + /* zcm reserved keywords */ + "encode", "getEncodedSize", "decode", "getHash", "getTypeName", + "_encodeNoHash", "_getEncodedSizeNoHash", "_decodeNoHash", + "_computeHash" }; } diff --git a/gen/emit/EmitJava.cpp b/gen/emit/EmitJava.cpp index 4aee091a..f27428c8 100644 --- a/gen/emit/EmitJava.cpp +++ b/gen/emit/EmitJava.cpp @@ -690,5 +690,9 @@ unordered_set getReservedKeywordsJava() "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", - "transient", "true", "try", "void", "volatile", "while" }; + "transient", "true", "try", "void", "volatile", "while", + /* Zcm reserved keywords */ + "ZCM_FINGERPRINT", "ZCM_FINGERPRINT_BASE", "IS_LITTLE_ENDIAN", + "_hashRecursive", "encode", "_encodeRecursive", + "_decodeRecursiveFactory", "_decodeRecursive", "copy" }; } diff --git a/gen/emit/EmitNode.cpp b/gen/emit/EmitNode.cpp index 6d69038e..16987b92 100644 --- a/gen/emit/EmitNode.cpp +++ b/gen/emit/EmitNode.cpp @@ -863,5 +863,7 @@ unordered_set getReservedKeywordsNode() "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "var", - "void", "volatile", "while", "with", "yield" }; + "void", "volatile", "while", "with", "yield", + /* Zcm reserved keywords */ + "IS_LITTLE_ENDIAN", "__hash" }; } diff --git a/gen/emit/EmitPython.cpp b/gen/emit/EmitPython.cpp index 14cce624..926e9ce1 100644 --- a/gen/emit/EmitPython.cpp +++ b/gen/emit/EmitPython.cpp @@ -929,5 +929,9 @@ unordered_set getReservedKeywordsPython() "for", "lambda", "try", "True", "def", "from", "nonlocal", "while", "and", "del", "global", "not", "with", "as", "elif", "if", "or", "yield", "assert", "else", "import", "pass", "break", - "except", "in", "raise" }; + "except", "in", "raise", + /* Zcm reserved keywords */ + "__init__", "encode", "_encode_one", "decode", "_decode_one", + "_hash", "_get_hash_recursive", "_packed_fingerprint", + "_get_packed_fingerprint" }; }