use of cfml.parsing.cfscript.CFMember in project CFLint by cflint.
the class CFLint method process.
/**
* @param expression
* CF expression
* @param elem
* Jericho HTML element
* @param oldcontext
* The previous context
*/
private void process(final CFExpression expression, final Element elem, final Context oldcontext) {
if (expression != null) {
final Context context = oldcontext.subContext(elem);
for (final CFLintScanner plugin : extensions) {
try {
plugin.expression(expression, context, bugs);
for (final ContextMessage message : context.getMessages()) {
reportRule(elem, expression, context, plugin, message);
}
context.getMessages().clear();
} catch (final Exception e) {
printException(e);
reportRule(elem, expression, context, plugin, PLUGIN_ERROR);
}
}
// Handle a few expression types in a special fashion.
if (expression instanceof CFVarDeclExpression) {
handler.addVariable(((CFVarDeclExpression) expression).getName());
}
// CFIdentifier should not decompose
if (expression.getClass().equals(CFIdentifier.class)) {
final String name = ((CFIdentifier) expression).getName();
handler.checkVariable(name);
}
if (expression instanceof CFStructElementExpression) {
final Context assignmentContext = context.subContext(elem);
// assignmentContext.setInAssignmentExpression(true);
handler.push(CF.STRUCT);
process(((CFStructElementExpression) expression).getKey(), elem, assignmentContext);
handler.pop();
process(((CFStructElementExpression) expression).getValue(), elem, context);
} else if (expression instanceof CFVarDeclExpression) {
final Context assignmentContext = context.subContext(elem);
assignmentContext.setInAssignmentExpression(true);
process(((CFVarDeclExpression) expression).getVar(), elem, assignmentContext);
// Right hand side is handled below. Left hand side gets a
// special context.
process(((CFVarDeclExpression) expression).getInit(), elem, context);
// Only process function call expressions
} else if (expression instanceof CFAssignmentExpression && !(expression instanceof CFTernaryExpression)) {
final Context assignmentContext = context.subContext(elem);
assignmentContext.setInAssignmentExpression(true);
process(((CFAssignmentExpression) expression).getLeft(), elem, assignmentContext);
// Right hand side is handled below. Left hand side gets a
// special context.
process(((CFAssignmentExpression) expression).getRight(), elem, context);
// Only process function call expressions
} else if (expression instanceof CFFullVarExpression) {
final CFFullVarExpression fullVarExpression = (CFFullVarExpression) expression;
if (context.isInAssignmentExpression() && new CFScopes().isScoped(fullVarExpression, "local") && fullVarExpression.getExpressions().size() > 1) {
handler.addVariable(fullVarExpression.getExpressions().get(1).Decompile(0));
}
final Context subContext = context.subContext(context.getElement());
subContext.setInAssignmentExpression(false);
for (final CFExpression expr : fullVarExpression.getExpressions()) {
if (expr instanceof CFFunctionExpression) {
process(expr, elem, subContext);
}
if (expr instanceof CFMember) {
process(((CFMember) expr).getExpression(), elem, subContext);
}
if (expr instanceof CFArrayExpression) {
final CFArrayExpression aryExpr = (CFArrayExpression) expr;
if (!aryExpr.getElements().isEmpty()) {
process(aryExpr.getElements().get(0), elem, subContext);
}
}
}
} else {
// Loop into all relevant nested (child) expressions.
for (final CFExpression child : expression.decomposeExpression()) {
process(child, elem, context.subContextInAssignment(false));
}
}
}
}
use of cfml.parsing.cfscript.CFMember in project CFLint by cflint.
the class UnusedLocalVarChecker method expression.
//protected Map<String, Integer> variableLineNo = new HashMap<String, Integer>();
@Override
public void expression(final CFExpression expression, final Context context, final BugList bugs) {
if (expression instanceof CFFullVarExpression) {
final CFFullVarExpression fullVarExpression = (CFFullVarExpression) expression;
final CFExpression variable = fullVarExpression.getExpressions().get(0);
if (variable instanceof CFIdentifier) {
final String name = ((CFIdentifier) variable).getName();
if (!scopes.isCFScoped(name)) {
localVariables.put(name.toLowerCase(), new VarInfo(name, true));
} else if (scopes.isLocalScoped(name) && fullVarExpression.getExpressions().size() > 1) {
final CFExpression variable2 = fullVarExpression.getExpressions().get(1);
if (variable2 instanceof CFIdentifier) {
final String namepart = ((CFIdentifier) variable2).getName();
localVariables.put(namepart.toLowerCase(), new VarInfo(namepart, true));
}
}
}
for (CFExpression subexpr : ((CFFullVarExpression) expression).getExpressions()) {
if (subexpr instanceof CFMember) {
CFMember memberExpr = (CFMember) subexpr;
if (memberExpr.getExpression() != null) {
expression(memberExpr.getExpression(), context, bugs);
}
}
}
} else if (expression instanceof CFVarDeclExpression) {
final String name = ((CFVarDeclExpression) expression).getName();
final int lineNo = expression.getLine() + context.startLine() - 1;
addLocalVariable(name, lineNo);
} else if (expression instanceof CFIdentifier) {
final String name = ((CFIdentifier) expression).getName();
if (name != null) {
localVariables.put(name.toLowerCase(), new VarInfo(name, true));
}
}
}
Aggregations