PragmaHandler.java revision 608:7e06bf1dcb09
1139749Simp/*
259477Swpaul * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
359477Swpaul * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
459477Swpaul *
559477Swpaul * This code is free software; you can redistribute it and/or modify it
659477Swpaul * under the terms of the GNU General Public License version 2 only, as
759477Swpaul * published by the Free Software Foundation.  Oracle designates this
859477Swpaul * particular file as subject to the "Classpath" exception as provided
959477Swpaul * by Oracle in the LICENSE file that accompanied this code.
1059477Swpaul *
1159477Swpaul * This code is distributed in the hope that it will be useful, but WITHOUT
1259477Swpaul * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1359477Swpaul * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1459477Swpaul * version 2 for more details (a copy is included in the LICENSE file that
1559477Swpaul * accompanied this code).
1659477Swpaul *
1759477Swpaul * You should have received a copy of the GNU General Public License version
1859477Swpaul * 2 along with this work; if not, write to the Free Software Foundation,
1959477Swpaul * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2059477Swpaul *
2159477Swpaul * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2259477Swpaul * or visit www.oracle.com if you need additional information or have any
2359477Swpaul * questions.
2459477Swpaul */
2559477Swpaul/*
2659477Swpaul * COMPONENT_NAME: idl.parser
2759477Swpaul *
2859477Swpaul * ORIGINS: 27
2959477Swpaul *
3059477Swpaul * Licensed Materials - Property of IBM
3159477Swpaul * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
3259477Swpaul * RMI-IIOP v1.0
33119418Sobrien *
34119418Sobrien */
35119418Sobrien
3659477Swpaulpackage com.sun.tools.corba.se.idl;
37166680Sjkim
3859477Swpaul// NOTES:
3959477Swpaul// - Add openScope and closeScope.
4059477Swpaul
4159477Swpaulimport java.io.IOException;
4259477Swpaul
43129876Sphkpublic abstract class PragmaHandler
4459477Swpaul{
4559477Swpaul  public abstract boolean process (String pragma, String currentToken) throws IOException;
4659477Swpaul
4759477Swpaul  void init (Preprocessor p)
48157642Sps  {
4959477Swpaul    preprocessor = p;
5059477Swpaul  } // init
5159477Swpaul
5259477Swpaul  // Utility methods.
53109514Sobrien
5459477Swpaul  /** Get the current token. */
5559477Swpaul  protected String currentToken ()
56117659Swpaul  {
57117659Swpaul    return preprocessor.currentToken ();
58117659Swpaul  } // currentToken
59157642Sps
6059477Swpaul  /** This method, given an entry name, returns the entry with that name.
61119285Simp      It can take fully or partially qualified names and returns the
62119285Simp      appropriate entry defined within the current scope.  If no entry
63118814Swpaul      exists, null is returned. */
6459477Swpaul  protected SymtabEntry getEntryForName (String string)
6559477Swpaul  {
66105135Salfred    return preprocessor.getEntryForName (string);
67105135Salfred  } // getEntryForName
6859477Swpaul
69166037Sjkim  /** This method returns a string of all of the characters from the input
70166037Sjkim      file from the current position up to, but not including, the end-of-line
71170391Sdavidch      character(s). */
72204941Ssobomax  protected String getStringToEOL () throws IOException
73204941Ssobomax  {
74204941Ssobomax    return preprocessor.getStringToEOL ();
75205299Sdavidch  } // getStringToEOL
76179772Sdavidch
77166037Sjkim  /** This method returns a string of all of the characters from the input
78166037Sjkim      file from the current position up to, but not including, the given
7959477Swpaul      character.  It encapsulates parenthesis and quoted strings, meaning
8059477Swpaul      it does not stop if the given character is found within parentheses
8159477Swpaul      or quotes.  For instance, given the input of `start(inside)end',
8259477Swpaul      getUntil ('n') will return "start(inside)e" */
8395722Sphk  protected String getUntil (char c) throws IOException
8459477Swpaul  {
8559477Swpaul    return preprocessor.getUntil (c);
8659477Swpaul  } // getUntil
8759477Swpaul
8859477Swpaul  /** This method returns the next token String from the input file. */
8959477Swpaul  protected String nextToken () throws IOException
9059477Swpaul  {
9159477Swpaul    return preprocessor.nextToken ();
9259477Swpaul  } // nextToken
93166049Sjkim
9459477Swpaul  /** This method assumes that the current token marks the beginning
9559477Swpaul      of a scoped name.  It then parses the subsequent identifier and
9659477Swpaul      double colon tokens, builds the scoped name, and finds the symbol
9759477Swpaul      table entry with that name. */
9884145Sjlemon  protected SymtabEntry scopedName () throws IOException
99215297Smarius  {
10084145Sjlemon    return preprocessor.scopedName ();
101215297Smarius  } // scopedName
102114590Sps
103170391Sdavidch  /** Skip to the end of the line. */
104114590Sps  protected void skipToEOL () throws IOException
105114590Sps  {
106204144Smarius    preprocessor.skipToEOL ();
107166676Sjkim  } // skipToEOL
108166031Sjkim
109166673Sjkim  /** This method skips the data in the input file until the specified
110166031Sjkim      character is encountered, then it returns the next token. */
111166677Sjkim  protected String skipUntil (char c) throws IOException
112166031Sjkim  {
113166032Sjkim    return preprocessor.skipUntil (c);
114166032Sjkim  } // skipUntil
11559477Swpaul
116160078Syongari  /** This method displays a Parser Exception complete with line number
117221407Smarius      and position information with the given message string. */
118221407Smarius  protected void parseException (String message)
119221407Smarius  {
120221407Smarius    preprocessor.parseException (message);
121221407Smarius  } // parseException
122221407Smarius
123221407Smarius  /** This method is called when the parser encounters a left curly brace.
124221407Smarius      An extender of PragmaHandler may find scope information useful.
125221407Smarius      For example, the prefix pragma takes effect as soon as it is
126221407Smarius      encountered and stays in effect until the current scope is closed.
127221407Smarius      If a similar pragma extension is desired, then the openScope and
128221407Smarius      closeScope methods are available for overriding.
129221407Smarius      @param entry the symbol table entry whose scope has just been opened.
130221407Smarius       Be aware that, since the scope has just been entered, this entry is
131221407Smarius       incomplete at this point.  */
132221407Smarius  protected void openScope (SymtabEntry entry)
133221407Smarius  {
134221407Smarius  } // openScope
135221407Smarius
136221407Smarius  /** This method is called when the parser encounters a right curly brace.
137221407Smarius      An extender of PragmaHandler may find scope information useful.
138221407Smarius      For example, the prefix pragma takes effect as soon as it is
139221407Smarius      encountered and stays in effect until the current scope is closed.
140221407Smarius      If a similar pragma extension is desired, then the openScope and
141221407Smarius      closeScope methods are available for overriding.
142221407Smarius      @param entry the symbol table entry whose scope has just been closed. */
143221407Smarius  protected void closeScope (SymtabEntry entry)
144221407Smarius  {
145160078Syongari  } // closeScope
146160078Syongari
147160078Syongari  private Preprocessor preprocessor = null;
148221407Smarius} // class PragmaHandler
149221407Smarius