Exemplo n.º 1
0
    def identify_pattern(self, node):
        print_writeofd("Pattern identified", self.ofd)
        self.identifed = True

        # Now check to see if this API pattern is defined in a function
        while isinstance(node.parent, ast.Module) == False:
            if isinstance(node.parent, ast.FunctionDef):
                print_writeofd("Note: The API call is defined in function: {}".format(node.parent.name), self.ofd)
                self.fct.append((node.parent.name, self.url, []))
                break
            node = node.parent
Exemplo n.º 2
0
 def search_multi(self):
     self.all_fct_name = list2treelist(self.all_fct_name)
     start = datetime.now().time()
     end = datetime.now().time()
     time_elapsed = (datetime.combine(date.min, end) -
                     datetime.combine(date.min, start)).total_seconds()
     # If a particular project takes more than 20 minutes, flag it and move on
     while self._round < MAXIMUM_SEARCH_ROUND:
         end = datetime.now().time()
         time_elapsed = (datetime.combine(date.min, end) -
                         datetime.combine(date.min, start)).total_seconds()
         self.retrieve_and_search()
         self._round += 1
         if time_elapsed > 20 * 60:
             print_writeofd(
                 "This project took more than 20 minutes, jumping over for now",
                 self.ofd)
             break
     # Print tree searched:
     print_writeofd("***", self.ofd)
     print_counter = 1
     for elements in self.all_fct_name:
         print_writeofd("Tree Number {}".format(print_counter), self.ofd)
         render_beautify_tree_1(elements, self.ofd)
         print_counter += 1
     print_writeofd("***", self.ofd)
Exemplo n.º 3
0
def add_backward_links(content):
    try:
        p = ast.parse(content)
    except SyntaxError:
        try:
            content = use_2to3(content)
            p = ast.parse(content)
        except Exception as e:
            print_writeofd("EXCEPTION OCCURS: {}".format(e), ofd)
            return None
    except Exception as e:
        print_writeofd("EXCEPTION OCCURS: {}".format(e), ofd)
        return None
    # Traverse the tree to add links from child to parent, making it a doubly-linked tree
    for node in ast.walk(p):
        for child in ast.iter_child_nodes(node):
            child.parent = node
    return p
Exemplo n.º 4
0
 def check_recursion(self, node):
     while isinstance(node.parent, ast.Module) == False:
         if isinstance(node.parent, ast.FunctionDef):
             break_status = True
             for arguments in node.parent.args.args:
                 if arguments.arg not in ["event", "context"]:
                     break_status = False
                     break
             if break_status:
                 print_writeofd(
                     "Function ({}, {}) is a lambda function".format(
                         node.parent.name, slice_url(self.url_inspect)),
                     self.ofd)
                 self.traced_lambda = True
             inspect_tuple = (node.parent.name, self.url_inspect)
             if node.parent.name in NEGLECT_FUNCTION_NAME:
                 print_writeofd(
                     "The function call [{}] is defined in function [{}], NEGLECTED"
                     .format(self.fct_inspect, node.parent.name), self.ofd)
                 break
             # This case below is also ruled out because such tracing will make the graph very complicated and difficult to understand
             elif node.parent.name == self.fct_inspect:
                 print_writeofd(
                     "The function call [{}] is defined in function [{}], SAME ONE, NEGLECTED"
                     .format(self.fct_inspect, node.parent.name), self.ofd)
             # If function of the same name is already traced either in the current round or in the tree, also neglect
             elif search_tuple_list(self.fctname_thisround,
                                    inspect_tuple) or search_tree(
                                        self.all_fct_name, inspect_tuple):
                 print_writeofd(
                     "The function call [{}] is defined in function [{}], ALREADY SEARCHED, NEGLECTED"
                     .format(self.fct_inspect, node.parent.name), self.ofd)
             else:
                 print_writeofd(
                     "The function call [{}] is defined in function [{}]".
                     format(self.fct_inspect, node.parent.name), self.ofd)
                 self.fctname_thisround.append(
                     (node.parent.name, self.url_inspect))
                 break
         node = node.parent
