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$
   }
 }