-
Notifications
You must be signed in to change notification settings - Fork 4
Abstract API
FausticSun edited this page Apr 14, 2019
·
10 revisions
Exposes interfaces to the SPA.
VOID parseSIMPLEFile(STRING filename)
// Parses the SIMPLE source code located at filename, extracting design abstractions and storing them in the PKB
VOID evaluateQuery(STRING query, LIST<STRING> RESULTS)
// Parses the query and answer it using information stored in the PKB and writes the results to the passed in results listTakes in the SIMPLE source code or PQL query and tokenize it.
LIST<TOKEN> tokenize(STRING code)
// Parses the SIMPLE source code or PQL query and return a list of tokens corresponding to the given source code/queryContain the parsers for SIMPLE and PQL, and an expression parser used by both
PKB parseSIMPLE(LIST<TOKEN> tokens)
// Parses the list of tokens and return a PKB containg the base facts of the given tokenized program. Throws an error if there are any systax errors in the SIMPLE progrma.
QUERY parsePQL(LIST<TOKEN> tokens)
// Parses the list of tokens and return a query object that encodes the given tokenized PQL query. Throws an error if there are syntactic or semantic errors in the PQL query.
LIST<TOKEN> parseExpr(LIST<TOKEN> tokens)
// Parses the list of tokens and return the expression in postfix format. Throws an error if the tokens are not a valid expression.Takes in the prefilled PKB, deriving addtional facts and filling the same PKB with them.
void populateDesigns(PKB pkb)
// Use the existing base facts in the PKB to derive derived facts and fill the PKB with the derived facts. Throws an error if there are any semantic errors in the given PKB such as cyclic calls and calling non-existant procedures.Takes in a Query and PKB and query the PKB to answer the Query.
void executeQuery(QUERY query, LIST<STRING> results)
// Answers the given query using information in the given PKB and writes the results in the passed in results listStores the knowledge of a single SIMPLE source code and exposes interfaces to store and query these knowledge
//// Entity setters
VOID setVar(STRING var)
// Inserts var into the varTable. Do nothing if var already exists.
VOID setProc(STRING proc, INT startStmtNo, INT endStmtNo)
// Adds an entry to the procTable with proc as key and {startStmtNo, endStmtNo} as value. Throws an error if proc already exists.
VOID setStatement(INT statementNo, STATEMENT_TYPE stmtType)
// Adds an entry to the stmtTable with statementNo as key and stmtType as value
VOID setConstant(INT cons)
// Insert cons into the constTable. Do nothing if cons already exists.
//// Relation setters
VOID setFollows(INT s1, INT s2)
// Adds an entry to the followsTable with {s1, s2}
VOID setFollowsT(INT s1, INT s2)
// Adds an entry to the followsTTable with {s1, s2}
VOID setParent(INT s1, INT s2)
// Adds an entry to the parentTable with {s1, s2}
VOID setParentT(INT s1, INT s2)
// Adds an entry to the parentTTable with {s1, s2}
VOID setUses(INT s, STRING v)
// Adds an entry to the usesSTable with {s, v}
VOID setUses(STRING p, STRING v)
// Adds an entry to the usesPTable with {p, v}
VOID setModifies(INT s, STRING v)
// Adds an entry to the modifiesSTable with {s, v}
VOID setModifies(STRING p, STRING v)
// Adds an entry to the modifiesPTable with {p, v}
VOID setCalls(STRING p1, STRING p2)
// Adds an entry to the callsTable with {p1, p2}
VOID setCallsT(STRING p1, STRING p2)
// Adds an entry to the callsTTable with {p1, p2}
VOID setNext(INT s1, INT s2)
// Adds an entry to the nextTable with {s1, s2}
//// Pattern setters
VOID setAssign(INT s, STRING v, STRING expr)
// Adds an entry to the assignTable with s as the key and {v, expr} as the value
VOID setIf(INT s, STRING v)
// Adds an entry to the ifTable with {s, v}
VOID setWhile(INT s, STRING v)
// Adds an entry to the whileTable with {s, v}
//// Other setters
VOID setCallProcName(INT s, STRING p)
// Adds an entry to the callProcNameTable with {s, p}
VOID setCFG(CFG cfg)
// Sets the CFG in the PKB to cfg
//// Entity getters
TABLE getVarTable()
// Returns a table with a 1 column containing the variables
TABLE getProcTable()
// Returns a table with 1 column containing the procedures
TABLE getConstTable()
// Returns a table with 1 column containing the constants
TABLE getStmtType(STATEMENT_TYPE type)
// Returns a table with 1 column containing the statement number of statements of type type
//// Relation getters
TABLE getFollows()
// Returns a table with 2 columns containing the follows relations
TABLE getFollowsT()
// Returns a table with 2 columns containing the follows* relations
TABLE getParent()
// Returns a table with 2 columns containing the parent relations
TABLE getParentT()
// Returns a table with 2 columns containing the parent* relations
TABLE getUsesS()
// Returns a table with 2 columns containing the uses relations with statement numbers in the first column
TABLE getUsesP()
// Returns a table with 2 columns containing the uses relations with proc names in the first column
TABLE getModifiesS()
// Returns a table with 2 columns containing the modifies relations with statement numbers in the first column
TABLE getModifiesP()
// Returns a table with 2 columns containing the modifies relations with proc names in the first column
TABLE getCalls()
// Returns a table with 2 columns containing the calls relations
TABLE getCallsT()
// Returns a table with 2 columns containing the calls* relations
TABLE getNext()
// Returns a table with 2 columns containing the next relations
BOOL isNextT(INT n1, INT n2)
// Returns true if next*(n1, n2), false otherwise
TABLE getNextT(INT n, BOOL isLeft)
// Returns a table with 1 column containing the next*(n, _) relations if isLeft is true or next*(_, n) relations otherwise
TABLE getNextT()
// Returns a table with 2 columns containing the next* relations
BOOL isAffects(INT a1, INT a2)
// Returns true if affects(a1, a2), false otherwise
TABLE getAffects(INT a, BOOL isLeft)
// Returns a table with 1 column containing the affects(a, _) relations if isLeft is true or affects(_, a) relations otherwise
TABLE getAffects()
// Returns a table with 2 columns containing the affects relations
TABLE getAffectsT()
// Returns a table with 2 columns containing the affects* relations
// Pattern getters
TABLE getAssignMatches(STRING expr, BOOL isPartialMatch)
// Returns a table with 2 columns with the first column being the assignment statements that have an expression partial or full matching with expr depending on isPartialMatch and the second column containing the corresponding variable modified by the assignment statement
TABLE getWhileMatches()
// Returns a table with 2 columns containing uses relations where the statement is of type while and the variazle is used in the coodition of the corresponding while statement
TABLE getIfMatches()
// Returns a table with 2 columns containing uses relations where the statement is of type if and the variable is used in the condition of the corresponding if statement
Takes in a some information from PKB and build a CFG. Exposes interfaces to query Next*, Affects and Affects* relations.
BOOL isNextT(INT n1, INT n2)
// Returns true if next*(n1, n2), false otherwise
TABLE getNextT(INT n, BOOL isLeft)
// Returns a table with 1 column containing the next*(n, _) or next*(_, n) relations
TABLE getNextT()
// Returns a table with 2 columns containing all next* relations
BOOL isAffects(INT a1, INT a2)
// Returns true if affects(a1, a2), false otherwise
TABLE getAffects(INT a, BOOL isLeft)
// Returns a table with 1 column containing the affects(a, _) or affects(_, n) relations
TABLE getAffects()
// Returns a table with 2 columns containing the affects relations
TABLE getAffectsT()
// Returns a table with 2 columns containing the affects* relations