Exemplo n.º 5
0
    def identify_pattern(self, node, keyword):
        print_writeofd("Keyword identified: {}".format(keyword), self.ofd)

        # Now check to see if this API pattern is defined in a function
        while isinstance(node.parent, ast.Module) == False:
            if isinstance(node.parent, ast.FunctionDef):
                print_writeofd(
                    "Note: The API call is defined in function: {}".format(
                        node.parent.name), self.ofd)
                for arguments in node.parent.args.args:
                    if arguments.arg not in ["event", "context"]:
                        print_writeofd("This is not a lambda function",
                                       self.ofd)
                        return False
                print_writeofd("This is a lambda function", self.ofd)
                return True
            node = node.parent
        return False
Exemplo n.º 6
0
        i = j
        continue

    # Judge if there is any other exception triggered
    if scan_block(lines, i, j, "EXCEPTION OCCURS"):
        proces_exception += 1
        ofd.write("process_exception: {}".format(lines[k]))
        i = j
        continue

    # Judge if this is a no pattern identified case
    # If only relying on auto-tool: this should be a parallelism-used case
    if "NO PATTERN IDENTIFIED" in lines[j - 1]:
        if MANUAL_CHECKING:
            print("\n\n\n\n\n\n")
            print_writeofd("no_pattern: {}".format(lines[k].strip("\n")), ofd)
            print(
                "Please inspect the above. Enter 1 if this is a no parallelism case, and enter 2 if this is a use-parallelism case"
            )
            user = input()
            while user != '1' and user != '2':
                print("PRESS 1 OR 2, NOT ANYTHING ELSE!")
                user = input()
            if user == '1':
                det_no_para += 1
                print_writeofd(
                    "no_pattern (no_parallelism): {}".format(
                        lines[k].strip("\n")), ofd)
                i = j
                continue
            elif user == '2':
Exemplo n.º 7
0
def render_beautify_tree(tree, ofd):
    tree = beautify_tree(tree)
    for pre, _, node in RenderTree(tree, style=AsciiStyle()):
        print_writeofd("%s%s" % (pre, node.name), ofd)
Exemplo n.º 8
0
 def retrieve_and_search(self):
     search_round = 0
     end = self.all_fct_name
     while search_round < self._round:
         intmediate = []
         for elements in end:
             for children in elements.children:
                 intmediate.append(children)
         search_round += 1
         end = intmediate
     print_writeofd(
         "Round {}, beginning tracing functions: ".format(self._round) +
         print_node_list(end), self.ofd)
     for elements in end:
         self.fctname_thisround = []
         self.fct_inspect = elements.name[0]
         self.fct_inspect_url = elements.name[1]
         url_list = search_github(self.fct_inspect, self.repo, self.ofd)
         time.sleep(SLEEP_TIME)
         appear_url_list = url_list
         to_delete_list = []
         for item in url_list:
             urlcontent = get_url_content(item, self.ofd)
             if urlcontent == None:
                 continue
             p = add_backward_links(urlcontent)
             if p == None:
                 continue
             self.url_inspect = item
             if (item == self.fct_inspect_url
                 ) and self.manual_control_import:
                 print_writeofd(
                     "Info: importation file and to be imported function in the same file, importation check fulfilled",
                     self.ofd)
             elif (item !=
                   self.fct_inspect_url) and self.manual_control_import:
                 # Now checks for import
                 self.checking_import = True
                 self.import_true = False
                 self.generic_visit(p)
                 self.checking_import = False
                 if self.import_true == False:
                     print_writeofd(
                         "Info: Importation check failed: function [{}] at url [{}], importation occurs in [{}]"
                         .format(self.fct_inspect,
                                 slice_url(self.fct_inspect_url),
                                 slice_url(item)), self.ofd)
                     to_delete_list.append(item)
                     continue
                 else:
                     print_writeofd("Info: Importation check succeeded",
                                    self.ofd)
             self.generic_visit(p)
         for searched in self.fctname_thisround:
             node = Node((searched[0], searched[1], []), parent=elements)
         print_writeofd(
             "Traced functions {} based on [{}]".format(
                 self.fctname_thisround, self.fct_inspect), self.ofd)
         for i in to_delete_list:
             appear_url_list.remove(i)
         print_writeofd(
             "This function [{}] appears in {}".format(
                 self.fct_inspect, slice_list(appear_url_list)), self.ofd)
         for tree in self.all_fct_name:
             for members in PreOrderIter(tree):
                 if members.name == (elements.name[0], elements.name[1],
                                     []):
                     members.name = (elements.name[0], elements.name[1],
                                     appear_url_list)
