Exemplo n.º 1
0
 /**
  * Parses the current line as a function parameter list.
  *
  * @return PARAMETER_DECL_LIST AST node with the PARAMETER nodes (containing a type and a name) as
  *     its children.
  * @throws ParserException parser spots a syntax error
  */
 private ASTNode parseParameterDeclarationList() throws ParserException {
   ASTNode parameters = new ASTNode(TokenType.PARAMETER_DECL_LIST);
   int i = 3;
   int paramNumber = 1;
   while (true) {
     LexerToken lastOfLine = currentLine.get(currentLine.size() - 1);
     if (i != 3 && currentLine.get(i).hasNotType(TokenType.COMMA)) {
       throw createParseException("Expected ',' and parameter declaration", currentLine.get(i));
     }
     if (currentLine.size() <= i + 1) {
       throw createParseException("Expected type of parameter no. " + paramNumber, lastOfLine);
     }
     if (currentLine.get(i + 1).hasNotType(TokenType.TYPE)) {
       throw createParseException(
           "Expected type of parameter no. " + paramNumber, currentLine.get(i + 1));
     }
     if (currentLine.size() <= i + 2) {
       throw createParseException("Expected name of parameter no. " + paramNumber, lastOfLine);
     }
     if (currentLine.get(i + 2).hasNotType(TokenType.NAME)) {
       throw createParseException(
           "Expected name of parameter no. " + paramNumber, currentLine.get(i + 2));
     }
     ASTNode parameter = new ASTNode(TokenType.PARAMETER_DECL);
     parameter.addChildren(currentLine.get(i + 1), currentLine.get(i + 2));
     parameters.addChild(parameter);
     if (currentLine.size() <= i + 3) {
       break;
     }
     i += 3;
     paramNumber++;
   }
   return parameters;
 }
Exemplo n.º 2
0
 /**
  * Instantiates a new function node.
  *
  * @param returnType the return type
  * @param id the identifier name
  * @param parameterList the parameter list
  * @param statementList the statement list of the body
  * @param yyline the corresponding line in the input file
  * @param yycol the corresponding column in the input file
  * @throws Exception if a function with the same identifier has already been defined
  */
 public FunctionNode(
     String returnType,
     String id,
     ArrayList<ASTNode> parameterList,
     ASTNode statementList,
     int yyline,
     int yycol)
     throws Exception {
   super(yyline, yycol);
   rtrnType = returnType;
   paramList = parameterList;
   stmtList = statementList;
   identifier = id;
   if (Parser.functionSymbolsTable.containsKey(identifier.toLowerCase())) {
     throw new Exception(
         "Line "
             + this.getYyline()
             + ": Function "
             + identifier.toLowerCase()
             + " is already defined");
   } else {
     String javaID = "_smartestFunction_" + identifier;
     ArrayList<String> myParameterList = new ArrayList<String>();
     if (paramList != null) {
       for (ASTNode param : paramList) {
         myParameterList.add(param.getType());
       }
     }
     Parser.functionSymbolsTable.put(
         identifier.toLowerCase(),
         new FunctionSymbolTableEntry(identifier, javaID, rtrnType, myParameterList));
     HashMap<String, FunctionSymbolTableEntry> hashMap = Parser.functionSymbolsTable;
   }
 }
Exemplo n.º 3
0
 @Override
 public Object getReducedValueAccelerated(
     final Object ctx, final Object thisValue, final VariableResolverFactory factory) {
   return similarity(
       String.valueOf(soundslike.getReducedValueAccelerated(ctx, thisValue, factory)),
       ((String) stmt.getReducedValueAccelerated(ctx, thisValue, factory)));
 }
