MCPcopy Create free account
hub / github.com/NICUP14/MiniLang / block_statement

Method block_statement

src/Parser.py:2255–2289  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2253 '', Def.deferred, node)
2254
2255 def block_statement(self) -> Optional[Node]:
2256 if Def.fun_name == '' and Def.macro_name == '':
2257 print_error('block_statement',
2258 'Global block declarations are not allowed', self)
2259
2260 unnamed_block = self.no_more_tokens()
2261 block_name = f'block{Def.block_cnt}'
2262 Def.block_cnt += 1
2263
2264 name = ''
2265 if not unnamed_block:
2266 name = self.match_token(TokenKind.IDENT).value
2267 full_name = full_name_of_var(name, force_local=True)
2268 full_block_name = full_name_of_var(block_name, force_local=True)
2269
2270 self.next_line()
2271 scopeless_block = name.startswith('_')
2272
2273 if not scopeless_block:
2274 Def.fun_name_list.append(block_name)
2275
2276 Def.ident_map[full_name] = VariableMetaKind.BLOCK
2277 Def.block_map[full_name] = Block(full_name, full_block_name)
2278
2279 if Def.macro_name != '':
2280 macro = Def.macro_map[Def.macro_name]
2281 macro.local_names.append(full_name)
2282
2283 block_node = Node(NodeKind.BLOCK, void_type,
2284 name, self.compound_statement())
2285
2286 if not scopeless_block:
2287 Def.fun_name_list.pop()
2288
2289 return Node(NodeKind.GLUE, void_type, '', block_node, Node(NodeKind.END, void_type, 'end'))
2290
2291 def macro_statement(self) -> None:
2292 if Def.macro_name != '':

Callers 1

statementMethod · 0.95

Calls 8

no_more_tokensMethod · 0.95
match_tokenMethod · 0.95
next_lineMethod · 0.95
compound_statementMethod · 0.95
print_errorFunction · 0.90
full_name_of_varFunction · 0.90
BlockClass · 0.90
NodeClass · 0.90

Tested by

no test coverage detected