| | 278 | # do doxygen-style name->file mapping |
|---|
| | 279 | # this is a little different than doxygen, but I don't see another |
|---|
| | 280 | # way to make doxygen:Type<bool> links work, as it inserts a ' ' (or |
|---|
| | 281 | # '_01') after/before the type name. |
|---|
| | 282 | |
|---|
| | 283 | doxygen_file_map = { '_':'__', ':':'_1', '/':'_2', '<':'_3_01', '>':'_01_4', \ |
|---|
| | 284 | '*':'_5', '&':'_6', '|':'_7', '.':'_8', '!':'_9', \ |
|---|
| | 285 | ',':'_00',' ':'_01' } |
|---|
| | 286 | |
|---|
| | 287 | re_name_map = { '+':'\\+', '*':'\\*', '(':'\\(', ')':'\\)', '[':'\\[', ']':'\\]', ' ':'' } |
|---|
| | 288 | |
|---|
| | 289 | space_map = {' ':'' } |
|---|
| | 290 | |
|---|
| | 291 | def map_string(str, map): |
|---|
| | 292 | if str == None: |
|---|
| | 293 | return None |
|---|
| | 294 | mangledstring = '' |
|---|
| | 295 | for i in str: |
|---|
| | 296 | if i in map.keys(): |
|---|
| | 297 | mangledstring += map[i] |
|---|
| | 298 | else: |
|---|
| | 299 | mangledstring += i |
|---|
| | 300 | |
|---|
| | 301 | return mangledstring |
|---|
| | 302 | |
|---|
| | 303 | # Mangle doxygen arguments from WikiLink format to doxygen format |
|---|
| | 304 | def mangle_doxygen_args(args): |
|---|
| | 305 | charmap = { '<':'< ', '>':' >', '&':'&'} |
|---|
| | 306 | spaceargs = re.sub('%20', ' ', args) |
|---|
| | 307 | mangledargs = '' |
|---|
| | 308 | for i in spaceargs: |
|---|
| | 309 | if i in charmap.keys(): |
|---|
| | 310 | mangledargs += charmap[i] |
|---|
| | 311 | else: |
|---|
| | 312 | mangledargs += i |
|---|
| | 313 | |
|---|
| | 314 | return mangledargs |
|---|
| | 315 | |
|---|
| | 368 | # Try in the default_namespace |
|---|
| | 369 | if self.default_namespace != "": |
|---|
| | 370 | dnmangledfile = self.default_namespace + '_1_1' + mangledfile |
|---|
| | 371 | path, link = lookup('class%s.html' % dnmangledfile, 'class') |
|---|
| | 372 | if not path: |
|---|
| | 373 | path, link = lookup('struct%s.html' % dnmangledfile, 'struct') |
|---|
| | 374 | if path: |
|---|
| | 375 | return 'view', path, link |
|---|
| | 376 | |
|---|
| | 377 | # Could have a method attached to the classname... |
|---|
| | 378 | # Remove the last ::XXX segment and try again |
|---|
| | 379 | method_re = '::([^:]*)$' |
|---|
| | 380 | nmfile = re.sub(method_re, "", file); |
|---|
| | 381 | |
|---|
| | 382 | mangledfile = map_string(nmfile, doxygen_file_map) |
|---|
| | 383 | namespace = '' |
|---|
| | 384 | |
|---|
| | 385 | path, link = lookup('class%s.html' % mangledfile, 'class') |
|---|
| | 386 | if not path: |
|---|
| | 387 | path, link = lookup('struct%s.html' % mangledfile, 'struct') |
|---|
| | 388 | if not path and self.default_namespace != "": |
|---|
| | 389 | # Try in the default_namespace |
|---|
| | 390 | namespace = self.default_namespace |
|---|
| | 391 | dnmangledfile = self.default_namespace + '_1_1' + mangledfile |
|---|
| | 392 | path, link = lookup('class%s.html' % dnmangledfile, 'class') |
|---|
| | 393 | if not path: |
|---|
| | 394 | path, link = lookup('struct%s.html' % dnmangledfile, 'struct') |
|---|
| | 395 | |
|---|
| | 396 | if path: |
|---|
| | 397 | self.log.debug('Found method %s %s' % (path, link)) |
|---|
| | 398 | member = re.search(method_re, file).group(1) |
|---|
| | 399 | mangledmember = mangle_doxygen_args(member) |
|---|
| | 400 | pieces = re.search("([^(]*)(\(([^)]*)\)(.*))?$", mangledmember) |
|---|
| | 401 | classname = mangle_doxygen_args(nmfile) |
|---|
| | 402 | if namespace != '': |
|---|
| | 403 | classname = namespace + '::' + classname |
|---|
| | 404 | re_name = map_string(classname + "::" + pieces.groups()[0], re_name_map) |
|---|
| | 405 | if pieces.groups()[2] != None: |
|---|
| | 406 | re_args = '(%s)%s' % (pieces.groups()[2], pieces.groups()[3]) |
|---|
| | 407 | re_args = map_string(re_args, re_name_map) |
|---|
| | 408 | else: |
|---|
| | 409 | re_args = None |
|---|
| | 410 | self.log.debug("re_name = %s, re_args = %s" % (re_name, re_args)) |
|---|
| | 411 | fd = open(path) |
|---|
| | 412 | filedata = fd.read() |
|---|
| | 413 | anchor = None |
|---|
| | 414 | anchor_pat='<!-- doxytag: member="([\w:;<>& !=\+\*\-/%]*)" ref="([\w]*)"(?: args="([\w, ()\*\&]*)")?' |
|---|
| | 415 | for p in re.finditer(anchor_pat, filedata): |
|---|
| | 416 | n = map_string(p.groups()[0], re_name_map) |
|---|
| | 417 | #self.log.debug("match: %s %s %s" % (n, p.groups()[1], p.groups()[2])) |
|---|
| | 418 | if n != re_name: |
|---|
| | 419 | continue |
|---|
| | 420 | if re_args == None: |
|---|
| | 421 | anchor = p.groups()[1] |
|---|
| | 422 | break |
|---|
| | 423 | a = map_string(p.groups()[2], re_name_map) |
|---|
| | 424 | if a == re_args: |
|---|
| | 425 | anchor = p.groups()[1] |
|---|
| | 426 | break |
|---|
| | 427 | if anchor != None: |
|---|
| | 428 | link = link + '#' + anchor |
|---|
| | 429 | self.log.debug('Found method in %s: %s %s' % (file, path, link)) |
|---|
| | 430 | return 'anchor', None, link |
|---|
| | 431 | |
|---|