def make_const(self): """ Add a const modifier to the type. Has no effect if the type is already const. """ if self.type_is_const: return self.type_is_const = True self.ctype.tokens.append( tokenizer.Token(tokenizer.NAME, "const", None, None))
def _parse_type_recursive(tokens): ctype = CType() while tokens: token = tokens.pop(0) if token.name.startswith('::'): token.name = token.name[2:] if token.token_type == tokenizer.SYNTAX: if token.name in ['>>']: tokens.insert( 0, tokenizer.Token(tokenizer.SYNTAX, token.name[0], None, None)) tokens.insert( 0, tokenizer.Token(tokenizer.SYNTAX, token.name[0], None, None)) continue if token.name in [',', '>', ')']: ctype.reorder_modifiers() return ctype, token elif token.name in ['<', '(']: ctype.tokens.append(token) while 1: nested_ctype, last_token = _parse_type_recursive(tokens) ctype.tokens.append(nested_ctype) ctype.tokens.append(last_token) assert token.token_type == tokenizer.SYNTAX if last_token.name == ',': continue elif last_token.name in ['>', ')']: break else: assert False, ("last_token invalid: %s" % last_token) else: ctype.tokens.append(token) else: ctype.tokens.append(token) ctype.reorder_modifiers() return ctype, None
def make_target_const(self): """ Add a const modifier to the type target. Has no effect if the type target is already const. """ assert self.type_is_pointer or self.type_is_reference if self.target_is_const: return self.target_is_const = True for tokens in self.ctype.tokens, self.ctype_no_const.tokens: for token_i in range(len(tokens) - 1, -1, -1): token = tokens[token_i] if isinstance(token, CType): continue elif token.name in ['*', '&']: tokens.insert( token_i, tokenizer.Token(tokenizer.NAME, "const", None, None)) break