aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2024-01-03 21:44:53 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-01-03 21:44:53 +0000
commit226a0666a5c920c9efd1bb7fb0f3b5f372135f15 (patch)
treed70d227e8479f8cf4948b1e687851ccb36d06363
parentadbdd46a81c648d46cf1197734fc67386586b594 (diff)
parent26b26f481ceaee377d2be6d64e322b10ed98bb05 (diff)
downloadaidl-226a0666a5c920c9efd1bb7fb0f3b5f372135f15.tar.gz
AIDL: allow '_' in int/hex const exprs am: 26b26f481c
Original change: https://android-review.googlesource.com/c/platform/system/tools/aidl/+/2891692 Change-Id: I016a8f034b08f00995de5dd41009ad78a536580c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--aidl_const_expressions.cpp13
-rw-r--r--aidl_language_l.ll4
-rw-r--r--aidl_unittest.cpp62
-rw-r--r--tests/android/aidl/tests/StructuredParcelable.aidl8
-rw-r--r--tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h2
-rw-r--r--tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/StructuredParcelable.java2
-rw-r--r--tests/golden_output/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h2
-rw-r--r--tests/golden_output/aidl-test-interface-rust-source/gen/android/aidl/tests/StructuredParcelable.rs2
-rw-r--r--tests/golden_output/frozen/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h2
-rw-r--r--tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/StructuredParcelable.java2
-rw-r--r--tests/golden_output/frozen/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h2
-rw-r--r--tests/golden_output/frozen/aidl-test-interface-rust-source/gen/android/aidl/tests/StructuredParcelable.rs2
-rw-r--r--tests/java/src/android/aidl/tests/TestServiceClient.java2
13 files changed, 90 insertions, 15 deletions
diff --git a/aidl_const_expressions.cpp b/aidl_const_expressions.cpp
index 79c10cc1..0e8d3006 100644
--- a/aidl_const_expressions.cpp
+++ b/aidl_const_expressions.cpp
@@ -31,6 +31,7 @@
using android::base::ConsumeSuffix;
using android::base::EndsWith;
using android::base::Join;
+using android::base::Split;
using android::base::StartsWith;
using std::string;
using std::unique_ptr;
@@ -477,7 +478,17 @@ bool AidlConstantValue::ParseIntegral(const string& value, int64_t* parsed_value
std::string_view value_view = value;
const bool is_byte = ConsumeSuffix(&value_view, "u8");
const bool is_long = ConsumeSuffix(&value_view, "l") || ConsumeSuffix(&value_view, "L");
- const std::string value_substr = std::string(value_view);
+
+ const std::string value_substr = ({
+ std::string raw_value_substr = std::string(value_view);
+ // remove "_" in integral constant
+ const std::vector<std::string> value_pieces = Split(raw_value_substr, "_");
+ if (std::any_of(value_pieces.begin(), value_pieces.end(),
+ [](const auto& s) { return s.empty(); })) {
+ return false;
+ }
+ Join(value_pieces, "");
+ });
*parsed_value = 0;
*parsed_type = Type::ERROR;
diff --git a/aidl_language_l.ll b/aidl_language_l.ll
index 7d3d57b2..9d563a1f 100644
--- a/aidl_language_l.ll
+++ b/aidl_language_l.ll
@@ -44,8 +44,8 @@
identifier [_a-zA-Z][_a-zA-Z0-9]*
whitespace ([ \t\r]+)
-intvalue [0-9]+[lL]?(u8)?
-hexvalue 0[x|X][0-9a-fA-F]+[lL]?(u8)?
+intvalue [0-9_]+[lL]?(u8)?
+hexvalue 0[x|X][0-9a-fA-F_]+[lL]?(u8)?
floatvalue [0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?
%%
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 21693e1c..cd5ca026 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -1337,6 +1337,68 @@ TEST_P(AidlTest, FailOnDuplicateConstantNames) {
EXPECT_EQ(AidlError::BAD_TYPE, error);
}
+TEST_P(AidlTest, FailOnDoubleUnderscore) {
+ AidlError error;
+ const string expected_stderr = "ERROR: p/IFoo.aidl:3.52-57: Could not parse integer: 1__0\n";
+ CaptureStderr();
+ EXPECT_EQ(nullptr, Parse("p/IFoo.aidl",
+ R"(package p;
+ interface IFoo {
+ const int UNDERSCORE_USER = 1__0;
+ }
+ )",
+ typenames_, GetLanguage(), &error));
+ EXPECT_EQ(expected_stderr, GetCapturedStderr());
+ EXPECT_EQ(AidlError::PARSE_ERROR, error);
+}
+
+TEST_P(AidlTest, FailOnUnderscoreBeforeModifier) {
+ AidlError error;
+ const string expected_stderr = "ERROR: p/IFoo.aidl:3.52-59: Could not parse hexvalue: 0xFF_L\n";
+ CaptureStderr();
+ EXPECT_EQ(nullptr, Parse("p/IFoo.aidl",
+ R"(package p;
+ interface IFoo {
+ const int UNDERSCORE_USER = 0xFF_L;
+ }
+ )",
+ typenames_, GetLanguage(), &error));
+ EXPECT_EQ(expected_stderr, GetCapturedStderr());
+ EXPECT_EQ(AidlError::PARSE_ERROR, error);
+}
+
+TEST_P(AidlTest, FailOnEndingUnderscore) {
+ AidlError error;
+ const string expected_stderr = "ERROR: p/IFoo.aidl:3.52-56: Could not parse integer: 10_\n";
+ CaptureStderr();
+ EXPECT_EQ(nullptr, Parse("p/IFoo.aidl",
+ R"(package p;
+ interface IFoo {
+ const int UNDERSCORE_USER = 10_;
+ }
+ )",
+ typenames_, GetLanguage(), &error));
+ EXPECT_EQ(expected_stderr, GetCapturedStderr());
+ EXPECT_EQ(AidlError::PARSE_ERROR, error);
+}
+
+TEST_P(AidlTest, FailOnLeadingUnderscore) {
+ AidlError error;
+ const string expected_stderr =
+ "ERROR: p/IFoo.aidl:3.52-56: Can't find _10 in IFoo\nERROR: p/IFoo.aidl:3.52-56: Unknown "
+ "reference '_10'\n";
+ CaptureStderr();
+ EXPECT_EQ(nullptr, Parse("p/IFoo.aidl",
+ R"(package p;
+ interface IFoo {
+ const int UNDERSCORE_USER = _10;
+ }
+ )",
+ typenames_, GetLanguage(), &error));
+ EXPECT_EQ(expected_stderr, GetCapturedStderr());
+ EXPECT_EQ(AidlError::BAD_TYPE, error);
+}
+
TEST_P(AidlTest, InvalidConstString) {
AidlError error;
const string expected_stderr =
diff --git a/tests/android/aidl/tests/StructuredParcelable.aidl b/tests/android/aidl/tests/StructuredParcelable.aidl
index 41fcdfb7..e3ebb6b0 100644
--- a/tests/android/aidl/tests/StructuredParcelable.aidl
+++ b/tests/android/aidl/tests/StructuredParcelable.aidl
@@ -91,9 +91,9 @@ parcelable StructuredParcelable {
(~(-1)) == 0,
~~(1 << 31) == (1 << 31),
-0x7fffffff < 0,
- 0x80000000 < 0,
+ 0x8000_0000 < 0,
- 0x7fffffff == 2147483647,
+ 0x7fffffff == 2_147_483_647,
// Shifting for more than 31 bits are undefined. Not tested.
(1 << 31) == 0x80000000,
@@ -161,11 +161,13 @@ parcelable StructuredParcelable {
~~(1L << 63) == (1L << 63),
-0x7FFFFFFFFFFFFFFF < 0,
- 0x7fffffff == 2147483647,
+ 0x7fff_ffff == 2147483647,
0xfffffffff == 68719476735,
0xffffffffffffffff == -1,
(0xfL << 32L) == 0xf00000000,
(0xfL << 32) == 0xf00000000,
+ 10L == 1_0L,
+ 10_0_0 == 1000L,
};
int hexInt32_pos_1 = -0xffffffff;
int hexInt64_pos_1 = -0xfffffffffff < 0;
diff --git a/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h b/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h
index 1f55c8fb..d89f4e1a 100644
--- a/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h
+++ b/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h
@@ -96,7 +96,7 @@ public:
::android::aidl::tests::StructuredParcelable::Empty empty;
::std::vector<uint8_t> int8_1 = {1, 1, 1, 1, 1};
::std::vector<int32_t> int32_1 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
- ::std::vector<int64_t> int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
+ ::std::vector<int64_t> int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
int32_t hexInt32_pos_1 = 1;
int32_t hexInt64_pos_1 = 1;
::android::aidl::tests::ConstantExpressionEnum const_exprs_1 = ::android::aidl::tests::ConstantExpressionEnum(0);
diff --git a/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/StructuredParcelable.java b/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/StructuredParcelable.java
index 797d05c6..e0c8e43b 100644
--- a/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/StructuredParcelable.java
+++ b/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/StructuredParcelable.java
@@ -44,7 +44,7 @@ public class StructuredParcelable implements android.os.Parcelable
// Constant expressions that evaluate to 1
public byte[] int8_1 = {1, 1, 1, 1, 1};
public int[] int32_1 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
- public long[] int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
+ public long[] int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
public int hexInt32_pos_1 = 1;
public int hexInt64_pos_1 = 1;
public int const_exprs_1;
diff --git a/tests/golden_output/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h b/tests/golden_output/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h
index e83fd64d..23f8f0eb 100644
--- a/tests/golden_output/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h
+++ b/tests/golden_output/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h
@@ -103,7 +103,7 @@ public:
::aidl::android::aidl::tests::StructuredParcelable::Empty empty;
std::vector<uint8_t> int8_1 = {1, 1, 1, 1, 1};
std::vector<int32_t> int32_1 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
- std::vector<int64_t> int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
+ std::vector<int64_t> int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
int32_t hexInt32_pos_1 = 1;
int32_t hexInt64_pos_1 = 1;
::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_1 = ::aidl::android::aidl::tests::ConstantExpressionEnum(0);
diff --git a/tests/golden_output/aidl-test-interface-rust-source/gen/android/aidl/tests/StructuredParcelable.rs b/tests/golden_output/aidl-test-interface-rust-source/gen/android/aidl/tests/StructuredParcelable.rs
index 079431d7..bd076e0a 100644
--- a/tests/golden_output/aidl-test-interface-rust-source/gen/android/aidl/tests/StructuredParcelable.rs
+++ b/tests/golden_output/aidl-test-interface-rust-source/gen/android/aidl/tests/StructuredParcelable.rs
@@ -104,7 +104,7 @@ impl Default for r#StructuredParcelable {
r#empty: Default::default(),
r#int8_1: vec![1, 1, 1, 1, 1],
r#int32_1: vec![1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
- r#int64_1: vec![1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+ r#int64_1: vec![1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
r#hexInt32_pos_1: 1,
r#hexInt64_pos_1: 1,
r#const_exprs_1: Default::default(),
diff --git a/tests/golden_output/frozen/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h b/tests/golden_output/frozen/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h
index 1f55c8fb..d89f4e1a 100644
--- a/tests/golden_output/frozen/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h
+++ b/tests/golden_output/frozen/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/StructuredParcelable.h
@@ -96,7 +96,7 @@ public:
::android::aidl::tests::StructuredParcelable::Empty empty;
::std::vector<uint8_t> int8_1 = {1, 1, 1, 1, 1};
::std::vector<int32_t> int32_1 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
- ::std::vector<int64_t> int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
+ ::std::vector<int64_t> int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
int32_t hexInt32_pos_1 = 1;
int32_t hexInt64_pos_1 = 1;
::android::aidl::tests::ConstantExpressionEnum const_exprs_1 = ::android::aidl::tests::ConstantExpressionEnum(0);
diff --git a/tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/StructuredParcelable.java b/tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/StructuredParcelable.java
index 797d05c6..e0c8e43b 100644
--- a/tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/StructuredParcelable.java
+++ b/tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/StructuredParcelable.java
@@ -44,7 +44,7 @@ public class StructuredParcelable implements android.os.Parcelable
// Constant expressions that evaluate to 1
public byte[] int8_1 = {1, 1, 1, 1, 1};
public int[] int32_1 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
- public long[] int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
+ public long[] int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
public int hexInt32_pos_1 = 1;
public int hexInt64_pos_1 = 1;
public int const_exprs_1;
diff --git a/tests/golden_output/frozen/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h b/tests/golden_output/frozen/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h
index e83fd64d..23f8f0eb 100644
--- a/tests/golden_output/frozen/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h
+++ b/tests/golden_output/frozen/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/StructuredParcelable.h
@@ -103,7 +103,7 @@ public:
::aidl::android::aidl::tests::StructuredParcelable::Empty empty;
std::vector<uint8_t> int8_1 = {1, 1, 1, 1, 1};
std::vector<int32_t> int32_1 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
- std::vector<int64_t> int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
+ std::vector<int64_t> int64_1 = {1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L};
int32_t hexInt32_pos_1 = 1;
int32_t hexInt64_pos_1 = 1;
::aidl::android::aidl::tests::ConstantExpressionEnum const_exprs_1 = ::aidl::android::aidl::tests::ConstantExpressionEnum(0);
diff --git a/tests/golden_output/frozen/aidl-test-interface-rust-source/gen/android/aidl/tests/StructuredParcelable.rs b/tests/golden_output/frozen/aidl-test-interface-rust-source/gen/android/aidl/tests/StructuredParcelable.rs
index 079431d7..bd076e0a 100644
--- a/tests/golden_output/frozen/aidl-test-interface-rust-source/gen/android/aidl/tests/StructuredParcelable.rs
+++ b/tests/golden_output/frozen/aidl-test-interface-rust-source/gen/android/aidl/tests/StructuredParcelable.rs
@@ -104,7 +104,7 @@ impl Default for r#StructuredParcelable {
r#empty: Default::default(),
r#int8_1: vec![1, 1, 1, 1, 1],
r#int32_1: vec![1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
- r#int64_1: vec![1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+ r#int64_1: vec![1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
r#hexInt32_pos_1: 1,
r#hexInt64_pos_1: 1,
r#const_exprs_1: Default::default(),
diff --git a/tests/java/src/android/aidl/tests/TestServiceClient.java b/tests/java/src/android/aidl/tests/TestServiceClient.java
index 37181952..0ae8d84b 100644
--- a/tests/java/src/android/aidl/tests/TestServiceClient.java
+++ b/tests/java/src/android/aidl/tests/TestServiceClient.java
@@ -818,7 +818,7 @@ public class TestServiceClient {
+ "int32_1: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, "
+ "1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, "
+ "1, 1, 1, 1], "
- + "int64_1: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "
+ + "int64_1: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "
+ "hexInt32_pos_1: 1, "
+ "hexInt64_pos_1: 1, "
+ "const_exprs_1: 1, "