MCPcopy
hub / github.com/rocky/python-uncompyle6 / build_ast

Method build_ast

uncompyle6/semantics/pysource.py:1207–1296  ·  view source on GitHub ↗
(
        self,
        tokens,
        customize,
        code,
        is_lambda=False,
        noneInNames=False,
        is_top_level_module=False,
        compile_mode="exec",
    )

Source from the content-addressed store, hash-verified

1205 self.return_none = rn
1206
1207 def build_ast(
1208 self,
1209 tokens,
1210 customize,
1211 code,
1212 is_lambda=False,
1213 noneInNames=False,
1214 is_top_level_module=False,
1215 compile_mode="exec",
1216 ) -> GenericASTTraversal:
1217 # FIXME: DRY with fragments.py
1218
1219 # assert isinstance(tokens[0], Token)
1220
1221 if is_lambda:
1222 for t in tokens:
1223 if t.kind == "RETURN_END_IF":
1224 t.kind = "RETURN_END_IF_LAMBDA"
1225 elif t.kind == "RETURN_VALUE":
1226 t.kind = "RETURN_VALUE_LAMBDA"
1227 tokens.append(Token("LAMBDA_MARKER"))
1228 try:
1229 # FIXME: have p.insts update in a better way
1230 # modularity is broken here
1231 p_insts = self.p.insts
1232 self.p.insts = self.scanner.insts
1233 self.p.offset2inst_index = self.scanner.offset2inst_index
1234 ast = parse(self.p, tokens, customize, code)
1235 self.customize(customize)
1236 self.p.insts = p_insts
1237
1238 except (ParserError, AssertionError) as e:
1239 raise ParserError(e, tokens, self.p.debug["reduce"])
1240 transform_tree = self.treeTransform.transform(ast, code)
1241 self.maybe_show_tree(ast, phase="after")
1242 del ast # Save memory
1243 return transform_tree
1244
1245 # The bytecode for the end of the main routine has a "return
1246 # None". However, you can't issue a "return" statement in
1247 # main. So as the old cigarette slogan goes: I'd rather switch
1248 # (the token stream) than fight (with the grammar to not emit
1249 # "return None").
1250 if self.hide_internal:
1251 if len(tokens) >= 2 and not noneInNames:
1252 if tokens[-1].kind in ("RETURN_VALUE", "RETURN_VALUE_LAMBDA"):
1253 # Python 3.4's classes can add a "return None" which is
1254 # invalid syntax.
1255 load_const = tokens[-2]
1256 # We should have:
1257 # LOAD_CONST None
1258 # with *no* line number associated the token.
1259 # A line number on the token or a non-None
1260 # token value a token based on user source
1261 # text.
1262 if (
1263 load_const.kind == "LOAD_CONST"
1264 and load_const.linestart is None

Callers 11

build_classMethod · 0.95
code_deparseFunction · 0.45
make_function2Function · 0.45
make_function3_annotateFunction · 0.45
make_function3Function · 0.45
make_function36Function · 0.45
code_deparse_alignFunction · 0.45
comprehension_walkMethod · 0.45
listcomp_closure3Method · 0.45
make_function1Function · 0.45

Calls 8

customizeMethod · 0.95
maybe_show_treeMethod · 0.95
TokenClass · 0.90
parseFunction · 0.90
ParserErrorClass · 0.90
checkerFunction · 0.90
transformMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected