[fidl] Fix constant generation
- Fixes constant generation in go bindings.
- Fixes constant from enum whose members are reserved keywords in HLCPP
and LLCPP.
Fixed: 55762
Fixed: 55764
Change-Id: Ief8b550f4ad4abe769276ac79a32ac24d74b47d0
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/405478
Commit-Queue: Pascal Perez <pascallouis@google.com>
Reviewed-by: Mitchell Kember <mkember@google.com>
Reviewed-by: Tamir Duberstein <tamird@google.com>
Reviewed-by: André Pang <apang@google.com>
Testability-Review: Mitchell Kember <mkember@google.com>
Testability-Review: André Pang <apang@google.com>
diff --git a/garnet/go/src/fidl/compiler/backend/cpp/ir.go b/garnet/go/src/fidl/compiler/backend/cpp/ir.go
index 993b172..8df02d9 100644
--- a/garnet/go/src/fidl/compiler/backend/cpp/ir.go
+++ b/garnet/go/src/fidl/compiler/backend/cpp/ir.go
@@ -579,8 +579,8 @@
strs = append(strs, c.namespaceFormatter(val.Library, appendNamespace))
}
strs = append(strs, changeIfReserved(val.Name, ext))
- if string(val.Member) != "" {
- strs = append(strs, string(val.Member))
+ if len(val.Member) != 0 {
+ strs = append(strs, changeIfReserved(val.Member, ext))
}
return strings.Join(strs, "::")
}
diff --git a/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json b/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json
index 565ac87..4410487 100644
--- a/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json
+++ b/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json
@@ -238,7 +238,7 @@
"name": "test.name/enumVal",
"location": {
"filename": "consts.test.fidl",
- "line": 17,
+ "line": 18,
"column": 16,
"length": 7
},
@@ -258,7 +258,7 @@
"name": "test.name/enumPrimitiveVal",
"location": {
"filename": "consts.test.fidl",
- "line": 18,
+ "line": 19,
"column": 13,
"length": 16
},
@@ -274,10 +274,49 @@
}
},
{
+ "name": "test.name/enumTrue",
+ "location": {
+ "filename": "consts.test.fidl",
+ "line": 20,
+ "column": 16,
+ "length": 8
+ },
+ "type": {
+ "kind": "identifier",
+ "identifier": "test.name/EnumType",
+ "nullable": false
+ },
+ "value": {
+ "kind": "identifier",
+ "value": "2",
+ "expression": "EnumType.true",
+ "identifier": "test.name/EnumType.true"
+ }
+ },
+ {
+ "name": "test.name/enumPrimitiveTrue",
+ "location": {
+ "filename": "consts.test.fidl",
+ "line": 21,
+ "column": 13,
+ "length": 17
+ },
+ "type": {
+ "kind": "primitive",
+ "subtype": "int32"
+ },
+ "value": {
+ "kind": "identifier",
+ "value": "2",
+ "expression": "EnumType.true",
+ "identifier": "test.name/EnumType.true"
+ }
+ },
+ {
"name": "test.name/bitsVal",
"location": {
"filename": "consts.test.fidl",
- "line": 24,
+ "line": 27,
"column": 16,
"length": 7
},
@@ -297,7 +336,7 @@
"name": "test.name/bitsPrimitiveVal",
"location": {
"filename": "consts.test.fidl",
- "line": 25,
+ "line": 28,
"column": 13,
"length": 16
},
@@ -311,6 +350,45 @@
"expression": "BitsType.VALUE",
"identifier": "test.name/BitsType.VALUE"
}
+ },
+ {
+ "name": "test.name/bitsTrue",
+ "location": {
+ "filename": "consts.test.fidl",
+ "line": 29,
+ "column": 16,
+ "length": 8
+ },
+ "type": {
+ "kind": "identifier",
+ "identifier": "test.name/BitsType",
+ "nullable": false
+ },
+ "value": {
+ "kind": "identifier",
+ "value": "2",
+ "expression": "BitsType.true",
+ "identifier": "test.name/BitsType.true"
+ }
+ },
+ {
+ "name": "test.name/bitsPrimitiveTrue",
+ "location": {
+ "filename": "consts.test.fidl",
+ "line": 30,
+ "column": 13,
+ "length": 17
+ },
+ "type": {
+ "kind": "primitive",
+ "subtype": "int32"
+ },
+ "value": {
+ "kind": "identifier",
+ "value": "2",
+ "expression": "BitsType.true",
+ "identifier": "test.name/BitsType.true"
+ }
}
],
"enum_declarations": [
@@ -342,6 +420,25 @@
"expression": "1"
}
}
+ },
+ {
+ "name": "true",
+ "location": {
+ "filename": "consts.test.fidl",
+ "line": 16,
+ "column": 5,
+ "length": 4
+ },
+ "value": {
+ "kind": "literal",
+ "value": "2",
+ "expression": "2",
+ "literal": {
+ "kind": "numeric",
+ "value": "2",
+ "expression": "2"
+ }
+ }
}
],
"strict": true
@@ -350,7 +447,7 @@
"name": "test.name/BitsType",
"location": {
"filename": "consts.test.fidl",
- "line": 21,
+ "line": 23,
"column": 6,
"length": 8
},
@@ -360,7 +457,7 @@
"name": "VALUE",
"location": {
"filename": "consts.test.fidl",
- "line": 22,
+ "line": 24,
"column": 5,
"length": 5
},
@@ -374,6 +471,25 @@
"expression": "0x00000001"
}
}
+ },
+ {
+ "name": "true",
+ "location": {
+ "filename": "consts.test.fidl",
+ "line": 25,
+ "column": 5,
+ "length": 4
+ },
+ "value": {
+ "kind": "literal",
+ "value": "2",
+ "expression": "2",
+ "literal": {
+ "kind": "numeric",
+ "value": "2",
+ "expression": "2"
+ }
+ }
}
],
"strict": true
@@ -394,13 +510,17 @@
"test.name/FUCHSIA",
"test.name/EnumType",
"test.name/enumVal",
+ "test.name/enumTrue",
"test.name/enumPrimitiveVal",
+ "test.name/enumPrimitiveTrue",
"test.name/ENABLED_FLAG",
"test.name/DIAMOND",
"test.name/CONVERSION_FACTOR",
"test.name/BitsType",
"test.name/bitsVal",
+ "test.name/bitsTrue",
"test.name/bitsPrimitiveVal",
+ "test.name/bitsPrimitiveTrue",
"test.name/ANSWER_IN_BINARY",
"test.name/ANSWER"
],
@@ -417,8 +537,12 @@
"test.name/CONVERSION_FACTOR": "const",
"test.name/enumVal": "const",
"test.name/enumPrimitiveVal": "const",
+ "test.name/enumTrue": "const",
+ "test.name/enumPrimitiveTrue": "const",
"test.name/bitsVal": "const",
"test.name/bitsPrimitiveVal": "const",
+ "test.name/bitsTrue": "const",
+ "test.name/bitsPrimitiveTrue": "const",
"test.name/EnumType": "enum",
"test.name/BitsType": "enum"
}
diff --git a/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.go.golden b/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.go.golden
index c840ba3..675ea4d 100644
--- a/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.go.golden
+++ b/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.go.golden
@@ -13,27 +13,35 @@
Username string = "\"squeenze\""
MinTemp float32 = -273.15
ConversionFactor float64 = 1.41421
- EnumVal EnumType = EnumType.VALUE
- EnumPrimitiveVal int32 = EnumType.VALUE
- BitsVal BitsType = BitsType.VALUE
- BitsPrimitiveVal int32 = BitsType.VALUE
+ EnumVal EnumType = EnumTypeValue
+ EnumPrimitiveVal int32 = EnumTypeValue
+ EnumTrue EnumType = EnumTypeTrue
+ EnumPrimitiveTrue int32 = EnumTypeTrue
+ BitsVal BitsType = BitsTypeValue
+ BitsPrimitiveVal int32 = BitsTypeValue
+ BitsTrue BitsType = BitsTypeTrue
+ BitsPrimitiveTrue int32 = BitsTypeTrue
)
type EnumType int32
const (
EnumTypeValue EnumType = 1
+ EnumTypeTrue EnumType = 2
)
func (_ EnumType) I_EnumValues() []EnumType {
return []EnumType{
EnumTypeValue,
+ EnumTypeTrue,
}
}
func (x EnumType) String() string {
switch x {
case 1:
return "Value"
+ case 2:
+ return "True"
}
return "Unknown"
}
@@ -42,17 +50,21 @@
const (
BitsTypeValue BitsType = 1
+ BitsTypeTrue BitsType = 2
)
func (_ BitsType) I_EnumValues() []BitsType {
return []BitsType{
BitsTypeValue,
+ BitsTypeTrue,
}
}
func (x BitsType) String() string {
switch x {
case 1:
return "Value"
+ case 2:
+ return "True"
}
return "Unknown"
}
diff --git a/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.h.golden b/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.h.golden
index 49ccbc7..c861c94 100644
--- a/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.h.golden
+++ b/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.h.golden
@@ -10,6 +10,8 @@
enum class EnumType : int32_t {
VALUE = 1u,
+
+ true_ = 2u,
};
inline zx_status_t Clone(::test::name::EnumType value,
@@ -21,6 +23,8 @@
enum class BitsType : int32_t {
VALUE = 1u,
+
+ true_ = 2u,
};
inline zx_status_t Clone(::test::name::BitsType value,
@@ -41,8 +45,12 @@
constexpr EnumType enumVal = EnumType::VALUE;
+constexpr EnumType enumTrue = EnumType::true_;
+
constexpr int32_t enumPrimitiveVal = EnumType::VALUE;
+constexpr int32_t enumPrimitiveTrue = EnumType::true_;
+
constexpr bool ENABLED_FLAG = true;
constexpr uint64_t DIAMOND = 1746410393481133080u;
@@ -51,8 +59,12 @@
constexpr BitsType bitsVal = BitsType::VALUE;
+constexpr BitsType bitsTrue = BitsType::true_;
+
constexpr int32_t bitsPrimitiveVal = BitsType::VALUE;
+constexpr int32_t bitsPrimitiveTrue = BitsType::true_;
+
constexpr uint16_t ANSWER_IN_BINARY = 42u;
constexpr uint16_t ANSWER = 42u;
diff --git a/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.llcpp.h.golden b/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.llcpp.h.golden
index 8505d60..f9242cd 100644
--- a/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.llcpp.h.golden
+++ b/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.llcpp.h.golden
@@ -34,10 +34,12 @@
enum class EnumType : int32_t {
VALUE = 1u,
+ true_ = 2u,
};
enum class BitsType : int32_t {
VALUE = 1u,
+ true_ = 2u,
};
extern const char USERNAME[];
@@ -52,8 +54,12 @@
constexpr ::llcpp::test::name::EnumType enumVal = EnumType::VALUE;
+constexpr ::llcpp::test::name::EnumType enumTrue = EnumType::true_;
+
constexpr int32_t enumPrimitiveVal = EnumType::VALUE;
+constexpr int32_t enumPrimitiveTrue = EnumType::true_;
+
constexpr bool ENABLED_FLAG = true;
constexpr uint64_t DIAMOND = 1746410393481133080u;
@@ -62,8 +68,12 @@
constexpr ::llcpp::test::name::BitsType bitsVal = BitsType::VALUE;
+constexpr ::llcpp::test::name::BitsType bitsTrue = BitsType::true_;
+
constexpr int32_t bitsPrimitiveVal = BitsType::VALUE;
+constexpr int32_t bitsPrimitiveTrue = BitsType::true_;
+
constexpr uint16_t ANSWER_IN_BINARY = 42u;
constexpr uint16_t ANSWER = 42u;
diff --git a/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.rs.golden b/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.rs.golden
index 1436d69..ee366f11 100644
--- a/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.rs.golden
+++ b/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.rs.golden
@@ -39,18 +39,28 @@
pub const ENUM_PRIMITIVE_VAL: i32 = EnumType::Value;
+pub const ENUM_TRUE: EnumType = EnumType::True_;
+
+pub const ENUM_PRIMITIVE_TRUE: i32 = EnumType::True_;
+
pub const BITS_VAL: BitsType = BitsType::Value;
pub const BITS_PRIMITIVE_VAL: i32 = BitsType::Value;
+pub const BITS_TRUE: BitsType = BitsType::True_;
+
+pub const BITS_PRIMITIVE_TRUE: i32 = BitsType::True_;
+
fidl_enum! {
EnumType(i32) {
Value = 1,
+ True_ = 2,
}
}
fidl_enum! {
BitsType(i32) {
Value = 1,
+ True_ = 2,
}
}
diff --git a/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.syz.txt.golden b/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.syz.txt.golden
index 4ad8773..6d1bf0c 100644
--- a/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.syz.txt.golden
+++ b/garnet/go/src/fidl/compiler/backend/goldens/consts.test.json.syz.txt.golden
@@ -4,6 +4,6 @@
# WARNING: This file is machine generated by fidlgen.
include <test/name/c/fidl.h>
-test_name_EnumType = test_name_EnumType_VALUE
-test_name_BitsType = test_name_BitsType_VALUE
+test_name_EnumType = test_name_EnumType_VALUE, test_name_EnumType_true
+test_name_BitsType = test_name_BitsType_VALUE, test_name_BitsType_true
diff --git a/tools/fidl/fidldoc/src/templates/markdown/testdata/consts.test.json.golden.md b/tools/fidl/fidldoc/src/templates/markdown/testdata/consts.test.json.golden.md
index ce12de5..efbeea0 100644
--- a/tools/fidl/fidldoc/src/templates/markdown/testdata/consts.test.json.golden.md
+++ b/tools/fidl/fidldoc/src/templates/markdown/testdata/consts.test.json.golden.md
@@ -21,12 +21,16 @@
<td><code>VALUE</code></td>
<td><code>1</code></td>
<td></td>
+ </tr><tr>
+ <td><code>true</code></td>
+ <td><code>2</code></td>
+ <td></td>
</tr></table>
### BitsType {#BitsType}
Type: <code>int32</code>
-*Defined in [test.name/consts.test.fidl](https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#21)*
+*Defined in [test.name/consts.test.fidl](https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#23)*
@@ -35,6 +39,10 @@
<td><code>VALUE</code></td>
<td><code>1</code></td>
<td></td>
+ </tr><tr>
+ <td><code>true</code></td>
+ <td><code>2</code></td>
+ <td></td>
</tr></table>
@@ -127,31 +135,57 @@
<td></td>
</tr>
<tr id="enumVal">
- <td><a href="https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#17">enumVal</a></td>
+ <td><a href="https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#18">enumVal</a></td>
<td></td>
</tr>
<tr id="enumPrimitiveVal">
- <td><a href="https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#18">enumPrimitiveVal</a></td>
+ <td><a href="https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#19">enumPrimitiveVal</a></td>
<td>
<code><a class='link' href='#EnumType.VALUE'>EnumType.VALUE</a></code>
</td>
<td><code>int32</code></td>
<td></td>
</tr>
+ <tr id="enumTrue">
+ <td><a href="https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#20">enumTrue</a></td>
+
+ <td></td>
+ </tr>
+ <tr id="enumPrimitiveTrue">
+ <td><a href="https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#21">enumPrimitiveTrue</a></td>
+ <td>
+ <code><a class='link' href='#EnumType.true'>EnumType.true</a></code>
+ </td>
+ <td><code>int32</code></td>
+ <td></td>
+ </tr>
<tr id="bitsVal">
- <td><a href="https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#24">bitsVal</a></td>
+ <td><a href="https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#27">bitsVal</a></td>
<td></td>
</tr>
<tr id="bitsPrimitiveVal">
- <td><a href="https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#25">bitsPrimitiveVal</a></td>
+ <td><a href="https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#28">bitsPrimitiveVal</a></td>
<td>
<code><a class='link' href='#BitsType.VALUE'>BitsType.VALUE</a></code>
</td>
<td><code>int32</code></td>
<td></td>
</tr>
+ <tr id="bitsTrue">
+ <td><a href="https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#29">bitsTrue</a></td>
+
+ <td></td>
+ </tr>
+ <tr id="bitsPrimitiveTrue">
+ <td><a href="https://fuchsia.googlesource.com/fuchsia/+/master/consts.test.fidl#30">bitsPrimitiveTrue</a></td>
+ <td>
+ <code><a class='link' href='#BitsType.true'>BitsType.true</a></code>
+ </td>
+ <td><code>int32</code></td>
+ <td></td>
+ </tr>
</table>
diff --git a/tools/fidl/fidlgen_go/ir/ir.go b/tools/fidl/fidlgen_go/ir/ir.go
index ed44968..316b6d4 100644
--- a/tools/fidl/fidlgen_go/ir/ir.go
+++ b/tools/fidl/fidlgen_go/ir/ir.go
@@ -606,7 +606,7 @@
}
strs = append(strs, changeIfReserved(types.Identifier(name), ext))
if ci.Member != "" {
- strs = append(strs, string(ci.Member))
+ strs[len(strs)-1] += c.compileIdentifier(ci.Member, true, "")
}
return strings.Join(strs, ".")
}
diff --git a/zircon/tools/fidl/goldens/consts.test.json.golden b/zircon/tools/fidl/goldens/consts.test.json.golden
index 565ac87..4410487 100644
--- a/zircon/tools/fidl/goldens/consts.test.json.golden
+++ b/zircon/tools/fidl/goldens/consts.test.json.golden
@@ -238,7 +238,7 @@
"name": "test.name/enumVal",
"location": {
"filename": "consts.test.fidl",
- "line": 17,
+ "line": 18,
"column": 16,
"length": 7
},
@@ -258,7 +258,7 @@
"name": "test.name/enumPrimitiveVal",
"location": {
"filename": "consts.test.fidl",
- "line": 18,
+ "line": 19,
"column": 13,
"length": 16
},
@@ -274,10 +274,49 @@
}
},
{
+ "name": "test.name/enumTrue",
+ "location": {
+ "filename": "consts.test.fidl",
+ "line": 20,
+ "column": 16,
+ "length": 8
+ },
+ "type": {
+ "kind": "identifier",
+ "identifier": "test.name/EnumType",
+ "nullable": false
+ },
+ "value": {
+ "kind": "identifier",
+ "value": "2",
+ "expression": "EnumType.true",
+ "identifier": "test.name/EnumType.true"
+ }
+ },
+ {
+ "name": "test.name/enumPrimitiveTrue",
+ "location": {
+ "filename": "consts.test.fidl",
+ "line": 21,
+ "column": 13,
+ "length": 17
+ },
+ "type": {
+ "kind": "primitive",
+ "subtype": "int32"
+ },
+ "value": {
+ "kind": "identifier",
+ "value": "2",
+ "expression": "EnumType.true",
+ "identifier": "test.name/EnumType.true"
+ }
+ },
+ {
"name": "test.name/bitsVal",
"location": {
"filename": "consts.test.fidl",
- "line": 24,
+ "line": 27,
"column": 16,
"length": 7
},
@@ -297,7 +336,7 @@
"name": "test.name/bitsPrimitiveVal",
"location": {
"filename": "consts.test.fidl",
- "line": 25,
+ "line": 28,
"column": 13,
"length": 16
},
@@ -311,6 +350,45 @@
"expression": "BitsType.VALUE",
"identifier": "test.name/BitsType.VALUE"
}
+ },
+ {
+ "name": "test.name/bitsTrue",
+ "location": {
+ "filename": "consts.test.fidl",
+ "line": 29,
+ "column": 16,
+ "length": 8
+ },
+ "type": {
+ "kind": "identifier",
+ "identifier": "test.name/BitsType",
+ "nullable": false
+ },
+ "value": {
+ "kind": "identifier",
+ "value": "2",
+ "expression": "BitsType.true",
+ "identifier": "test.name/BitsType.true"
+ }
+ },
+ {
+ "name": "test.name/bitsPrimitiveTrue",
+ "location": {
+ "filename": "consts.test.fidl",
+ "line": 30,
+ "column": 13,
+ "length": 17
+ },
+ "type": {
+ "kind": "primitive",
+ "subtype": "int32"
+ },
+ "value": {
+ "kind": "identifier",
+ "value": "2",
+ "expression": "BitsType.true",
+ "identifier": "test.name/BitsType.true"
+ }
}
],
"enum_declarations": [
@@ -342,6 +420,25 @@
"expression": "1"
}
}
+ },
+ {
+ "name": "true",
+ "location": {
+ "filename": "consts.test.fidl",
+ "line": 16,
+ "column": 5,
+ "length": 4
+ },
+ "value": {
+ "kind": "literal",
+ "value": "2",
+ "expression": "2",
+ "literal": {
+ "kind": "numeric",
+ "value": "2",
+ "expression": "2"
+ }
+ }
}
],
"strict": true
@@ -350,7 +447,7 @@
"name": "test.name/BitsType",
"location": {
"filename": "consts.test.fidl",
- "line": 21,
+ "line": 23,
"column": 6,
"length": 8
},
@@ -360,7 +457,7 @@
"name": "VALUE",
"location": {
"filename": "consts.test.fidl",
- "line": 22,
+ "line": 24,
"column": 5,
"length": 5
},
@@ -374,6 +471,25 @@
"expression": "0x00000001"
}
}
+ },
+ {
+ "name": "true",
+ "location": {
+ "filename": "consts.test.fidl",
+ "line": 25,
+ "column": 5,
+ "length": 4
+ },
+ "value": {
+ "kind": "literal",
+ "value": "2",
+ "expression": "2",
+ "literal": {
+ "kind": "numeric",
+ "value": "2",
+ "expression": "2"
+ }
+ }
}
],
"strict": true
@@ -394,13 +510,17 @@
"test.name/FUCHSIA",
"test.name/EnumType",
"test.name/enumVal",
+ "test.name/enumTrue",
"test.name/enumPrimitiveVal",
+ "test.name/enumPrimitiveTrue",
"test.name/ENABLED_FLAG",
"test.name/DIAMOND",
"test.name/CONVERSION_FACTOR",
"test.name/BitsType",
"test.name/bitsVal",
+ "test.name/bitsTrue",
"test.name/bitsPrimitiveVal",
+ "test.name/bitsPrimitiveTrue",
"test.name/ANSWER_IN_BINARY",
"test.name/ANSWER"
],
@@ -417,8 +537,12 @@
"test.name/CONVERSION_FACTOR": "const",
"test.name/enumVal": "const",
"test.name/enumPrimitiveVal": "const",
+ "test.name/enumTrue": "const",
+ "test.name/enumPrimitiveTrue": "const",
"test.name/bitsVal": "const",
"test.name/bitsPrimitiveVal": "const",
+ "test.name/bitsTrue": "const",
+ "test.name/bitsPrimitiveTrue": "const",
"test.name/EnumType": "enum",
"test.name/BitsType": "enum"
}
diff --git a/zircon/tools/fidl/goldens/consts.test.tables.c.golden b/zircon/tools/fidl/goldens/consts.test.tables.c.golden
index 9d84ff5..ed5478a 100644
--- a/zircon/tools/fidl/goldens/consts.test.tables.c.golden
+++ b/zircon/tools/fidl/goldens/consts.test.tables.c.golden
@@ -8,9 +8,9 @@
-static bool EnumValidatorFor_test_name_EnumType(uint64_t v) { return (v == 1ul) || false; }
+static bool EnumValidatorFor_test_name_EnumType(uint64_t v) { return (v == 1ul) || (v == 2ul) || false; }
const struct FidlCodedEnum test_name_EnumTypeTable = {.tag=kFidlTypeEnum, .underlying_type=kFidlCodedPrimitiveSubtype_Int32, .validate=&EnumValidatorFor_test_name_EnumType, .name="test.name/EnumType"};
-static bool EnumValidatorFor_test_name_BitsType(uint64_t v) { return (v == 1ul) || false; }
+static bool EnumValidatorFor_test_name_BitsType(uint64_t v) { return (v == 1ul) || (v == 2ul) || false; }
const struct FidlCodedEnum test_name_BitsTypeTable = {.tag=kFidlTypeEnum, .underlying_type=kFidlCodedPrimitiveSubtype_Int32, .validate=&EnumValidatorFor_test_name_BitsType, .name="test.name/BitsType"};
diff --git a/zircon/tools/fidl/testdata/consts.test.fidl b/zircon/tools/fidl/testdata/consts.test.fidl
index b3530b9..0ea1b6ec 100644
--- a/zircon/tools/fidl/testdata/consts.test.fidl
+++ b/zircon/tools/fidl/testdata/consts.test.fidl
@@ -13,13 +13,18 @@
enum EnumType : int32 {
VALUE = 1;
+ true = 2;
};
const EnumType enumVal = EnumType.VALUE;
const int32 enumPrimitiveVal = EnumType.VALUE;
-
+const EnumType enumTrue = EnumType.true;
+const int32 enumPrimitiveTrue = EnumType.true;
enum BitsType : int32 {
VALUE = 0x00000001;
+ true = 2;
};
const BitsType bitsVal = BitsType.VALUE;
const int32 bitsPrimitiveVal = BitsType.VALUE;
+const BitsType bitsTrue = BitsType.true;
+const int32 bitsPrimitiveTrue = BitsType.true;