private CodeLineProfile addCodeProfile(string profileVar, CodeLineProfile newCdp) //this.mc can be used here { switch (profileVar) { case "variable": newCdp.numberofVars += this.mc.Count; Console.WriteLine("\tFound {0} variables on line {1}", newCdp.numberofVars, this.curLineNumber); break; case "loop": newCdp.weightIndex += LOOP_CWU; Console.WriteLine("\tFound Loop on line {0}", this.curLineNumber); break; case "functioncall": newCdp.weightIndex += FUNCALL_CWU; Console.WriteLine("\tFound Function call on line {0}", this.curLineNumber); break; case "condition": newCdp.weightIndex += CONDITION_CWU; Console.WriteLine("\tFound condition on line {0}", this.curLineNumber); break; default: newCdp.weightIndex += SEQUENCE_CWU; Console.WriteLine("\tLine {0} is a sequence", this.curLineNumber); break; } ++newCdp.flag; return(newCdp); }
private CodeLineProfile matchPredicate(string code) { //what if it has a loop and condition? then we sum the CWU together CodeLineProfile cdp = new CodeLineProfile(); int stmtMatch = 0; if ((this.mc = Regex.Matches(code, matches["hasVariable"])).Count != 0 || (this.mc = Regex.Matches(code, matches["hasVariableEqual"])).Count != 0 || (this.mc = Regex.Matches(code, matches["hasVariableMore"])).Count != 0 || (this.mc = Regex.Matches(code, matches["hasVariableMore2"])).Count != 0) //matches only one, need to be slpit into more ifs { stmtMatch++; string type = sourceFile.Substring(sourceFile.LastIndexOf(".")); string variableType = ""; foreach (string key in langKeywords[type]) { foreach (Match match in this.mc) { foreach (Capture capture in match.Captures) { variableType = capture.Value.Substring(0, capture.Value.IndexOf(" ")).Trim(); if (key == variableType) { return(cdp); } cdp.weightIndex = 1; } } } cdp = this.addCodeProfile("variable", cdp); } if ((this.mc = Regex.Matches(code, matches["hasLoop"])).Count != 0) { stmtMatch++; cdp = this.addCodeProfile("loop", cdp); } if ((this.mc = Regex.Matches(code, matches["hasFunctionCall"])).Count != 0) { // introduced so as to fix the issue of finding loop,sequence and function call on the same line if (Regex.Match(code, @"(if|switch|else)").Length == 1) { stmtMatch++; cdp = this.addCodeProfile("functioncall", cdp); } } if ((this.mc = Regex.Matches(code, matches["hasCondition"])).Count != 0) { stmtMatch++; cdp = this.addCodeProfile("condition", cdp); } if (stmtMatch == 0) //then its a sequence { cdp = this.addCodeProfile("sequence", cdp); } return(cdp); }