[C#] Use @ for keyword escaping (#6834)

This commit is contained in:
Derek Bailey
2021-09-09 10:29:27 -07:00
committed by GitHub
parent 1d063d87cf
commit 8fb8c2ce1d
19 changed files with 111 additions and 164 deletions

View File

@@ -0,0 +1,97 @@
// automatically generated by the FlatBuffers compiler, do not modify
extern crate flatbuffers;
use std::mem;
use std::cmp::Ordering;
use self::flatbuffers::{EndianScalar, Follow};
use super::*;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MIN_ABC: i32 = 0;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MAX_ABC: i32 = 2;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[allow(non_camel_case_types)]
pub const ENUM_VALUES_ABC: [ABC; 3] = [
ABC::void,
ABC::where_,
ABC::stackalloc,
];
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct ABC(pub i32);
#[allow(non_upper_case_globals)]
impl ABC {
pub const void: Self = Self(0);
pub const where_: Self = Self(1);
pub const stackalloc: Self = Self(2);
pub const ENUM_MIN: i32 = 0;
pub const ENUM_MAX: i32 = 2;
pub const ENUM_VALUES: &'static [Self] = &[
Self::void,
Self::where_,
Self::stackalloc,
];
/// Returns the variant's name or "" if unknown.
pub fn variant_name(self) -> Option<&'static str> {
match self {
Self::void => Some("void"),
Self::where_ => Some("where_"),
Self::stackalloc => Some("stackalloc"),
_ => None,
}
}
}
impl std::fmt::Debug for ABC {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if let Some(name) = self.variant_name() {
f.write_str(name)
} else {
f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
}
}
}
impl<'a> flatbuffers::Follow<'a> for ABC {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i32>(buf, loc)
};
Self(b)
}
}
impl flatbuffers::Push for ABC {
type Output = ABC;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i32>(dst, self.0); }
}
}
impl flatbuffers::EndianScalar for ABC {
#[inline]
fn to_little_endian(self) -> Self {
let b = i32::to_le(self.0);
Self(b)
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i32::from_le(self.0);
Self(b)
}
}
impl<'a> flatbuffers::Verifiable for ABC {
#[inline]
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
i32::run_verifier(v, pos)
}
}
impl flatbuffers::SimpleToVerifyInSlice for ABC {}

View File