Exemplo n.º 4
0
    public boolean apply(ASTNode node) {

      // stops when found - that's the reason to use ApplyAll
      if (exists) return false;

      if (node.getType() == ASTNode.CLASS_DECLARATION
          || node.getType() == ASTNode.FUNCTION_DECLARATION) {
        isGlobalScope = false;
        node.childrenAccept(this);
        isGlobalScope = true;
        return false;
      } else if (node instanceof Identifier) {
        Identifier identifier = (Identifier) node;
        if (identifier.getParent().getType() == ASTNode.VARIABLE) {
          Variable variable = (Variable) identifier.getParent();
          if (variable.isDollared() && isGlobalScope && name.equals(identifier.getName())) {
            exists = true;
          }
        }
      } else if (node.getType() == ASTNode.GLOBAL_STATEMENT) {
        GlobalStatement globalStatement = (GlobalStatement) node;
        final List<Variable> variables = globalStatement.variables();
        for (final Variable variable : variables) {
          final Expression variableName = variable.getName();
          if (variable.isDollared() && variableName instanceof Identifier) {
            Identifier identifier = (Identifier) variableName;
            if (name.equals(identifier.getName())) {
              exists = true;
            }
          }
        }
      }

      return true;
    }
Exemplo n.º 5
0
  public void staticBlockInlining(SootClass sootClass) {
    this.sootClass = sootClass;
    // retrieve the clinit method if any for sootClass
    if (!sootClass.declaresMethod("void <clinit>()")) {
      System.out.println("no clinit");
      return;
    }

    SootMethod clinit = sootClass.getMethod("void <clinit>()");
    // System.out.println(clinit);

    // retireve the active body
    if (!clinit.hasActiveBody())
      throw new RuntimeException("method " + clinit.getName() + " has no active body!");

    Body clinitBody = clinit.getActiveBody();

    Chain units = ((DavaBody) clinitBody).getUnits();

    if (units.size() != 1) {
      throw new RuntimeException("DavaBody AST doesn't have single root.");
    }

    ASTNode AST = (ASTNode) units.getFirst();
    if (!(AST instanceof ASTMethodNode))
      throw new RuntimeException("Starting node of DavaBody AST is not an ASTMethodNode");

    AST.apply(new MethodCallFinder(this));
  }
Exemplo n.º 6
0
 /**
  * Parses the current line as a function declaration header.
  *
  * <p>The AST node has the type token, the name token and the PARAMETER_DECL_LIST node as its
  * children. The last node (PARAMETER_DECL_LIST) is omitted, if the function hasn't any
  * parameters. The first token of the current line has to be a FUNCTION_KEYWORD token.
  *
  * @return AST node
  * @throws ParserException parser spots a syntax error
  */
 protected ASTNode parseFunctionHeader() throws ParserException {
   if (currentLine.size() < 3) {
     throw createParseException("Expected function header");
   }
   LexerToken typeToken = currentLine.get(1);
   if (typeToken.hasNotType(TokenType.TYPE) && typeToken.hasNotType(TokenType.VOID)) {
     throw createParseException("Expected return type", typeToken);
   }
   LexerToken nameToken = currentLine.get(2);
   if (nameToken.hasNotType(TokenType.NAME)) {
     throw createParseException("Expected function name", nameToken);
   }
   ASTNode node = new ASTNode(TokenType.FUNCTION_HEADER);
   node.addChild(typeToken);
   node.addChild(nameToken);
   if (currentLine.size() <= 3) {
     return node;
   }
   if (currentLine.get(3).hasType(TokenType.COLON)) {
     node.addChild(parseParameterDeclarationList());
   } else {
     throw createParseException(
         "Expected colon and function parameter declarations", currentLine.get(3));
   }
   return node;
 }
