MCPcopy Create free account
hub / github.com/alibaba/GraphScope / InTemplateArgumentList

Method InTemplateArgumentList

analytical_engine/misc/cpplint.py:2967–3017  ·  view source on GitHub ↗

Check if current position is inside template argument list. Args: clean_lines: A CleansedLines instance containing the file. linenum: The number of the line to check. pos: position just after the suspected template argument. Returns: True if (linenum, pos) is inside

(self, clean_lines, linenum, pos)

Source from the content-addressed store, hash-verified

2965 return self.stack and self.stack[-1].inline_asm != _NO_ASM
2966
2967 def InTemplateArgumentList(self, clean_lines, linenum, pos):
2968 """Check if current position is inside template argument list.
2969
2970 Args:
2971 clean_lines: A CleansedLines instance containing the file.
2972 linenum: The number of the line to check.
2973 pos: position just after the suspected template argument.
2974 Returns:
2975 True if (linenum, pos) is inside template arguments.
2976 """
2977 while linenum < clean_lines.NumLines():
2978 # Find the earliest character that might indicate a template argument
2979 line = clean_lines.elided[linenum]
2980 match = Match(r'^[^{};=\[\]\.<>]*(.)', line[pos:])
2981 if not match:
2982 linenum += 1
2983 pos = 0
2984 continue
2985 token = match.group(1)
2986 pos += len(match.group(0))
2987
2988 # These things do not look like template argument list:
2989 # class Suspect {
2990 # class Suspect x; }
2991 if token in ('{', '}', ';'): return False
2992
2993 # These things look like template argument list:
2994 # template <class Suspect>
2995 # template <class Suspect = default_value>
2996 # template <class Suspect[]>
2997 # template <class Suspect...>
2998 if token in ('>', '=', '[', ']', '.'): return True
2999
3000 # Check if token is an unmatched '<'.
3001 # If not, move on to the next character.
3002 if token != '<':
3003 pos += 1
3004 if pos >= len(line):
3005 linenum += 1
3006 pos = 0
3007 continue
3008
3009 # We can't be sure if we just find a single '<', and need to
3010 # find the matching '>'.
3011 (_, end_line, end_pos) = CloseExpression(clean_lines, linenum, pos - 1)
3012 if end_pos < 0:
3013 # Not sure if template argument list or syntax error in file
3014 return False
3015 linenum = end_line
3016 pos = end_pos
3017 return False
3018
3019 def UpdatePreprocessor(self, line):
3020 """Update preprocessor stack.

Callers 1

UpdateMethod · 0.95

Calls 4

CloseExpressionFunction · 0.85
NumLinesMethod · 0.80
MatchFunction · 0.70
groupMethod · 0.45

Tested by

no test coverage detected