Example #1
0
    def analyze_content(self):
        if self._content_was_analyzed:
            return

        self._content_was_analyzed = True

        if self.is_compact_ast:
            body = self._functionNotParsed['body']

            if body and body[self.get_key()] == 'Block':
                self._is_implemented = True
                self._parse_cfg(body)

            for modifier in self._functionNotParsed['modifiers']:
                self._parse_modifier(modifier)

        else:
            children = self._functionNotParsed[self.get_children('children')]
            self._is_implemented = False
            for child in children[2:]:
                if child[self.get_key()] == 'Block':
                    self._is_implemented = True
                    self._parse_cfg(child)

            # Parse modifier after parsing all the block
            # In the case a local variable is used in the modifier
            for child in children[2:]:
                if child[self.get_key()] == 'ModifierInvocation':
                    self._parse_modifier(child)

        for local_vars in self.variables:
            local_vars.analyze(self)

        for node in self.nodes:
            node.analyze_expressions(self)

        ternary_found = True
        while ternary_found:
            ternary_found = False
            for node in self.nodes:
                has_cond = HasConditional(node.expression)
                if has_cond.result():
                    st = SplitTernaryExpression(node.expression)
                    condition = st.condition
                    assert condition
                    true_expr = st.true_expression
                    false_expr = st.false_expression
                    self.split_ternary_node(node, condition, true_expr,
                                            false_expr)
                    ternary_found = True
                    break
        self._remove_alone_endif()
Example #2
0
 def _filter_ternary(self):
     ternary_found = True
     while ternary_found:
         ternary_found = False
         for node in self.nodes:
             has_cond = HasConditional(node.expression)
             if has_cond.result():
                 st = SplitTernaryExpression(node.expression)
                 condition = st.condition
                 assert condition
                 true_expr = st.true_expression
                 false_expr = st.false_expression
                 self.split_ternary_node(node, condition, true_expr, false_expr)
                 ternary_found = True
                 break
Example #3
0
 def _filter_ternary(self):
     ternary_found = True
     while ternary_found:
         ternary_found = False
         for node in self.nodes:
             has_cond = HasConditional(node.expression)
             if has_cond.result():
                 st = SplitTernaryExpression(node.expression)
                 condition = st.condition
                 if not condition:
                     raise ParsingError(f'Incorrect ternary conversion {node.expression} {node.source_mapping_str}')
                 true_expr = st.true_expression
                 false_expr = st.false_expression
                 self.split_ternary_node(node, condition, true_expr, false_expr)
                 ternary_found = True
                 break
Example #4
0
    def analyze_content(self):
        if self._content_was_analyzed:
            return

        self._content_was_analyzed = True

        children = self._functionNotParsed['children']
        self._is_implemented = False
        for child in children[2:]:
            if child['name'] == 'Block':
                self._is_implemented = True
                self._parse_cfg(child)
                continue

            assert child['name'] == 'ModifierInvocation'

            self._parse_modifier(child)

        for local_vars in self.variables:
            local_vars.analyze(self)

        for node in self.nodes:
            node.analyze_expressions(self)

        ternary_found = True
        while ternary_found:
            ternary_found = False
            for node in self.nodes:
                has_cond = HasConditional(node.expression)
                if has_cond.result():
                    st = SplitTernaryExpression(node.expression)
                    condition = st.condition
                    assert condition
                    true_expr = st.true_expression
                    false_expr = st.false_expression
                    self.split_ternary_node(node, condition, true_expr,
                                            false_expr)
                    ternary_found = True
                    break
        self._remove_alone_endif()

        self._analyze_read_write()
        self._analyze_calls()