Skip to content

Conversation

@andykdy
Copy link

@andykdy andykdy commented Feb 22, 2019

Hello, I have implemented a solution for your challenge using Python.

Part 1: Diff Logger

Instruction : python -p 1 -f <location of diff file>

There is a regex pattern for each stat being logged.
Each line of the diff file is checked using each pattern.
Depending on the stat, a counter is incremented, a value is appended to a list, or both in the case of function calls.

Known problems:

functionCalls will catch offsets from assembly code as a function call.
e.g. In the line
- "movl 8(%ebp),%eax \n\t"
'8' will be noted as a function call which isn't correct.

Possible improvement:

I could see a modular approach to this question where each stat being recorded could be compartmentalized with its own regex pattern and method of storage.

For example,
Stat Name : Lineadded
Regex Pattern : ^(\+).*
When Found: Increment

This way, the user could create new stats easily without having to change the code allowing extension but not modification.

Part 2: Variable declarations in Abstract Syntax Tree

Instruction : python -p 2 -f <astChallenge.json>

All variables are located within a 'VariableDeclaration' node, thus the code traverses through the AST recursively and stores all 'VariableDeclaration' nodes to a list.
Each 'VariableDeclaration' node in the list is then converted into a tuple.
The name of the variable is found under VariableDeclarator while the type of the variable is found under PredefinedType.

Copy link

@lbajolet lbajolet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it's concise, and the results are close to what is expected (the file list needs a rework)
The runtime looks ok to me, ~400ms for diff1; I guess a full run on all files takes ~450ms, a note on performance might have been nice though.
The commit's contents and messages look off in a few places (160e8e7 especially comes to mind).

Sorry for the delay for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants