/*
 * This file is released under terms of BSD license
 * See LICENSE file for more information
 */

package cx2x.translator.language;

import cx2x.xcodeml.exception.IllegalDirectiveException;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.BailErrorStrategy;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.misc.ParseCancellationException;

/**
 * ClawLanguage class represent an analyzed pragma statement.
 *
 * @author clementval
 */
public class ClawLanguage {

  private ClawDirective _directive;
  private String _groupName;
  private boolean _valid, _hasGroup;

  /**
   * Constructs an empty ClawLanguage section.
   * WARNING: This ctor should only be used by the parser.
   */
  protected ClawLanguage(){
    _directive = null;
    _valid = false;
    _hasGroup = false;
    _groupName = null;
  }


  /**
   * Analyze a raw string input and match it with the CLAW language definition.
   * @param rawInput A string line to be analyzed against the CLAW language.
   * @return A ClawLanguage object with the corresponding extracted information.
   */
  public static ClawLanguage analyze(String rawInput)
      throws IllegalDirectiveException
  {
    // Instantiate the lexer with the raw string input
    ClawLexer lexer = new ClawLexer(new ANTLRInputStream(rawInput));

    // Get a list of matched tokens
    CommonTokenStream tokens = new CommonTokenStream(lexer);

    // Pass the tokens to the parser
    ClawParser parser = new ClawParser(tokens);
    parser.setErrorHandler(new BailErrorStrategy());

    try {
      // Start the parser analysis from the "analyze" entry point
      ClawParser.AnalyzeContext ctx = parser.analyze();
      // Get the ClawLanguage object return by the parser after analysis.
      return ctx.language;
    } catch(ParseCancellationException pcex){
      throw new IllegalDirectiveException(rawInput, "Unvalid CLAW directive");
    }
  }

  /**
   * Check whether the current language section is valid.
   * @return True if the language is valid.
   */
  public boolean isValid(){
    return _valid;
  }

  /**
   * Check whether a group option was specified.
   * @return True if group option was specified.
   */
  public boolean hasGroupOption(){
    return _hasGroup;
  }

  public void setGroupOption(String groupName){
    _hasGroup = true;
    _groupName = groupName;
  }

  public String getGroupName(){
    return _groupName;
  }

  /**
   * Define the current directive of the language section.
   * @param directive A value of the ClawDirective enumeration.
   */
  public void setDirective(ClawDirective directive){
    _directive = directive;
  }

  /**
   * Get the current directive of the language section.
   * @return Value of the current directive.
   */
  public ClawDirective getDirective(){
    return _directive;
  }




}

@@ -388,16 +388,40 @@
 ption;%0A%0A
+import java.util.List;%0A%0A
 /**%0A * C
@@ -601,16 +601,49 @@
 upName;%0A
+  private List%3CString%3E _indexes;%0A
   privat
@@ -669,16 +669,29 @@
 hasGroup
+, _hasIndexes
 ;%0A%0A  /**
@@ -893,24 +893,49 @@
 up = false;%0A
+    _hasIndexes = false;%0A
     _groupNa
@@ -945,16 +945,37 @@
 = null;%0A
+    _indexes = null;%0A
   %7D%0A%0A%0A  
@@ -2212,24 +2212,62 @@
 valid;%0A  %7D%0A%0A
+%0A%0A  // Group option specific methods%0A%0A
   /**%0A   * C
@@ -2432,167 +2432,1013 @@
 %0A%0A  
-public void setGroupOption(String groupName)%7B%0A    _hasGroup = true;%0A    _groupName = groupName;%0A  %7D%0A%0A  public String getGroupName()%7B%0A    return _groupName;%0A  %7D
+/**%0A   * Set the group name and hasGroupOption to true%0A   * @param groupName The group name defined in the group option.%0A   */%0A  protected void setGroupOption(String groupName)%7B%0A    _hasGroup = true;%0A    _groupName = groupName;%0A  %7D%0A%0A  /**%0A   * Get the group name defined in the group option.%0A   * @return The group name as a String value.%0A   */%0A  public String getGroupName()%7B%0A    return _groupName;%0A  %7D%0A%0A  // Loop interchange specific methods%0A%0A  /**%0A   * Set the list of interhcnage indexes.%0A   * @param indexes List of indexes as string.%0A   */%0A  public void setIdList(List%3CString%3E indexes)%7B%0A    _hasIndexes = true;%0A    _indexes = indexes;%0A  %7D%0A%0A  /**%0A   * Get the loop index list%0A   * @return List of loop index%0A   */%0A  public List%3CString%3E getIndexes()%7B%0A    return _indexes;%0A  %7D%0A%0A  /**%0A   * Check whether the interchange directive has indexes values.%0A   * @return True if the directive has interchange value.%0A   */%0A  public boolean hasIndexes()%7B%0A    return _hasIndexes;%0A  %7D%0A%0A  // Directive generic method
 %0A%0A  

Add methods holder for loop interchange information