Package com.icona.tree.nodes

Source Code of com.icona.tree.nodes.Declaration

package com.icona.tree.nodes;

import antlr.debug.NewLineEvent;

import com.icona.tree.nodes.Expression.AssignmentExpression;
import com.icona.tree.nodes.Expression.ListExpression;
import com.icona.tree.nodes.Operator.AssignmentOperator.AssignmentSymbol;
import com.icona.tree.nodes.Type.ArrayType;
import com.icona.tree.nodes.Type.BasicDataType;
import com.icona.tree.nodes.interfaces.Conversion;

public class Declaration extends Statement implements Conversion{
 
  public BasicModifier modifier=new BasicModifier(this);//All the basic modifiers
  public Specifier specifier=new Specifier(this);
  public Identifier identifier=new Identifier();
  public BasicDataType dataType=new BasicDataType(); // TODO Hardcoded for now, will be generic type later on
  public ArrayType arrayDimensions=new ArrayType();
  public Expression listExpression=new ListExpression(null,-1)
 
  public Declaration(Node parent, int line_no) {
    super(parent, line_no);
   
    // TODO Auto-generated constructor stub
   
  }

 
 
 
  public Expression getListExpression() {
    return listExpression;
  }




  public void setListExpression(Expression listExpression) {
    this.listExpression = listExpression;
  }




  public BasicModifier getModifier() {
    return modifier;
  }




  public void setModifier(BasicModifier modifier) {
    this.modifier = modifier;
  }




  public Specifier getSpecifier() {
    return specifier;
  }




  public void setSpecifier(Specifier specifier) {
    this.specifier = specifier;
  }




  public Identifier getIdentifier() {
    return identifier;
  }

  public void setIdentifier(Identifier identifier) {
    this.identifier = identifier;
  }




  public BasicDataType getDataType() {
    return dataType;
  }




  public void setDataType(BasicDataType dataType) {
    this.dataType = dataType;
  }




  public ArrayType getArrayDimensions() {
    return arrayDimensions;
  }




  public void setArrayDimensions(ArrayType arrayDimensions) {
    this.arrayDimensions = arrayDimensions;
  }




  @Override
  public Node getNextChild(Node existing) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public Node getPreviousChild(Node existing) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public boolean replaceChild(Node existing, Node by) {
    // TODO Auto-generated method stub
    return false;
  }

  @Override
  public Node getNextSibling() {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public Node getPreviousSibling() {
    // TODO Auto-generated method stub
    return null;
  }
 
  @Override
  public String toString(){
    transformSelf();
   
    StringBuilder sb=new StringBuilder();
    sb.append(modifier.toString());
    sb.append(dataType.toString());
    if(arrayDimensions!=null)
      sb.append(arrayDimensions.toStringEmptyBraces());
    sb.append(identifier.toString());
   
    //TODO This part is hard coded should be generic LHS later on
    if( arrayDimensions!=null && arrayDimensions.numOfNonEmptyDimensions()>0){
      sb.append("= new ");
      sb.append(dataType.toString());
      sb.append(arrayDimensions.toString());
    }
    if(listExpression!=null)
    {
      sb.append("=");
      sb.append(listExpression.toString());
     
    }
   
    //sb.append(";");
    //sb.append("\n"); //New line
   
    return sb.toString();
  }


  @Override
  public void addChild(Node node) {
    // TODO Auto-generated method stub
   
  }
 
  @Override
  public Object clone(){
    Declaration d=new Declaration(parent, line_no);
    d.arrayDimensions=(ArrayType)arrayDimensions.clone();
    d.dataType=(BasicDataType)dataType.clone(); //TODO cloning dataType should be generic
    d.identifier=(Identifier)identifier.clone();
    d.modifier=(BasicModifier)modifier.clone();
    d.specifier=(Specifier)specifier.clone();
   
    return (Object)d;
   
  }




  @Override
  public void transformSelf() {
    // NOTE: The order here matters //TODO Declaration: Try to get rid of order
    BasicDataType tempDataType=(BasicDataType)modifier.transformDependents();
    if(tempDataType!=null)
      dataType=tempDataType;
    tempDataType=(BasicDataType)specifier.transformDependents();
    if(tempDataType!=null)
      dataType=tempDataType;
   
  }




  @Override
  public Object transformDependents() {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException();
   
  }




  @Override
  public boolean hasMultipleExpressions() {
    // TODO Auto-generated method stub
    return false;
  }

}
TOP

Related Classes of com.icona.tree.nodes.Declaration

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.