@@ -0,0 +1,172 @@
// automatically generated by the FlatBuffers compiler, do not modify
extern crate flatbuffers;
use std::mem;
use std::cmp::Ordering;
use self::flatbuffers::{EndianScalar, Follow};
use super::*;
pub enum KeywordsInTableOffset {}
#[derive(Copy, Clone, PartialEq)]
pub struct KeywordsInTable<'a> {
pub _tab: flatbuffers::Table<'a>,
}
impl<'a> flatbuffers::Follow<'a> for KeywordsInTable<'a> {
type Inner = KeywordsInTable<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
}
}
impl<'a> KeywordsInTable<'a> {
pub const VT_IS: flatbuffers::VOffsetT = 4;
pub const VT_PRIVATE: flatbuffers::VOffsetT = 6;
pub const VT_TYPE_: flatbuffers::VOffsetT = 8;
pub const fn get_fully_qualified_name() -> &'static str {
"KeywordTest.KeywordsInTable"
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
KeywordsInTable { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args KeywordsInTableArgs
) -> flatbuffers::WIPOffset<KeywordsInTable<'bldr>> {
let mut builder = KeywordsInTableBuilder::new(_fbb);
builder.add_type_(args.type_);
builder.add_private(args.private);
builder.add_is(args.is);
builder.finish()
}
pub fn unpack(&self) -> KeywordsInTableT {
let is = self.is();
let private = self.private();
let type_ = self.type_();
KeywordsInTableT {
is,
private,
type_,
}
}
#[inline]
pub fn is(&self) -> ABC {
self._tab.get::<ABC>(KeywordsInTable::VT_IS, Some(ABC::void)).unwrap()
}
#[inline]
pub fn private(&self) -> public {
self._tab.get::<public>(KeywordsInTable::VT_PRIVATE, Some(public::NONE)).unwrap()
}
#[inline]
pub fn type_(&self) -> i32 {
self._tab.get::<i32>(KeywordsInTable::VT_TYPE_, Some(0)).unwrap()
}
}
impl flatbuffers::Verifiable for KeywordsInTable<'_> {
#[inline]
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
v.visit_table(pos)?
.visit_field::<ABC>("is", Self::VT_IS, false)?
.visit_field::<public>("private", Self::VT_PRIVATE, false)?
.visit_field::<i32>("type_", Self::VT_TYPE_, false)?
.finish();
Ok(())
}
}
pub struct KeywordsInTableArgs {
pub is: ABC,
pub private: public,
pub type_: i32,
}
impl<'a> Default for KeywordsInTableArgs {
#[inline]
fn default() -> Self {
KeywordsInTableArgs {
is: ABC::void,
private: public::NONE,
type_: 0,
}
}
}
pub struct KeywordsInTableBuilder<'a: 'b, 'b> {
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
}
impl<'a: 'b, 'b> KeywordsInTableBuilder<'a, 'b> {
#[inline]
pub fn add_is(&mut self, is: ABC) {
self.fbb_.push_slot::<ABC>(KeywordsInTable::VT_IS, is, ABC::void);
}
#[inline]
pub fn add_private(&mut self, private: public) {
self.fbb_.push_slot::<public>(KeywordsInTable::VT_PRIVATE, private, public::NONE);
}
#[inline]
pub fn add_type_(&mut self, type_: i32) {
self.fbb_.push_slot::<i32>(KeywordsInTable::VT_TYPE_, type_, 0);
}
#[inline]
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> KeywordsInTableBuilder<'a, 'b> {
let start = _fbb.start_table();
KeywordsInTableBuilder {
fbb_: _fbb,
start_: start,
}
}
#[inline]
pub fn finish(self) -> flatbuffers::WIPOffset<KeywordsInTable<'a>> {
let o = self.fbb_.end_table(self.start_);
flatbuffers::WIPOffset::new(o.value())
}
}
impl std::fmt::Debug for KeywordsInTable<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut ds = f.debug_struct("KeywordsInTable");
ds.field("is", &self.is());
ds.field("private", &self.private());
ds.field("type_", &self.type_());
ds.finish()
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub struct KeywordsInTableT {
pub is: ABC,
pub private: public,
pub type_: i32,
}
impl Default for KeywordsInTableT {
fn default() -> Self {
Self {
is: ABC::void,
private: public::NONE,
type_: 0,
}
}
}
impl KeywordsInTableT {
pub fn pack<'b>(
&self,
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
) -> flatbuffers::WIPOffset<KeywordsInTable<'b>> {
let is = self.is;
let private = self.private;
let type_ = self.type_;
KeywordsInTable::create(_fbb, &KeywordsInTableArgs{
is,
private,
type_,
})
}
}

View File

