• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/compiler/config.h"
24 #include "src/compiler/generator_helpers.h"
25 
26 #include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
27 
28 namespace grpc_objective_c_generator {
29 
30 using ::grpc::protobuf::FileDescriptor;
31 using ::grpc::protobuf::ServiceDescriptor;
32 using ::grpc::string;
33 
MessageHeaderName(const FileDescriptor * file)34 inline string MessageHeaderName(const FileDescriptor* file) {
35   return google::protobuf::compiler::objectivec::FilePath(file) + ".pbobjc.h";
36 }
37 
ServiceClassName(const ServiceDescriptor * service)38 inline string ServiceClassName(const ServiceDescriptor* service) {
39   const FileDescriptor* file = service->file();
40   string prefix = file->options().objc_class_prefix();
41   return prefix + service->name();
42 }
43 
LocalImport(const::grpc::string & import)44 inline ::grpc::string LocalImport(const ::grpc::string& import) {
45   return ::grpc::string("#import \"" + import + "\"\n");
46 }
47 
SystemImport(const::grpc::string & import)48 inline ::grpc::string SystemImport(const ::grpc::string& import) {
49   return ::grpc::string("#import <" + import + ">\n");
50 }
51 
PreprocConditional(::grpc::string symbol,bool invert)52 inline ::grpc::string PreprocConditional(::grpc::string symbol, bool invert) {
53   return invert ? "!defined(" + symbol + ") || !" + symbol
54                 : "defined(" + symbol + ") && " + symbol;
55 }
56 
PreprocIf(const::grpc::string & symbol,const::grpc::string & if_true)57 inline ::grpc::string PreprocIf(const ::grpc::string& symbol,
58                                 const ::grpc::string& if_true) {
59   return ::grpc::string("#if " + PreprocConditional(symbol, false) + "\n" +
60                         if_true + "#endif\n");
61 }
62 
PreprocIfNot(const::grpc::string & symbol,const::grpc::string & if_true)63 inline ::grpc::string PreprocIfNot(const ::grpc::string& symbol,
64                                    const ::grpc::string& if_true) {
65   return ::grpc::string("#if " + PreprocConditional(symbol, true) + "\n" +
66                         if_true + "#endif\n");
67 }
68 
PreprocIfElse(const::grpc::string & symbol,const::grpc::string & if_true,const::grpc::string & if_false)69 inline ::grpc::string PreprocIfElse(const ::grpc::string& symbol,
70                                     const ::grpc::string& if_true,
71                                     const ::grpc::string& if_false) {
72   return ::grpc::string("#if " + PreprocConditional(symbol, false) + "\n" +
73                         if_true + "#else\n" + if_false + "#endif\n");
74 }
75 
PreprocIfNotElse(const::grpc::string & symbol,const::grpc::string & if_true,const::grpc::string & if_false)76 inline ::grpc::string PreprocIfNotElse(const ::grpc::string& symbol,
77                                        const ::grpc::string& if_true,
78                                        const ::grpc::string& if_false) {
79   return ::grpc::string("#if " + PreprocConditional(symbol, true) + "\n" +
80                         if_true + "#else\n" + if_false + "#endif\n");
81 }
82 
83 }  // namespace grpc_objective_c_generator
84 #endif  // GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
85