Пример #1
0
 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());
 }
Пример #2
0
 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());
 }
Пример #3
0
  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());
    }
  }