MCPcopy Create free account
hub / github.com/apache/thrift / is_common_namespace

Method is_common_namespace

compiler/cpp/src/thrift/parse/t_program.h:192–246  ·  view source on GitHub ↗

* Determine whether identical typenames will collide based on namespaces. * * Because we do not know which languages the user will generate code for, * collisions within programs (IDL files) having namespace declarations can be * difficult to determine. Only guaranteed collisions return true (cause an error). * Possible collisions involving explicit namespace declarations produce a

Source from the content-addressed store, hash-verified

190 * @return true if a collision within namespaces is found, otherwise false
191 */
192 bool is_common_namespace(const t_program* prog, const t_type* t) const {
193 // Case 1: Typenames are in the same program [collision]
194 if (prog == t->get_program()) {
195 pwarning(1,
196 "Duplicate typename %s found in %s",
197 t->get_name().c_str(),
198 t->get_program()->get_name().c_str());
199 return true;
200 }
201
202 // Case 2: Both programs have identical namespace scope/name declarations [collision]
203 bool match = true;
204 for (auto it = prog->namespaces_.cbegin();
205 it != prog->namespaces_.cend();
206 ++it) {
207 if (0 == it->second.compare(t->get_program()->get_namespace(it->first))) {
208 pwarning(1,
209 "Duplicate typename %s found in %s,%s,%s and %s,%s,%s [file,scope,ns]",
210 t->get_name().c_str(),
211 t->get_program()->get_name().c_str(),
212 it->first.c_str(),
213 it->second.c_str(),
214 prog->get_name().c_str(),
215 it->first.c_str(),
216 it->second.c_str());
217 } else {
218 match = false;
219 }
220 }
221 for (auto it = t->get_program()->namespaces_.cbegin();
222 it != t->get_program()->namespaces_.cend();
223 ++it) {
224 if (0 == it->second.compare(prog->get_namespace(it->first))) {
225 pwarning(1,
226 "Duplicate typename %s found in %s,%s,%s and %s,%s,%s [file,scope,ns]",
227 t->get_name().c_str(),
228 t->get_program()->get_name().c_str(),
229 it->first.c_str(),
230 it->second.c_str(),
231 prog->get_name().c_str(),
232 it->first.c_str(),
233 it->second.c_str());
234 } else {
235 match = false;
236 }
237 }
238 if (0 == prog->namespaces_.size() && 0 == t->get_program()->namespaces_.size()) {
239 pwarning(1,
240 "Duplicate typename %s found in %s and %s",
241 t->get_name().c_str(),
242 t->get_program()->get_name().c_str(),
243 prog->get_name().c_str());
244 }
245 return match;
246 }
247
248 // Scoping and namespacing
249 void set_namespace(std::string name) { namespace_ = name; }

Callers

nothing calls this directly

Calls 6

pwarningFunction · 0.50
get_programMethod · 0.45
get_nameMethod · 0.45
compareMethod · 0.45
get_namespaceMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected