001/*
002 * Copyright (c) 2012-2017 Institut National des Sciences Appliquées de Lyon (INSA-Lyon)
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 */
009
010package org.eclipse.golo.compiler.parser;
011
012import org.eclipse.golo.compiler.ir.GoloElement;
013import org.eclipse.golo.compiler.ir.PositionInSourceCode;
014
015public class GoloASTNode extends SimpleNode {
016
017  private GoloElement irElement;
018  private String documentation;
019
020  public void setIrElement(GoloElement element) {
021    this.irElement = element;
022
023    if (jjtGetFirstToken() != null) {
024      // Only add a reverse weak ref to this ASTNode if it was constructed by
025      // the parser and is  really part of the AST (on the contrary, temporary
026      // AST elements used in the ParseTreeToGoloIR visitor to create IR
027      // elements should not be referenced, since they can be garbage collected
028      // at any moment and they don't reflect the source code exactly
029      element.setASTNode(this);
030    }
031  }
032
033  public GoloElement getIrElement() {
034    return irElement;
035  }
036
037  public GoloASTNode(int i) {
038    super(i);
039  }
040
041  public GoloASTNode(GoloParser p, int i) {
042    super(p, i);
043  }
044
045  public int getLineInSourceCode() {
046    return jjtGetFirstToken().beginLine;
047  }
048
049  public int getColumnInSourceCode() {
050    return jjtGetFirstToken().beginColumn;
051  }
052
053  public PositionInSourceCode getPositionInSourceCode() {
054    return new PositionInSourceCode(getLineInSourceCode(), getColumnInSourceCode());
055  }
056
057  @Override
058  public Object jjtAccept(GoloParserVisitor visitor, Object data) {
059    return visitor.visit(this, data);
060  }
061
062  public String getDocumentation() {
063    return documentation;
064  }
065
066  public void setDocumentation(String documentation) {
067    this.documentation = documentation;
068  }
069}