Exemplo n.º 7
0
  public void test_addAll() {
    ASTNode parent = argumentList();
    ArrayList<ASTNode> firstNodes = new ArrayList<ASTNode>();
    ASTNode firstNode = booleanLiteral(true);
    ASTNode secondNode = booleanLiteral(false);
    firstNodes.add(firstNode);
    firstNodes.add(secondNode);
    NodeList<ASTNode> list = new NodeList<ASTNode>(parent);
    list.addAll(firstNodes);
    assertSize(2, list);
    assertSame(firstNode, list.get(0));
    assertSame(secondNode, list.get(1));
    assertSame(parent, firstNode.getParent());
    assertSame(parent, secondNode.getParent());

    ArrayList<ASTNode> secondNodes = new ArrayList<ASTNode>();
    ASTNode thirdNode = booleanLiteral(true);
    ASTNode fourthNode = booleanLiteral(false);
    secondNodes.add(thirdNode);
    secondNodes.add(fourthNode);
    list.addAll(secondNodes);
    assertSize(4, list);
    assertSame(firstNode, list.get(0));
    assertSame(secondNode, list.get(1));
    assertSame(thirdNode, list.get(2));
    assertSame(fourthNode, list.get(3));
    assertSame(parent, firstNode.getParent());
    assertSame(parent, secondNode.getParent());
    assertSame(parent, thirdNode.getParent());
    assertSame(parent, fourthNode.getParent());
  }
 public void addCompileWarning(String msg, ASTNode node) {
   Token token =
       new Token(Types.UNKNOWN, node.getText(), node.getLineNumber(), node.getColumnNumber());
   sourceUnit
       .getErrorCollector()
       .addWarning(WarningMessage.POSSIBLE_ERRORS, msg, token, sourceUnit);
 }
Exemplo n.º 9
0
 InfixExpression(int type, ASTNode leftOperand, ASTNode rightOperand) {
   this.type = type;
   this.leftOperand = leftOperand;
   this.rightOperand = rightOperand;
   leftOperand.setParent(this);
   rightOperand.setParent(this);
 }
Exemplo n.º 10
0
 /*
  * (non-Javadoc)
  *
  * @see ASTNode#generateCode()
  */
 public StringBuffer generateCode() {
   StringBuffer output = new StringBuffer();
   StringBuffer statementsOutput;
   FunctionSymbolTableEntry entry = Parser.functionSymbolsTable.get(identifier.toLowerCase());
   if (entry == null) return null;
   output.append("public static ");
   if ("float".equalsIgnoreCase(rtrnType)) rtrnType = "double";
   output.append(rtrnType);
   output.append(" ");
   output.append(entry.getJavaID());
   output.append("( ");
   if (paramList != null) {
     boolean firstParam = true;
     for (ASTNode param : paramList) {
       if (!firstParam) output.append(", ");
       else firstParam = false;
       output.append(param.generateCode());
       firstParam = false;
     }
   }
   output.append(" )\n");
   output.append("{\n");
   statementsOutput = stmtList.generateCode();
   if (statementsOutput != null) output.append(statementsOutput);
   output.append("}\n");
   return output;
 }
 /**
  * Appends the text representation of the given modifier flags, followed by a single space. Used
  * for 3.0 modifiers and annotations.
  *
  * @param ext the list of modifier and annotation nodes (element type: <code>IExtendedModifier
  *     </code>)
  */
 private void printModifiers(List<IExtendedModifier> ext) {
   for (Iterator<IExtendedModifier> it = ext.iterator(); it.hasNext(); ) {
     ASTNode p = (ASTNode) it.next();
     p.accept(this);
     this.fBuffer.append(" "); // $NON-NLS-1$
   }
 }
  public static String asString(ASTNode node) {
    Assert.isTrue(node.getAST().apiLevel() == ASTProvider.SHARED_AST_LEVEL);

    ASTFlattener flattener = new ASTFlattener();
    node.accept(flattener);
    return flattener.getResult();
  }
 /* (omit javadoc for this method)
  * Method declared on ASTNode.
  */
 ASTNode clone0(AST target) {
   DeclareAtTypeDeclaration result = new DeclareAtTypeDeclaration(target);
   result.setSourceRange(this.getStartPosition(), this.getLength());
   result.setJavadoc((Javadoc) ASTNode.copySubtree(target, getJavadoc()));
   result.setPatternNode((PatternNode) ASTNode.copySubtree(target, getPatternNode()));
   result.setAnnotationName((SimpleName) ASTNode.copySubtree(target, getAnnotationName()));
   return result;
 }
