MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / ToType

Method ToType

tests/external/gmock-1.7.0/scripts/generator/cpp/ast.py:476–532  ·  view source on GitHub ↗

Convert [Token,...] to [Class(...), ] useful for base classes. For example, code like class Foo : public Bar { ... }; the "Bar " portion gets converted to an AST. Returns: [Class(...), ...]

(self, tokens)

Source from the content-addressed store, hash-verified

474 return tokens[start:end-1], end
475
476 def ToType(self, tokens):
477 """Convert [Token,...] to [Class(...), ] useful for base classes.
478 For example, code like class Foo : public Bar<x, y> { ... };
479 the "Bar<x, y>" portion gets converted to an AST.
480
481 Returns:
482 [Class(...), ...]
483 """
484 result = []
485 name_tokens = []
486 reference = pointer = array = False
487
488 def AddType(templated_types):
489 # Partition tokens into name and modifier tokens.
490 names = []
491 modifiers = []
492 for t in name_tokens:
493 if keywords.IsKeyword(t.name):
494 modifiers.append(t.name)
495 else:
496 names.append(t.name)
497 name = ''.join(names)
498 result.append(Type(name_tokens[0].start, name_tokens[-1].end,
499 name, templated_types, modifiers,
500 reference, pointer, array))
501 del name_tokens[:]
502
503 i = 0
504 end = len(tokens)
505 while i < end:
506 token = tokens[i]
507 if token.name == '<':
508 new_tokens, new_end = self._GetTemplateEnd(tokens, i+1)
509 AddType(self.ToType(new_tokens))
510 # If there is a comma after the template, we need to consume
511 # that here otherwise it becomes part of the name.
512 i = new_end
513 reference = pointer = array = False
514 elif token.name == ',':
515 AddType([])
516 reference = pointer = array = False
517 elif token.name == '*':
518 pointer = True
519 elif token.name == '&':
520 reference = True
521 elif token.name == '[':
522 pointer = True
523 elif token.name == ']':
524 pass
525 else:
526 name_tokens.append(token)
527 i += 1
528
529 if name_tokens:
530 # No '<' in the tokens, just a simple name and no template.
531 AddType([])
532 return result
533

Callers 3

DeclarationToPartsMethod · 0.95
handle_typedefMethod · 0.45
_GetBasesMethod · 0.45

Calls 1

_GetTemplateEndMethod · 0.95

Tested by

no test coverage detected