objective_c_generator_helpers.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
20 #define GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
21 
22 #include <map>
23 
24 #include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
25 
26 #include "src/compiler/config.h"
28 
30 
34 
35 inline string MessageHeaderName(const FileDescriptor* file) {
37 }
38 
39 inline bool AsciiIsUpper(char c) { return c >= 'A' && c <= 'Z'; }
40 
42  const FileDescriptor* file = service->file();
46  // We add the prefix in the cases where the string is missing a prefix.
47  // We define "missing a prefix" as where 'input':
48  // a) Doesn't start with the prefix or
49  // b) Isn't equivalent to the prefix or
50  // c) Has the prefix, but the letter after the prefix is lowercase
51  // This is the same semantics as the Objective-C protoc.
52  // https://github.com/protocolbuffers/protobuf/blob/c160ae52a91ca4c76936531d68cc846f8230dbb1/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc#L389
53  if (class_name.rfind(prefix, 0) == 0) {
54  if (class_name.length() == prefix.length() ||
55  !AsciiIsUpper(class_name[prefix.length()])) {
56  return prefix + class_name;
57  } else {
58  return class_name;
59  }
60  } else {
61  return prefix + class_name;
62  }
63 }
64 
66  return ::std::string("#import \"" + import + "\"\n");
67 }
68 
71  // Flattens the directory structure: grab the file name only
72  std::size_t pos = import.rfind("/");
73  // If pos is npos, pos + 1 is 0, which gives us the entire string,
74  // so there's no need to check that
75  ::std::string filename = import.substr(pos + 1, import.size() - (pos + 1));
76  return ::std::string("#import <" + framework + "/" + filename + ">\n");
77 }
78 
80  return ::std::string("#import <" + import + ">\n");
81 }
82 
84  return invert ? "!defined(" + symbol + ") || !" + symbol
85  : "defined(" + symbol + ") && " + symbol;
86 }
87 
89  const ::std::string& if_true) {
90  return ::std::string("#if " + PreprocConditional(symbol, false) + "\n" +
91  if_true + "#endif\n");
92 }
93 
95  const ::std::string& if_true) {
96  return ::std::string("#if " + PreprocConditional(symbol, true) + "\n" +
97  if_true + "#endif\n");
98 }
99 
101  const ::std::string& if_true,
102  const ::std::string& if_false) {
103  return ::std::string("#if " + PreprocConditional(symbol, false) + "\n" +
104  if_true + "#else\n" + if_false + "#endif\n");
105 }
106 
108  const ::std::string& if_true,
109  const ::std::string& if_false) {
110  return ::std::string("#if " + PreprocConditional(symbol, true) + "\n" +
111  if_true + "#else\n" + if_false + "#endif\n");
112 }
113 
114 } // namespace grpc_objective_c_generator
115 #endif // GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
grpc_objective_c_generator::LocalImport
inline ::std::string LocalImport(const ::std::string &import)
Definition: objective_c_generator_helpers.h:65
filename
const char * filename
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
google::protobuf::compiler::objectivec::FileClassPrefix
string FileClassPrefix(const FileDescriptor *file)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc:398
pos
int pos
Definition: libuv/docs/code/tty-gravity/main.c:11
grpc_objective_c_generator
Definition: objective_c_generator.cc:38
config.h
FileDescriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:128
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
grpc_objective_c_generator::ServiceClassName
inline ::std::string ServiceClassName(const ServiceDescriptor *service)
Definition: objective_c_generator_helpers.h:41
grpc_objective_c_generator::SystemImport
inline ::std::string SystemImport(const ::std::string &import)
Definition: objective_c_generator_helpers.h:79
grpc_objective_c_generator::MessageHeaderName
string MessageHeaderName(const FileDescriptor *file)
Definition: objective_c_generator_helpers.h:35
grpc_objective_c_generator::PreprocIf
inline ::std::string PreprocIf(const ::std::string &symbol, const ::std::string &if_true)
Definition: objective_c_generator_helpers.h:88
grpc_objective_c_generator::AsciiIsUpper
bool AsciiIsUpper(char c)
Definition: objective_c_generator_helpers.h:39
grpc_objective_c_generator::PreprocIfElse
inline ::std::string PreprocIfElse(const ::std::string &symbol, const ::std::string &if_true, const ::std::string &if_false)
Definition: objective_c_generator_helpers.h:100
grpc_objective_c_generator::FrameworkImport
inline ::std::string FrameworkImport(const ::std::string &import, const ::std::string &framework)
Definition: objective_c_generator_helpers.h:69
class_name
static const char * class_name(int dnsclass)
Definition: adig.c:901
grpc_objective_c_generator::PreprocIfNotElse
inline ::std::string PreprocIfNotElse(const ::std::string &symbol, const ::std::string &if_true, const ::std::string &if_false)
Definition: objective_c_generator_helpers.h:107
framework
Definition: tools/run_tests/xds_k8s_test_driver/framework/__init__.py:1
generator_helpers.h
prefix
static const char prefix[]
Definition: head_of_line_blocking.cc:28
FileDescriptor
struct FileDescriptor FileDescriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:56
grpc_objective_c_generator::PreprocConditional
inline ::std::string PreprocConditional(::std::string symbol, bool invert)
Definition: objective_c_generator_helpers.h:83
service
__attribute__((deprecated("Please use GRPCProtoMethod."))) @interface ProtoMethod NSString * service
Definition: ProtoMethod.h:25
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
google::protobuf::compiler::objectivec::FilePath
string FilePath(const FileDescriptor *file)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc:404
grpc::protobuf::ServiceDescriptor
GRPC_CUSTOM_SERVICEDESCRIPTOR ServiceDescriptor
Definition: include/grpcpp/impl/codegen/config_protobuf.h:88
grpc_objective_c_generator::PreprocIfNot
inline ::std::string PreprocIfNot(const ::std::string &symbol, const ::std::string &if_true)
Definition: objective_c_generator_helpers.h:94


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:44