org.eclipse.cdt.codan.core.cxx_1.0.0.201202111925

16:41:35.457 INFO  jd.cli.Main - Decompiling org.eclipse.cdt.codan.core.cxx_1.0.0.201202111925.jar
package org.eclipse.cdt.codan.core.cxx;

import java.util.HashMap;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
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.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
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.Kind;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.INodeFactory;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.rewrite.DeclarationGenerator;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;

public final class CxxAstUtils
{
  private static CxxAstUtils instance;
  
  public static class NameFinderVisitor
    extends ASTVisitor
  {
    public IASTName name;
    
    public NameFinderVisitor()
    {
      shouldVisitNames = true;
    }
    
    public int visit(IASTName name)
    {
      this.name = name;
      return 2;
    }
  }
  
  private class FunctionNameFinderVisitor
    extends CxxAstUtils.NameFinderVisitor
  {
    private FunctionNameFinderVisitor()
    {
      shouldVisitExpressions = true;
    }
    
    public int visit(IASTExpression expression)
    {
      if ((expression instanceof IASTFieldReference))
      {
        name = ((IASTFieldReference)expression).getFieldName();
        return 2;
      }
      return super.visit(expression);
    }
  }
  
  public static synchronized CxxAstUtils getInstance()
  {
    if (instance == null) {
      instance = new CxxAstUtils();
    }
    return instance;
  }
  
  public IType unwindTypedef(IType type)
  {
    if (!(type instanceof IBinding)) {
      return type;
    }
    IBinding typeName = (IBinding)type;
    try
    {
      while ((typeName instanceof ITypedef))
      {
        IType t = ((ITypedef)typeName).getType();
        if ((t instanceof IBinding)) {
          typeName = (IBinding)t;
        } else {
          return t;
        }
      }
    }
    catch (Exception e)
    {
      Activator.log(e);
    }
    return (IType)typeName;
  }
  
  public static boolean isInMacro(IASTNode node)
  {
    IASTNodeSelector nodeSelector = node.getTranslationUnit().getNodeSelector(node.getTranslationUnit().getFilePath());
    IASTFileLocation fileLocation = node.getFileLocation();
    IASTPreprocessorMacroExpansion macro = nodeSelector.findEnclosingMacroExpansion(fileLocation.getNodeOffset(), 
      fileLocation.getNodeLength());
    return macro != null;
  }
  
  public IASTFunctionDefinition getEnclosingFunction(IASTNode node)
  {
    while ((node != null) && (!(node instanceof IASTFunctionDefinition))) {
      node = node.getParent();
    }
    return (IASTFunctionDefinition)node;
  }
  
  public IASTCompositeTypeSpecifier getEnclosingCompositeTypeSpecifier(IASTNode node)
  {
    while ((node != null) && (!(node instanceof IASTCompositeTypeSpecifier))) {
      node = node.getParent();
    }
    return (IASTCompositeTypeSpecifier)node;
  }
  
  public IASTStatement getEnclosingStatement(IASTNode node)
  {
    while ((node != null) && (!(node instanceof IASTStatement))) {
      node = node.getParent();
    }
    return (IASTStatement)node;
  }
  
  public IASTDeclaration createDeclaration(IASTName astName, INodeFactory factory, IIndex index)
  {
    IType inferredType = null;
    IASTSimpleDeclaration declaration = null;
    inferredType = tryInferTypeFromBinaryExpr(astName);
    if (inferredType == null) {
      declaration = tryInferTypeFromFunctionCall(astName, factory, index);
    }
    if (declaration != null) {
      return declaration;
    }
    if (inferredType != null)
    {
      DeclarationGenerator generator = DeclarationGenerator.create(factory);
      IASTDeclarator declarator = generator.createDeclaratorFromType(inferredType, astName.toCharArray());
      IASTDeclSpecifier declspec = generator.createDeclSpecFromType(inferredType);
      IASTSimpleDeclaration simpleDeclaration = factory.newSimpleDeclaration(declspec);
      simpleDeclaration.addDeclarator(declarator);
      return simpleDeclaration;
    }
    IASTDeclarator declarator = factory.newDeclarator(astName.copy());
    IASTSimpleDeclSpecifier declspec = factory.newSimpleDeclSpecifier();
    declspec.setType(IBasicType.Kind.eInt);
    IASTSimpleDeclaration simpleDeclaration = factory.newSimpleDeclaration(declspec);
    simpleDeclaration.addDeclarator(declarator);
    return simpleDeclaration;
  }
  
  private IType tryInferTypeFromBinaryExpr(IASTName astName)
  {
    if (((astName.getParent() instanceof IASTIdExpression)) && ((astName.getParent().getParent() instanceof IASTBinaryExpression)))
    {
      IASTNode binaryExpr = astName.getParent().getParent();
      IASTNode[] arrayOfIASTNode;
      int j = (arrayOfIASTNode = binaryExpr.getChildren()).length;
      for (int i = 0; i < j; i++)
      {
        IASTNode node = arrayOfIASTNode[i];
        if (node != astName.getParent()) {
          return ((IASTExpression)node).getExpressionType();
        }
      }
    }
    return null;
  }
  
  /* Error */
  private IASTSimpleDeclaration tryInferTypeFromFunctionCall(IASTName astName, INodeFactory factory, IIndex index)
  {
    // Byte code:
    //   0: aload_1
    //   1: invokeinterface 460 1 0
    //   6: instanceof 213
    //   9: ifeq +685 -> 694
    //   12: aload_1
    //   13: invokeinterface 460 1 0
    //   18: invokeinterface 464 1 0
    //   23: instanceof 210
    //   26: ifeq +668 -> 694
    //   29: aload_1
    //   30: invokeinterface 460 1 0
    //   35: invokeinterface 462 1 0
    //   40: getstatic 414	org/eclipse/cdt/core/dom/ast/IASTFunctionCallExpression:ARGUMENT	Lorg/eclipse/cdt/core/dom/ast/ASTNodeProperty;
    //   43: if_acmpne +651 -> 694
    //   46: aload_1
    //   47: invokeinterface 460 1 0
    //   52: invokeinterface 464 1 0
    //   57: checkcast 210	org/eclipse/cdt/core/dom/ast/IASTFunctionCallExpression
    //   60: astore 4
    //   62: new 201	org/eclipse/cdt/codan/core/cxx/CxxAstUtils$FunctionNameFinderVisitor
    //   65: dup
    //   66: aload_0
    //   67: aconst_null
    //   68: invokespecial 433	org/eclipse/cdt/codan/core/cxx/CxxAstUtils$FunctionNameFinderVisitor:<init>	(Lorg/eclipse/cdt/codan/core/cxx/CxxAstUtils;Lorg/eclipse/cdt/codan/core/cxx/CxxAstUtils$FunctionNameFinderVisitor;)V
    //   71: astore 5
    //   73: aload 4
    //   75: invokeinterface 455 1 0
    //   80: aload 5
    //   82: invokeinterface 450 2 0
    //   87: pop
    //   88: aload 5
    //   90: getfield 413	org/eclipse/cdt/codan/core/cxx/CxxAstUtils$FunctionNameFinderVisitor:name	Lorg/eclipse/cdt/core/dom/ast/IASTName;
    //   93: astore 6
    //   95: iconst_0
    //   96: istore 7
    //   98: iconst_m1
    //   99: istore 8
    //   101: aload 4
    //   103: invokeinterface 456 1 0
    //   108: dup
    //   109: astore 12
    //   111: arraylength
    //   112: istore 11
    //   114: iconst_0
    //   115: istore 10
    //   117: goto +54 -> 171
    //   120: aload 12
    //   122: iload 10
    //   124: aaload
    //   125: astore 9
    //   127: aload 9
    //   129: invokeinterface 462 1 0
    //   134: getstatic 414	org/eclipse/cdt/core/dom/ast/IASTFunctionCallExpression:ARGUMENT	Lorg/eclipse/cdt/core/dom/ast/ASTNodeProperty;
    //   137: if_acmpne +31 -> 168
    //   140: aload 9
    //   142: instanceof 213
    //   145: ifeq +20 -> 165
    //   148: aload 9
    //   150: invokeinterface 465 1 0
    //   155: iconst_0
    //   156: aaload
    //   157: aload_1
    //   158: if_acmpne +7 -> 165
    //   161: iload 7
    //   163: istore 8
    //   165: iinc 7 1
    //   168: iinc 10 1
    //   171: iload 10
    //   173: iload 11
    //   175: if_icmplt -55 -> 120
    //   178: iload 8
    //   180: iconst_m1
    //   181: if_icmpne +5 -> 186
    //   184: aconst_null
    //   185: areturn
    //   186: aload 6
    //   188: invokeinterface 461 1 0
    //   193: astore 10
    //   195: aload 10
    //   197: instanceof 227
    //   200: ifeq +18 -> 218
    //   203: aload 10
    //   205: checkcast 227	org/eclipse/cdt/core/dom/ast/IProblemBinding
    //   208: invokeinterface 480 1 0
    //   213: astore 9
    //   215: goto +14 -> 229
    //   218: iconst_1
    //   219: anewarray 224	org/eclipse/cdt/core/dom/ast/IBinding
    //   222: dup
    //   223: iconst_0
    //   224: aload 10
    //   226: aastore
    //   227: astore 9
    //   229: aload_3
    //   230: invokeinterface 482 1 0
    //   235: new 196	java/util/HashSet
    //   238: dup
    //   239: invokespecial 425	java/util/HashSet:<init>	()V
    //   242: astore 10
    //   244: aload 9
    //   246: dup
    //   247: astore 14
    //   249: arraylength
    //   250: istore 13
    //   252: iconst_0
    //   253: istore 12
    //   255: goto +64 -> 319
    //   258: aload 14
    //   260: iload 12
    //   262: aaload
    //   263: astore 11
    //   265: aload 11
    //   267: instanceof 225
    //   270: ifeq +46 -> 316
    //   273: aload 11
    //   275: checkcast 225	org/eclipse/cdt/core/dom/ast/IFunction
    //   278: astore 15
    //   280: aload 15
    //   282: invokeinterface 476 1 0
    //   287: arraylength
    //   288: iload 7
    //   290: if_icmpne +26 -> 316
    //   293: aload_3
    //   294: aload 11
    //   296: invokeinterface 484 2 0
    //   301: astore 16
    //   303: aload 10
    //   305: aload 16
    //   307: invokestatic 420	java/util/Arrays:asList	([Ljava/lang/Object;)Ljava/util/List;
    //   310: invokeinterface 443 2 0
    //   315: pop
    //   316: iinc 12 1
    //   319: iload 12
    //   321: iload 13
    //   323: if_icmplt -65 -> 258
    //   326: new 195	java/util/HashMap
    //   329: dup
    //   330: invokespecial 421	java/util/HashMap:<init>	()V
    //   333: astore 11
    //   335: aload 10
    //   337: invokeinterface 444 1 0
    //   342: astore 13
    //   344: goto +294 -> 638
    //   347: aload 13
    //   349: invokeinterface 442 1 0
    //   354: checkcast 234	org/eclipse/cdt/core/index/IIndexName
    //   357: astore 12
    //   359: aload_0
    //   360: aload 12
    //   362: invokevirtual 430	org/eclipse/cdt/codan/core/cxx/CxxAstUtils:getTranslationUnitFromIndexName	(Lorg/eclipse/cdt/core/index/IIndexName;)Lorg/eclipse/cdt/core/model/ITranslationUnit;
    //   365: astore 14
    //   367: aconst_null
    //   368: astore 15
    //   370: aload 11
    //   372: aload 14
    //   374: invokevirtual 422	java/util/HashMap:containsKey	(Ljava/lang/Object;)Z
    //   377: ifeq +18 -> 395
    //   380: aload 11
    //   382: aload 14
    //   384: invokevirtual 423	java/util/HashMap:get	(Ljava/lang/Object;)Ljava/lang/Object;
    //   387: checkcast 221	org/eclipse/cdt/core/dom/ast/IASTTranslationUnit
    //   390: astore 15
    //   392: goto +24 -> 416
    //   395: aload 14
    //   397: aload_3
    //   398: iconst_2
    //   399: invokeinterface 490 3 0
    //   404: astore 15
    //   406: aload 11
    //   408: aload 14
    //   410: aload 15
    //   412: invokevirtual 424	java/util/HashMap:put	(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    //   415: pop
    //   416: aload 15
    //   418: aconst_null
    //   419: invokeinterface 474 2 0
    //   424: aload 12
    //   426: invokeinterface 488 1 0
    //   431: aload 12
    //   433: invokeinterface 487 1 0
    //   438: invokeinterface 467 3 0
    //   443: checkcast 214	org/eclipse/cdt/core/dom/ast/IASTName
    //   446: astore 16
    //   448: aload 16
    //   450: astore 17
    //   452: goto +12 -> 464
    //   455: aload 17
    //   457: invokeinterface 464 1 0
    //   462: astore 17
    //   464: aload 17
    //   466: instanceof 214
    //   469: ifne -14 -> 455
    //   472: getstatic 411	org/eclipse/cdt/codan/core/cxx/CxxAstUtils:$assertionsDisabled	Z
    //   475: ifne +19 -> 494
    //   478: aload 17
    //   480: instanceof 211
    //   483: ifne +11 -> 494
    //   486: new 188	java/lang/AssertionError
    //   489: dup
    //   490: invokespecial 416	java/lang/AssertionError:<init>	()V
    //   493: athrow
    //   494: iconst_0
    //   495: istore 18
    //   497: aload 17
    //   499: invokeinterface 465 1 0
    //   504: dup
    //   505: astore 22
    //   507: arraylength
    //   508: istore 21
    //   510: iconst_0
    //   511: istore 20
    //   513: goto +110 -> 623
    //   516: aload 22
    //   518: iload 20
    //   520: aaload
    //   521: astore 19
    //   523: aload 19
    //   525: instanceof 217
    //   528: ifeq +92 -> 620
    //   531: iload 18
    //   533: iload 8
    //   535: if_icmpne +82 -> 617
    //   538: aload 19
    //   540: checkcast 217	org/eclipse/cdt/core/dom/ast/IASTParameterDeclaration
    //   543: astore 23
    //   545: aload 23
    //   547: invokeinterface 469 1 0
    //   552: invokeinterface 445 1 0
    //   557: astore 24
    //   559: aload 23
    //   561: invokeinterface 470 1 0
    //   566: invokeinterface 446 1 0
    //   571: astore 25
    //   573: aload_0
    //   574: aload 25
    //   576: aload_1
    //   577: invokeinterface 459 1 0
    //   582: invokespecial 428	org/eclipse/cdt/codan/core/cxx/CxxAstUtils:setNameInNestedDeclarator	(Lorg/eclipse/cdt/core/dom/ast/IASTDeclarator;Lorg/eclipse/cdt/core/dom/ast/IASTName;)V
    //   585: aload_2
    //   586: aload 24
    //   588: invokeinterface 479 2 0
    //   593: astore 26
    //   595: aload 26
    //   597: aload 25
    //   599: invokeinterface 472 2 0
    //   604: aload 26
    //   606: astore 28
    //   608: aload_3
    //   609: invokeinterface 483 1 0
    //   614: aload 28
    //   616: areturn
    //   617: iinc 18 1
    //   620: iinc 20 1
    //   623: iload 20
    //   625: iload 21
    //   627: if_icmplt -111 -> 516
    //   630: aload 16
    //   632: invokeinterface 460 1 0
    //   637: pop
    //   638: aload 13
    //   640: invokeinterface 441 1 0
    //   645: ifne -298 -> 347
    //   648: goto +40 -> 688
    //   651: pop
    //   652: aload_3
    //   653: invokeinterface 483 1 0
    //   658: goto +36 -> 694
    //   661: astore 10
    //   663: aload 10
    //   665: invokestatic 426	org/eclipse/cdt/codan/core/cxx/Activator:log	(Ljava/lang/Throwable;)V
    //   668: aload_3
    //   669: invokeinterface 483 1 0
    //   674: goto +20 -> 694
    //   677: astore 27
    //   679: aload_3
    //   680: invokeinterface 483 1 0
    //   685: aload 27
    //   687: athrow
    //   688: aload_3
    //   689: invokeinterface 483 1 0
    //   694: aconst_null
    //   695: areturn
    // Line number table:
    //   Java source line #218	-> byte code offset #0
    //   Java source line #219	-> byte code offset #29
    //   Java source line #220	-> byte code offset #46
    //   Java source line #221	-> byte code offset #62
    //   Java source line #222	-> byte code offset #73
    //   Java source line #223	-> byte code offset #88
    //   Java source line #224	-> byte code offset #95
    //   Java source line #225	-> byte code offset #98
    //   Java source line #226	-> byte code offset #101
    //   Java source line #227	-> byte code offset #127
    //   Java source line #228	-> byte code offset #140
    //   Java source line #229	-> byte code offset #161
    //   Java source line #231	-> byte code offset #165
    //   Java source line #226	-> byte code offset #168
    //   Java source line #234	-> byte code offset #178
    //   Java source line #235	-> byte code offset #184
    //   Java source line #239	-> byte code offset #186
    //   Java source line #240	-> byte code offset #195
    //   Java source line #241	-> byte code offset #203
    //   Java source line #243	-> byte code offset #218
    //   Java source line #247	-> byte code offset #229
    //   Java source line #248	-> byte code offset #235
    //   Java source line #250	-> byte code offset #244
    //   Java source line #251	-> byte code offset #265
    //   Java source line #252	-> byte code offset #273
    //   Java source line #253	-> byte code offset #280
    //   Java source line #255	-> byte code offset #293
    //   Java source line #256	-> byte code offset #303
    //   Java source line #250	-> byte code offset #316
    //   Java source line #260	-> byte code offset #326
    //   Java source line #261	-> byte code offset #335
    //   Java source line #263	-> byte code offset #359
    //   Java source line #264	-> byte code offset #367
    //   Java source line #265	-> byte code offset #370
    //   Java source line #266	-> byte code offset #380
    //   Java source line #268	-> byte code offset #395
    //   Java source line #269	-> byte code offset #406
    //   Java source line #272	-> byte code offset #416
    //   Java source line #273	-> byte code offset #448
    //   Java source line #274	-> byte code offset #452
    //   Java source line #275	-> byte code offset #455
    //   Java source line #274	-> byte code offset #464
    //   Java source line #277	-> byte code offset #472
    //   Java source line #279	-> byte code offset #494
    //   Java source line #280	-> byte code offset #497
    //   Java source line #281	-> byte code offset #523
    //   Java source line #282	-> byte code offset #531
    //   Java source line #283	-> byte code offset #538
    //   Java source line #284	-> byte code offset #545
    //   Java source line #285	-> byte code offset #559
    //   Java source line #286	-> byte code offset #573
    //   Java source line #287	-> byte code offset #585
    //   Java source line #288	-> byte code offset #595
    //   Java source line #289	-> byte code offset #604
    //   Java source line #301	-> byte code offset #608
    //   Java source line #289	-> byte code offset #614
    //   Java source line #291	-> byte code offset #617
    //   Java source line #280	-> byte code offset #620
    //   Java source line #294	-> byte code offset #630
    //   Java source line #261	-> byte code offset #638
    //   Java source line #296	-> byte code offset #651
    //   Java source line #301	-> byte code offset #652
    //   Java source line #298	-> byte code offset #661
    //   Java source line #299	-> byte code offset #663
    //   Java source line #301	-> byte code offset #668
    //   Java source line #300	-> byte code offset #677
    //   Java source line #301	-> byte code offset #679
    //   Java source line #302	-> byte code offset #685
    //   Java source line #301	-> byte code offset #688
    //   Java source line #304	-> byte code offset #694
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	696	0	this	CxxAstUtils
    //   0	696	1	astName	IASTName
    //   0	696	2	factory	INodeFactory
    //   0	696	3	index	IIndex
    //   60	42	4	call	IASTFunctionCallExpression
    //   71	18	5	visitor	FunctionNameFinderVisitor
    //   93	94	6	funcname	IASTName
    //   96	193	7	expectedParametersNum	int
    //   99	435	8	targetParameterNum	int
    //   125	24	9	n	IASTNode
    //   213	3	9	bindings	IBinding[]
    //   227	18	9	bindings	IBinding[]
    //   115	61	10	i	int
    //   193	32	10	binding	IBinding
    //   242	94	10	declSet	Object
    //   661	3	10	e	CoreException
    //   112	64	11	j	int
    //   263	32	11	b	IBinding
    //   333	74	11	astCache	Object
    //   109	12	12	arrayOfIASTNode1	IASTNode[]
    //   253	71	12	k	int
    //   357	75	12	decl	IIndexName
    //   250	74	13	m	int
    //   342	297	13	localIterator	java.util.Iterator
    //   247	12	14	arrayOfIBinding1	IBinding[]
    //   365	44	14	tu	ITranslationUnit
    //   278	3	15	f	org.eclipse.cdt.core.dom.ast.IFunction
    //   368	49	15	ast	IASTTranslationUnit
    //   301	5	16	decls	IIndexName[]
    //   446	185	16	name	IASTName
    //   450	48	17	fdecl	IASTNode
    //   495	123	18	nthParam	int
    //   521	18	19	child	IASTNode
    //   511	117	20	n	int
    //   508	120	21	i1	int
    //   505	12	22	arrayOfIASTNode2	IASTNode[]
    //   543	17	23	pd	org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration
    //   557	30	24	declspec	IASTDeclSpecifier
    //   571	27	25	declarator	IASTDeclarator
    //   593	12	26	declaration	IASTSimpleDeclaration
    //   677	9	27	localObject1	Object
    //   606	9	28	localIASTSimpleDeclaration1	IASTSimpleDeclaration
    //   651	1	42	localInterruptedException	InterruptedException
    // Exception table:
    //   from	to	target	type
    //   229	608	651	java/lang/InterruptedException
    //   617	648	651	java/lang/InterruptedException
    //   229	608	661	org/eclipse/core/runtime/CoreException
    //   617	648	661	org/eclipse/core/runtime/CoreException
    //   229	608	677	finally
    //   617	652	677	finally
    //   661	668	677	finally
  }
  
  private void setNameInNestedDeclarator(IASTDeclarator declarator, IASTName astName)
  {
    while (declarator.getNestedDeclarator() != null) {
      declarator = declarator.getNestedDeclarator();
    }
    declarator.setName(astName);
  }
  
  public ITranslationUnit getTranslationUnitFromIndexName(IIndexName decl)
    throws CoreException
  {
    Path path = new Path(decl.getFile().getLocation().getFullPath());
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file);
    return tu;
  }
  
  public IASTCompositeTypeSpecifier getCompositeTypeFromFunction(final IASTFunctionDefinition function, final IIndex index)
  {
    final IASTCompositeTypeSpecifier[] returnSpecifier = new IASTCompositeTypeSpecifier[1];
    final HashMap<ITranslationUnit, IASTTranslationUnit> astCache = new HashMap();
    function.accept(new ASTVisitor()
    {
      public int visit(IASTName name)
      {
        if ((!(name instanceof ICPPASTQualifiedName)) || (name.getParent().getParent() != function)) {
          return 3;
        }
        ICPPASTQualifiedName qname = (ICPPASTQualifiedName)name;
        if (qname.getChildren().length < 2) {
          return 3;
        }
        IASTName namePart = (IASTName)qname.getChildren()[(qname.getChildren().length - 2)];
        IBinding binding = namePart.resolveBinding();
        try
        {
          index.acquireReadLock();
          IIndexName[] declarations = index.findDeclarations(binding);
          IIndexName[] arrayOfIIndexName1;
          int j = (arrayOfIIndexName1 = declarations).length;
          for (int i = 0; i < j; i++)
          {
            IIndexName decl = arrayOfIIndexName1[i];
            ITranslationUnit tu = getTranslationUnitFromIndexName(decl);
            IASTTranslationUnit ast = null;
            if (astCache.containsKey(tu))
            {
              ast = (IASTTranslationUnit)astCache.get(tu);
            }
            else
            {
              ast = tu.getAST(index, 2);
              astCache.put(tu, ast);
            }
            IASTNode node = ast.getNodeSelector(null).findEnclosingNode(decl.getNodeOffset(), decl.getNodeLength());
            IASTCompositeTypeSpecifier specifier = getEnclosingCompositeTypeSpecifier(node);
            if (specifier != null)
            {
              returnSpecifier[0] = specifier;
              break;
            }
          }
        }
        catch (InterruptedException localInterruptedException)
        {
          return 2;
        }
        catch (CoreException e)
        {
          Activator.log(e);
          return 2;
        }
        finally
        {
          index.releaseReadLock();
        }
        index.releaseReadLock();
        
        return 2;
      }
    });
    return returnSpecifier[0];
  }
  
  public boolean isThrowStatement(IASTNode body)
  {
    if (!(body instanceof IASTExpressionStatement)) {
      return false;
    }
    IASTExpression expression = ((IASTExpressionStatement)body).getExpression();
    if (!(expression instanceof IASTUnaryExpression)) {
      return false;
    }
    return ((IASTUnaryExpression)expression).getOperator() == 12;
  }
  
  public boolean isExitStatement(IASTNode body)
  {
    if (!(body instanceof IASTExpressionStatement)) {
      return false;
    }
    IASTExpression expression = ((IASTExpressionStatement)body).getExpression();
    if (!(expression instanceof IASTFunctionCallExpression)) {
      return false;
    }
    IASTExpression functionNameExpression = ((IASTFunctionCallExpression)expression).getFunctionNameExpression();
    return functionNameExpression.getRawSignature().equals("exit");
  }
}

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

import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;

class CxxAstUtils$FunctionNameFinderVisitor
  extends CxxAstUtils.NameFinderVisitor
{
  private CxxAstUtils$FunctionNameFinderVisitor(CxxAstUtils paramCxxAstUtils)
  {
    shouldVisitExpressions = true;
  }
  
  public int visit(IASTExpression expression)
  {
    if ((expression instanceof IASTFieldReference))
    {
      name = ((IASTFieldReference)expression).getFieldName();
      return 2;
    }
    return super.visit(expression);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.core.cxx.CxxAstUtils.FunctionNameFinderVisitor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.core.cxx.model;

import java.util.WeakHashMap;
import org.eclipse.cdt.codan.core.cxx.Activator;
import org.eclipse.cdt.codan.core.cxx.internal.model.CodanCommentMap;
import org.eclipse.cdt.codan.core.cxx.internal.model.cfg.CxxControlFlowGraph;
import org.eclipse.cdt.codan.core.model.ICodanDisposable;
import org.eclipse.cdt.codan.core.model.cfg.IControlFlowGraph;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.OperationCanceledException;

public class CxxModelsCache
  implements ICodanDisposable
{
  private static final int PARSE_MODE = 230;
  private final IFile file;
  private final ITranslationUnit tu;
  private IASTTranslationUnit ast;
  private IIndex index;
  private final WeakHashMap<IASTFunctionDefinition, IControlFlowGraph> cfgmap;
  private ICodanCommentMap commentMap;
  private boolean disposed;
  
  CxxModelsCache(ITranslationUnit tu)
  {
    this.tu = tu;
    file = (tu != null ? (IFile)tu.getResource() : null);
    cfgmap = new WeakHashMap(0);
  }
  
  CxxModelsCache(IASTTranslationUnit ast)
  {
    this(ast.getOriginatingTranslationUnit());
    this.ast = ast;
  }
  
  public IASTTranslationUnit getAST()
    throws OperationCanceledException, CoreException
  {
    return getAST(tu);
  }
  
  public IASTTranslationUnit getAST(ITranslationUnit tu)
    throws OperationCanceledException, CoreException
  {
    if (!this.tu.equals(tu)) {
      throw new IllegalArgumentException();
    }
    if (ast == null)
    {
      getIndex();
      ast = tu.getAST(index, 230);
    }
    return ast;
  }
  
  public ITranslationUnit getTranslationUnit()
  {
    return tu;
  }
  
  public IFile getFile()
  {
    return file;
  }
  
  public synchronized IControlFlowGraph getControlFlowGraph(IASTFunctionDefinition func)
  {
    IControlFlowGraph cfg = (IControlFlowGraph)cfgmap.get(func);
    if (cfg != null) {
      return cfg;
    }
    cfg = CxxControlFlowGraph.build(func);
    if (cfgmap.size() > 20) {
      cfgmap.clear();
    }
    cfgmap.put(func, cfg);
    return cfg;
  }
  
  public synchronized ICodanCommentMap getCommentedNodeMap()
  {
    return getCommentedNodeMap(tu);
  }
  
  public synchronized ICodanCommentMap getCommentedNodeMap(ITranslationUnit tu)
  {
    if (!this.tu.equals(tu)) {
      throw new IllegalArgumentException();
    }
    if (commentMap == null)
    {
      if (ast == null) {
        throw new IllegalStateException("getCommentedNodeMap called before getAST");
      }
      commentMap = new CodanCommentMap(ASTCommenter.getCommentedNodeMap(ast));
    }
    return commentMap;
  }
  
  public synchronized IIndex getIndex()
    throws CoreException, OperationCanceledException
  {
    Assert.isTrue(!disposed, "CxxASTCache is already disposed.");
    if (this.index == null)
    {
      ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects();
      IIndex index = CCorePlugin.getIndexManager().getIndex(projects);
      try
      {
        index.acquireReadLock();
      }
      catch (InterruptedException localInterruptedException)
      {
        throw new OperationCanceledException();
      }
      this.index = index;
    }
    return this.index;
  }
  
  public void dispose()
  {
    Assert.isTrue(!disposed, "CxxASTCache.dispose() called more than once.");
    disposed = true;
    if (index != null) {
      index.releaseReadLock();
    }
  }
  
  protected void finalize()
    throws Throwable
  {
    if (!disposed) {
      Activator.log("CxxASTCache was not disposed.");
    }
    super.finalize();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.core.cxx.model.CxxModelsCache
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.core.cxx.model;

import org.eclipse.cdt.codan.core.model.IChecker;
import org.eclipse.cdt.core.model.ITranslationUnit;

public abstract interface ICIndexChecker
  extends IChecker
{
  public abstract void processUnit(ITranslationUnit paramITranslationUnit);
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.core.cxx.model.ICIndexChecker
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.core.cxx.model;

import org.eclipse.cdt.codan.core.model.IChecker;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;

public abstract interface ICAstChecker
  extends IChecker
{
  public abstract void processAst(IASTTranslationUnit paramIASTTranslationUnit);
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.core.cxx.model.ICAstChecker
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.core.cxx.model;

import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;

class AbstractAstFunctionChecker$1
  extends ASTVisitor
{
  AbstractAstFunctionChecker$1(AbstractAstFunctionChecker paramAbstractAstFunctionChecker)
  {
    shouldVisitDeclarations = true;
  }
  
  public int visit(IASTDeclaration element)
  {
    if ((element instanceof IASTFunctionDefinition)) {
      this$0.processFunction((IASTFunctionDefinition)element);
    }
    return 3;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.cdt.codan.core.cxx.model.AbstractAstFunctionChecker.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.cdt.codan.core.cxx.model;

import org.eclipse.cdt.codan.core.CodanRuntime;
import org.eclipse.cdt.codan.core.cxx.Activator;
import org.eclipse.cdt.codan.core.model.AbstractCheckerWithProblemPreferences;
import org.eclipse.cdt.codan.core.model.ICheckerInvocationContext;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemLocation;
import org.eclipse.cdt.codan.core.model.IProblemLocationFactory;
import org.eclipse.cdt.codan.core.model.IRunnableInEditorChecker;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTImageLocation;
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.OperationCanceledException;

public abstract class AbstractIndexAstChecker
  extends AbstractCheckerWithProblemPreferences
  implements ICAstChecker, IRunnableInEditorChecker
{
  private CxxModelsCache modelCache;
  
  public synchronized boolean processResource(IResource resource)
    throws OperationCanceledException
  {
    if (!shouldProduceProblems(resource)) {
      return false;
    }
    if (!(resource instanceof IFile)) {
      return true;
    }
    processFile((IFile)resource);
    return false;
  }
  
  private void processFile(IFile file)
    throws OperationCanceledException
  {
    ICheckerInvocationContext context = getContext();
    synchronized (context)
    {
      modelCache = ((CxxModelsCache)context.get(CxxModelsCache.class));
      if (modelCache == null)
      {
        ICElement celement = CoreModel.getDefault().create(file);
        if (!(celement instanceof ITranslationUnit)) {
          return;
        }
        modelCache = new CxxModelsCache((ITranslationUnit)celement);
        context.add(modelCache);
      }
    }
    try
    {
      IASTTranslationUnit ast = modelCache.getAST();
      if (ast != null) {
        synchronized (ast)
        {
          processAst(ast);
        }
      }
    }
    catch (CoreException e)
    {
      e = e;
      Activator.log(e);
      
      modelCache = null; return;
    }
    finally
    {
      localObject1 = 
        finally;modelCache = null;
      throw ((Throwable)localObject1);
    }
    modelCache = null;
  }
  
  /* Error */
  public synchronized void processModel(Object model, ICheckerInvocationContext context)
  {
    // Byte code:
    //   0: aload_1
    //   1: instanceof 96
    //   4: ifeq +105 -> 109
    //   7: aload_0
    //   8: aload_2
    //   9: invokevirtual 191	org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker:setContext	(Lorg/eclipse/cdt/codan/core/model/ICheckerInvocationContext;)V
    //   12: aload_1
    //   13: checkcast 96	org/eclipse/cdt/core/dom/ast/IASTTranslationUnit
    //   16: astore_3
    //   17: aload_2
    //   18: dup
    //   19: astore 4
    //   21: monitorenter
    //   22: aload_0
    //   23: aload_2
    //   24: ldc 1
    //   26: invokeinterface 210 2 0
    //   31: checkcast 1	org/eclipse/cdt/codan/core/cxx/model/CxxModelsCache
    //   34: putfield 186	org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker:modelCache	Lorg/eclipse/cdt/codan/core/cxx/model/CxxModelsCache;
    //   37: aload_0
    //   38: getfield 186	org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker:modelCache	Lorg/eclipse/cdt/codan/core/cxx/model/CxxModelsCache;
    //   41: ifnonnull +25 -> 66
    //   44: aload_0
    //   45: new 1	org/eclipse/cdt/codan/core/cxx/model/CxxModelsCache
    //   48: dup
    //   49: aload_3
    //   50: invokespecial 203	org/eclipse/cdt/codan/core/cxx/model/CxxModelsCache:<init>	(Lorg/eclipse/cdt/core/dom/ast/IASTTranslationUnit;)V
    //   53: putfield 186	org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker:modelCache	Lorg/eclipse/cdt/codan/core/cxx/model/CxxModelsCache;
    //   56: aload_2
    //   57: aload_0
    //   58: getfield 186	org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker:modelCache	Lorg/eclipse/cdt/codan/core/cxx/model/CxxModelsCache;
    //   61: invokeinterface 209 2 0
    //   66: aload 4
    //   68: monitorexit
    //   69: goto +7 -> 76
    //   72: aload 4
    //   74: monitorexit
    //   75: athrow
    //   76: aload_0
    //   77: aload_3
    //   78: invokevirtual 193	org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker:processAst	(Lorg/eclipse/cdt/core/dom/ast/IASTTranslationUnit;)V
    //   81: goto +18 -> 99
    //   84: astore 4
    //   86: aload_0
    //   87: aconst_null
    //   88: putfield 186	org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker:modelCache	Lorg/eclipse/cdt/codan/core/cxx/model/CxxModelsCache;
    //   91: aload_0
    //   92: aconst_null
    //   93: invokevirtual 191	org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker:setContext	(Lorg/eclipse/cdt/codan/core/model/ICheckerInvocationContext;)V
    //   96: aload 4
    //   98: athrow
    //   99: aload_0
    //   100: aconst_null
    //   101: putfield 186	org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker:modelCache	Lorg/eclipse/cdt/codan/core/cxx/model/CxxModelsCache;
    //   104: aload_0
    //   105: aconst_null
    //   106: invokevirtual 191	org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker:setContext	(Lorg/eclipse/cdt/codan/core/model/ICheckerInvocationContext;)V
    //   109: return
    // Line number table:
    //   Java source line #92	-> byte code offset #0
    //   Java source line #93	-> byte code offset #7
    //   Java source line #94	-> byte code offset #12
    //   Java source line #95	-> byte code offset #17
    //   Java source line #96	-> byte code offset #22
    //   Java source line #97	-> byte code offset #37
    //   Java source line #98	-> byte code offset #44
    //   Java source line #99	-> byte code offset #56
    //   Java source line #95	-> byte code offset #66
    //   Java source line #103	-> byte code offset #76
    //   Java source line #104	-> byte code offset #84
    //   Java source line #105	-> byte code offset #86
    //   Java source line #106	-> byte code offset #91
    //   Java source line #107	-> byte code offset #96
    //   Java source line #105	-> byte code offset #99
    //   Java source line #106	-> byte code offset #104
    //   Java source line #109	-> byte code offset #109
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	110	0	this	AbstractIndexAstChecker
    //   0	110	1	model	Object
    //   0	110	2	context	ICheckerInvocationContext
    //   16	62	3	ast	IASTTranslationUnit
    //   19	78	4	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
1 2 3

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