Exemplo n.º 14
0
 @Override
 ASTNode clone0(AST target) {
   final VariableBase left = ASTNode.copySubtree(target, getLeftHandSide());
   final Expression right = ASTNode.copySubtree(target, getRightHandSide());
   final Assignment result =
       new Assignment(this.getStart(), this.getEnd(), target, left, this.getOperator(), right);
   return result;
 }
Exemplo n.º 15
0
 private void printAST(ASTNode<?> ast, int level) {
   if (ast != null) {
     printTab(level);
     System.out.println(level + ":" + ast.getClass().getName() + "@" + ast.getId());
     int n = ast.getNumChild();
     for (int i = 0; i < n; i++) printAST(ast.getChild(i), level + 1);
   }
 }
Exemplo n.º 16
0
 private DrawingTree layoutBinary(String name, ASTNode child1, ASTNode child2) {
   DrawingTree dt = layoutCaption(name);
   DrawingTree d1 = (DrawingTree) child1.accept(this);
   DrawingTree d2 = (DrawingTree) child2.accept(this);
   dt.setChildren(new DrawingTree[] {d1, d2});
   attachParent(dt, join(dt));
   return dt;
 }
Exemplo n.º 17
0
 /**
  * Parses the current line as a function call.
  *
  * <p>The first token of the current line has to be a NAME token.
  *
  * @return FUNCTION_CALL AST node with the name token and the parameter VALUE nodes as its
  *     children.
  * @throws ParserException parser spots a syntax error
  */
 protected ASTNode parseFunctionCall() throws ParserException {
   ASTNode node = new ASTNode(TokenType.FUNCTION_CALL);
   node.addChild(currentLine.get(0));
   for (int i = 1; i < currentLine.size(); i++) {
     node.addChild(parseTokenAsValue(currentLine.get(i)));
   }
   return node;
 }
Exemplo n.º 18
0
 /* (omit javadoc for this method)
  * Method declared on ASTNode.
  */
 ASTNode clone0(AST target) {
   SuperMethodReference result = new SuperMethodReference(target);
   result.setSourceRange(getStartPosition(), getLength());
   result.setName((SimpleName) getName().clone(target));
   result.setQualifier((Name) ASTNode.copySubtree(target, getQualifier()));
   result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments()));
   return result;
 }
 @Override
 ASTNode clone0(AST target) {
   final Expression className = ASTNode.copySubtree(target, getClassName());
   final Identifier constant = ASTNode.copySubtree(target, getConstant());
   final StaticConstantAccess result =
       new StaticConstantAccess(getStart(), getEnd(), target, className, constant);
   return result;
 }
Exemplo n.º 20
0
 ASTNode clone0(AST target) {
   Type clonedType = getType();
   if (clonedType != null) {
     clonedType = (Type) clonedType.clone(target);
   }
   ASTNode node = new ExactTypePattern(target, clonedType);
   node.setSourceRange(getStartPosition(), getLength());
   return node;
 }
Exemplo n.º 21
0
 /* (omit javadoc for this method)
  * Method declared on ASTNode.
  */
 ASTNode clone0(AST target) {
   TryStatement result = new TryStatement(target);
   result.setSourceRange(this.getStartPosition(), this.getLength());
   result.copyLeadingComment(this);
   result.setBody((Block) getBody().clone(target));
   result.catchClauses().addAll(ASTNode.copySubtrees(target, catchClauses()));
   result.setFinally((Block) ASTNode.copySubtree(target, getFinally()));
   return result;
 }
 /* (omit javadoc for this method)
  * Method declared on ASTNode.
  */
 ASTNode clone0(AST target) {
   InvariantDeclaration result = new InvariantDeclaration(target);
   result.setSourceRange(this.getStartPosition(), this.getLength());
   result.preDDocs.addAll(ASTNode.copySubtrees(target, preDDocs()));
   result.modifiers.addAll(ASTNode.copySubtrees(target, modifiers()));
   result.setBody((Block) getBody().clone(target));
   result.setPostDDoc((DDocComment) ASTNode.copySubtree(target, getPostDDoc()));
   return result;
 }
