From c13d71c5f42dbd9080dd8dcdbed4590f601b7f7b Mon Sep 17 00:00:00 2001 From: andykdy Date: Thu, 24 Jan 2019 22:29:17 -0800 Subject: [PATCH 01/11] Initial Python commit --- ast_parser.py | 12 ++++++++++++ diff_parser.py | 18 ++++++++++++++++++ diff_result.py | 41 +++++++++++++++++++++++++++++++++++++++++ main.py | 26 ++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 ast_parser.py create mode 100644 diff_parser.py create mode 100644 diff_result.py create mode 100644 main.py diff --git a/ast_parser.py b/ast_parser.py new file mode 100644 index 0000000..cc76b29 --- /dev/null +++ b/ast_parser.py @@ -0,0 +1,12 @@ +# *Goal* +# Parse an AST to return all the declared variables in the following format +# {int}{myInt} +# {string}{myInt} +# {Foo}{myFooObject} +# + + +class ASTParser: + def __init__(self, foobar): + self.foobar = foobar + print("ASTParser created") diff --git a/diff_parser.py b/diff_parser.py new file mode 100644 index 0000000..cba2c1e --- /dev/null +++ b/diff_parser.py @@ -0,0 +1,18 @@ +# *Goal* +# Parse a diff files in the most efficient way possible. +# Keep these in mind, speed, maintainability, evolvability, etc.... +# Compute the following +# - List of files in the diffs +# - number of regions +# - number of lines added +# - number of lines deleted +# - list of function calls seen in the diffs and their number of calls + + +class DiffParser: + def __init__(self): + print("DiffParser created") + def parse(self, file): + lines = file.readlines() + for line in lines: + print(line) diff --git a/diff_result.py b/diff_result.py new file mode 100644 index 0000000..e398d9d --- /dev/null +++ b/diff_result.py @@ -0,0 +1,41 @@ +class DiffResult: + class __DiffResult: + def __init__(self): + self.files = [] + self.regions = 0 + self.lineAdded = 0 + self.lineDeleted = 0 + self.functionCalls = {} + print("DiffResult created") + instance = None + + def __init__(self): + if not DiffResult.instance: + DiffResult.instance = DiffResult.__DiffResult() + else: + DiffResult.instance.files = [] + DiffResult.instance.regions = 0 + DiffResult.instance.lineAdded = 0 + DiffResult.instance.lineDeleted = 0 + DiffResult.instance.functionCalls = {} + +def toText(): + with open('diffResult.txt', 'w') as output: + output.write("Files: \n") + for file in DiffResult.files: + output.write(" -") + output.write(file) + output.write("\n") + output.write("Regions: " + DiffResult.regions + "\n") + output.write("Lines Added: " + DiffResult.lineAdded + "\n") + output.write("Lines Deleted: " + DiffResult.lineDeleted + "\n") + for key,value in DiffResult.functionCalls.items(): + output.write(" -") + output.write(key + ": " + value) + output.write("\n") + + + + + + diff --git a/main.py b/main.py new file mode 100644 index 0000000..b0ea147 --- /dev/null +++ b/main.py @@ -0,0 +1,26 @@ +import argparse +from diff_parser import DiffParser +from ast_parser import ASTParser + + +def main(): + if part == "1": + print("Running Part 1 - Parsing diff files from... diffs/" + filename + "\n") + diffParser = DiffParser() + with open("diffs/" + filename) as file: + diffParser.parse(file) + + + + elif part == "2": + print("Running Part 2 - AST ") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('-p', '--part', required=True) + parser.add_argument('-f', '--filename') + args = parser.parse_args() + part = args.part + filename = args.filename + main() From 1c36624d5c9f7dc4c48534e9faa7cea2cddedfb0 Mon Sep 17 00:00:00 2001 From: andykdy Date: Thu, 24 Jan 2019 23:17:52 -0800 Subject: [PATCH 02/11] Deleting Go files --- Gopkg.lock | 9 --------- Gopkg.toml | 22 ---------------------- astResult.go | 34 ---------------------------------- diffResult.go | 50 -------------------------------------------------- main.go | 47 ----------------------------------------------- 5 files changed, 162 deletions(-) delete mode 100644 Gopkg.lock delete mode 100644 Gopkg.toml delete mode 100644 astResult.go delete mode 100644 diffResult.go delete mode 100644 main.go diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index bef2d00..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,9 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "ab4fef131ee828e96ba67d31a7d690bd5f2f42040c6766b1b12fe856f87e0ff7" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 9425a54..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,22 +0,0 @@ - -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - diff --git a/astResult.go b/astResult.go deleted file mode 100644 index 345ea18..0000000 --- a/astResult.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "bytes" - "fmt" -) - -//astResult contains the result of the AST analysis -type astResult struct { - //array of all variable declarations - variablesDeclarations []variableDescription -} - -type variableDescription struct { - //type name, in a short version, ex: int, float, Foo... - typeName string - //variable name - varName string -} - -//String returns the value of results as a formatted string -func (v *variableDescription) String() string { - return fmt.Sprintf("{%s}{%s}", v.varName, v.typeName) -} - -//String returns the value of results as a formatted string -func (r *astResult) String() string { - var buffer bytes.Buffer - for _, e := range r.variablesDeclarations { - buffer.WriteString(fmt.Sprintf("%s\n", e.String())) - } - - return buffer.String() -} diff --git a/diffResult.go b/diffResult.go deleted file mode 100644 index 95943c5..0000000 --- a/diffResult.go +++ /dev/null @@ -1,50 +0,0 @@ -package main - -import ( - "bytes" - "strconv" -) - -//result contains an analysis of a set of commit -type diffResult struct { - //The name of the files seen - files []string - //How many region we have (i.e. seperated by @@) - regions int - //How many line were added total - lineAdded int - //How many line were deleted totla - lineDeleted int - //How many times the function seen in the code are called. - functionCalls map[string]int -} - -//String returns the value of results as a formated string -func (r *diffResult) String() string { - - var buffer bytes.Buffer - buffer.WriteString("Files: \n") - for _, file := range r.files { - buffer.WriteString(" -") - buffer.WriteString(file) - buffer.WriteString("\n") - } - r.appendIntValueToBuffer(r.regions, "Regions", &buffer) - r.appendIntValueToBuffer(r.lineAdded, "LA", &buffer) - r.appendIntValueToBuffer(r.lineDeleted, "LD", &buffer) - - buffer.WriteString("Functions calls: \n") - for key, value := range r.functionCalls { - r.appendIntValueToBuffer(value, key, &buffer) - } - - return buffer.String() -} - -//appendIntValueToBuffer appends int value to a bytes buffer -func (r diffResult) appendIntValueToBuffer(value int, label string, buffer *bytes.Buffer) { - buffer.WriteString(label) - buffer.WriteString(" : ") - buffer.WriteString(strconv.Itoa(value)) - buffer.WriteString("\n") -} diff --git a/main.go b/main.go deleted file mode 100644 index ac77289..0000000 --- a/main.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "fmt" - "time" -) - -//timeTrack tracks the time it took to do things. -//It's a convenient method that you can use everywhere -//you feel like it -func timeTrack(start time.Time, name string) { - elapsed := time.Since(start) - fmt.Printf("%s took %s\n", name, elapsed) -} - -//main is the entry point of our go program. It defers -//the execution of timeTrack so we can know how long it -//took for the main to complete. -//It also calls the compute and output the returned struct -//to stdout. -func main() { - defer timeTrack(time.Now(), "compute diff") - fmt.Println(computeDiff()) - - defer timeTrack(time.Now(), "compute AST") - fmt.Println(computeAST()) -} - -//compute parses the git diffs in ./diffs and returns -//a diffResult struct that contains all the relevant informations -//about these diffs -// list of files in the diffs -// number of regions -// number of line added -// number of line deleted -// list of function calls seen in the diffs and their number of calls -func computeDiff() *diffResult { - - return nil -} - -//computeAST go through the AST and returns -//a astResult struct that contains all the variable declarations -func computeAST() *astResult { - - return nil -} From 95cc23c0eb962a213e360cd9ee7555a3c663af6a Mon Sep 17 00:00:00 2001 From: andykdy Date: Wed, 30 Jan 2019 00:51:37 -0800 Subject: [PATCH 03/11] regex for Regions and corrected diff results --- .idea/vcs.xml | 6 ++++++ diff_parser.py | 21 +++++++++++++++++++- diff_result.py | 53 +++++++++++++++++++------------------------------- main.py | 3 ++- 4 files changed, 48 insertions(+), 35 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/diff_parser.py b/diff_parser.py index cba2c1e..4d221b8 100644 --- a/diff_parser.py +++ b/diff_parser.py @@ -1,3 +1,6 @@ +import re +from diff_result import DiffResult + # *Goal* # Parse a diff files in the most efficient way possible. # Keep these in mind, speed, maintainability, evolvability, etc.... @@ -10,9 +13,25 @@ class DiffParser: + def __init__(self): print("DiffParser created") + def parse(self, file): + # Regex Patterns + fileListRgx = r'' + regionRgx = r'(@@) -\d+,\d+ \+\d+,\d+ (@@)[^\n]*' + addedRgx = r'' + deletedRgx = r'' + fnListRgx = r'' + + # Object holding results + diffRes = DiffResult() + lines = file.readlines() for line in lines: - print(line) + if re.match(regionRgx, line): + diffRes.regions += 1 + + return diffRes + diff --git a/diff_result.py b/diff_result.py index e398d9d..849b6a5 100644 --- a/diff_result.py +++ b/diff_result.py @@ -1,38 +1,25 @@ class DiffResult: - class __DiffResult: - def __init__(self): - self.files = [] - self.regions = 0 - self.lineAdded = 0 - self.lineDeleted = 0 - self.functionCalls = {} - print("DiffResult created") - instance = None - def __init__(self): - if not DiffResult.instance: - DiffResult.instance = DiffResult.__DiffResult() - else: - DiffResult.instance.files = [] - DiffResult.instance.regions = 0 - DiffResult.instance.lineAdded = 0 - DiffResult.instance.lineDeleted = 0 - DiffResult.instance.functionCalls = {} - -def toText(): - with open('diffResult.txt', 'w') as output: - output.write("Files: \n") - for file in DiffResult.files: - output.write(" -") - output.write(file) - output.write("\n") - output.write("Regions: " + DiffResult.regions + "\n") - output.write("Lines Added: " + DiffResult.lineAdded + "\n") - output.write("Lines Deleted: " + DiffResult.lineDeleted + "\n") - for key,value in DiffResult.functionCalls.items(): - output.write(" -") - output.write(key + ": " + value) - output.write("\n") + self.files = [] + self.regions = 0 + self.lineAdded = 0 + self.lineDeleted = 0 + self.functionCalls = {} + + def toText(self): + with open('diffResult.txt', 'w') as output: + output.write("Files: \n") + for file in self.files: + output.write(" -") + output.write(file) + output.write("\n") + output.write("Regions: " + str(self.regions) + "\n") + output.write("Lines Added: " + str(self.lineAdded) + "\n") + output.write("Lines Deleted: " + str(self.lineDeleted) + "\n") + for key,value in self.functionCalls.items(): + output.write(" -") + output.write(key + ": " + value) + output.write("\n") diff --git a/main.py b/main.py index b0ea147..d31b934 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,8 @@ def main(): print("Running Part 1 - Parsing diff files from... diffs/" + filename + "\n") diffParser = DiffParser() with open("diffs/" + filename) as file: - diffParser.parse(file) + result = diffParser.parse(file) + result.toText() From 5da7be3a913c18b7504e0ce37106a190b3eab912 Mon Sep 17 00:00:00 2001 From: Andy Kim Date: Wed, 30 Jan 2019 12:25:57 -0800 Subject: [PATCH 04/11] addline and deleteline --- diff_parser.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/diff_parser.py b/diff_parser.py index 4d221b8..1cdeb41 100644 --- a/diff_parser.py +++ b/diff_parser.py @@ -19,19 +19,33 @@ def __init__(self): def parse(self, file): # Regex Patterns - fileListRgx = r'' - regionRgx = r'(@@) -\d+,\d+ \+\d+,\d+ (@@)[^\n]*' - addedRgx = r'' - deletedRgx = r'' - fnListRgx = r'' + filelist_rgx = r'' + region_rgx = r'^(@@) -\d+,\d+ \+\d+,\d+ (@@)[^\n]*' + added_rgx = r'^(\+){1}[^\n]*' + added_files = r'^(\+\+\+){1}( )[^\n]*' + deleted_rgx = r'^(\-){1}[^\n]*' + added_files = r'^(\-\-\-){1}( )[^\n]*' + fnList_rgx = r'' # Object holding results - diffRes = DiffResult() + diff_res = DiffResult() lines = file.readlines() for line in lines: - if re.match(regionRgx, line): - diffRes.regions += 1 + if re.match(region_rgx, line): + diff_res.regions += 1 + if re.match(added_rgx, line): + diff_res.lineAdded += 1 + if re.match(deleted_rgx, line): + diff_res.lineDeleted += 1 + if re.match(added_files, line): + diff_res.lineAdded -= 1 + if re.match(deleted_rgx, line): + diff_res.lineDeleted -= 1 + + + + return diff_res + - return diffRes From 6b7c1c9821ab8cca14a47ffdb4dd93c11721c798 Mon Sep 17 00:00:00 2001 From: Andy Kim Date: Sat, 2 Feb 2019 00:10:23 -0800 Subject: [PATCH 05/11] files regex partial --- diff_parser.py | 11 +++++------ diffs/diff4.diff | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 diffs/diff4.diff diff --git a/diff_parser.py b/diff_parser.py index 1cdeb41..907dc70 100644 --- a/diff_parser.py +++ b/diff_parser.py @@ -19,12 +19,12 @@ def __init__(self): def parse(self, file): # Regex Patterns - filelist_rgx = r'' + filelist_rgx = r'diff --git ([^\n]*)' region_rgx = r'^(@@) -\d+,\d+ \+\d+,\d+ (@@)[^\n]*' added_rgx = r'^(\+){1}[^\n]*' added_files = r'^(\+\+\+){1}( )[^\n]*' deleted_rgx = r'^(\-){1}[^\n]*' - added_files = r'^(\-\-\-){1}( )[^\n]*' + deleted_files = r'^(\-\-\-){1}( )[^\n]*' fnList_rgx = r'' # Object holding results @@ -32,6 +32,8 @@ def parse(self, file): lines = file.readlines() for line in lines: + if re.match(filelist_rgx, line): + print(re.search(filelist_rgx, line)) if re.match(region_rgx, line): diff_res.regions += 1 if re.match(added_rgx, line): @@ -40,11 +42,8 @@ def parse(self, file): diff_res.lineDeleted += 1 if re.match(added_files, line): diff_res.lineAdded -= 1 - if re.match(deleted_rgx, line): + if re.match(deleted_files, line): diff_res.lineDeleted -= 1 - - - return diff_res diff --git a/diffs/diff4.diff b/diffs/diff4.diff new file mode 100644 index 0000000..0156033 --- /dev/null +++ b/diffs/diff4.diff @@ -0,0 +1,27 @@ +*TEST FILE FOR DIFF* + + +diff --git a/Documentation/accelerators/ocxl.rst b/Documentation/accelerators/ocxl.rst +index 4f7af84..ddcc58d 100644 +--- a/Documentation/accelerators/ocxl.rst ++++ b/Documentation/accelerators/ocxl.rst +@@ -152,6 +152,11 @@ OCXL_IOCTL_IRQ_SET_FD: + Associate an event fd to an AFU interrupt so that the user process + can be notified when the AFU sends an interrupt. + ++OCXL_IOCTL_GET_METADATA: ++ ++ Obtains configuration information from the card, such at the size of ++ MMIO areas, the AFU version, and the PASID for the current context. ++ +- +- +- +--testing +-testing +---testing +------------------- +- continued line + - on the next place with a + + sign +@@ \ No newline at end of file From 160e8e7c4ce8dd7ce4ffe09bb8daac080896e582 Mon Sep 17 00:00:00 2001 From: andykdy Date: Sat, 2 Feb 2019 01:12:15 -0800 Subject: [PATCH 06/11] part 1 complete TODO refactor for SOLID principles --- diff_parser.py | 9 +++++++-- diff_result.py | 9 +++++---- diffs/diff4.diff | 41 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/diff_parser.py b/diff_parser.py index 907dc70..3776217 100644 --- a/diff_parser.py +++ b/diff_parser.py @@ -25,7 +25,7 @@ def parse(self, file): added_files = r'^(\+\+\+){1}( )[^\n]*' deleted_rgx = r'^(\-){1}[^\n]*' deleted_files = r'^(\-\-\-){1}( )[^\n]*' - fnList_rgx = r'' + fnList_rgx = r'[^\n]*int ([a-z,A-Z,0-9,_]*)' # Object holding results diff_res = DiffResult() @@ -33,7 +33,8 @@ def parse(self, file): lines = file.readlines() for line in lines: if re.match(filelist_rgx, line): - print(re.search(filelist_rgx, line)) + for filepath in re.search(filelist_rgx, line).group(1).split(" "): + diff_res.files.append(filepath) if re.match(region_rgx, line): diff_res.regions += 1 if re.match(added_rgx, line): @@ -44,6 +45,10 @@ def parse(self, file): diff_res.lineAdded -= 1 if re.match(deleted_files, line): diff_res.lineDeleted -= 1 + if re.match(fnList_rgx, line): + print(re.search(fnList_rgx, line).group(0)) + diff_res.functionCalls[re.search(fnList_rgx, line).group(1)] += 1 + print(diff_res.functionCalls) return diff_res diff --git a/diff_result.py b/diff_result.py index 849b6a5..9c4fb6d 100644 --- a/diff_result.py +++ b/diff_result.py @@ -1,24 +1,25 @@ +from collections import defaultdict class DiffResult: def __init__(self): self.files = [] self.regions = 0 self.lineAdded = 0 self.lineDeleted = 0 - self.functionCalls = {} + self.functionCalls = defaultdict(int) def toText(self): with open('diffResult.txt', 'w') as output: output.write("Files: \n") for file in self.files: - output.write(" -") + output.write(" - ") output.write(file) output.write("\n") output.write("Regions: " + str(self.regions) + "\n") output.write("Lines Added: " + str(self.lineAdded) + "\n") output.write("Lines Deleted: " + str(self.lineDeleted) + "\n") for key,value in self.functionCalls.items(): - output.write(" -") - output.write(key + ": " + value) + output.write(" - ") + output.write(key + ": " + str(value)) output.write("\n") diff --git a/diffs/diff4.diff b/diffs/diff4.diff index 0156033..bd5ab9d 100644 --- a/diffs/diff4.diff +++ b/diffs/diff4.diff @@ -24,4 +24,43 @@ index 4f7af84..ddcc58d 100644 - continued line - on the next place with a + sign -@@ \ No newline at end of file +@@ +diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c +index 3a2ca0f..d0c34df 100644 +--- a/drivers/cpufreq/acpi-cpufreq.c ++++ b/drivers/cpufreq/acpi-cpufreq.c +@@ -629,7 +629,7 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c) + if (c->x86_vendor == X86_VENDOR_INTEL) { + if ((c->x86 == 15) && + (c->x86_model == 6) && +- (c->x86_mask == 8)) { ++ (c->x86_stepping == 8)) { + pr_info("Intel(R) Xeon(R) 7100 Errata AL30, processors may lock up on frequency changes: disabling acpi-cpufreq\n"); + return -ENODEV; + } +diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c +index 3a2ca0f..d0c34df 100644 +--- a/drivers/cpufreq/acpi-cpufreq.c ++++ b/drivers/cpufreq/acpi-cpufreq.c +@@ -629,7 +629,7 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c) + if (c->x86_vendor == X86_VENDOR_INTEL) { + if ((c->x86 == 15) && + (c->x86_model == 6) && +- (c->x86_mask == 8)) { ++ (c->x86_stepping == 8)) { + pr_info("Intel(R) Xeon(R) 7100 Errata AL30, processors may lock up on frequency changes: disabling acpi-cpufreq\n"); + return -ENODEV; + } +diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c +index 3a2ca0f..d0c34df 100644 +--- a/drivers/cpufreq/acpi-cpufreq.c ++++ b/drivers/cpufreq/acpi-cpufreq.c +@@ -629,7 +629,7 @@ static int bcpi_cpufreq_blacklist(struct cpuinfo_x86 *c) + if (c->x86_vendor == X86_VENDOR_INTEL) { + if ((c->x86 == 15) && + (c->x86_model == 6) && +- (c->x86_mask == 8)) { ++ (c->x86_stepping == 8)) { + pr_info("Intel(R) Xeon(R) 7100 Errata AL30, processors may lock up on frequency changes: disabling acpi-cpufreq\n"); + return -ENODEV; + } \ No newline at end of file From 4d6bb13caaab50773cac019542968860cdc47190 Mon Sep 17 00:00:00 2001 From: Andy Kim Date: Mon, 4 Feb 2019 16:44:50 -0800 Subject: [PATCH 07/11] changes for Feb 4th and addition of thoughts.md --- Thoughts.md | 11 +++++++++++ diff_parser.py | 27 ++++++++++----------------- diff_result.py | 1 + main.py | 2 -- 4 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 Thoughts.md diff --git a/Thoughts.md b/Thoughts.md new file mode 100644 index 0000000..aba8c59 --- /dev/null +++ b/Thoughts.md @@ -0,0 +1,11 @@ +A place to convey my thoughts. + +Feb 4th 2019\ +DiffParser is mostly "complete" functionally speaking but some of the regex are hard coded and untested.\ +Before moving to ASTParser I will do a small check. Then once both AST and Diff are complete, I will do another sweep to refactor the code.\ +- I tried allowing users to input a flag they wanted to log information on, but allowing users to manipulate the regex seems to be opening up the program a bit too much, instead the information should be kept within\ +- Is there any way I can group the list of "if" statements? \ +- I think I have misunderstood what functionCalls is asking for. TODO\ +- Commas are optional for regions\ +- Replaced [^n]* with .* +- For some reason it catches 196480 in * (0x007d0000-0x00800000) starting at offset 196480 (0x2ff80). as a function call.\ diff --git a/diff_parser.py b/diff_parser.py index 3776217..81e3237 100644 --- a/diff_parser.py +++ b/diff_parser.py @@ -19,37 +19,30 @@ def __init__(self): def parse(self, file): # Regex Patterns - filelist_rgx = r'diff --git ([^\n]*)' - region_rgx = r'^(@@) -\d+,\d+ \+\d+,\d+ (@@)[^\n]*' - added_rgx = r'^(\+){1}[^\n]*' - added_files = r'^(\+\+\+){1}( )[^\n]*' - deleted_rgx = r'^(\-){1}[^\n]*' - deleted_files = r'^(\-\-\-){1}( )[^\n]*' - fnList_rgx = r'[^\n]*int ([a-z,A-Z,0-9,_]*)' + filelist_rgx = r'^diff --[^\s]* (.*)' + region_rgx = r'^(@@) -\d+(,\d+)? \+\d+(,\d+)? (@@).*' + added_rgx = r'^(\+).*' + deleted_rgx = r'^(\-).*' + fnList_rgx = r'[^\n]*[^\s^\n]* ([a-z,A-Z,0-9,_, ]+)[(]' # Object holding results diff_res = DiffResult() lines = file.readlines() + area_start = 0 for line in lines: if re.match(filelist_rgx, line): for filepath in re.search(filelist_rgx, line).group(1).split(" "): diff_res.files.append(filepath) + area_start = 4 if re.match(region_rgx, line): diff_res.regions += 1 - if re.match(added_rgx, line): + if re.match(added_rgx, line) and area_start < 0: diff_res.lineAdded += 1 - if re.match(deleted_rgx, line): + if re.match(deleted_rgx, line) and area_start < 0: diff_res.lineDeleted += 1 - if re.match(added_files, line): - diff_res.lineAdded -= 1 - if re.match(deleted_files, line): - diff_res.lineDeleted -= 1 if re.match(fnList_rgx, line): - print(re.search(fnList_rgx, line).group(0)) diff_res.functionCalls[re.search(fnList_rgx, line).group(1)] += 1 - print(diff_res.functionCalls) + area_start -= 1 return diff_res - - diff --git a/diff_result.py b/diff_result.py index 9c4fb6d..ab215ed 100644 --- a/diff_result.py +++ b/diff_result.py @@ -17,6 +17,7 @@ def toText(self): output.write("Regions: " + str(self.regions) + "\n") output.write("Lines Added: " + str(self.lineAdded) + "\n") output.write("Lines Deleted: " + str(self.lineDeleted) + "\n") + output.write("Function Calls: \n") for key,value in self.functionCalls.items(): output.write(" - ") output.write(key + ": " + str(value)) diff --git a/main.py b/main.py index d31b934..de40f9e 100644 --- a/main.py +++ b/main.py @@ -11,8 +11,6 @@ def main(): result = diffParser.parse(file) result.toText() - - elif part == "2": print("Running Part 2 - AST ") From d4db93765a271212e3c216093a2afa48db839054 Mon Sep 17 00:00:00 2001 From: Andy Kim Date: Sat, 16 Feb 2019 22:21:37 -0800 Subject: [PATCH 08/11] ASTParser start --- Thoughts.md | 8 +++++++- ast_parser.py | 42 +++++++++++++++++++++++++++++++++++++++--- ast_result.py | 22 ++++++++++++++++++++++ diffs/diff4.diff | 17 ++++++++++++++++- main.py | 5 +++++ 5 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 ast_result.py diff --git a/Thoughts.md b/Thoughts.md index aba8c59..92e5f96 100644 --- a/Thoughts.md +++ b/Thoughts.md @@ -5,7 +5,13 @@ DiffParser is mostly "complete" functionally speaking but some of the regex are Before moving to ASTParser I will do a small check. Then once both AST and Diff are complete, I will do another sweep to refactor the code.\ - I tried allowing users to input a flag they wanted to log information on, but allowing users to manipulate the regex seems to be opening up the program a bit too much, instead the information should be kept within\ - Is there any way I can group the list of "if" statements? \ -- I think I have misunderstood what functionCalls is asking for. TODO\ +- I think I have misunderstood what functionCalls is asking for.\ - Commas are optional for regions\ - Replaced [^n]* with .* - For some reason it catches 196480 in * (0x007d0000-0x00800000) starting at offset 196480 (0x2ff80). as a function call.\ + +Feb 16th 2019\ +DiffParser FunctionCall is still incorrect, but I have moved on to ASTParser.\ +ASTParser seems relatively simple, because we are only looking for declared variables. +- Recursive traversal of AST should return a node instead of variable_declaration +- Should variable_declaration be in ast_result? Would a tuple suffice? diff --git a/ast_parser.py b/ast_parser.py index cc76b29..08cec9b 100644 --- a/ast_parser.py +++ b/ast_parser.py @@ -1,5 +1,8 @@ +import json +from ast_result import ASTResult, variable_description + # *Goal* -# Parse an AST to return all the declared variables in the following format +# Parse an AST to return all the declared variables in the following format # {int}{myInt} # {string}{myInt} # {Foo}{myFooObject} @@ -7,6 +10,39 @@ class ASTParser: - def __init__(self, foobar): - self.foobar = foobar + def __init__(self): print("ASTParser created") + + def parse(self, file): + y = json.load(file) + ast_res = ASTResult() + root = y['Root'] + resultlist = [] + traverseSearch(root, 'VariableDeclaration', resultlist) + ast_res.variableDeclarations = resultlist + return ast_res + + +def traverseSearch(root,lookfor, resultList): + for child in root['Children']: + if child['Type'] == lookfor: + resultList.append(variableDecl(child)) + else: + traverseSearch(child,lookfor, resultList) + + +def variableDecl(node): + varName, varType = "", "" + for i,child in enumerate(node['Children']): + if child['Type'] == 'VariableDeclarator': + varName = child['Children'][0]['ValueText'] + if child['Type'] == 'PredefinedType': + varType = child['Children'][0]['ValueText'] + # if varType == "": + # foobar = [] + # traverseSearch(child, 'PredefinedType', foobar) + # if foobar: + # varType = foobar[0]['Children'][0]['ValueText'] + return variable_description(varName,varType) + + diff --git a/ast_result.py b/ast_result.py new file mode 100644 index 0000000..1c25a04 --- /dev/null +++ b/ast_result.py @@ -0,0 +1,22 @@ +class ASTResult: + def __init__(self): + self.variableDeclarations = [] + + def addVariable(self, typeName, varName): + self.variableDeclarations.append(variable_description(typeName,varName)) + + def toText(self): + with open('astResult.txt', 'w') as output: + for variable in self.variableDeclarations: + output.write(variable.toString() + "\n") + + +class variable_description: + def __init__(self, typeName, varName): + # type name, in a short version, ex: int, float, Foo... + self.typeName = typeName + # variable name + self.varName = varName + + def toString(self): + return "{" + self.varName + "}{" + self.typeName + "}" diff --git a/diffs/diff4.diff b/diffs/diff4.diff index bd5ab9d..f45e4c6 100644 --- a/diffs/diff4.diff +++ b/diffs/diff4.diff @@ -63,4 +63,19 @@ index 3a2ca0f..d0c34df 100644 + (c->x86_stepping == 8)) { pr_info("Intel(R) Xeon(R) 7100 Errata AL30, processors may lock up on frequency changes: disabling acpi-cpufreq\n"); return -ENODEV; - } \ No newline at end of file + } ++void dell_smbios_unregister_device(struct device *d) ++{ ++ struct smbios_device *priv; ++ ++ mutex_lock(&smbios_mutex); ++ list_for_each_entry(priv, &smbios_device_list, list) { ++ if (priv->device == d) { ++ list_del(&priv->list); ++ put_device(d); ++ break; ++ } ++ } ++ mutex_unlock(&smbios_mutex); ++ dev_dbg(d, "Remove device: %s\n", d->driver->name); ++} \ No newline at end of file diff --git a/main.py b/main.py index de40f9e..7f7a797 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,11 @@ def main(): elif part == "2": print("Running Part 2 - AST ") + astParser = ASTParser() + with open("ast/" + filename) as file: + result = astParser.parse(file) + + result.toText() if __name__ == "__main__": From 9c0c07010ee7d9be8a4e51202f1341aff3ab87d5 Mon Sep 17 00:00:00 2001 From: andykdy Date: Thu, 21 Feb 2019 17:37:06 -0800 Subject: [PATCH 09/11] Final Commit --- Thoughts.md | 4 ++++ ast_parser.py | 37 ++++++++++++++++--------------------- ast_result.py | 16 +--------------- diff_parser.py | 14 +++++++------- diffs/diff4.diff | 29 ++++++++++++++++++++++++++++- main.py | 1 - 6 files changed, 56 insertions(+), 45 deletions(-) diff --git a/Thoughts.md b/Thoughts.md index 92e5f96..2e527b8 100644 --- a/Thoughts.md +++ b/Thoughts.md @@ -15,3 +15,7 @@ DiffParser FunctionCall is still incorrect, but I have moved on to ASTParser.\ ASTParser seems relatively simple, because we are only looking for declared variables. - Recursive traversal of AST should return a node instead of variable_declaration - Should variable_declaration be in ast_result? Would a tuple suffice? + +Feb 21st 2019\ +DiffParser is complete, but functionCall captures "8" as a functional when parsing assembly offset such as 8(%rdi). +ASTParser is complete, not sure if the tree traversal is too hardcoded. \ No newline at end of file diff --git a/ast_parser.py b/ast_parser.py index 08cec9b..0fb5b3a 100644 --- a/ast_parser.py +++ b/ast_parser.py @@ -1,5 +1,5 @@ import json -from ast_result import ASTResult, variable_description +from ast_result import ASTResult # *Goal* # Parse an AST to return all the declared variables in the following format @@ -17,32 +17,27 @@ def parse(self, file): y = json.load(file) ast_res = ASTResult() root = y['Root'] - resultlist = [] - traverseSearch(root, 'VariableDeclaration', resultlist) - ast_res.variableDeclarations = resultlist + varNodes = [] + traverseSearch(root, 'VariableDeclaration', varNodes) + ast_res.variableDeclarations = nodeToVar(varNodes) return ast_res +def nodeToVar(varNodes): + newList = [] + for node in varNodes: + newList.append((findVal(node, 'PredefinedType'), findVal(node, 'VariableDeclarator'))) + return newList def traverseSearch(root,lookfor, resultList): for child in root['Children']: if child['Type'] == lookfor: - resultList.append(variableDecl(child)) + resultList.append(child) else: - traverseSearch(child,lookfor, resultList) - - -def variableDecl(node): - varName, varType = "", "" - for i,child in enumerate(node['Children']): - if child['Type'] == 'VariableDeclarator': - varName = child['Children'][0]['ValueText'] - if child['Type'] == 'PredefinedType': - varType = child['Children'][0]['ValueText'] - # if varType == "": - # foobar = [] - # traverseSearch(child, 'PredefinedType', foobar) - # if foobar: - # varType = foobar[0]['Children'][0]['ValueText'] - return variable_description(varName,varType) + traverseSearch(child, lookfor, resultList) +def findVal(varNode, searchFor): + found = [] + traverseSearch(varNode, searchFor, found) + if found: + return found[0]['Children'][0]['ValueText'] diff --git a/ast_result.py b/ast_result.py index 1c25a04..6f3ecab 100644 --- a/ast_result.py +++ b/ast_result.py @@ -2,21 +2,7 @@ class ASTResult: def __init__(self): self.variableDeclarations = [] - def addVariable(self, typeName, varName): - self.variableDeclarations.append(variable_description(typeName,varName)) - def toText(self): with open('astResult.txt', 'w') as output: for variable in self.variableDeclarations: - output.write(variable.toString() + "\n") - - -class variable_description: - def __init__(self, typeName, varName): - # type name, in a short version, ex: int, float, Foo... - self.typeName = typeName - # variable name - self.varName = varName - - def toString(self): - return "{" + self.varName + "}{" + self.typeName + "}" + output.write("{" + variable[0] + "}{" + variable[1] + "}\n") diff --git a/diff_parser.py b/diff_parser.py index 81e3237..9eed8a5 100644 --- a/diff_parser.py +++ b/diff_parser.py @@ -20,10 +20,10 @@ def __init__(self): def parse(self, file): # Regex Patterns filelist_rgx = r'^diff --[^\s]* (.*)' - region_rgx = r'^(@@) -\d+(,\d+)? \+\d+(,\d+)? (@@).*' + region_rgx = r'^@@ -\d+(,\d+)? \+\d+(,\d+)? @@.*' added_rgx = r'^(\+).*' deleted_rgx = r'^(\-).*' - fnList_rgx = r'[^\n]*[^\s^\n]* ([a-z,A-Z,0-9,_, ]+)[(]' + fnList_rgx = r'(?<=(?:\s|\.))([\w]+)(?=\()' # Object holding results diff_res = DiffResult() @@ -31,17 +31,17 @@ def parse(self, file): lines = file.readlines() area_start = 0 for line in lines: - if re.match(filelist_rgx, line): + if re.search(filelist_rgx, line): for filepath in re.search(filelist_rgx, line).group(1).split(" "): diff_res.files.append(filepath) area_start = 4 - if re.match(region_rgx, line): + if re.search(region_rgx, line): diff_res.regions += 1 - if re.match(added_rgx, line) and area_start < 0: + if re.search(added_rgx, line) and area_start < 0: diff_res.lineAdded += 1 - if re.match(deleted_rgx, line) and area_start < 0: + if re.search(deleted_rgx, line) and area_start < 0: diff_res.lineDeleted += 1 - if re.match(fnList_rgx, line): + if re.search(fnList_rgx, line): diff_res.functionCalls[re.search(fnList_rgx, line).group(1)] += 1 area_start -= 1 return diff_res diff --git a/diffs/diff4.diff b/diffs/diff4.diff index f45e4c6..c9b7101 100644 --- a/diffs/diff4.diff +++ b/diffs/diff4.diff @@ -78,4 +78,31 @@ index 3a2ca0f..d0c34df 100644 + } + mutex_unlock(&smbios_mutex); + dev_dbg(d, "Remove device: %s\n", d->driver->name); -+} \ No newline at end of file ++} +- pushq %rdi /* pt_regs->di */ ++ pushq 6*8(%rdi) /* regs->ss */ ++ pushq 5*8(%rdi) /* regs->rsp */ ++ pushq 4*8(%rdi) /* regs->eflags */ ++ pushq 3*8(%rdi) /* regs->cs */ ++ pushq 2*8(%rdi) /* regs->ip */ ++ pushq 1*8(%rdi) /* regs->orig_ax */ +- "pushf \n\t" +- "push %es \n\t" +- "push %ds \n\t" +- "pop %es \n\t" +- "movl 8(%ebp),%eax \n\t" +- "movl 4(%eax),%ebx \n\t" +- "movl 8(%eax),%ecx \n\t" +- "movl 12(%eax),%edx \n\t" +- "movl 16(%eax),%esi \n\t" +- "movl 20(%eax),%edi \n\t" +- "movl (%eax),%eax \n\t" +- "push %cs \n\t" +- "call *12(%ebp) \n\t" +- "pushf \n\t" +- "pushl %eax \n\t" +- "movl 8(%ebp),%eax \n\t" +- "movl %ebx,4(%eax) \n\t" +- "movl %ecx,8(%eax) \n\t" +- "movl %edx,12(%eax) \n\t" +- "movl %esi,16(%eax) \n\t" \ No newline at end of file diff --git a/main.py b/main.py index 7f7a797..f9a6d5a 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,6 @@ def main(): astParser = ASTParser() with open("ast/" + filename) as file: result = astParser.parse(file) - result.toText() From f95e4d7cd9e016e67e85693915688e9aed23f5d5 Mon Sep 17 00:00:00 2001 From: andykdy Date: Thu, 21 Feb 2019 18:13:52 -0800 Subject: [PATCH 10/11] added documentation and included array in astParser --- ast_parser.py | 24 ++++++++++++++++++------ diff_parser.py | 4 ++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ast_parser.py b/ast_parser.py index 0fb5b3a..6024459 100644 --- a/ast_parser.py +++ b/ast_parser.py @@ -6,28 +6,37 @@ # {int}{myInt} # {string}{myInt} # {Foo}{myFooObject} -# class ASTParser: def __init__(self): print("ASTParser created") + # Load JSON file into dictionary and parse def parse(self, file): y = json.load(file) ast_res = ASTResult() root = y['Root'] varNodes = [] - traverseSearch(root, 'VariableDeclaration', varNodes) - ast_res.variableDeclarations = nodeToVar(varNodes) + traverseSearch(root, 'VariableDeclaration', varNodes) # Returns a list of nodes from the AST that are variables + ast_res.variableDeclarations = nodeToVar(varNodes) # Parses each variable node to a variable tuple and returns a list of tuples return ast_res +# Converts each variable node to a variable tuple def nodeToVar(varNodes): newList = [] for node in varNodes: - newList.append((findVal(node, 'PredefinedType'), findVal(node, 'VariableDeclarator'))) + isArray = [] + traverseSearch(node, 'ArrayCreationExpression', isArray) + varType = findVal(node, 'PredefinedType') + varName = findVal(node, 'VariableDeclarator') + if isArray: + varType += "[]" + newList.append((varType, varName)) return newList +# Recursive traversal of AST to find a node with Type == lookfor +# Appends all nodes that match to resultList which is maintained because python is pass by reference def traverseSearch(root,lookfor, resultList): for child in root['Children']: if child['Type'] == lookfor: @@ -35,9 +44,12 @@ def traverseSearch(root,lookfor, resultList): else: traverseSearch(child, lookfor, resultList) -def findVal(varNode, searchFor): +# Use traverseSearch() to find... +# Variable Name found under node VariableDeclarator +# Variable Type found under node PredefinedType +def findVal(varNode, lookFor): found = [] - traverseSearch(varNode, searchFor, found) + traverseSearch(varNode, lookFor, found) if found: return found[0]['Children'][0]['ValueText'] diff --git a/diff_parser.py b/diff_parser.py index 9eed8a5..47a19a6 100644 --- a/diff_parser.py +++ b/diff_parser.py @@ -29,6 +29,10 @@ def parse(self, file): diff_res = DiffResult() lines = file.readlines() + # Lines such as + # +++ + # --- + # are caught in the regex for added lines, having a "bubble" after a region starts allows us to manually filter those out. area_start = 0 for line in lines: if re.search(filelist_rgx, line): From f3f8853b343faf9e5562e6dd9ddccc01cca43cc2 Mon Sep 17 00:00:00 2001 From: Andy Kim Date: Mon, 4 Mar 2019 12:15:33 -0800 Subject: [PATCH 11/11] Addressing code review. Fixed duplicate filelist. Code adheres to PEP8 conventions --- .idea/vcs.xml | 6 ----- ast_parser.py | 69 ++++++++++++++++++++++++++++---------------------- ast_result.py | 2 +- diff_parser.py | 19 +++++++++----- diff_result.py | 3 ++- main.py | 14 +++++----- 6 files changed, 62 insertions(+), 51 deletions(-) delete mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/ast_parser.py b/ast_parser.py index 6024459..69873e2 100644 --- a/ast_parser.py +++ b/ast_parser.py @@ -12,44 +12,53 @@ class ASTParser: def __init__(self): print("ASTParser created") - # Load JSON file into dictionary and parse def parse(self, file): - y = json.load(file) + """ Load JSON file into dictionary and parse """ + tree_json = json.load(file) ast_res = ASTResult() - root = y['Root'] - varNodes = [] - traverseSearch(root, 'VariableDeclaration', varNodes) # Returns a list of nodes from the AST that are variables - ast_res.variableDeclarations = nodeToVar(varNodes) # Parses each variable node to a variable tuple and returns a list of tuples + root = tree_json['Root'] + var_nodes = [] + # Returns a list of nodes from the AST that are variables + traverse_search(root, 'VariableDeclaration', var_nodes) + # Parses each variable node to a variable tuple and returns a list of tuples + ast_res.variableDeclarations = node_to_var(var_nodes) return ast_res -# Converts each variable node to a variable tuple -def nodeToVar(varNodes): - newList = [] - for node in varNodes: - isArray = [] - traverseSearch(node, 'ArrayCreationExpression', isArray) - varType = findVal(node, 'PredefinedType') - varName = findVal(node, 'VariableDeclarator') - if isArray: - varType += "[]" - newList.append((varType, varName)) - return newList - -# Recursive traversal of AST to find a node with Type == lookfor -# Appends all nodes that match to resultList which is maintained because python is pass by reference -def traverseSearch(root,lookfor, resultList): + +def node_to_var(var_nodes): + """Converts each variable node to a variable tuple""" + var_array = [] + for node in var_nodes: + array_variables = [] + traverse_search(node, 'ArrayCreationExpression', array_variables) + var_type = find_val(node, 'PredefinedType') + var_name = find_val(node, 'VariableDeclarator') + if array_variables: + var_type += "[]" + var_array.append((var_type, var_name)) + return var_array + + +def traverse_search(root, look_for, result_list): + """ + Recursive traversal of AST to find a node with Type == lookfor + Appends all nodes that match to resultList which is maintained because python is pass by reference + """ for child in root['Children']: - if child['Type'] == lookfor: - resultList.append(child) + if child['Type'] == look_for: + result_list.append(child) else: - traverseSearch(child, lookfor, resultList) + traverse_search(child, look_for, result_list) + -# Use traverseSearch() to find... -# Variable Name found under node VariableDeclarator -# Variable Type found under node PredefinedType -def findVal(varNode, lookFor): +def find_val(var_node, look_for): + """ + Use traverseSearch() to find... + Variable Name found under node VariableDeclarator + Variable Type found under node PredefinedType + """ found = [] - traverseSearch(varNode, lookFor, found) + traverse_search(var_node, look_for, found) if found: return found[0]['Children'][0]['ValueText'] diff --git a/ast_result.py b/ast_result.py index 6f3ecab..4ba7b46 100644 --- a/ast_result.py +++ b/ast_result.py @@ -2,7 +2,7 @@ class ASTResult: def __init__(self): self.variableDeclarations = [] - def toText(self): + def to_text(self): with open('astResult.txt', 'w') as output: for variable in self.variableDeclarations: output.write("{" + variable[0] + "}{" + variable[1] + "}\n") diff --git a/diff_parser.py b/diff_parser.py index 47a19a6..d827c9e 100644 --- a/diff_parser.py +++ b/diff_parser.py @@ -1,5 +1,6 @@ import re from diff_result import DiffResult +from difflib import SequenceMatcher # *Goal* # Parse a diff files in the most efficient way possible. @@ -23,7 +24,7 @@ def parse(self, file): region_rgx = r'^@@ -\d+(,\d+)? \+\d+(,\d+)? @@.*' added_rgx = r'^(\+).*' deleted_rgx = r'^(\-).*' - fnList_rgx = r'(?<=(?:\s|\.))([\w]+)(?=\()' + fnlist_rgx = r'(?<=(?:\s|\.))([\w]+)(?=\()' # Object holding results diff_res = DiffResult() @@ -32,12 +33,18 @@ def parse(self, file): # Lines such as # +++ # --- - # are caught in the regex for added lines, having a "bubble" after a region starts allows us to manually filter those out. + # are caught in the regex for added lines + # having a "bubble" after a region starts allows us to manually filter those out. area_start = 0 for line in lines: if re.search(filelist_rgx, line): - for filepath in re.search(filelist_rgx, line).group(1).split(" "): - diff_res.files.append(filepath) + path_a = re.search(filelist_rgx, line).group(1).split(" ")[0] + path_b = re.search(filelist_rgx, line).group(1).split(" ")[1] + if len(path_a) is 0 or len(path_b) is 0: + raise ValueError + match = SequenceMatcher(None, path_a, path_b).find_longest_match(0, len(path_a), 0, len(path_b)) + diff_res.files.append(path_a[match.a: match.a + match.size]) + area_start = 4 if re.search(region_rgx, line): diff_res.regions += 1 @@ -45,8 +52,8 @@ def parse(self, file): diff_res.lineAdded += 1 if re.search(deleted_rgx, line) and area_start < 0: diff_res.lineDeleted += 1 - if re.search(fnList_rgx, line): - diff_res.functionCalls[re.search(fnList_rgx, line).group(1)] += 1 + if re.search(fnlist_rgx, line): + diff_res.functionCalls[re.search(fnlist_rgx, line).group(1)] += 1 area_start -= 1 return diff_res diff --git a/diff_result.py b/diff_result.py index ab215ed..07ec436 100644 --- a/diff_result.py +++ b/diff_result.py @@ -1,4 +1,5 @@ from collections import defaultdict + class DiffResult: def __init__(self): self.files = [] @@ -7,7 +8,7 @@ def __init__(self): self.lineDeleted = 0 self.functionCalls = defaultdict(int) - def toText(self): + def to_text(self): with open('diffResult.txt', 'w') as output: output.write("Files: \n") for file in self.files: diff --git a/main.py b/main.py index f9a6d5a..1a169a3 100644 --- a/main.py +++ b/main.py @@ -6,23 +6,23 @@ def main(): if part == "1": print("Running Part 1 - Parsing diff files from... diffs/" + filename + "\n") - diffParser = DiffParser() + diff_parser = DiffParser() with open("diffs/" + filename) as file: - result = diffParser.parse(file) - result.toText() + result = diff_parser.parse(file) + result.to_text() elif part == "2": print("Running Part 2 - AST ") - astParser = ASTParser() + ast_parser = ASTParser() with open("ast/" + filename) as file: - result = astParser.parse(file) - result.toText() + result = ast_parser.parse(file) + result.to_text() if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('-p', '--part', required=True) - parser.add_argument('-f', '--filename') + parser.add_argument('-f', '--filename', required=True) args = parser.parse_args() part = args.part filename = args.filename