org.eclipse.cdt.codan.checkers_1.0.1.201202111925

16:41:34.923 INFO  jd.cli.Main - Decompiling org.eclipse.cdt.codan.checkers_1.0.1.201202111925.jar
package org.eclipse.cdt.codan.checkers;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;

public class CodanCheckersActivator
  extends Plugin
{
  public static final String PLUGIN_ID = "org.eclipse.cdt.codan.checkers";
  private static CodanCheckersActivator plugin;
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    plugin = this;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    plugin = null;
    super.stop(context);
  }
  
  public static CodanCheckersActivator getDefault()
  {
    return plugin;
  }
  
  public static void log(Throwable e)
  {
    getDefault().getLog().log(getStatus(e));
  }
  
  public static void log(String message)
  {
    getDefault().getLog().log(new Status(4, "org.eclipse.cdt.codan.checkers", message));
  }
  
  public static IStatus getStatus(Throwable e)
  {
    return new Status(4, "org.eclipse.cdt.codan.checkers", e.getLocalizedMessage(), e);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.checkers.CodanCheckersActivator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.internal.checkers.fs;

import java.util.Iterator;
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;

public class ScanfFormatStringSecurityChecker
  extends AbstractIndexAstChecker
{
  private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem";
  private static final VulnerableFunction[] VULNERABLE_FUNCTIONS = {
  
    new VulnerableFunction("scanf", 0, null), 
    new VulnerableFunction("fscanf", 1, null), 
    new VulnerableFunction("fwscanf", 1, null), 
    new VulnerableFunction("wscanf", 0, null), 
    new VulnerableFunction("swscanf", 1, null), 
    new VulnerableFunction("sscanf", 1, null) };
  
  public void processAst(IASTTranslationUnit ast)
  {
    ast.accept(new FormatStringVisitor(null));
  }
  
  private static final class VulnerableFunction
  {
    private final String name;
    private final int formatStringArgumentIndex;
    
    private VulnerableFunction(String name, int formatStringArgumentIndex)
    {
      this.name = name;
      this.formatStringArgumentIndex = formatStringArgumentIndex;
    }
    
    public String getName()
    {
      return name;
    }
    
    public int getFormatStringArgumentIndex()
    {
      return formatStringArgumentIndex;
    }
  }
  
  private class FormatStringVisitor
    extends ASTVisitor
  {
    private FormatStringVisitor()
    {
      shouldVisitExpressions = true;
    }
    
    public int visit(IASTExpression expression)
    {
      if ((expression instanceof IASTFunctionCallExpression))
      {
        IASTFunctionCallExpression callExpression = (IASTFunctionCallExpression)expression;
        ScanfFormatStringSecurityChecker.VulnerableFunction vulnerableFunction = getVulnerableFunctionForExpression(callExpression);
        if (vulnerableFunction == null) {
          return 3;
        }
        IASTInitializerClause[] arguments = callExpression.getArguments();
        int stringArgumentIndex = vulnerableFunction.getFormatStringArgumentIndex();
        detectFaulyArguments(callExpression, arguments, stringArgumentIndex);
      }
      return 3;
    }
    
    private ScanfFormatStringSecurityChecker.VulnerableFunction getVulnerableFunctionForExpression(IASTFunctionCallExpression callExpression)
    {
      String rawSignature = callExpression.getFunctionNameExpression().getRawSignature();
      for (int i = 0; i < ScanfFormatStringSecurityChecker.VULNERABLE_FUNCTIONS.length; i++) {
        if (ScanfFormatStringSecurityChecker.VULNERABLE_FUNCTIONS[i].getName().equals(rawSignature)) {
          return ScanfFormatStringSecurityChecker.VULNERABLE_FUNCTIONS[i];
        }
      }
      return null;
    }
    
    private void detectFaulyArguments(IASTFunctionCallExpression callExpression, IASTInitializerClause[] arguments, int formatStringArgumentIndex)
    {
      IASTInitializerClause formatArgument = arguments[formatStringArgumentIndex];
      String formatArgumentValue = formatArgument.getRawSignature();
      CFormatStringParser formatStringParser = new CFormatStringParser(formatArgumentValue);
      if (!formatStringParser.isVulnerable()) {
        return;
      }
      Iterator<VulnerableFormatStringArgument> vulnerableArgumentsIterator = formatStringParser
        .getVulnerableArgumentsIterator();
      while (vulnerableArgumentsIterator.hasNext())
      {
        VulnerableFormatStringArgument currentArgument = (VulnerableFormatStringArgument)vulnerableArgumentsIterator.next();
        int argumentIndex = currentArgument.getArgumentIndex();
        int argumentSize = currentArgument.getArgumentSize();
        if (argumentSize == -1) {
          reportProblem("org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem", callExpression, new Object[] { callExpression.getRawSignature() });
        }
        int suspectArgumentIndex = 1 + formatStringArgumentIndex + argumentIndex;
        IASTInitializerClause suspectArgument = arguments[suspectArgumentIndex];
        if ((suspectArgument instanceof IASTIdExpression))
        {
          IASTIdExpression idExpression = (IASTIdExpression)suspectArgument;
          IType expressionType = idExpression.getExpressionType();
          if ((expressionType instanceof IArrayType))
          {
            IArrayType arrayExpressionType = (IArrayType)expressionType;
            long arraySize = arrayExpressionType.getSize().numericalValue().longValue();
            if (argumentSize > arraySize) {
              reportProblem("org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem", idExpression, new Object[] { idExpression.getRawSignature() });
            }
          }
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.internal.checkers.fs.ScanfFormatStringSecurityChecker
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.internal.checkers.fs;

import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CFormatStringParser
{
  private static final String DIGIT_PATTERN = "[0-9][0-9]*";
  private static final String STRING_FORMAT_PATTERN = "%[\\*]?[0-9]*[hlL]?[cdeEfgGsuxX]";
  private static final String VULNERABLE_PATTERN = "%[0-9]*s";
  private final Pattern argumentPattern;
  private final Matcher argumentMatcher;
  private final Pattern vulnerablePattern;
  private final Collection<VulnerableFormatStringArgument> vulnerableArguments;
  public static final int ARGUMENT_SIZE_NOT_SPECIFIED = -1;
  
  protected CFormatStringParser(String argument)
  {
    argumentPattern = Pattern.compile("%[\\*]?[0-9]*[hlL]?[cdeEfgGsuxX]");
    argumentMatcher = argumentPattern.matcher(argument);
    vulnerablePattern = Pattern.compile("%[0-9]*s");
    vulnerableArguments = new ConcurrentLinkedQueue();
    extractVulnerableArguments();
  }
  
  public boolean isVulnerable()
  {
    return !vulnerableArguments.isEmpty();
  }
  
  public Iterator<VulnerableFormatStringArgument> getVulnerableArgumentsIterator()
  {
    return vulnerableArguments.iterator();
  }
  
  private void extractVulnerableArguments()
  {
    vulnerableArguments.clear();
    boolean hasMore = argumentMatcher.find();
    int indexOfCurrentArgument = 0;
    while (hasMore)
    {
      String formatString = argumentMatcher.group();
      String matchedArgument = formatString;
      Matcher vulnerabilityMatcher = vulnerablePattern.matcher(matchedArgument);
      boolean isVulnerable = vulnerabilityMatcher.find();
      if (isVulnerable)
      {
        int argumentSize = parseArgumentSize(formatString);
        VulnerableFormatStringArgument vulnerableArgument = new VulnerableFormatStringArgument(indexOfCurrentArgument, 
          formatString, argumentSize);
        vulnerableArguments.add(vulnerableArgument);
      }
      hasMore = argumentMatcher.find();
      indexOfCurrentArgument++;
    }
  }
  
  private int parseArgumentSize(String formatString)
  {
    int argumentSize = -1;
    if (formatString.length() > 2)
    {
      Pattern numberPattern = Pattern.compile("[0-9][0-9]*");
      Matcher numberMatcher = numberPattern.matcher(formatString);
      if (numberMatcher.find())
      {
        String sizeModifierString = numberMatcher.group();
        argumentSize = Integer.parseInt(sizeModifierString);
      }
    }
    return argumentSize;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.internal.checkers.fs.CFormatStringParser
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.internal.checkers.fs;

final class ScanfFormatStringSecurityChecker$VulnerableFunction
{
  private final String name;
  private final int formatStringArgumentIndex;
  
  private ScanfFormatStringSecurityChecker$VulnerableFunction(String name, int formatStringArgumentIndex)
  {
    this.name = name;
    this.formatStringArgumentIndex = formatStringArgumentIndex;
  }
  
  public String getName()
  {
    return name;
  }
  
  public int getFormatStringArgumentIndex()
  {
    return formatStringArgumentIndex;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.internal.checkers.fs.ScanfFormatStringSecurityChecker.VulnerableFunction
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.internal.checkers.fs;

public class VulnerableFormatStringArgument
{
  private final int indexOfArgument;
  private final String argument;
  private final int size;
  
  public VulnerableFormatStringArgument(int indexOfArgument, String rgument, int size)
  {
    this.indexOfArgument = indexOfArgument;
    argument = rgument;
    this.size = size;
  }
  
  public int getArgumentIndex()
  {
    return indexOfArgument;
  }
  
  public String getArgument()
  {
    return argument;
  }
  
  public int getArgumentSize()
  {
    return size;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.internal.checkers.fs.VulnerableFormatStringArgument
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.internal.checkers.fs;

import java.util.Iterator;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;

class ScanfFormatStringSecurityChecker$FormatStringVisitor
  extends ASTVisitor
{
  private ScanfFormatStringSecurityChecker$FormatStringVisitor(ScanfFormatStringSecurityChecker paramScanfFormatStringSecurityChecker)
  {
    shouldVisitExpressions = true;
  }
  
  public int visit(IASTExpression expression)
  {
    if ((expression instanceof IASTFunctionCallExpression))
    {
      IASTFunctionCallExpression callExpression = (IASTFunctionCallExpression)expression;
      ScanfFormatStringSecurityChecker.VulnerableFunction vulnerableFunction = getVulnerableFunctionForExpression(callExpression);
      if (vulnerableFunction == null) {
        return 3;
      }
      IASTInitializerClause[] arguments = callExpression.getArguments();
      int stringArgumentIndex = vulnerableFunction.getFormatStringArgumentIndex();
      detectFaulyArguments(callExpression, arguments, stringArgumentIndex);
    }
    return 3;
  }
  
  private ScanfFormatStringSecurityChecker.VulnerableFunction getVulnerableFunctionForExpression(IASTFunctionCallExpression callExpression)
  {
    String rawSignature = callExpression.getFunctionNameExpression().getRawSignature();
    for (int i = 0; i < ScanfFormatStringSecurityChecker.access$0().length; i++) {
      if (ScanfFormatStringSecurityChecker.access$0()[i].getName().equals(rawSignature)) {
        return ScanfFormatStringSecurityChecker.access$0()[i];
      }
    }
    return null;
  }
  
  private void detectFaulyArguments(IASTFunctionCallExpression callExpression, IASTInitializerClause[] arguments, int formatStringArgumentIndex)
  {
    IASTInitializerClause formatArgument = arguments[formatStringArgumentIndex];
    String formatArgumentValue = formatArgument.getRawSignature();
    CFormatStringParser formatStringParser = new CFormatStringParser(formatArgumentValue);
    if (!formatStringParser.isVulnerable()) {
      return;
    }
    Iterator<VulnerableFormatStringArgument> vulnerableArgumentsIterator = formatStringParser
      .getVulnerableArgumentsIterator();
    while (vulnerableArgumentsIterator.hasNext())
    {
      VulnerableFormatStringArgument currentArgument = (VulnerableFormatStringArgument)vulnerableArgumentsIterator.next();
      int argumentIndex = currentArgument.getArgumentIndex();
      int argumentSize = currentArgument.getArgumentSize();
      if (argumentSize == -1) {
        this$0.reportProblem("org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem", callExpression, new Object[] { callExpression.getRawSignature() });
      }
      int suspectArgumentIndex = 1 + formatStringArgumentIndex + argumentIndex;
      IASTInitializerClause suspectArgument = arguments[suspectArgumentIndex];
      if ((suspectArgument instanceof IASTIdExpression))
      {
        IASTIdExpression idExpression = (IASTIdExpression)suspectArgument;
        IType expressionType = idExpression.getExpressionType();
        if ((expressionType instanceof IArrayType))
        {
          IArrayType arrayExpressionType = (IArrayType)expressionType;
          long arraySize = arrayExpressionType.getSize().numericalValue().longValue();
          if (argumentSize > arraySize) {
            this$0.reportProblem("org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem", idExpression, new Object[] { idExpression.getRawSignature() });
          }
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.internal.checkers.fs.ScanfFormatStringSecurityChecker.FormatStringVisitor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.internal.checkers;

import org.eclipse.cdt.codan.core.cxx.CxxAstUtils;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;

class CaseBreakChecker$SwitchFindingVisitor
  extends ASTVisitor
{
  CaseBreakChecker$SwitchFindingVisitor(CaseBreakChecker paramCaseBreakChecker)
  {
    shouldVisitStatements = true;
  }
  
  protected boolean isBreakOrExitStatement(IASTStatement statement)
  {
    CxxAstUtils utils = CxxAstUtils.getInstance();
    
    return ((statement instanceof IASTBreakStatement)) || ((statement instanceof IASTReturnStatement)) || ((statement instanceof IASTContinueStatement)) || ((statement instanceof IASTGotoStatement)) || (utils.isThrowStatement(statement)) || (utils.isExitStatement(statement));
  }
  
  public int visit(IASTStatement statement)
  {
    if (((statement instanceof IASTSwitchStatement)) && (!CaseBreakChecker.access$0(this$0, statement)))
    {
      IASTSwitchStatement switchStmt = (IASTSwitchStatement)statement;
      IASTStatement body = switchStmt.getBody();
      if ((body instanceof IASTCompoundStatement))
      {
        IASTStatement[] statements = ((IASTCompoundStatement)body).getStatements();
        IASTStatement prevCase = null;
        for (int i = 0; i < statements.length; i++)
        {
          IASTStatement curr = statements[i];
          if ((curr instanceof IASTSwitchStatement)) {
            visit(curr);
          }
          IASTStatement next = null;
          if (i < statements.length - 1) {
            next = statements[(i + 1)];
          }
          if (isCaseStatement(curr)) {
            prevCase = curr;
          }
          if ((prevCase != null) && ((isCaseStatement(next)) || (next == null))) {
            if ((CaseBreakChecker.access$1(this$0).booleanValue()) || (!isCaseStatement(curr)) || (next == null)) {
              if ((CaseBreakChecker.access$2(this$0).booleanValue()) || (next != null)) {
                if ((!CaseBreakChecker.access$0(this$0, prevCase)) && (isFallThroughStamement(curr)))
                {
                  IASTComment comment = null;
                  if (next != null)
                  {
                    comment = this$0.getLeadingComment(next);
                  }
                  else
                  {
                    comment = this$0.getFreestandingComment(statement);
                    if (comment == null) {
                      comment = this$0.getFreestandingComment(body);
                    }
                  }
                  if (comment != null)
                  {
                    String str = this$0.getTrimmedComment(comment);
                    if (str.toLowerCase().contains(CaseBreakChecker.access$3(this$0).toLowerCase())) {}
                  }
                  else
                  {
                    this$0.reportProblem(curr, prevCase);
                  }
                }
              }
            }
          }
        }
      }
      return 1;
    }
    return 3;
  }
  
  public boolean isCaseStatement(IASTStatement statement)
  {
    return ((statement instanceof IASTCaseStatement)) || ((statement instanceof IASTDefaultStatement));
  }
  
  public boolean isFallThroughStamement(IASTStatement body)
  {
    if (body == null) {
      return true;
    }
    if ((body instanceof IASTCompoundStatement))
    {
      IASTStatement[] statements = ((IASTCompoundStatement)body).getStatements();
      if (statements.length > 0) {
        return isFallThroughStamement(statements[(statements.length - 1)]);
      }
      return true;
    }
    if (isBreakOrExitStatement(body)) {
      return false;
    }
    if ((body instanceof IASTExpressionStatement)) {
      return true;
    }
    if ((body instanceof IASTIfStatement))
    {
      IASTIfStatement ifs = (IASTIfStatement)body;
      return (isFallThroughStamement(ifs.getThenClause())) || (isFallThroughStamement(ifs.getElseClause()));
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.internal.checkers.CaseBreakChecker.SwitchFindingVisitor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.internal.checkers;

import org.eclipse.cdt.codan.checkers.CodanCheckersActivator;
import org.eclipse.cdt.codan.core.cxx.CxxAstUtils;
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
import org.eclipse.cdt.codan.core.param.LaunchModeProblemPreference;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;

public class ProblemBindingChecker
  extends AbstractIndexAstChecker
{
  public static String ERR_ID_OverloadProblem = "org.eclipse.cdt.codan.internal.checkers.OverloadProblem";
  public static String ERR_ID_AmbiguousProblem = "org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem";
  public static String ERR_ID_CircularReferenceProblem = "org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem";
  public static String ERR_ID_RedeclarationProblem = "org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem";
  public static String ERR_ID_RedefinitionProblem = "org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem";
  public static String ERR_ID_MemberDeclarationNotFoundProblem = "org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem";
  public static String ERR_ID_LabelStatementNotFoundProblem = "org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem";
  public static String ERR_ID_InvalidTemplateArgumentsProblem = "org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem";
  public static String ERR_ID_TypeResolutionProblem = "org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem";
  public static String ERR_ID_FunctionResolutionProblem = "org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem";
  public static String ERR_ID_InvalidArguments = "org.eclipse.cdt.codan.internal.checkers.InvalidArguments";
  public static String ERR_ID_MethodResolutionProblem = "org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem";
  public static String ERR_ID_FieldResolutionProblem = "org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem";
  public static String ERR_ID_VariableResolutionProblem = "org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem";
  public static String ERR_ID_Candidates = "org.eclipse.cdt.codan.internal.checkers.Candidates";
  
  public boolean runInEditor()
  {
    return true;
  }
  
  public void initPreferences(IProblemWorkingCopy problem)
  {
    super.initPreferences(problem);
    
    getLaunchModePreference(problem).enableInLaunchModes(new CheckerLaunchMode[] { CheckerLaunchMode.RUN_AS_YOU_TYPE, CheckerLaunchMode.RUN_ON_DEMAND });
  }
  
  public void processAst(IASTTranslationUnit ast)
  {
    try
    {
      ast.accept(new ASTVisitor()
      {
        public int visit(IASTName name)
        {
          try
          {
            IBinding binding = name.resolveBinding();
            if ((binding instanceof IProblemBinding))
            {
              IASTNode parentNode = name.getParent();
              if (((parentNode instanceof ICPPASTQualifiedName)) && 
                ((((ICPPASTQualifiedName)parentNode).resolveBinding() instanceof IProblemBinding))) {
                return 3;
              }
              String contextFlagsString = createContextFlagsString(name);
              IProblemBinding problemBinding = (IProblemBinding)binding;
              int id = problemBinding.getID();
              if (id == 2)
              {
                reportProblem(ProblemBindingChecker.ERR_ID_OverloadProblem, name, new Object[] { name.getRawSignature(), contextFlagsString });
                return 3;
              }
              if (id == 4)
              {
                String candidatesString = ProblemBindingChecker.this.getCandidatesString(problemBinding);
                reportProblem(ProblemBindingChecker.ERR_ID_AmbiguousProblem, name, new Object[] { name.getRawSignature(), candidatesString, contextFlagsString });
                return 3;
              }
              if (id == 6)
              {
                IASTNode problemNode;
                IASTNode problemNode;
                String typeString;
                if ((parentNode instanceof IASTFieldReference))
                {
                  IASTExpression ownerExpression = ((IASTFieldReference)parentNode).getFieldOwner();
                  String typeString = ASTTypeUtil.getType(ownerExpression.getExpressionType());
                  problemNode = ownerExpression;
                }
                else
                {
                  problemNode = name;
                  typeString = name.getRawSignature();
                }
                reportProblem(ProblemBindingChecker.ERR_ID_CircularReferenceProblem, problemNode, new Object[] { typeString, contextFlagsString });
                return 3;
              }
              if (id == 12)
              {
                reportProblem(ProblemBindingChecker.ERR_ID_RedeclarationProblem, name, new Object[] { name.getRawSignature(), contextFlagsString });
                return 3;
              }
              if (id == 11)
              {
                reportProblem(ProblemBindingChecker.ERR_ID_RedefinitionProblem, name, new Object[] { name.getRawSignature(), contextFlagsString });
                return 3;
              }
              if (id == 13)
              {
                reportProblem(ProblemBindingChecker.ERR_ID_MemberDeclarationNotFoundProblem, name, new Object[] { contextFlagsString });
                return 3;
              }
              if (id == 9)
              {
                reportProblem(ProblemBindingChecker.ERR_ID_LabelStatementNotFoundProblem, name, new Object[] { name.getRawSignature(), contextFlagsString });
                return 3;
              }
              if (id == 15)
              {
                IASTNode templateName = getTemplateName(name);
                reportProblem(ProblemBindingChecker.ERR_ID_InvalidTemplateArgumentsProblem, templateName, new Object[] { contextFlagsString });
                return 3;
              }
              if (id != 1) {
                return 3;
              }
              if (ProblemBindingChecker.this.isFunctionCall(parentNode)) {
                ProblemBindingChecker.this.handleFunctionProblem(name, problemBinding, contextFlagsString);
              } else if ((parentNode instanceof IASTFieldReference)) {
                ProblemBindingChecker.this.handleMemberProblem(name, parentNode, problemBinding, contextFlagsString);
              } else if ((parentNode instanceof IASTNamedTypeSpecifier)) {
                reportProblem(ProblemBindingChecker.ERR_ID_TypeResolutionProblem, name, new Object[] { name.getRawSignature(), contextFlagsString });
              } else {
                ProblemBindingChecker.this.handleVariableProblem(name, contextFlagsString);
              }
            }
          }
          catch (DOMException e)
          {
            CodanCheckersActivator.log(e);
          }
          return 3;
        }
      });
    }
    catch (Exception e)
    {
      CodanCheckersActivator.log(e);
    }
  }
  
  protected String createContextFlagsString(IASTName name)
  {
    StringBuilder buf = new StringBuilder();
    if (isInClassContext(name)) {
      buf.append(":class");
    }
    if (isInFunctionContext(name)) {
      buf.append(":func");
    }
    return buf.toString();
  }
  
  private boolean isInClassContext(IASTName name)
  {
    CxxAstUtils utils = CxxAstUtils.getInstance();
    if (utils.getEnclosingCompositeTypeSpecifier(name) != null) {
      return true;
    }
    IASTFunctionDefinition function = utils.getEnclosingFunction(name);
    if (function == null) {
      return false;
    }
    IASTDeclarator innermostDeclarator = ASTQueries.findInnermostDeclarator(function.getDeclarator());
    IBinding binding = innermostDeclarator.getName().resolveBinding();
    return binding instanceof ICPPMethod;
  }
  
  private boolean isInFunctionContext(IASTName name)
  {
    CxxAstUtils utils = CxxAstUtils.getInstance();
    IASTFunctionDefinition function = utils.getEnclosingFunction(name);
    return function != null;
  }
  
  private void handleFunctionProblem(IASTName name, IProblemBinding problemBinding, String contextFlagsString)
    throws DOMException
  {
    if (problemBinding.getCandidateBindings().length == 0)
    {
      reportProblem(ERR_ID_FunctionResolutionProblem, name.getLastName(), new Object[] { new String(name.getSimpleID()), contextFlagsString });
    }
    else
    {
      String candidatesString = getCandidatesString(problemBinding);
      reportProblem(ERR_ID_InvalidArguments, name.getLastName(), new Object[] { candidatesString, contextFlagsString });
    }
  }
  
  private void handleMemberProblem(IASTName name, IASTNode parentNode, IProblemBinding problemBinding, String contextFlagsString)
    throws DOMException
  {
    IASTNode parentParentNode = parentNode.getParent();
    
    boolean isMethod = ((parentParentNode instanceof IASTFunctionCallExpression)) && (parentParentNode.getChildren()[0] == parentNode);
    if (isMethod)
    {
      if (problemBinding.getCandidateBindings().length == 0)
      {
        reportProblem(ERR_ID_MethodResolutionProblem, name.getLastName(), new Object[] { new String(name.getSimpleID()), contextFlagsString });
      }
      else
      {
        String candidatesString = getCandidatesString(problemBinding);
        reportProblem(ERR_ID_InvalidArguments, name.getLastName(), new Object[] { candidatesString, contextFlagsString });
      }
    }
    else {
      reportProblem(ERR_ID_FieldResolutionProblem, name.getLastName(), new Object[] { name.getRawSignature(), contextFlagsString });
    }
  }
  
  private void handleVariableProblem(IASTName name, String contextFlagsString)
  {
    reportProblem(ERR_ID_VariableResolutionProblem, name, new Object[] { name.getBinding().getName(), contextFlagsString, name.getRawSignature() });
  }
  
  private boolean isFunctionCall(IASTNode parentNode)
  {
    if ((parentNode instanceof IASTIdExpression))
    {
      IASTIdExpression expression = (IASTIdExpression)parentNode;
      IASTNode parentParentNode = expression.getParent();
      if (((parentParentNode instanceof IASTFunctionCallExpression)) && 
        (expression.getPropertyInParent().getName().equals(IASTFunctionCallExpression.FUNCTION_NAME.getName()))) {
        return true;
      }
    }
    return false;
  }
  
  protected IASTNode getTemplateName(IASTName name)
  {
    IASTName nameToGetTempate = name.getLastName();
    if ((nameToGetTempate instanceof ICPPASTTemplateId)) {
      return ((ICPPASTTemplateId)nameToGetTempate).getTemplateName();
    }
    return nameToGetTempate;
  }
  
  private String getCandidatesString(IProblemBinding problemBinding)
    throws DOMException
  {
    String candidatesString = "\n" + CheckersMessages.ProblemBindingChecker_Candidates + "\n";
    String lastSignature = "";
    IBinding[] arrayOfIBinding;
    int j = (arrayOfIBinding = problemBinding.getCandidateBindings()).length;
    for (int i = 0; i < j; i++)
    {
      IBinding candidateBinding = arrayOfIBinding[i];
      if ((candidateBinding instanceof ICPPFunction))
      {
        ICPPFunction functionBinding = (ICPPFunction)candidateBinding;
        String signature = getFunctionSignature(functionBinding);
        if (!signature.equals(lastSignature))
        {
          candidatesString = candidatesString + signature + "\n";
          lastSignature = signature;
        }
      }
      else if ((candidateBinding instanceof ICPPClassType))
      {
        ICPPClassType classType = (ICPPClassType)candidateBinding;
        ICPPConstructor[] arrayOfICPPConstructor;
        int m = (arrayOfICPPConstructor = classType.getConstructors()).length;
        for (int k = 0; k < m; k++)
        {
          ICPPFunction constructor = arrayOfICPPConstructor[k];
          String signature = getFunctionSignature(constructor);
          if (!signature.equals(lastSignature))
          {
            candidatesString = candidatesString + signature + "\n";
            lastSignature = signature;
          }
        }
      }
    }
    return candidatesString;
  }
  
  private String getFunctionSignature(ICPPFunction functionBinding)
    throws DOMException
  {
    IFunctionType functionType = functionBinding.getType();
    String returnTypeString = ASTTypeUtil.getType(functionBinding.getType().getReturnType()) + " ";
    String functionName = functionBinding.getName();
    String parameterTypeString = ASTTypeUtil.getParameterTypeString(functionType);
    return returnTypeString + functionName + parameterTypeString;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.internal.checkers.ProblemBindingChecker
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.internal.checkers;

import org.eclipse.cdt.codan.core.cxx.CxxAstUtils;
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;

public class StatementHasNoEffectChecker
  extends AbstractIndexAstChecker
{
  public static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem";
  public static final String PARAM_MACRO_ID = "macro";
  public static final String PARAM_EXCEPT_ARG_LIST = "exceptions";
  
  public void processAst(IASTTranslationUnit ast)
  {
    ast.accept(new CheckStmpVisitor());
  }
  
  class CheckStmpVisitor
    extends ASTVisitor
  {
    CheckStmpVisitor()
    {
      shouldVisitStatements = true;
    }
    
    public int visit(IASTStatement stmt)
    {
      if ((stmt instanceof IASTExpressionStatement))
      {
        IASTExpression expression = ((IASTExpressionStatement)stmt).getExpression();
        if (hasNoEffect(expression))
        {
          if ((!shouldReportInMacro()) && (CxxAstUtils.isInMacro(expression))) {
            return 1;
          }
          String arg = expression.getRawSignature();
          if (!isFilteredArg(arg)) {
            reportProblem("org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem", stmt, new Object[] { arg });
          }
        }
        return 1;
      }
      return 3;
    }
    
    private boolean hasNoEffect(IASTExpression e)
    {
      if ((e instanceof IASTBinaryExpression))
      {
        IASTBinaryExpression binExpr = (IASTBinaryExpression)e;
        if (isPossibleAssignment(binExpr)) {
          return false;
        }
        switch (binExpr.getOperator())
        {
        case 15: 
        case 16: 
          return (hasNoEffect(binExpr.getOperand1())) && (hasNoEffect(binExpr.getOperand2()));
        }
        return true;
      }
      if ((e instanceof IASTUnaryExpression))
      {
        IASTUnaryExpression unaryExpr = (IASTUnaryExpression)e;
        int operator = unaryExpr.getOperator();
        switch (operator)
        {
        case 0: 
        case 1: 
        case 9: 
        case 10: 
        case 12: 
          return false;
        case 11: 
          return hasNoEffect(unaryExpr.getOperand());
        }
        return true;
      }
      if ((e instanceof IASTIdExpression))
      {
        IASTNode parent = e.getParent();
        if ((parent instanceof IASTExpressionStatement))
        {
          IASTNode parent2 = parent.getParent();
          if ((parent2 instanceof IASTCompoundStatement))
          {
            IASTNode parent3 = parent2.getParent();
            if ((parent3 instanceof IGNUASTCompoundStatementExpression)) {
              return false;
            }
          }
        }
        return true;
      }
      return false;
    }
  }
  
  public void initPreferences(IProblemWorkingCopy problem)
  {
    super.initPreferences(problem);
    addPreference(problem, "macro", CheckersMessages.StatementHasNoEffectChecker_ParameterMacro, Boolean.TRUE);
    addListPreference(problem, "exceptions", CheckersMessages.GenericParameter_ParameterExceptions, 
      CheckersMessages.GenericParameter_ParameterExceptionsItem);
  }
  
  public boolean isFilteredArg(String arg)
  {
    return isFilteredArg(arg, getProblemById("org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem", getFile()), "exceptions");
  }
  
  public boolean shouldReportInMacro()
  {
    return ((Boolean)getPreference(getProblemById("org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem", getFile()), "macro")).booleanValue();
  }
  
  public boolean isPossibleAssignment(IASTBinaryExpression expr)
  {
    switch (expr.getOperator())
    {
    case 17: 
    case 18: 
    case 19: 
    case 20: 
    case 21: 
    case 22: 
    case 23: 
    case 24: 
    case 25: 
    case 26: 
    case 27: 
      return true;
    }
    if ((expr instanceof IASTImplicitNameOwner))
    {
      IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner)expr).getImplicitNames();
      if (implicitNames.length > 0) {
        return true;
      }
      IType expressionType = expr.getOperand1().getExpressionType();
      if (!(expressionType instanceof IBasicType)) {
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectChecker
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.internal.checkers;

import java.util.HashSet;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;

class NonVirtualDestructor$OnEachClass
  extends ASTVisitor
{
  NonVirtualDestructor$OnEachClass(NonVirtualDestructor 
1 2 3 4

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd