public boolean forFriendship() { if (astName == null) return false; IASTNode node = astName.getParent(); while (node instanceof IASTName) node = node.getParent(); IASTDeclaration decl = null; IASTDeclarator dtor = null; if (node instanceof ICPPASTDeclSpecifier && node.getParent() instanceof IASTDeclaration) { decl = (IASTDeclaration) node.getParent(); } else if (node instanceof IASTDeclarator) { dtor = (IASTDeclarator) node; while (dtor.getParent() instanceof IASTDeclarator) dtor = (IASTDeclarator) dtor.getParent(); if (!(dtor.getParent() instanceof IASTDeclaration)) return false; decl = (IASTDeclaration) dtor.getParent(); } else { return false; } if (decl instanceof IASTSimpleDeclaration) { IASTSimpleDeclaration simple = (IASTSimpleDeclaration) decl; if (!((ICPPASTDeclSpecifier) simple.getDeclSpecifier()).isFriend()) return false; if (dtor != null) return true; return simple.getDeclarators().length == 0; } else if (decl instanceof IASTFunctionDefinition) { IASTFunctionDefinition fnDef = (IASTFunctionDefinition) decl; if (!((ICPPASTDeclSpecifier) fnDef.getDeclSpecifier()).isFriend()) return false; return (dtor != null); } return false; }
// _MYMACRO_ myType foo(); // _MYMACRO_ myType foo() {} // extern void foo2() _MYMACRO_; public void testUndefinedMacrosInFunctionDeclarations_Bug234085() throws Exception { final String comment = getAboveComment(); for (ParserLanguage lang : ParserLanguage.values()) { IASTTranslationUnit tu = parse(comment, lang, false, false); IASTProblemDeclaration pd = getDeclaration(tu, 0); assertEquals("_MYMACRO_", pd.getRawSignature()); IASTSimpleDeclaration sdecl = getDeclaration(tu, 1); assertEquals("myType foo();", sdecl.getRawSignature()); pd = getDeclaration(tu, 2); assertEquals("_MYMACRO_", pd.getRawSignature()); IASTFunctionDefinition fdef = getDeclaration(tu, 3); assertEquals("myType foo() {}", fdef.getRawSignature()); sdecl = getDeclaration(tu, 4); assertEquals("extern void foo2()", sdecl.getRawSignature()); pd = getDeclaration(tu, 5); // the missing semicolon if (lang == ParserLanguage.CPP) { pd = getDeclaration(tu, 6); assertEquals("_MYMACRO_;", pd.getRawSignature()); } else { sdecl = getDeclaration(tu, 6); assertEquals("_MYMACRO_;", sdecl.getRawSignature()); } } }
public void testObjectMacroExpansionNested() throws Exception { StringBuffer buffer = new StringBuffer("#define XYZ const\n"); // $NON-NLS-1$ buffer.append("#define PO *\n"); // $NON-NLS-1$ buffer.append("#define C_PO PO XYZ\n"); // $NON-NLS-1$ buffer.append("int C_PO var;"); // $NON-NLS-1$ String code = buffer.toString(); for (ParserLanguage language : languages) { IASTTranslationUnit tu = parse(code, language); final IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions(); IASTPreprocessorMacroDefinition XYZ = macroDefinitions[0]; IASTPreprocessorMacroDefinition PO = macroDefinitions[1]; IASTPreprocessorMacroDefinition C_PO = macroDefinitions[2]; IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0]; assertTrue(var.getDeclarators()[0].getPointerOperators().length > 0); IASTNodeLocation[] locations = var.getNodeLocations(); assertEquals(3, locations.length); IASTFileLocation start_loc = (IASTFileLocation) locations[0]; assertEquals(start_loc.getNodeOffset(), code.indexOf("int")); // $NON-NLS-1$ assertEquals(start_loc.getNodeLength(), "int ".length()); // $NON-NLS-1$ IASTMacroExpansionLocation mac_loc = (IASTMacroExpansionLocation) locations[1]; final IASTPreprocessorMacroDefinition C_PO2 = mac_loc.getExpansion().getMacroDefinition(); assertEqualsMacros(C_PO, C_PO2); assertEquals(0, mac_loc.getNodeOffset()); assertEquals(2, mac_loc.getNodeLength()); IASTFileLocation end_loc = (IASTFileLocation) locations[2]; assertEquals(code.indexOf(" var"), end_loc.getNodeOffset()); // $NON-NLS-1$ assertEquals(" var;".length(), end_loc.getNodeLength()); // $NON-NLS-1$ } }
public void testObjectStyleMacroExpansionSimpleDeclarator() throws Exception { StringBuffer buffer = new StringBuffer("#define ABC D\n"); // $NON-NLS-1$ buffer.append("int ABC;"); // $NON-NLS-1$ String code = buffer.toString(); for (ParserLanguage language : languages) { IASTTranslationUnit tu = parse(code, language); IASTPreprocessorObjectStyleMacroDefinition ABC = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0]; IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTDeclarator d = var.getDeclarators()[0]; assertEquals(d.getName().toString(), "D"); // $NON-NLS-1$ IASTNodeLocation[] declaratorLocations = d.getNodeLocations(); assertEquals(declaratorLocations.length, 1); IASTMacroExpansionLocation expansion = (IASTMacroExpansionLocation) declaratorLocations[0]; IASTPreprocessorObjectStyleMacroDefinition fromExpansion = (IASTPreprocessorObjectStyleMacroDefinition) expansion.getExpansion().getMacroDefinition(); assertEqualsMacros(fromExpansion, ABC); assertEquals(expansion.getNodeOffset(), 0); assertEquals(expansion.getNodeLength(), 1); IASTNodeLocation[] macroLocation = expansion.getExpansion().getNodeLocations(); assertEquals(macroLocation.length, 1); assertTrue(macroLocation[0] instanceof IASTFileLocation); assertEquals( macroLocation[0].getNodeOffset(), code.indexOf("int ABC;") + "int ".length()); // $NON-NLS-1$ //$NON-NLS-2$ assertEquals(macroLocation[0].getNodeLength(), "ABC".length()); // $NON-NLS-1$ } }
public void testObjectMacroExpansionPartialDeclSpec() throws Exception { StringBuffer buffer = new StringBuffer("#define XYZ const\n"); // $NON-NLS-1$ buffer.append("XYZ int var;"); // $NON-NLS-1$ String code = buffer.toString(); for (ParserLanguage language : languages) { IASTTranslationUnit tu = parse(code, language); IASTPreprocessorObjectStyleMacroDefinition defXYZ = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0]; IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTSimpleDeclSpecifier declSpec = (IASTSimpleDeclSpecifier) var.getDeclSpecifier(); IASTNodeLocation[] declSpecLocations = declSpec.getNodeLocations(); assertEquals(declSpecLocations.length, 2); IASTMacroExpansionLocation expansion = (IASTMacroExpansionLocation) declSpecLocations[0]; assertEqualsMacros(defXYZ, expansion.getExpansion().getMacroDefinition()); assertEquals(expansion.getNodeOffset(), 0); assertEquals(expansion.getNodeLength(), 1); IASTNodeLocation[] expansionLocations = expansion.getExpansion().getNodeLocations(); assertEquals(expansionLocations.length, 1); assertTrue(expansionLocations[0] instanceof IASTFileLocation); assertEquals(expansionLocations[0].getNodeOffset(), code.indexOf("XYZ int")); // $NON-NLS-1$ assertEquals(expansionLocations[0].getNodeLength(), "XYZ".length()); // $NON-NLS-1$ IASTFileLocation second = (IASTFileLocation) declSpecLocations[1]; assertEquals(second.getNodeOffset(), code.indexOf(" int")); // $NON-NLS-1$ assertEquals(second.getNodeLength(), " int".length()); // $NON-NLS-1$ } }
// typedef int tint; // int a() // tint b; public void testPrototypeWithoutSemi() throws Exception { final String comment = getAboveComment(); for (ParserLanguage lang : ParserLanguage.values()) { IASTTranslationUnit tu = parse(comment, lang, false, false); IASTSimpleDeclaration sdecl = getDeclaration(tu, 1); assertEquals("int a()", sdecl.getRawSignature()); IASTProblemDeclaration pdecl = getDeclaration(tu, 2); sdecl = getDeclaration(tu, 3); } }
private void assertExpressionLocation(IASTDeclaration decl, int index, int length) { IASTSimpleDeclaration var = (IASTSimpleDeclaration) decl; IASTEqualsInitializer initializer = (IASTEqualsInitializer) var.getDeclarators()[0].getInitializer(); IASTInitializerClause expr = initializer.getInitializerClause(); IASTFileLocation fileLocation = expr.getFileLocation(); assertNotNull(fileLocation); assertEquals(index, fileLocation.getNodeOffset()); assertEquals(length, fileLocation.getNodeLength()); }
// class A { // enum _T { I J, K }; // missing comma // int i; // }; public void testEnumError_Bug72685() throws Exception { final String comment = getAboveComment(); IASTTranslationUnit tu = parse(comment, ParserLanguage.CPP, false, false); IASTCompositeTypeSpecifier ct = getCompositeType(tu, 0); IASTSimpleDeclaration e = getDeclaration(ct, 0); IASTProblemDeclaration p = getDeclaration(ct, 1); assertEquals("J, K };", p.getRawSignature()); IASTSimpleDeclaration s = getDeclaration(ct, 2); assertEquals("int i;", s.getRawSignature()); }
// typedef int tint; // struct X { // int a; // } c // tint b; public void testCompositeTypeWithDtorWithoutSemi() throws Exception { final String comment = getAboveComment(); for (ParserLanguage lang : ParserLanguage.values()) { IASTTranslationUnit tu = parse(comment, lang, false, false); IASTSimpleDeclaration sdecl = getDeclaration(tu, 1); assertInstance(sdecl.getDeclSpecifier(), IASTCompositeTypeSpecifier.class); assertEquals(1, sdecl.getDeclarators().length); IASTProblemDeclaration pdecl = getDeclaration(tu, 2); sdecl = getDeclaration(tu, 3); } }
// enum _T { I J, K }; // missing comma // int i; public void testEnumProblem() throws Exception { final String comment = getAboveComment(); for (ParserLanguage lang : ParserLanguage.values()) { IASTTranslationUnit tu = parse(comment, lang, false, false); IASTSimpleDeclaration e = getDeclaration(tu, 0); IASTProblemDeclaration p = getDeclaration(tu, 1); assertEquals("J, K };", p.getRawSignature()); IASTSimpleDeclaration s = getDeclaration(tu, 2); assertEquals("int i;", s.getRawSignature()); } }
public void testObjectMacroExpansionComplex() throws Exception { StringBuffer buffer = new StringBuffer("#define XYZ const\n"); // $NON-NLS-1$ buffer.append("#define PO *\n"); // $NON-NLS-1$ buffer.append("#define C_PO PO XYZ\n"); // $NON-NLS-1$ buffer.append("#define IT int\n"); // $NON-NLS-1$ buffer.append("#define V var\n"); // $NON-NLS-1$ buffer.append("XYZ IT C_PO C_PO V;"); // $NON-NLS-1$ String code = buffer.toString(); for (ParserLanguage language : languages) { IASTTranslationUnit tu = parse(code, language); IASTPreprocessorObjectStyleMacroDefinition XYZ = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0]; // IASTPreprocessorObjectStyleMacroDefinition PO = // (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[1]; IASTPreprocessorObjectStyleMacroDefinition C_PO = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[2]; IASTPreprocessorObjectStyleMacroDefinition IT = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[3]; IASTPreprocessorObjectStyleMacroDefinition V = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[4]; IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0]; final IASTNodeLocation[] nodeLocations = var.getNodeLocations(); assertEquals(10, nodeLocations.length); IASTMacroExpansionLocation first_loc = (IASTMacroExpansionLocation) nodeLocations[0]; assertEqualsMacros(first_loc.getExpansion().getMacroDefinition(), XYZ); IASTFileLocation second_loc = (IASTFileLocation) nodeLocations[1]; assertEquals(1, second_loc.getNodeLength()); IASTMacroExpansionLocation third_loc = (IASTMacroExpansionLocation) nodeLocations[2]; assertEqualsMacros(third_loc.getExpansion().getMacroDefinition(), IT); IASTFileLocation fourth_loc = (IASTFileLocation) nodeLocations[3]; assertEquals(1, fourth_loc.getNodeLength()); IASTMacroExpansionLocation fifth_loc = (IASTMacroExpansionLocation) nodeLocations[4]; assertEqualsMacros(fifth_loc.getExpansion().getMacroDefinition(), C_PO); IASTFileLocation sixth_loc = (IASTFileLocation) nodeLocations[5]; assertEquals(1, sixth_loc.getNodeLength()); IASTMacroExpansionLocation seventh_loc = (IASTMacroExpansionLocation) nodeLocations[6]; assertEqualsMacros(seventh_loc.getExpansion().getMacroDefinition(), C_PO); IASTFileLocation eighth_loc = (IASTFileLocation) nodeLocations[7]; assertEquals(1, eighth_loc.getNodeLength()); IASTMacroExpansionLocation ninth_loc = (IASTMacroExpansionLocation) nodeLocations[8]; assertEqualsMacros(ninth_loc.getExpansion().getMacroDefinition(), V); IASTFileLocation tenth_loc = (IASTFileLocation) nodeLocations[9]; assertEquals(1, tenth_loc.getNodeLength()); final IASTFileLocation flatLocation = var.getFileLocation(); assertNotNull(flatLocation); assertEquals( code.indexOf("XYZ IT C_PO C_PO V;"), flatLocation.getNodeOffset()); // $NON-NLS-1$ assertEquals("XYZ IT C_PO C_PO V;".length(), flatLocation.getNodeLength()); // $NON-NLS-1$ } }
private void assertMacroLocation(IASTDeclaration decl, int index, int length) { IASTSimpleDeclaration var = (IASTSimpleDeclaration) decl; IASTEqualsInitializer initializer = (IASTEqualsInitializer) var.getDeclarators()[0].getInitializer(); IASTInitializerClause expr = initializer.getInitializerClause(); assertNotNull(expr.getFileLocation()); IASTNodeLocation[] locations = expr.getNodeLocations(); assertEquals(1, locations.length); IASTMacroExpansionLocation macroExpansion = (IASTMacroExpansionLocation) locations[0]; IASTNodeLocation[] expLocations = macroExpansion.getExpansion().getNodeLocations(); assertEquals(1, expLocations.length); IASTFileLocation fileLocation = expLocations[0].asFileLocation(); assertEquals(index, fileLocation.getNodeOffset()); assertEquals(length, fileLocation.getNodeLength()); }
@Override public int getRoleForName(IASTName n) { // 3.1.2 IASTNode parent = ASTQueries.findOutermostDeclarator(this).getParent(); if (parent instanceof IASTDeclaration) { // a declaration is a definition unless ... if (parent instanceof IASTFunctionDefinition) return r_definition; if (parent instanceof IASTSimpleDeclaration) { final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) parent; // unless it declares a function without body if (this instanceof IASTFunctionDeclarator) { return r_declaration; } final int storage = sdecl.getDeclSpecifier().getStorageClass(); // unless it contains the extern specifier or a linkage-specification and neither // initializer nor function-body if (getInitializer() == null && (storage == IASTDeclSpecifier.sc_extern || isSimpleLinkageSpec(sdecl))) { return r_declaration; } // unless it declares a static data member in a class declaration if (storage == IASTDeclSpecifier.sc_static && CPPVisitor.getContainingScope(parent) instanceof ICPPClassScope) { return r_declaration; } // unless it is a class name declaration: no declarator in this case // unless it is a typedef declaration if (storage == IASTDeclSpecifier.sc_typedef) return r_definition; // should actually be a declaration // unless it is a using-declaration or using-directive: no declarator in this case } // all other cases return r_definition; } if (parent instanceof IASTTypeId) return r_reference; if (parent instanceof IASTParameterDeclaration) return (n.getLookupKey().length > 0) ? r_definition : r_declaration; return r_unclear; }
private void findDefinitionInsertLocation(IProgressMonitor pm) throws CoreException { if (definitionInsertLocation != null) { return; } IASTSimpleDeclaration decl = context.existingFields.get(0); MethodDefinitionInsertLocationFinder locationFinder = new MethodDefinitionInsertLocationFinder(); InsertLocation location = locationFinder.find(tu, decl.getFileLocation(), decl.getParent(), astCache, pm); if (location.getFile() == null || NodeHelper.isContainedInTemplateDeclaration(decl)) { location.setNodeToInsertAfter(NodeHelper.findTopLevelParent(decl), tu); } definitionInsertLocation = location; }
public void testStdioBug() throws ParserException { StringBuffer buffer = new StringBuffer("#define _PTR void *\n"); // $NON-NLS-1$ buffer.append("#define __cdecl __attribute__ ((__cdecl__))\n"); // $NON-NLS-1$ buffer.append("#define _EXFUN(name, proto) __cdecl name proto\n"); // $NON-NLS-1$ buffer.append("_PTR _EXFUN(memchr,(const _PTR, int, size_t));\n"); // $NON-NLS-1$ String code = buffer.toString(); for (ParserLanguage language : languages) { IASTTranslationUnit tu = parse(code, language, true, true); final IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions(); IASTPreprocessorObjectStyleMacroDefinition _PTR = (IASTPreprocessorObjectStyleMacroDefinition) macroDefinitions[0]; IASTPreprocessorFunctionStyleMacroDefinition _EXFUN = (IASTPreprocessorFunctionStyleMacroDefinition) macroDefinitions[2]; IASTSimpleDeclaration memchr = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTNodeLocation[] locations = memchr.getNodeLocations(); assertEquals(locations.length, 4); IASTMacroExpansionLocation loc_1 = (IASTMacroExpansionLocation) locations[0]; assertEqualsMacros(_PTR, loc_1.getExpansion().getMacroDefinition()); IASTFileLocation loc_2 = (IASTFileLocation) locations[1]; assertEquals(loc_2.getNodeOffset(), code.indexOf(" _EXFUN(")); // $NON-NLS-1$ assertEquals(loc_2.getNodeLength(), " ".length()); // $NON-NLS-1$ IASTMacroExpansionLocation loc_3 = (IASTMacroExpansionLocation) locations[2]; assertEqualsMacros(_EXFUN, loc_3.getExpansion().getMacroDefinition()); IASTFileLocation loc_4 = (IASTFileLocation) locations[3]; assertEquals(loc_4.getNodeOffset(), code.indexOf(";")); // $NON-NLS-1$ assertEquals(loc_4.getNodeLength(), 1); IASTFileLocation flat = memchr.getFileLocation(); assertEquals( flat.getNodeOffset(), code.indexOf("_PTR _EXFUN(memchr,(const _PTR, int, size_t));")); // $NON-NLS-1$ assertEquals( flat.getNodeLength(), "_PTR _EXFUN(memchr,(const _PTR, int, size_t));".length()); // $NON-NLS-1$ IASTDeclarator d = memchr.getDeclarators()[0]; IASTFileLocation f = d.getFileLocation(); assertEquals( code.indexOf("_PTR _EXFUN(memchr,(const _PTR, int, size_t))"), f.getNodeOffset()); // $NON-NLS-1$ assertEquals( "_PTR _EXFUN(memchr,(const _PTR, int, size_t))".length(), f.getNodeLength()); // $NON-NLS-1$ } }
private void visitType(IASTSimpleDeclaration declaration) throws BadLocationException { /* TODO: specific params: include type('class' / 'struct') */ IASTDeclSpecifier spec = declaration.getDeclSpecifier(); if (spec instanceof IASTCompositeTypeSpecifier) { String hint = ((IASTCompositeTypeSpecifier) spec).getName().getRawSignature(); if (hint.isEmpty()) return; IASTFileLocation location = declaration.getFileLocation(); int endLoc = location.getNodeOffset() + location.getNodeLength() - 1; int startLoc = location.getNodeOffset(); _container.add(new Hint("type", startLoc, endLoc, hint)); // $NON-NLS-1$ } if (spec instanceof ICPPASTNamedTypeSpecifier) { IASTName name = ((ICPPASTNamedTypeSpecifier) spec).getName(); addBrackets(name); } }
private boolean isSimpleLinkageSpec(IASTSimpleDeclaration sdecl) { IASTNode parent = sdecl.getParent(); if (parent instanceof ICPPASTLinkageSpecification) { ICPPASTLinkageSpecification spec = (ICPPASTLinkageSpecification) parent; // todo distinction between braced enclose and simple linkage specification if (spec.getDeclarations().length == 1) { return true; } } return false; }
public void testFunctionMacroExpansionWithNameSubstitution_Bug173637() throws Exception { StringBuffer buffer = new StringBuffer("#define PLUS5(x) (x+5)\n"); // $NON-NLS-1$ buffer.append("#define FUNCTION PLUS5 \n"); // $NON-NLS-1$ buffer.append("int var= FUNCTION(1);"); // $NON-NLS-1$ String code = buffer.toString(); for (ParserLanguage language : languages) { IASTTranslationUnit tu = parse(code, language); IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTEqualsInitializer initializer = (IASTEqualsInitializer) var.getDeclarators()[0].getInitializer(); IASTInitializerClause expr = initializer.getInitializerClause(); assertNotNull(expr.getFileLocation()); IASTNodeLocation[] locations = expr.getNodeLocations(); assertEquals(1, locations.length); IASTMacroExpansionLocation macroExpansion = (IASTMacroExpansionLocation) locations[0]; IASTNodeLocation[] expLocations = macroExpansion.getExpansion().getNodeLocations(); assertEquals(1, expLocations.length); assertEquals(code.indexOf("FUNCTION(1)"), expLocations[0].getNodeOffset()); assertEquals("FUNCTION(1)".length(), expLocations[0].getNodeLength()); } }
/* * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#leave(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ @Override public int leave(IASTDeclaration node) { super.leave(node); boolean isTemplateDecl = isTemplateDecl(node); final int endOffset = isTemplateDecl ? getEndOffset(node.getParent()) : getEndOffset(node); if (node instanceof IASTFunctionDefinition) { final int nodeType; if (inClassBody()) { nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_METHOD : ICElement.C_METHOD; } else { nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_FUNCTION : ICElement.C_FUNCTION; } assert getCurrentContainer().getTypeCode() == nodeType; pop(endOffset); } else if (node instanceof IASTSimpleDeclaration) { IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) node; IASTDeclSpecifier declSpec = simpleDecl.getDeclSpecifier(); boolean isCompositeType = false; if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { isCompositeType = true; ICPPASTCompositeTypeSpecifier compositeTypeSpec = (ICPPASTCompositeTypeSpecifier) declSpec; final int nodeType; switch (compositeTypeSpec.getKey()) { case IASTCompositeTypeSpecifier.k_struct: nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_STRUCT : ICElement.C_STRUCT; break; case IASTCompositeTypeSpecifier.k_union: nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_UNION : ICElement.C_UNION; break; case ICPPASTCompositeTypeSpecifier.k_class: nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_CLASS : ICElement.C_CLASS; break; default: assert false : "Unexpected composite type specifier"; // $NON-NLS-1$ return PROCESS_CONTINUE; } assert getCurrentContainer().getTypeCode() == nodeType; pop(isTemplateDecl ? endOffset : getEndOffset(declSpec)); } else if (declSpec instanceof IASTEnumerationSpecifier) { isCompositeType = true; assert getCurrentContainer().getTypeCode() == ICElement.C_ENUMERATION; pop(getEndOffset(declSpec)); } if (isCompositeType) { IASTDeclarator[] declarators = simpleDecl.getDeclarators(); for (int i = 0; i < declarators.length; i++) { IASTDeclarator declarator = declarators[i]; final String nodeName = getDeclaratorName(declarator); final int declStartOffset = getStartOffset(declarator); final int declEndOffset = getEndOffset(declarator); if (declSpec.getStorageClass() == IASTDeclSpecifier.sc_typedef) { push(ICElement.C_TYPEDEF, nodeName, declStartOffset); pop(declEndOffset); } else if (declarator instanceof IASTFunctionDeclarator && !hasNestedPointerOperators(declarator)) { final int nodeType; if (inClassBody()) { nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_METHOD_DECLARATION : ICElement.C_METHOD_DECLARATION; } else { nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_FUNCTION_DECLARATION : ICElement.C_FUNCTION_DECLARATION; } push(nodeType, nodeName, declStartOffset); pop(declEndOffset); } else if (declarator != null) { final int nodeType; if (inClassBody()) { nodeType = ICElement.C_FIELD; } else { if (declSpec.getStorageClass() == IASTDeclSpecifier.sc_extern) { nodeType = ICElement.C_VARIABLE_DECLARATION; } else { nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_VARIABLE : ICElement.C_VARIABLE; } } push(nodeType, nodeName, declStartOffset); pop(declEndOffset); } } } } else if (node instanceof IASTASMDeclaration) { // ignored } else if (node instanceof ICPPASTVisibilityLabel) { // ignored } else if (node instanceof ICPPASTNamespaceDefinition) { // handled below } else if (node instanceof ICPPASTNamespaceAlias) { // ignored } else if (node instanceof ICPPASTUsingDeclaration) { // handled in visit } else if (node instanceof ICPPASTUsingDirective) { // handled in visit } else if (node instanceof ICPPASTLinkageSpecification) { // declarations get flattened } else if (node instanceof ICPPASTTemplateDeclaration) { // handled at child declaration level } else if (node instanceof ICPPASTTemplateSpecialization) { // ignored } else if (node instanceof ICPPASTExplicitTemplateInstantiation) { // ignored } else if (node instanceof IASTProblemDeclaration) { // ignored } return PROCESS_CONTINUE; }