@@ -0,0 +1,170 @@
// automatically generated by the FlatBuffers compiler, do not modify
extern crate flatbuffers;
use std::mem;
use std::cmp::Ordering;
use self::flatbuffers::{EndianScalar, Follow};
use super::*;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MIN_KEYWORDS_IN_UNION: u8 = 0;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MAX_KEYWORDS_IN_UNION: u8 = 2;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[allow(non_camel_case_types)]
pub const ENUM_VALUES_KEYWORDS_IN_UNION: [KeywordsInUnion; 3] = [
KeywordsInUnion::NONE,
KeywordsInUnion::static_,
KeywordsInUnion::internal,
];
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct KeywordsInUnion(pub u8);
#[allow(non_upper_case_globals)]
impl KeywordsInUnion {
pub const NONE: Self = Self(0);
pub const static_: Self = Self(1);
pub const internal: Self = Self(2);
pub const ENUM_MIN: u8 = 0;
pub const ENUM_MAX: u8 = 2;
pub const ENUM_VALUES: &'static [Self] = &[
Self::NONE,
Self::static_,
Self::internal,
];
/// Returns the variant's name or "" if unknown.
pub fn variant_name(self) -> Option<&'static str> {
match self {
Self::NONE => Some("NONE"),
Self::static_ => Some("static_"),
Self::internal => Some("internal"),
_ => None,
}
}
}
impl std::fmt::Debug for KeywordsInUnion {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if let Some(name) = self.variant_name() {
f.write_str(name)
} else {
f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
}
}
}
impl<'a> flatbuffers::Follow<'a> for KeywordsInUnion {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u8>(buf, loc)
};
Self(b)
}
}
impl flatbuffers::Push for KeywordsInUnion {
type Output = KeywordsInUnion;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
}
}
impl flatbuffers::EndianScalar for KeywordsInUnion {
#[inline]
fn to_little_endian(self) -> Self {
let b = u8::to_le(self.0);
Self(b)
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u8::from_le(self.0);
Self(b)
}
}
impl<'a> flatbuffers::Verifiable for KeywordsInUnion {
#[inline]
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
u8::run_verifier(v, pos)
}
}
impl flatbuffers::SimpleToVerifyInSlice for KeywordsInUnion {}
pub struct KeywordsInUnionUnionTableOffset {}
#[allow(clippy::upper_case_acronyms)]
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub enum KeywordsInUnionT {
NONE,
Static_(Box<KeywordsInTableT>),
Internal(Box<KeywordsInTableT>),
}
impl Default for KeywordsInUnionT {
fn default() -> Self {
Self::NONE
}
}
impl KeywordsInUnionT {
pub fn keywords_in_union_type(&self) -> KeywordsInUnion {
match self {
Self::NONE => KeywordsInUnion::NONE,
Self::Static_(_) => KeywordsInUnion::static_,
Self::Internal(_) => KeywordsInUnion::internal,
}
}
pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
match self {
Self::NONE => None,
Self::Static_(v) => Some(v.pack(fbb).as_union_value()),
Self::Internal(v) => Some(v.pack(fbb).as_union_value()),
}
}
/// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE.
pub fn take_static_(&mut self) -> Option<Box<KeywordsInTableT>> {
if let Self::Static_(_) = self {
let v = std::mem::replace(self, Self::NONE);
if let Self::Static_(w) = v {
Some(w)
} else {
unreachable!()
}
} else {
None
}
}
/// If the union variant matches, return a reference to the KeywordsInTableT.
pub fn as_static_(&self) -> Option<&KeywordsInTableT> {
if let Self::Static_(v) = self { Some(v.as_ref()) } else { None }
}
/// If the union variant matches, return a mutable reference to the KeywordsInTableT.
pub fn as_static__mut(&mut self) -> Option<&mut KeywordsInTableT> {
if let Self::Static_(v) = self { Some(v.as_mut()) } else { None }
}
/// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE.
pub fn take_internal(&mut self) -> Option<Box<KeywordsInTableT>> {
if let Self::Internal(_) = self {
let v = std::mem::replace(self, Self::NONE);
if let Self::Internal(w) = v {
Some(w)
} else {
unreachable!()
}
} else {
None
}
}
/// If the union variant matches, return a reference to the KeywordsInTableT.
pub fn as_internal(&self) -> Option<&KeywordsInTableT> {
if let Self::Internal(v) = self { Some(v.as_ref()) } else { None }
}
/// If the union variant matches, return a mutable reference to the KeywordsInTableT.
pub fn as_internal_mut(&mut self) -> Option<&mut KeywordsInTableT> {
if let Self::Internal(v) = self { Some(v.as_mut()) } else { None }
}
}

View File

@@ -0,0 +1,89 @@
// automatically generated by the FlatBuffers compiler, do not modify
extern crate flatbuffers;
use std::mem;
use std::cmp::Ordering;
use self::flatbuffers::{EndianScalar, Follow};
use super::*;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MIN_PUBLIC: i32 = 0;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MAX_PUBLIC: i32 = 0;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[allow(non_camel_case_types)]
pub const ENUM_VALUES_PUBLIC: [public; 1] = [
public::NONE,
];
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct public(pub i32);
#[allow(non_upper_case_globals)]
impl public {
pub const NONE: Self = Self(0);
pub const ENUM_MIN: i32 = 0;
pub const ENUM_MAX: i32 = 0;
pub const ENUM_VALUES: &'static [Self] = &[
Self::NONE,
];
/// Returns the variant's name or "" if unknown.
pub fn variant_name(self) -> Option<&'static str> {
match self {
Self::NONE => Some("NONE"),
_ => None,
}
}
}
impl std::fmt::Debug for public {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if let Some(name) = self.variant_name() {
f.write_str(name)
} else {
f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
}
}
}
impl<'a> flatbuffers::Follow<'a> for public {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i32>(buf, loc)
};
Self(b)
}
}
impl flatbuffers::Push for public {
type Output = public;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i32>(dst, self.0); }
}
}
impl flatbuffers::EndianScalar for public {
#[inline]
fn to_little_endian(self) -> Self {
let b = i32::to_le(self.0);
Self(b)
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i32::from_le(self.0);
Self(b)
}
}
impl<'a> flatbuffers::Verifiable for public {
#[inline]
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
i32::run_verifier(v, pos)
}
}
impl flatbuffers::SimpleToVerifyInSlice for public {}