CS3215 - Software Engineering Project
CS3215 - Software Engineering Project
Engineering Project
Team 8 – Static Program Analyzer
Presentation – Purpose
To highlight USPs of Team8’s SPA
“To show how unique we are and why we chose to
be so”
Robust
Capable of handling parse exceptions
Detailed Reporting using the global Exception
class
The Parser – Exceptions
Exceptions reported
Token Mismatch
Reports found and expected tokens and the line number
Invalid Variable Name
Empty Program or Empty Statement List
Procedure calling itself (Direct Recursion)
Called procedure is not found
Multiple procedures having the same identifier (name)
‘Crucial-Entity’ Relationship
CacheTable
Tables Tables
CFG API
AST API
Design Focus
Speed - Data structures must enable quick data retrieval
thereby aiding in the speed of the query in a small way
Extensibility
Data is handled by the Modifies, Uses (friends) and Variable Table APIs
y 1 17, 18, 19 - R -
z 2 - 4, 5, 7, 8, 9 - P
i 3 24, 25 4, 5, 7, 8, 9 P R, Q
PKB – Variable Table (3/3)
Variable Table = Hash_Map(Variable Name, Variable Vector)
Extensibility
Assume new relationship Coexist(variable, variable)
So, there is a relationship R such that entity ‘variable’ is one of
the arguments.
Two new columns need to be added to the Variable Table.
variable_coexisting, variable_coexisted
Generic View: <entity_relationship>
“Structure accommodates change” – Extensible design
PKB – ModifiesTable (1/3)
‘Hash Map with a Vector Key’
Key is a vector of two values (variable being modified and identifier of the
entity modifying the variable (From the entity table)
Speed is guaranteed
y 1 001
Varname 3
Taken from Variable Table
y 0000000000000000000000100
PKB – ModifiesTable (3/3)
Modifies Table = Hash_Map(<vector> Modifies Key, Modifies Vector)
Extensibility
Assume new entity Function such that Modifies is extended to
include Modifies(Function, variable)
Modifies Table neither be changed nor a new Modifies Table
be created
“Structure accommodates change” – Extensible design
PKB API – The ‘Narrow Passage’
Approach (1/3)
PKB API methods are covered by a ‘wrapper interface’
Query Processor Access
Restricted to the Entity Table, Relationship Table and the ‘wrapper’
interface – ‘Narrow Passage’
Interface
relationshipHandler(relationship, <vector> arguments)
withHandler(<vector> arguments)
patternHandler(<vector> arguments, pattern)
Fails as Pre-computation time and PKB space depend of the program size
and number of queries, Q
S, T is proportional to Q, N
Our Cache Table introduces the Q factor for design abstractions computed on
demand – “Don’t pre-compute, store when calculated”
PKB Optimization – Cache Table (4/4)
Global Parameters
CACHE, 0 or 1
CACHE_MAX_QUERIES, 0 to max
MIN_CALLS_CACHE_OPEN, 0 to max
Extremely useful when the User knows the number of queries that will be entered in a
particular ‘Querier’ session. (Which is the case mostly)
Cache miss doesn’t cost much as the Cache table is also a hash map.
Cache Table = Hash_map(QueryObj, QueryResult);
2 stmtList
3 stmt stmt# integer 1, 2, 3 … 25
4 assign stmt# integer 2, 4, 5, …
5 call stmt# integer 4, 3
6 while stmt# integer 6, 9
7 if stmt# integer 10
8, 9, 10 plus, minus,
times
11 variable varName name x, y, z, i
12 constant value value
13 program line stmt# integer 1, 2, 3 … 25
Number of fields under Type, Entity
varies with the number of arguments
Relationship Table
Index Name Arguments Type1 Type2 Entity1 Entity2
Case 2 and 3,
a) Non-constant is placeholder.
b) Non-constant is in ‘Select’ values.
c) Non-constant is not in ‘Select’ values.
Query Evaluation Strategy
Case 4,
a) Both non-constant are the same
i. Placeholder
ii. ‘Select’ values
iii. Non-’Select’ values
b) Both non-constant are different
i. Placeholder in either argument
ii. Both arguments in ‘Select’ values
iii. ‘Select’ value in either argument
iv. Both arguments not in ‘Select’ values
Query Evaluation Strategy
Variables not in ‘Select’ and ‘Relationship’
clauses, but are in ‘With’ and ‘Pattern’
clauses.
E.g. “Stmt s, s1; Select s such that
Follows(2,s) with s1.stmt#=5”
Query Pre-Processor
Validates queries
Transforms query string into query tree for
efficiency of query optimization and evaluation
Example Query
assign a, a1; stmt s, s1; Select <a, s> such
that Follows(a, s) and Next*(a1, s1) with
s.stmt# = 1 pattern a(_, _”x+z”_)
Query Validation
Rules for PQL:
Grammar table using static regular expressions
Rules for relationships and entities stored in static
“tables”, e.g. RelTable, EntTable
Rules are not “hardcoded”
Query Validation
Check full syntax of query
All variable synonyms are checked against
declared variable map
Relationships are checked for correct number
of arguments, correct type of arguments, and
non-ambiguity
Attribute references must correspond to those
of variable synonyms
Query Parsing
Regex expressions in grammar table are used
to extract parts of query
Parsing is recursive, similar to parsing of
SIMPLE source code
As parsing is done, query tree is built
PQL Optimization
Basic strategy
Reordering relationships for optimal linear
evaluation of relationships from left to right
Left: Most restrictive
Right: Least restrictive
Priority given to joins between relationships
compared to crosses between relationships
PQL Optimization
Order by relationship types
Follows vs. Affects
Order by number of occurrences for
relationship argument types
Follows*(a1, a2) vs. Follows*(a1, s1)
Order by combinations of variables and
constants as relationship arguments
Modifies(“First”, “x”) vs. Modifies(p, v)
Order by number of output variables with
relationship arguments
Select <a, s> …; Follows(a1, s1) vs. Follows(a, s)