Package etch.compiler.opt

Source Code of etch.compiler.opt.Extern

/* $Id: Extern.java 742162 2009-02-08 20:54:34Z dixson $
*
* Copyright 2007-2008 Cisco Systems Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package etch.compiler.opt;

import etch.compiler.EtchGrammarConstants;
import etch.compiler.ParseException;
import etch.compiler.Token;
import etch.compiler.ast.Name;
import etch.compiler.ast.Opt;

/**
* Option which sets the language specific attributes of an extern
* declaration.
*/
public class Extern extends Opt
{
  /**
   * Constructs the Extern.
   *
   * @param name
   * @param args
   * @throws ParseException
   */
  public Extern( Name name, Token... args ) throws ParseException
  {
    super( null, name.token.beginLine );
    addType( etch.compiler.ast.Extern.class );
   
    // usage: @Extern(language, name, nameImport, serializer, serializerImport)
    // example: @Extern(java, "java.util.Date", "", "etch.bindings.java.util.DateSerializer", "")
   
    if (args.length != 5)
      throw new ParseException( String.format(
        "usage: @Extern(language, \"xname\", \"xnameImport\", \"serializer\", \"serializerImport\") at line %d",
        name.token.beginLine ) );
   
    language = args[0];
    xname = args[1];
    xnameImport = args[2];
    serializer = args[3];
    serializerImport = args[4];
   
    if (language.kind != EtchGrammarConstants.ID)
      throw new ParseException( String.format(
        "Extern expected language to be <ID> at line %d",
        language.beginLine ) );
   
    if (xname.kind != EtchGrammarConstants.STR)
      throw new ParseException( String.format(
        "Extern expected xname to be <STR> at line %d",
        xname.beginLine ) );
   
    if (xnameImport.kind != EtchGrammarConstants.STR)
      throw new ParseException( String.format(
        "Extern expected xnameImport to be <STR> at line %d",
        xnameImport.beginLine ) );
   
    if (serializer.kind != EtchGrammarConstants.STR)
      throw new ParseException( String.format(
        "Extern expected serializer to be <STR> at line %d",
        serializer.beginLine ) );
   
    if (serializerImport.kind != EtchGrammarConstants.STR)
      throw new ParseException( String.format(
        "Extern expected serializerImport to be <STR> at line %d",
        serializerImport.beginLine ) );
  }
 
  @Override
  public String name()
  {
    return "Extern."+language.image;
  }
 
  /**
   * The language of this extern opt.
   */
  public final Token language;
 
  /**
   * The name of the external class.
   */
  public final Token xname;
 
  /**
   * How to make the external class available in the environment.
   */
  public final Token xnameImport;
 
  /**
   * The name of the serializer class.
   */
  public final Token serializer;

  /**
   * How to make the serializer name available in the environment.
   */
  public final Token serializerImport;

  @Override
  public void dump( String indent )
  {
    System.out.printf( "%s@Extern %s %s %s %s %s\n", indent, language, xname, xnameImport, serializer, serializerImport );
  }

  @Override
  public String toString()
  {
    return String.format( "@Extern %s %s %s %s %s", language, xname, xnameImport, serializer, serializerImport );
  }

  /**
   * @return the language (e.g., java) of this extern option.
   */
  public Token getLanguage() {
    return language;
  }

  /**
   * @return the fully qualified class name of the serializer for this extern.
   */
  public Token getSerializer() {
    return serializer;
  }

  /**
   * @return the "import" statement we might need to use to access the
   * serializer class. Blank ("") means none.
   */
  public Token getSerializerImport() {
    return serializerImport;
  }

  /**
   * @return the name of the external class.
   */
  public Token getXname() {
    return xname;
  }

  /**
   * @return the "import" statement we might need to use to access the
   * external class. Blank ("") means none.
   */
  public Token getXnameImport() {
    return xnameImport;
  }
}
TOP

Related Classes of etch.compiler.opt.Extern

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.