Giter Site home page Giter Site logo

qa-static-analyzer's Introduction

Static Analyzer Tool Project

Supervisor: Doc. Mustafa Assaf
(Team 12) Members:

  • Reema Khaseeb - 11924143
  • Yara Abu-Odeh - 11926410
  • Zubaida Sadder - 11925174

Written in Python.
11 - March - 2022

Description:

This project reads a text file that contains a code in Python. It analysis it based on the following:

  • Magic Number
  • Division by zero
  • Number of parameters
  • Unreachable code.

The code in the text file have different issues from the all of the above cases.
NOTES When writing the code :

  1. Add a space between operations (e.g: x == 10)
  2. Add a space before colomns (e.g function definitons: def foo(1,2,3) : )

DEMO Video:

Team 12 demo video link

General Functions

  • read_func : Reads the text file line by line
  • functions_lines : It finds the indicies of the lines.
  • find: It finds a specific string, or a specific line that contains the string.
  • split_by: Splits strings and return them in a list.

Magic Number

We considered the occurance of a magic number after valued in this list ['>', '<', '==','!=', '** ','+', '-', '/','*', 'return'] .
magic_num function checks if there exist a number after one of the values from the list.

Division by zero

Division by zero happens when a value is devided by 0 integer or a variable equals to zero. using DividByZero function.

Number of parameters

When writing functions, the maximum number of parameters is 3. so parameters_number function checks the number of parameters in each function in the code.
Functions appears either in definition or when its called for execution.
These two cases are handeled in parameters_number(filename) that reads the whole code searching for functions names.
After finding the function, get_parameters(func) is used to put the parameters in a list and then count & check them using len_parameters(pars,location) function that prints the error msg as well.

Unreachable Code cases:

  • False condition (if False)
    if the condition in if-statement is 'False' keyword, then it'll never be excecuted that causes Unreachable code warening
Code Explanation:
if the line contains 'if' then it's if-statement, check the condition, if it's 'False' keyword, then the blocks inside that conditon won't be excecuted and unreachable



  • True condition (if)
    if the condition in if-statement is 'True' keyword that is always excecuted, then else-statement will never be excecuted that causes Unreachable code warening
Code Explanation:
if the line contains 'if' then it's if-statement, check the condition, if it's 'True' keyword, then walk through the lines from that line until the next function, when encounter else-statement, then that line and the blocks inside it won't be excecuted and unreachable



  • After return statement
    When return statement is excecuted, it terminates the function call, therefore any line or line comes after return statement inside that function, it won't be excecuted, causing Unreachable code warening
Code Explanation:
if the line contains 'return' , check the next lines, if they're neither else-statement nor definition of a new function, besides not an empty lines, then they will never run they're unreachable



  • Same condition in if and else statement
Code Explanation:
if the line contains 'if' then it's if-statement, store the condition in a varable by removing any leading and trailing spaces, ':', and 'if'. And look for 'elif' condition if found, store its condition in another variable. Now compare both conditions of if-statement and elif-statement, if they're the same, the elif condition will never run as the same condition in if-statement has already been handled

qa-static-analyzer's People

Contributors

reema-khaseeb avatar zubaidasader avatar yaraabuodeh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.