Exemplo n.º 9
0
 def main_fct(self):
     self.generic_visit(self.entire_tree)
     if self.call_lineno == [] and self.while_lineno != []:
         print_writeofd("Start operation missing", self.ofd)
         return False
     if self.while_lineno == [] and self.call_lineno != []:
         print_writeofd("While loop operating missing", self.ofd)
         return False
     if self.while_lineno == [] and self.call_lineno == []:
         print_writeofd("Both start and loop operations missing", self.ofd)
         return False
     if len(self.while_lineno) != len(self.call_lineno):
         print_writeofd("Start and loop instance numbers do not match up",
                        self.ofd)
         return False
     self.while_lineno.sort()
     self.call_lineno.sort()
     for call_lineno, while_lineno in zip(self.call_lineno,
                                          self.while_lineno):
         self.stage2(call_lineno, while_lineno)
     if self.not_safe_list != []:
         print_writeofd("------", self.ofd)
         print_writeofd(
             "Nodes in between start statement and while statement",
             self.ofd)
         for node in self.not_safe_list:
             print_writeofd(astor.to_source(node), self.ofd)
         print_writeofd("------", self.ofd)
     return True
Exemplo n.º 10
0
        url = line.split()[1]
        repo = re.sub('https://github.com/', '', url)
        repo = re.sub('\n', '', repo)
        print(url)
        ofd.write("{}\n".format(url))

        url_list = []
        for keyword in ASYNC_KEYWORD_LIST_EXIST:
            return_value = search_github(keyword, repo, ofd)
            if return_value != None:
                url_list.extend(return_value)
            elif return_value == None or return_value == []:
                continue

        if url_list == []:
            print_writeofd("No use of async", ofd)
            continue

        url_list_1 = []
        for keyword in ASYNC_KEYWORD_LIST:
            return_value = search_github(keyword, repo, ofd)
            if return_value != None:
                url_list_1.extend(return_value)
            elif return_value == None or return_value == []:
                continue
            time.sleep(SLEEP_TIME)

        if url_list_1 == []:
            print_writeofd("No retrieve result", ofd)
            continue
        v = search_one_repo(remove_list_dup(url_list + url_list_1), ofd)
Exemplo n.º 11
0
 def check_instance_name(self, node):
     if not isinstance(node, ast.Name):
         print_writeofd("Node supposed to be name but not name: {}".format(ast.dump(node)), self.ofd)
         return False
     return True
            elif user == '3' and printed_ent == 1:
                experi_ent += 1
                ofd1.write("Entirely Experimental: ")
                ofd1.write(lines[k])
            printed_ent = 0
            printed_par = 0
            print("\n\n\n\n\n\n")
    else:
        if printed_ent == 1:
            ofd1.write("Entirely constant: ")
            ofd1.write(lines[k])
            accocc_ent += 1

        
    if excepted == 1:
        excep += 1
        ofd1.write(lines[k])
        excepted = 0
    
print_writeofd("\n\n\n\n\n", ofd1)
print_writeofd("Total file searched: {}".format(allfile), ofd1)
print_writeofd("Entirely Constants found: {}".format(accocc_ent), ofd1)
print_writeofd("Experimental Constants found: {}".format(experi_ent), ofd1)
print_writeofd("Exceptions occurred: {}".format(excep), ofd1)

if MANUAL_CHECKING:
    print_writeofd("RELYING ON MANUAL CHECKING: {} CONSTANT INPUTS".format(accocc_ent), ofd1)
    print_writeofd("RELYING ON MANUAL CHECKING: {} RELEVANT TOTAL PROJECTS".format(allfile - excep), ofd1)
else:
    print_writeofd("RELYING ON AUTO TOOL: {} CONSTANT INPUTS".format(accocc_ent), ofd1)
    print_writeofd("RELYING ON AUTO TOOL: {} RELEVANT TOTAL PROJECTS".format(allfile - excep), ofd1)