org.tizen.nativecpp.apichecker.core_2.0.0.201311042022

16:50:14.559 INFO  jd.cli.Main - Decompiling org.tizen.nativecpp.apichecker.core_2.0.0.201311042022.jar
package org.tizen.nativecpp.apichecker.core;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.tizen.nativecpp.apichecker.core.model.UnusedPrivileges;
import org.tizen.nativecpp.apichecker.core.utils.WorkspaceUtils;
import org.tizen.nativecpp.apichecker.core.xmlloader.ApiListXmlLoader;
import org.tizen.nativecpp.apichecker.core.xmlloader.PrivilegeListXmlLoader;

public class APCManager
  implements IResourceChangeListener
{
  private static final String DEV_MODE_FILE = ".dev";
  private static APCManager INSTANCE;
  private boolean isDevMode;
  private boolean doXMLsExist;
  private boolean enableUnusedPrivilegeCheck;
  private ApiListXmlLoader axLoader;
  private PrivilegeListXmlLoader privilegeXmlLoader;
  private Map<IProject, UnusedPrivileges> unusedPrivsMap;
  
  private APCManager()
  {
    INSTANCE = this;
    
    ResourcesPlugin.getWorkspace().addResourceChangeListener(this, 1);
    unusedPrivsMap = new HashMap();
    
    String devModeFilePath = WorkspaceUtils.getPathOfIDE() + Constants.FILE_SEP_STR + ".dev";
    File devModeFile = new File(devModeFilePath);
    if (devModeFile.exists()) {
      isDevMode = true;
    } else {
      isDevMode = false;
    }
    String xmlsLoc = WorkspaceUtils.getXmlsPath();
    File file = new File(xmlsLoc);
    if (file.exists()) {
      doXMLsExist = true;
    } else {
      doXMLsExist = false;
    }
    enableUnusedPrivilegeCheck = false;
    
    axLoader = new ApiListXmlLoader(false);
    axLoader.refineEnum();
    if (!getInstanceisDevMode) {
      axLoader.refineOverVersion(2000);
    }
    if (getInstanceisDevMode) {
      axLoader.printAll();
    }
    privilegeXmlLoader = new PrivilegeListXmlLoader();
  }
  
  public static APCManager getInstance()
  {
    if (INSTANCE == null) {
      return new APCManager();
    }
    return INSTANCE;
  }
  
  public ApiListXmlLoader getApiXmlLoader()
  {
    return axLoader;
  }
  
  public PrivilegeListXmlLoader getPrivilegeXmlLoader()
  {
    return privilegeXmlLoader;
  }
  
  public void putUnusedPrivileges(IProject prj, UnusedPrivileges newUnusedPrivs)
  {
    if (newUnusedPrivs != null) {
      unusedPrivsMap.put(prj, newUnusedPrivs);
    }
  }
  
  public UnusedPrivileges getUnusedPrivileges(IProject prj)
  {
    return (UnusedPrivileges)unusedPrivsMap.get(prj);
  }
  
  public boolean shouldCheckUnusedPrivilege()
  {
    return enableUnusedPrivilegeCheck;
  }
  
  public void enableUnusedPrivilegeCheck()
  {
    enableUnusedPrivilegeCheck = true;
  }
  
  public void disableUnusedPrivilegeCheck()
  {
    enableUnusedPrivilegeCheck = false;
  }
  
  public void resourceChanged(IResourceChangeEvent event)
  {
    if ((event.getResource() instanceof IProject))
    {
      IProject prj = (IProject)event.getResource();
      UnusedPrivileges unusedPrivs = new UnusedPrivileges(prj);
      unusedPrivsMap.put(prj, unusedPrivs);
    }
  }
  
  public boolean hasXMLs()
  {
    return doXMLsExist;
  }
  
  public boolean isDevMode()
  {
    return isDevMode;
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativecpp.apichecker.core.APCManager
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativecpp.apichecker.core;

import org.tizen.nativecpp.apichecker.core.model.IProblemLocationFactory;
import org.tizen.nativecpp.apichecker.core.model.IProblemReporter;
import org.tizen.nativecpp.apichecker.internal.core.Builder;
import org.tizen.nativecpp.apichecker.internal.core.model.ProblemLocationFactory;
import org.tizen.nativecpp.apichecker.internal.core.model.ProblemReporter;

public class APCRuntime
{
  private static APCRuntime Instance = new APCRuntime();
  private IProblemReporter problemReporter = ProblemReporter.getInstance();
  private IBuilder builder = new Builder();
  private IProblemLocationFactory locFactory = new ProblemLocationFactory();
  
  public IProblemReporter getProblemReporter()
  {
    return problemReporter;
  }
  
  public void setProblemReporter(IProblemReporter reporter)
  {
    problemReporter = reporter;
  }
  
  public static APCRuntime getInstance()
  {
    return Instance;
  }
  
  public IBuilder getBuilder()
  {
    return builder;
  }
  
  public IProblemLocationFactory getProblemLocationFactory()
  {
    return locFactory;
  }
  
  public void setProblemLocationFactory(IProblemLocationFactory factory)
  {
    locFactory = factory;
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativecpp.apichecker.core.APCRuntime
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativecpp.apichecker.core;

import java.io.File;

public class Constants
{
  public static final String NATURE_ID = "org.tizen.nativecpp.apichecker.core.tizenCppNature";
  public static final String BUILDER_ID = "org.tizen.nativecpp.apichecker.core.builder";
  public static final String PROJECT_FILE = ".project";
  public static final int BASE_VERSION = 2000;
  public static final String NOT_USED = "NOT_USED";
  public static final String USED = "USED";
  public static final String PREFIX_CHECKER_ID = "org.tizen.nativecpp.apichecker.internal.checkers.";
  public static final String CHECKER_ID_PARTNER_API = "org.tizen.nativecpp.apichecker.internal.checkers.PartnerApiProblem";
  public static final String CHECKER_ID_API_VERSION = "org.tizen.nativecpp.apichecker.internal.checkers.ApiVersionProblem";
  public static final String CHECKER_ID_DEPRECATED_API = "org.tizen.nativecpp.apichecker.internal.checkers.DeprecatedApiProblem";
  public static final String CHECKER_ID_DEPRECATED_CLASS = "org.tizen.nativecpp.apichecker.internal.checkers.DeprecatedClassProblem";
  public static final String CHECKER_ID_INCOMPATIBLE_API = "org.tizen.nativecpp.apichecker.internal.checkers.IncompatibleApiProblem";
  public static final String CHECKER_ID_FINAL_API = "org.tizen.nativecpp.apichecker.internal.checkers.FinalApiProblem";
  public static final String CHECKER_ID_FINAL_CLASS = "org.tizen.nativecpp.apichecker.internal.checkers.FinalClassProblem";
  public static final String CHECKER_ID_UNDEFINED_PRIVILEGE = "org.tizen.nativecpp.apichecker.internal.checkers.UndefinedPrivilegeProblem";
  public static final String CHECKER_ID_UNUSED_PRIVILEGE = "org.tizen.nativecpp.apichecker.internal.checkers.UnusedPrivilegeProblem";
  public static final String PREFIX_MARKER_TYPE = "org.tizen.nativecpp.apichecker.core.";
  public static final String MARKER_TYPE_PARTNER_API = "org.tizen.nativecpp.apichecker.core.PartnerApiProblem";
  public static final String MARKER_TYPE_API_VERSION = "org.tizen.nativecpp.apichecker.core.ApiVersionViolationProblem";
  public static final String MARKER_TYPE_DEPRECATED_API = "org.tizen.nativecpp.apichecker.core.DeprecatedApiProblem";
  public static final String MARKER_TYPE_INCOMPATIBLE_API = "org.tizen.nativecpp.apichecker.core.IncompatibleApiProblem";
  public static final String MARKER_TYPE_FINAL_API = "org.tizen.nativecpp.apichecker.core.FinalApiProblem";
  public static final String MARKER_TYPE_UNDEFINED_PRIVILEGE = "org.tizen.nativecpp.apichecker.core.UndefinedPrivilegeProblem";
  public static final String MARKER_TYPE_UNUSED_PRIVILEGE = "org.tizen.nativecpp.apichecker.core.UnusedPrivilegeProblem";
  public static final String MARKER_ATTRIBUTE_PRIVILEGE = "privilege";
  public static final String[] WEB_CONTROL_PRIVILEGES = {
    "http://tizen.org/privilege/web.privacy", 
    "http://tizen.org/privilege/web.service" };
  public static final String[] WEB_CONTROL_KEYWORD = { "Web" };
  public static final String DTD_FILE = "UIForm.dtd";
  public static final String SCOPE_OPERATOR = "::";
  public static final String DESTRUCTOR_TILDE = "~";
  public static final String DELIMITERS_FOR_MULTIPLE_PRIVILEGES = " ,";
  public static final String AND_FOR_MULTIPLE_PRIVILEGES = " and ";
  public static final String DELIMITERS_FOR_ORING_PRIVILEGES = " | ";
  public static final String VERSION_INTERVAL_DELIMITER = ":";
  public static final String VOID_TYPE = "void";
  public static final String PUBLIC_API = "public-api";
  public static final String DEPRECATED_API = "deprecated-api";
  public static final String FINAL_API = "final-api";
  public static final String INCOMPATIBLE_API = "incompatible-api";
  public static final String PRIVILEGED_API = "privileged-api";
  public static final String DEPRECATED_PRIVILEGED_API = "deprecated-privileged-api";
  public static final String KEYWORD_COMPAT_PREFIX = "compat-";
  public static final String KEYWORD_OPEN_API = "open-api";
  public static final String KEYWORD_PARTNER_API = "partner-api";
  public static final String FILE_SEP_STR = File.separator;
  public static final String PATH_TOOLS = FILE_SEP_STR + "tools";
  public static final String PATH_XMLS = PATH_TOOLS + FILE_SEP_STR + "checker";
  public static final String EXTENSION_XML = ".xml";
  
  public static String limitVersion(String ver)
  {
    int indexOfPoint = 0;
    if ((ver == null) || (ver.length() == 0)) {
      return "";
    }
    indexOfPoint = ver.indexOf('.');
    if (indexOfPoint == -1) {
      return ver;
    }
    indexOfPoint = ver.indexOf('.', indexOfPoint + 1);
    if (indexOfPoint == -1) {
      return ver;
    }
    return ver.substring(0, indexOfPoint);
  }
  
  public static int generateVersionInt(String ver)
  {
    int version = 2000;
    String vStr = limitVersion(ver);
    int indexOfPoint = vStr.indexOf('.');
    if (indexOfPoint != -1) {
      version = Integer.parseInt(vStr.substring(0, indexOfPoint)) * 1000 + 
        Integer.parseInt(vStr.substring(indexOfPoint + 1));
    }
    return version;
  }
  
  public static String generateVersionString(int version)
  {
    int major = version / 1000;
    String ver = Integer.toString(major) + "." + Integer.toString(version - major * 1000);
    return ver;
  }
  
  public static String generateQualifiedName(String cname, String mname)
  {
    if ((cname == null) || (cname.equals(""))) {
      return mname;
    }
    return cname + "::" + mname;
  }
  
  public static String generateQualifiedName(String[] names)
  {
    String qualifiedName = names[0];
    for (int i = 1; i < names.length; i++) {
      qualifiedName = qualifiedName + "::" + names[i];
    }
    return qualifiedName;
  }
  
  public static String generateQualifiedName(String[] cnames, String mname)
  {
    String qualifiedName = "";
    for (int i = 0; i < cnames.length; i++) {
      qualifiedName = qualifiedName + cnames[i] + "::";
    }
    return qualifiedName + mname;
  }
  
  public static String getLastName(String qualifiedName)
  {
    if (qualifiedName == null) {
      return null;
    }
    int index = qualifiedName.lastIndexOf("::");
    if (index >= 0) {
      return qualifiedName.substring(index + 2);
    }
    return qualifiedName;
  }
  
  public static String removeTemplateOperators(String name)
  {
    if (name.contains("<"))
    {
      int index = name.indexOf("<");
      String str = name.substring(0, index);
      
      return str;
    }
    return name;
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativecpp.apichecker.core.Constants
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativecpp.apichecker.core;

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.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.framework.BundleContext;

public class CorePlugin
  extends Plugin
{
  public static final String PLUGIN_ID = "org.tizen.nativecpp.apichecker.core";
  private static CorePlugin Plugin;
  
  public IEclipsePreferences getStorePreferences()
  {
    return InstanceScope.INSTANCE.getNode("org.tizen.nativecpp.apichecker.core");
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    Plugin = this;
    
    APCManager.getInstance();
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    Plugin = null;
    super.stop(context);
  }
  
  public static CorePlugin getDefault()
  {
    return Plugin;
  }
  
  public static void log(IStatus status)
  {
    getDefault().getLog().log(status);
  }
  
  public static void log(Throwable e)
  {
    log(new Status(4, "org.tizen.nativecpp.apichecker.core", 1, "Internal Error", e));
  }
  
  public static void log(String message)
  {
    log(new Status(4, "org.tizen.nativecpp.apichecker.core", 1, message, null));
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativecpp.apichecker.core.CorePlugin
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativecpp.apichecker.core;

import java.util.Set;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;

public abstract interface IBuilder
{
  public abstract void processResource(IResource paramIResource, Set<String> paramSet, IProgressMonitor paramIProgressMonitor);
  
  public abstract void processResource(IResource paramIResource, IProgressMonitor paramIProgressMonitor);
}

/* Location:
 * Qualified Name:     org.tizen.nativecpp.apichecker.core.IBuilder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativecpp.apichecker.core;

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.tizen.nativecpp.apichecker.core.messages";
  public static String Builder_CodeAnalysisOn;
  public static String MESSAGEPATTERN_PARTNER_API;
  public static String MESSAGEPATTERN_API_VERSION;
  public static String MESSAGEPATTERN_DEPRECATED_API;
  public static String MESSAGEPATTERN_DEPRECATED_CLASS;
  public static String MESSAGEPATTERN_INCOMPATIBLE_API;
  public static String MESSAGEPATTERN_FINAL_API;
  public static String MESSAGEPATTERN_FINAL_CLASS;
  public static String MESSAGEPATTERN_UNDEFINED_PRIVILEGE;
  public static String MESSAGEPATTERN_UNUSED_PRIVILEGE;
  
  static
  {
    NLS.initializeMessages("org.tizen.nativecpp.apichecker.core.messages", Messages.class);
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativecpp.apichecker.core.Messages
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativecpp.apichecker.core;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

public class TizenCppNature
  implements IProjectNature
{
  private IProject project;
  
  public TizenCppNature() {}
  
  public TizenCppNature(IProject project)
  {
    setProject(project);
  }
  
  public void configure()
    throws CoreException
  {}
  
  public void deconfigure()
    throws CoreException
  {}
  
  public IProject getProject()
  {
    return project;
  }
  
  public void setProject(IProject project)
  {
    this.project = project;
  }
  
  public static void addNature(IProject project, IProgressMonitor monitor)
    throws CoreException
  {
    addNature(project, "org.tizen.nativecpp.apichecker.core.tizenCppNature", monitor);
  }
  
  public static void removeNature(IProject project, IProgressMonitor monitor)
    throws CoreException
  {
    removeNature(project, "org.tizen.nativecpp.apichecker.core.tizenCppNature", monitor);
  }
  
  public static void addNature(IProject project, String natureId, IProgressMonitor monitor)
    throws CoreException
  {
    IProjectDescription description = project.getDescription();
    String[] prevNatures = description.getNatureIds();
    for (int i = 0; i < prevNatures.length; i++) {
      if (natureId.equals(prevNatures[i])) {
        return;
      }
    }
    IResource projectFile = project.findMember(".project");
    if ((projectFile instanceof IFile))
    {
      ResourceAttributes attributes = projectFile.getResourceAttributes();
      attributes.setReadOnly(false);
      projectFile.setResourceAttributes(attributes);
    }
    String[] newNatures = new String[prevNatures.length + 1];
    System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
    newNatures[prevNatures.length] = natureId;
    description.setNatureIds(newNatures);
    project.setDescription(description, monitor);
    if (natureId.equals("org.tizen.nativecpp.apichecker.core.tizenCppNature"))
    {
      ICommand[] commands = description.getBuildSpec();
      for (int i = 0; i < commands.length; i++) {
        if (commands[i].getBuilderName().equals("org.tizen.nativecpp.apichecker.core.builder")) {
          return;
        }
      }
      ICommand[] newCommands = new ICommand[commands.length + 1];
      System.arraycopy(commands, 0, newCommands, 0, commands.length);
      ICommand command = description.newCommand();
      command.setBuilderName("org.tizen.nativecpp.apichecker.core.builder");
      newCommands[(newCommands.length - 1)] = command;
      description.setBuildSpec(newCommands);
      project.setDescription(description, null);
    }
  }
  
  public static void removeNature(IProject project, String natureId, IProgressMonitor monitor)
    throws CoreException
  {
    IResource projectFile = project.findMember(".project");
    if ((projectFile instanceof IFile))
    {
      ResourceAttributes attributes = projectFile.getResourceAttributes();
      attributes.setReadOnly(false);
      projectFile.setResourceAttributes(attributes);
    }
    IProjectDescription description = project.getDescription();
    String[] prevNatures = description.getNatureIds();
    List<String> newNatures = new ArrayList(Arrays.asList(prevNatures));
    newNatures.remove(natureId);
    description.setNatureIds((String[])newNatures.toArray(new String[newNatures.size()]));
    project.setDescription(description, monitor);
    if (natureId.equals("org.tizen.nativecpp.apichecker.core.tizenCppNature"))
    {
      ICommand[] commands = description.getBuildSpec();
      for (int i = 0; i < commands.length; i++) {
        if (commands[i].getBuilderName().equals("org.tizen.nativecpp.apichecker.core.builder"))
        {
          ICommand[] newCommands = new ICommand[commands.length - 1];
          System.arraycopy(commands, 0, newCommands, 0, i);
          System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
          description.setBuildSpec(newCommands);
          project.setDescription(description, null);
          return;
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativecpp.apichecker.core.TizenCppNature
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativecpp.apichecker.core.cxx;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
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.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IProblemType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
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.ICPPEnumeration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
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.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.tizen.nativecpp.apichecker.core.APCManager;
import org.tizen.nativecpp.apichecker.core.Constants;
import org.tizen.nativecpp.apichecker.core.utils.TypeUtils;
import org.tizen.nativecpp.apichecker.core.xmlloader.ApiListXmlLoader;
import org.tizen.nativecpp.apichecker.core.xmlloader.PrivilegeListXmlLoader;

public final class CxxAstUtils
{
  private static CxxAstUtils instance;
  
  public static synchronized CxxAstUtils getInstance()
  {
    if (instance == null) {
      instance = new CxxAstUtils();
    }
    return instance;
  }
  
  public IASTName getIASTName(IASTNode node)
  {
    if ((node instanceof IASTFunctionCallExpression))
    {
      IASTExpression funcNameExpr = ((IASTFunctionCallExpression)node).getFunctionNameExpression();
      if ((funcNameExpr instanceof IASTIdExpression)) {
        return ((IASTIdExpression)funcNameExpr).getName();
      }
      if ((funcNameExpr instanceof IASTFieldReference)) {
        return ((IASTFieldReference)funcNameExpr).getFieldName();
      }
    }
    else if ((node instanceof ICPPASTNewExpression))
    {
      IASTDeclSpecifier declSpecifier = ((ICPPASTNewExpression)node).getTypeId().getDeclSpecifier();
      if ((declSpecifier instanceof IASTNamedTypeSpecifier)) {
        return ((IASTNamedTypeSpecifier)declSpecifier).getName();
      }
    }
    else
    {
      if ((node instanceof IASTFunctionDeclarator)) {
        return ((IASTFunctionDeclarator)node).getName();
      }
      if ((node instanceof ICPPASTDeclarator)) {
        return ((ICPPASTDeclarator)node).getName();
      }
      if ((node instanceof IASTNamedTypeSpecifier)) {
        return ((IASTNamedTypeSpecifier)node).getName();
      }
      if ((node instanceof IASTName)) {
        return (IASTName)node;
      }
    }
    return null;
  }
  
  private IBinding[] getAllDeclsFromIASTName(IASTName name)
  {
    IBinding[] bindings = (IBinding[])null;
    if (name != null)
    {
      if ((name.toString().startsWith("std::unique_ptr")) || 
        (name.toString().startsWith("unique"))) {
        return null;
      }
      IBinding binding1 = name.resolveBinding();
      if ((binding1 instanceof IProblemBinding))
      {
        bindings = ((IProblemBinding)binding1).getCandidateBindings();
        
        boolean isDebug = APCManager.getInstance().isDevMode();
        
        String rawSigOfName = name.getRawSignature();
        IASTNode parentNode = name.getParent();
        if ((parentNode != null) && 
          ((parentNode instanceof IASTFieldReference)))
        {
          IASTFieldReference fieldRef = (IASTFieldReference)parentNode;
          if (isDebug)
          {
            System.out.println("---------");
            System.out.println("Test: node (IASTName) = " + rawSigOfName);
            System.out.println("Test: parent node (IASTFieldReference) = " + fieldRef.getRawSignature());
          }
          IASTExpression ownerExpr = fieldRef.getFieldOwner();
          if ((ownerExpr instanceof IASTIdExpression))
          {
            IASTIdExpression ownerId = (IASTIdExpression)ownerExpr;
            IBinding ownerBinding = ownerId.getName().resolveBinding();
            if ((ownerBinding != null) && ((ownerBinding instanceof ICPPVariable)))
            {
              IType ownerType = ((ICPPVariable)ownerBinding).getType();
              if (isDebug)
              {
                System.out.println("Test: owner ID = " + ownerId.getRawSignature());
                System.out.println("Test: owner binding = " + ownerBinding);
                System.out.println("Test: owner type = " + ownerType);
              }
              if ((ownerType instanceof ICPPClassType))
              {
                ICPPClassType ownerClassType = (ICPPClassType)ownerType;
                ICPPClassType[] nestedClasses = ownerClassType.getNestedClasses();
                ICPPClassType[] arrayOfICPPClassType1;
                int j = (arrayOfICPPClassType1 = nestedClasses).length;
                for (int i = 0; i < j; i++)
                {
                  ICPPClassType cppClassType = arrayOfICPPClassType1[i];
                  if ((cppClassType instanceof ICPPClassSpecialization))
                  {
                    ICPPClassSpecialization clsSpec = (ICPPClassSpecialization)cppClassType;
                    ICPPTemplateParameterMap parMap = clsSpec.getTemplateParameterMap();
                    Integer[] pos = parMap.getAllParameterPositions();
                    Integer[] arrayOfInteger1;
                    int m = (arrayOfInteger1 = pos).length;
                    for (int k = 0; k < m; k++)
                    {
                      Integer i = arrayOfInteger1[k];
                      ICPPTemplateArgument par = parMap.getArgument(i.intValue());
                      
                      IType parType = par.getTypeValue();
                      if ((parType instanceof ICPPClassType))
                      {
                        bindings = getMethodBindingsFromClass((ICPPClassType)parType, rawSigOfName);
                        return bindings;
                      }
                    }
                  }
                }
              }
              else if ((ownerType instanceof IPointerType))
              {
                IPointerType ownerPointerType = (IPointerType)ownerType;
                IType typeOfPointer = ownerPointerType.getType();
                if ((typeOfPointer instanceof ICPPClassType))
                {
                  ICPPClassType clsType = (ICPPClassType)typeOfPointer;
                  bindings = getMethodBindingsFromClass(clsType, rawSigOfName);
                  return bindings;
                }
              }
            }
          }
        }
      }
      else
      {
        bindings = new IBinding[] { binding1 };
      }
    }
    return bindings;
  }
  
  private IBinding[] getBindings(IASTName name)
  {
    IBinding[] bindings = (IBinding[])null;
    if (name != null)
    {
      name.resolveBinding();
      IBinding binding1 = name.getBinding();
      if ((binding1 instanceof IProblemBinding)) {
        bindings = ((IProblemBinding)binding1).getCandidateBindings();
      } else {
        bindings = new IBinding[] { binding1 };
      }
    }
    return bindings;
  }
  
  public IBinding getBinding(IASTName name)
  {
    if (name == null) {
      return null;
    }
    IBinding[] bindings = getBindings(name);
    if (bindings != null)
    {
      if ((APCManager.getInstance().isDevMode()) && 
        (bindings.length > 1))
      {
        System.out.println("[Debug] binding candidates : ");
        IBinding[] arrayOfIBinding1;
        int j = (arrayOfIBinding1 = bindings).length;
        for (int i = 0; i < j; i++)
        {
          IBinding binding = arrayOfIBinding1[i];
          System.out.println("[Debug]   - " + binding.toString());
        }
      }
      if ((bindings.length > 0) && (bindings[0] != null)) {
        return bindings[0];
      }
    }
    return null;
  }
  
  private String getDeclaratorFromDeclarations(IName[] decls)
  {
    String declName = null;
    if (decls.length == 1) {
      declName = decls[0].toString();
    }
    return declName;
  }
  
  private IFunction getMatchedMethodFromBindings(IBinding[] bindings, int noOfArgs, IType[] argTypes)
  {
    List<ICPPFunction> candidates = new ArrayList();
    for (int i = 0; i < bindings.length; i++) {
      if ((bindings[i] instanceof ICPPFunction))
      {
        int minOfArgs = ((ICPPFunction)bindings[i]).getRequiredArgumentCount();
        int maxOfArgs = ((ICPPFunction)bindings[i]).getParameters().length;
        if ((minOfArgs <= noOfArgs) && (noOfArgs <= maxOfArgs)) {
          candidates.add((ICPPFunction)bindings[i]);
        }
      }
    }
    boolean isDebug = APCManager.getInstance().isDevMode();
    if (candidates.size() == 1) {
      return (IFunction)candidates.get(0);
    }
    for (int i = 0; i < noOfArgs; i++)
    {
      List<ICPPFunction> newCandidates = new ArrayList();
      for (ICPPFunction cand : candidates)
      {
        IParameter[] pars = cand.getParameters();
        if (TypeUtils.sameTypes(argTypes[i], pars[i].getType())) {
          newCandidates.add(cand);
        }
      }
      if (newCandidates.size() == 1) {
        return (IFunction)newCandidates.get(0);
      }
      if (newCandidates.size() == 0)
      {
        if (isDebug) {
          System.out.println("[Debug] 2nd chance to find the matched function from bindings");
        }
        for (ICPPFunction cand : candidates)
        {
          IParameter[] pars = cand.getParameters();
          if (TypeUtils.sameTypesExceptQualifier(argTypes[i], pars[i].getType())) {
            newCandidates.add(cand);
          }
        }
        if (newCandidates.size() == 1) {
          return (IFunction)newCandidates.get(0);
        }
        if (newCandidates.size() == 0)
        {
          if (isDebug) {
            System.out.println("[Debug] 3rd chance to find the matched function from bindings");
          }
          for (ICPPFunction cand : candidates)
          {
            IParameter[] pars = cand.getParameters();
            if (TypeUtils.compatibleTypes(argTypes[i], pars[i].getType())) {
              newCandidates.add(cand);
            }
          }
          if (newCandidates.size() == 1) {
            return (IFunction)newCandidates.get(0);
          }
        }
      }
      if (newCandidates.size() == 0)
      {
        if (!isDebug) {
          break;
        }
        System.out.println("[Debug] ERROR (getMatchedMethodFromBindings) : matched function not found");
        
        break;
      }
      if (isDebug)
      {
        System.out.println("[Debug] ERROR (getMatchedMethodFromBindings) : too many matched function");
        for (ICPPFunction cand : newCandidates) {
          try
          {
            System.out.println("[Debug]   - " + 
              Constants.generateQualifiedName(cand.getQualifiedName()) + " : " + cand);
          }
          catch (DOMException e)
          {
            e.printStackTrace();
          }
        }
      }
      candidates = new ArrayList(newCandidates);
    }
    if (candidates.size() > 1) {
      return (IFunction)candidates.get(0);
    }
    return null;
  }
  
  private IFunction getMatchedMethod(IBinding[] bindings, IASTInitializerClause[] initializerClauses)
  {
    if ((bindings == null) || (bindings.length < 1)) {
      return null;
    }
    if (bindings.length == 1)
    {
      if ((bindings[0] instanceof ICPPClassType))
      {
        IBinding[] methodBindings = getMethodBindingsFromClass((ICPPClassType)bindings[0], ((ICPPClassType)bindings[0]).getName());
        return getMatchedMethod(methodBindings, initializerClauses);
      }
      if ((bindings[0] instanceof IFunction)) {
        return (IFunction)bindings[0];
      }
    }
    ICPPParameter[] pars;
    IType parType;
    if ((initializerClauses == null) || (initializerClauses.length == 0))
    {
      IBinding[] arrayOfIBinding1;
      int j = (arrayOfIBinding1 = bindings).length;
      for (int i = 0; i < j; i++)
      {
        IBinding binding = arrayOfIBinding1[i];
        if ((binding instanceof ICPPConstructor))
        {
          pars = ((ICPPConstructor)binding).getParameters();
          if (pars == null) {
            return (IFunction)binding;
          }
          if (pars.length == 1)
          {
            parType = pars[0].getType();
            if (parType == null) {
              return null;
            }
            if (parType.toString().equals("void")) {
              return (IFunction)binding;
            }
          }
        }
      }
    }
    else
    {
      boolean isDebug = APCManager.getInstance().isDevMode();
      try
      {
        boolean found = false;
        pars = (parType = bindings).length;
        for (ICPPParameter[] arrayOfICPPParameter1 = 0; arrayOfICPPParameter1 < pars; arrayOfICPPParameter1++)
        {
          IBinding binding = parType[arrayOfICPPParameter1];
          if ((binding instanceof ICPPFunction))
          {
            qualifiedName = Constants.generateQualifiedName(((ICPPFunction)binding).getQualifiedName());
            apcMgr = APCManager.getInstance();
            if ((apcMgr.getApiXmlLoader().containApi(qualifiedName)) || 
              (apcMgr.getPrivilegeXmlLoader().containApi(qualifiedName)))
            {
              found = true;
              break;
            }
          }
        }
        if (!found)
        {
          if (isDebug) {
            System.out.println("[Debug] " + bindings[0] + " : not found in xmls");
          }
          return null;
        }
      }
      catch (DOMException e)
      {
        String qualifiedName;
        APCManager apcMgr;
        e.printStackTrace();
        
        int noOfArgs = initializerClauses.length;
        IType[] argTypes = getTypesOfArgsFromInitializerClause(initializerClauses);
        if (isDebug)
        {
          int theNoOfBindings = bindings.length;
          System.out.println("Test: # bindings = " + theNoOfBindings);
          if (theNoOfBindings > 1)
          {
            int i = 1;
            IBinding[] arrayOfIBinding2;
            apcMgr = (arrayOfIBinding2 = bindings).length;
            for (qualifiedName = 0; qualifiedName < apcMgr; qualifiedName++)
            {
              IBinding binding = arrayOfIBinding2[qualifiedName];
              if ((binding instanceof IFunction)) {
                System.out.println("Test: Candidate [" + i + "] = " + binding);
              }
              i++;
            }
          }
        }
        IFunction matchedFunc = getMatchedMethodFromBindings(bindings, noOfArgs, argTypes);
        if ((isDebug) && (matchedFunc != null)) {
          System.out.println("[Debug] matched function : " + matchedFunc);
        }
        return matchedFunc;
      }
    }
    return null;
  }
  
  public IFunction getMatchedMethod(IASTDeclarator declarator, IASTDeclSpecifier declSpecifier)
  {
    IASTName astName = null;
    IASTInitializerClause[] initializerClauses = (IASTInitializerClause[])null;
    if ((declSpecifier instanceof IASTNamedTypeSpecifier))
    {
      IASTNamedTypeSpecifier namedSpecifier = (IASTNamedTypeSpecifier)declSpecifier;
      astName = namedSpecifier.getName();
      IBinding[] bindings = getAllDeclsFromIASTName(astName);
      if (bindings != null)
      {
        if ((bindings.length == 1) && ((bindings[0] instanceof IFunction))) {
          return (IFunction)bindings[0];
        }
        IASTInitializer initializer = declarator.getInitializer();
        if (initializer != null)
        {
          ICPPASTConstructorInitializer cInitializer = (ICPPASTConstructorInitializer)initializer;
          initializerClauses = cInitializer.getArguments();
        }
        return getMatchedMethod(bindings, initializerClauses);
      }
    }
    return null;
  }
  
  public IFunction getMatchedMethod(IASTExpression expr)
  {
    IASTName astName = getIASTName(expr);
    IBinding[] bindings = getAllDeclsFromIASTName(astName);
    if (bindings != null)
    {
      if ((bindings.length == 1) && ((bindings[0] instanceof IFunction))) {
        return (IFunction)bindings[0];
      }
      IASTInitializerClause[] initializerClauses = (IASTInitializerClause[])null;
      if ((expr instanceof IASTFunctionCallExpression))
      {
        initializerClauses = ((IASTFunctionCallExpression)expr).getArguments();
      }
      else if ((expr instanceof ICPPASTNewExpression))
      {
        IASTInitializer initializer = ((ICPPASTNewExpression)expr).getInitializer();
        if (initializer != null)
        {
          ICPPASTConstructorInitializer cInitializer = (ICPPASTConstructorInitializer)initializer;
          initializerClauses = cInitializer.getArguments();
        }
      }
      else if (APCManager.getInstance().isDevMode())
      {
        System.out.println("[Debug] ERROR (getMatchedMethod) : cannot find args");
      }
      if (APCManager.getInstance().isDevMode()) {
        System.out.println("[Debug] processing - " + expr.getRawSignature());
      }
      return getMatchedMethod(bindings, initializerClauses);
    }
    return null;
  }
  
  private IBinding[] getMethodBindingsFromClass(ICPPClassType classType, String mname)
  {
    if (mname == null) {
      return null;
    }
    List<IBinding> matchedBindingList = new ArrayList();
    
    ICPPMethod[] methods = classType.getMethods();
    ICPPMethod[] arrayOfICPPMethod1;
    int j = (arrayOfICPPMethod1 = methods).length;
    for (int i = 0; i < j; i++)
    {
      ICPPMethod method = arrayOfICPPMethod1[i];
      if (method.getName().equals
1 2 3 4 5 6 7 8 9 10

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