Exemplo n.º 23
0
 /* (omit javadoc for this method)
  * Method declared on ASTNode.
  */
 ASTNode clone0(AST target) {
   TypeParameter result = new TypeParameter(target);
   result.setSourceRange(getStartPosition(), getLength());
   if (this.ast.apiLevel >= AST.JLS8) {
     result.annotations().addAll(ASTNode.copySubtrees(target, annotations()));
   }
   result.setName((SimpleName) ((ASTNode) getName()).clone(target));
   result.typeBounds().addAll(ASTNode.copySubtrees(target, typeBounds()));
   return result;
 }
Exemplo n.º 24
0
 /** @apilevel low-level */
 @SuppressWarnings({"unchecked", "cast"})
 public RawMethodDecl fullCopy() {
   RawMethodDecl res = (RawMethodDecl) copy();
   for (int i = 0; i < getNumChildNoTransform(); i++) {
     ASTNode node = getChildNoTransform(i);
     if (node != null) node = node.fullCopy();
     res.setChild(node, i);
   }
   return res;
 }
Exemplo n.º 25
0
 /** @apilevel low-level */
 @SuppressWarnings({"unchecked", "cast"})
 public AssignPlusExpr fullCopy() {
   AssignPlusExpr res = (AssignPlusExpr) copy();
   for (int i = 0; i < getNumChildNoTransform(); i++) {
     ASTNode node = getChildNoTransform(i);
     if (node != null) node = node.fullCopy();
     res.setChild(node, i);
   }
   return res;
 }
Exemplo n.º 26
0
 @SuppressWarnings({"unchecked", "cast"})
 public IfStmt fullCopy() {
   IfStmt res = (IfStmt) copy();
   for (int i = 0; i < getNumChildNoTransform(); i++) {
     ASTNode node = getChildNoTransform(i);
     if (node != null) node = node.fullCopy();
     res.setChild(node, i);
   }
   return res;
 }
 public IFunctionBinding getDeclaringMethod() {
   ASTNode parent = this.variableDeclaration.getParent();
   while (parent != null && parent.getNodeType() != ASTNode.FUNCTION_DECLARATION) {
     parent = parent.getParent();
   }
   if (parent != null) {
     return ((FunctionDeclaration) parent).resolveBinding();
   }
   return null;
 }
 public void test_Rule_setMath2() {
   ASTNode math = new ASTNode(libsbml.AST_TIMES);
   ASTNode a = new ASTNode();
   a.setName("a");
   math.addChild(a);
   int i = R.setMath(math);
   assertTrue(i == libsbml.LIBSBML_INVALID_OBJECT);
   assertEquals(false, R.isSetMath());
   math = null;
 }
 @SuppressWarnings({"unchecked", "cast"})
 public ParSuperConstructorAccess fullCopy() {
   ParSuperConstructorAccess res = (ParSuperConstructorAccess) copy();
   for (int i = 0; i < getNumChildNoTransform(); i++) {
     ASTNode node = getChildNoTransform(i);
     if (node != null) node = node.fullCopy();
     res.setChild(node, i);
   }
   return res;
 }
 public ITypeBinding getDeclaringClass() {
   ASTNode parent = this.variableDeclaration.getParent();
   while (parent != null && parent.getNodeType() != ASTNode.TYPE_DECLARATION) {
     parent = parent.getParent();
   }
   if (parent != null) {
     return ((TypeDeclaration) parent).resolveBinding();
   }
   return null;
 }