| // Copyright 2021 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package fidlgen_cpp |
| |
| import ( |
| "go.fuchsia.dev/fuchsia/tools/fidl/lib/fidlgen" |
| ) |
| |
| func isReservedWord(str string) bool { |
| _, ok := reservedWords[str] |
| return ok |
| } |
| |
| func changeIfReserved(i fidlgen.Identifier) string { |
| str := string(i) |
| if isReservedWord(str) { |
| return str + "_" |
| } |
| return str |
| } |
| |
| var reservedWords = map[string]struct{}{ |
| "alignas": {}, |
| "alignof": {}, |
| "and": {}, |
| "and_eq": {}, |
| "asm": {}, |
| "assert": {}, |
| "atomic_cancel": {}, |
| "atomic_commit": {}, |
| "atomic_noexcept": {}, |
| "auto": {}, |
| "bitand": {}, |
| "bitor": {}, |
| "bool": {}, |
| "break": {}, |
| "case": {}, |
| "catch": {}, |
| "char": {}, |
| "char16_t": {}, |
| "char32_t": {}, |
| "class": {}, |
| "compl": {}, |
| "concept": {}, |
| "const": {}, |
| "constexpr": {}, |
| "const_cast": {}, |
| "continue": {}, |
| "co_await": {}, |
| "co_return": {}, |
| "co_yield": {}, |
| "decltype": {}, |
| "default": {}, |
| "delete": {}, |
| "do": {}, |
| "double": {}, |
| "dynamic_cast": {}, |
| "else": {}, |
| "enum": {}, |
| "explicit": {}, |
| "export": {}, |
| "extern": {}, |
| "false": {}, |
| "float": {}, |
| "for": {}, |
| "friend": {}, |
| "goto": {}, |
| "if": {}, |
| "import": {}, |
| "inline": {}, |
| "int": {}, |
| "long": {}, |
| "module": {}, |
| "mutable": {}, |
| "namespace": {}, |
| "new": {}, |
| "noexcept": {}, |
| "not": {}, |
| "not_eq": {}, |
| "NULL": {}, |
| "nullptr": {}, |
| "offsetof": {}, |
| "operator": {}, |
| "or": {}, |
| "or_eq": {}, |
| "private": {}, |
| "protected": {}, |
| "public": {}, |
| "register": {}, |
| "reinterpret_cast": {}, |
| "requires": {}, |
| "return": {}, |
| "short": {}, |
| "signed": {}, |
| "sizeof": {}, |
| "static": {}, |
| "static_assert": {}, |
| "static_cast": {}, |
| "struct": {}, |
| "switch": {}, |
| "synchronized": {}, |
| "template": {}, |
| "this": {}, |
| "thread_local": {}, |
| "throw": {}, |
| "true": {}, |
| "try": {}, |
| "typedef": {}, |
| "typeid": {}, |
| "typename": {}, |
| "union": {}, |
| "unsigned": {}, |
| "using": {}, |
| "virtual": {}, |
| "void": {}, |
| "volatile": {}, |
| "wchar_t": {}, |
| "while": {}, |
| "xor": {}, |
| "xor_eq": {}, |
| "xunion": {}, |
| |
| // names used in specific contexts e.g. union accessors |
| "FidlType": {}, |
| "New": {}, |
| "Tag": {}, |
| "Which": {}, |
| "has_invalid_tag": {}, |
| "which": {}, |
| "Unknown": {}, |
| "unknown": {}, |
| "UnknownBytes": {}, |
| "UnknownData": {}, |
| "IsEmpty": {}, |
| "HandleEvents": {}, |
| // TODO(ianloic) add: "Clone" |
| // There are Clone methods on a couple of protocols that are used |
| // across layers so this will be a breaking change. |
| // fxbug.dev/7785 |
| |
| // All names from errno definitions. |
| "EPERM": {}, |
| "ENOENT": {}, |
| "ESRCH": {}, |
| "EINTR": {}, |
| "EIO": {}, |
| "ENXIO": {}, |
| "E2BIG": {}, |
| "ENOEXEC": {}, |
| "EBADF": {}, |
| "ECHILD": {}, |
| "EAGAIN": {}, |
| "ENOMEM": {}, |
| "EACCES": {}, |
| "EFAULT": {}, |
| "ENOTBLK": {}, |
| "EBUSY": {}, |
| "EEXIST": {}, |
| "EXDEV": {}, |
| "ENODEV": {}, |
| "ENOTDIR": {}, |
| "EISDIR": {}, |
| "EINVAL": {}, |
| "ENFILE": {}, |
| "EMFILE": {}, |
| "ENOTTY": {}, |
| "ETXTBSY": {}, |
| "EFBIG": {}, |
| "ENOSPC": {}, |
| "ESPIPE": {}, |
| "EROFS": {}, |
| "EMLINK": {}, |
| "EPIPE": {}, |
| "EDOM": {}, |
| "ERANGE": {}, |
| "EDEADLK": {}, |
| "ENAMETOOLONG": {}, |
| "ENOLCK": {}, |
| "ENOSYS": {}, |
| "ENOTEMPTY": {}, |
| "ELOOP": {}, |
| "EWOULDBLOCK": {}, |
| "ENOMSG": {}, |
| "EIDRM": {}, |
| "ECHRNG": {}, |
| "EL2NSYNC": {}, |
| "EL3HLT": {}, |
| "EL3RST": {}, |
| "ELNRNG": {}, |
| "EUNATCH": {}, |
| "ENOCSI": {}, |
| "EL2HLT": {}, |
| "EBADE": {}, |
| "EBADR": {}, |
| "EXFULL": {}, |
| "ENOANO": {}, |
| "EBADRQC": {}, |
| "EBADSLT": {}, |
| "EDEADLOCK": {}, |
| "EBFONT": {}, |
| "ENOSTR": {}, |
| "ENODATA": {}, |
| "ETIME": {}, |
| "ENOSR": {}, |
| "ENONET": {}, |
| "ENOPKG": {}, |
| "EREMOTE": {}, |
| "ENOLINK": {}, |
| "EADV": {}, |
| "ESRMNT": {}, |
| "ECOMM": {}, |
| "EPROTO": {}, |
| "EMULTIHOP": {}, |
| "EDOTDOT": {}, |
| "EBADMSG": {}, |
| "EOVERFLOW": {}, |
| "ENOTUNIQ": {}, |
| "EBADFD": {}, |
| "EREMCHG": {}, |
| "ELIBACC": {}, |
| "ELIBBAD": {}, |
| "ELIBSCN": {}, |
| "ELIBMAX": {}, |
| "ELIBEXEC": {}, |
| "EILSEQ": {}, |
| "ERESTART": {}, |
| "ESTRPIPE": {}, |
| "EUSERS": {}, |
| "ENOTSOCK": {}, |
| "EDESTADDRREQ": {}, |
| "EMSGSIZE": {}, |
| "EPROTOTYPE": {}, |
| "ENOPROTOOPT": {}, |
| "EPROTONOSUPPORT": {}, |
| "ESOCKTNOSUPPORT": {}, |
| "EOPNOTSUPP": {}, |
| "ENOTSUP": {}, |
| "EPFNOSUPPORT": {}, |
| "EAFNOSUPPORT": {}, |
| "EADDRINUSE": {}, |
| "EADDRNOTAVAIL": {}, |
| "ENETDOWN": {}, |
| "ENETUNREACH": {}, |
| "ENETRESET": {}, |
| "ECONNABORTED": {}, |
| "ECONNRESET": {}, |
| "ENOBUFS": {}, |
| "EISCONN": {}, |
| "ENOTCONN": {}, |
| "ESHUTDOWN": {}, |
| "ETOOMANYREFS": {}, |
| "ETIMEDOUT": {}, |
| "ECONNREFUSED": {}, |
| "EHOSTDOWN": {}, |
| "EHOSTUNREACH": {}, |
| "EALREADY": {}, |
| "EINPROGRESS": {}, |
| "ESTALE": {}, |
| "EUCLEAN": {}, |
| "ENOTNAM": {}, |
| "ENAVAIL": {}, |
| "EISNAM": {}, |
| "EREMOTEIO": {}, |
| "EDQUOT": {}, |
| "ENOMEDIUM": {}, |
| "EMEDIUMTYPE": {}, |
| "ECANCELED": {}, |
| "ENOKEY": {}, |
| "EKEYEXPIRED": {}, |
| "EKEYREVOKED": {}, |
| "EKEYREJECTED": {}, |
| "EOWNERDEAD": {}, |
| "ENOTRECOVERABLE": {}, |
| "ERFKILL": {}, |
| "EHWPOISON": {}, |
| } |