Thu, 31 Aug 2017 18:10:36 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | /* |
aoqi@0 | 26 | * COMPONENT_NAME: shasta |
aoqi@0 | 27 | * |
aoqi@0 | 28 | * ORIGINS: 27 |
aoqi@0 | 29 | * |
aoqi@0 | 30 | * Licensed Materials - Property of IBM |
aoqi@0 | 31 | * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997,1998,1999 |
aoqi@0 | 32 | * RMI-IIOP v1.0 |
aoqi@0 | 33 | * |
aoqi@0 | 34 | */ |
aoqi@0 | 35 | |
aoqi@0 | 36 | package com.sun.tools.corba.se.idl.som.idlemit; |
aoqi@0 | 37 | import java.util.Vector; |
aoqi@0 | 38 | import com.sun.tools.corba.se.idl.som.cff.Messages; |
aoqi@0 | 39 | /** |
aoqi@0 | 40 | * This is an implementation that handles |
aoqi@0 | 41 | * #pragma meta scoped_name string |
aoqi@0 | 42 | * where |
aoqi@0 | 43 | * <UL> |
aoqi@0 | 44 | * <LI> scoped_name == "::" separated scoped name |
aoqi@0 | 45 | * <LI> string == separated identifiers, such as "localonly", |
aoqi@0 | 46 | * "abstract", or "init". |
aoqi@0 | 47 | * D59407: NOTE: any non-white-space is grouped |
aoqi@0 | 48 | * as part of the identifier. |
aoqi@0 | 49 | * </UL> |
aoqi@0 | 50 | * |
aoqi@0 | 51 | * This pragma handler places a vector of Strings into the dynamicVariable() |
aoqi@0 | 52 | * part of the SymtabEntry. The key to access the dynamicVariable() |
aoqi@0 | 53 | * is com.sun.tools.corba.se.idl.som.idlemit.MetaPragma.metaKey |
aoqi@0 | 54 | * |
aoqi@0 | 55 | * It is possible to associate a meta pragma with a forward entry. |
aoqi@0 | 56 | * At some point after the parser has completed, |
aoqi@0 | 57 | * the method processForward(ForwardEntry entry) should be called |
aoqi@0 | 58 | * for each ForwardEntry so that the meta information can be folded from |
aoqi@0 | 59 | * the ForwardEntry into the corresponding InterfaceEntry. |
aoqi@0 | 60 | */ |
aoqi@0 | 61 | public class MetaPragma extends com.sun.tools.corba.se.idl.PragmaHandler { |
aoqi@0 | 62 | /* Class variables */ |
aoqi@0 | 63 | |
aoqi@0 | 64 | /* key to access the Cached meta info in com.sun.tools.corba.se.idl.SymtabEntry */ |
aoqi@0 | 65 | public static int metaKey = com.sun.tools.corba.se.idl.SymtabEntry.getVariableKey(); |
aoqi@0 | 66 | |
aoqi@0 | 67 | |
aoqi@0 | 68 | /** |
aoqi@0 | 69 | * Main entry point for the MetaPragma handler |
aoqi@0 | 70 | * @param pragma string for pragma name |
aoqi@0 | 71 | * @param currentToken next token in the input stream. |
aoqi@0 | 72 | * @return true if this is a meta pragma. |
aoqi@0 | 73 | */ |
aoqi@0 | 74 | public boolean process(String pragma, String currentToken) { |
aoqi@0 | 75 | if ( !pragma.equals("meta")) |
aoqi@0 | 76 | return false; |
aoqi@0 | 77 | |
aoqi@0 | 78 | com.sun.tools.corba.se.idl.SymtabEntry entry ; |
aoqi@0 | 79 | String msg; |
aoqi@0 | 80 | try { |
aoqi@0 | 81 | entry = scopedName(); |
aoqi@0 | 82 | if ( entry == null){ |
aoqi@0 | 83 | /* scoped name not found */ |
aoqi@0 | 84 | parseException(Messages.msg("idlemit.MetaPragma.scopedNameNotFound")); |
aoqi@0 | 85 | skipToEOL(); |
aoqi@0 | 86 | } |
aoqi@0 | 87 | else { |
aoqi@0 | 88 | msg = (currentToken()+ getStringToEOL()); |
aoqi@0 | 89 | // System.out.println(entry + ": " + msg); |
aoqi@0 | 90 | Vector v; |
aoqi@0 | 91 | v = (Vector) entry.dynamicVariable(metaKey); |
aoqi@0 | 92 | if ( v== null){ |
aoqi@0 | 93 | v = new Vector(); |
aoqi@0 | 94 | entry.dynamicVariable(metaKey, v); |
aoqi@0 | 95 | } |
aoqi@0 | 96 | parseMsg(v, msg); |
aoqi@0 | 97 | } |
aoqi@0 | 98 | } catch(Exception e){ |
aoqi@0 | 99 | // System.out.println("exception in MetaPragma"); |
aoqi@0 | 100 | } |
aoqi@0 | 101 | return true; |
aoqi@0 | 102 | } |
aoqi@0 | 103 | |
aoqi@0 | 104 | |
aoqi@0 | 105 | /** |
aoqi@0 | 106 | * Fold the meta info from the forward entry into its corresponding |
aoqi@0 | 107 | * interface entry. |
aoqi@0 | 108 | * @param forwardEntry the forward entry to process |
aoqi@0 | 109 | */ |
aoqi@0 | 110 | static public void processForward(com.sun.tools.corba.se.idl.ForwardEntry forwardEntry){ |
aoqi@0 | 111 | |
aoqi@0 | 112 | Vector forwardMeta; |
aoqi@0 | 113 | try { |
aoqi@0 | 114 | forwardMeta = (Vector)forwardEntry.dynamicVariable(metaKey); |
aoqi@0 | 115 | } catch (Exception e){ |
aoqi@0 | 116 | forwardMeta = null; |
aoqi@0 | 117 | } |
aoqi@0 | 118 | com.sun.tools.corba.se.idl.SymtabEntry forwardInterface = forwardEntry.type(); |
aoqi@0 | 119 | if (forwardMeta != null && forwardInterface!= null) { |
aoqi@0 | 120 | Vector interfaceMeta; |
aoqi@0 | 121 | try { |
aoqi@0 | 122 | interfaceMeta= (Vector)forwardInterface.dynamicVariable(metaKey); |
aoqi@0 | 123 | } catch ( Exception e){ |
aoqi@0 | 124 | interfaceMeta = null; |
aoqi@0 | 125 | } |
aoqi@0 | 126 | |
aoqi@0 | 127 | if ( interfaceMeta == null) { |
aoqi@0 | 128 | /* set */ |
aoqi@0 | 129 | try { |
aoqi@0 | 130 | forwardInterface.dynamicVariable(MetaPragma.metaKey, forwardMeta); |
aoqi@0 | 131 | } catch(Exception e){}; |
aoqi@0 | 132 | } |
aoqi@0 | 133 | else if (interfaceMeta != forwardMeta) { |
aoqi@0 | 134 | /* The above check is needed because sometimes |
aoqi@0 | 135 | a forward entry is processed more the once. |
aoqi@0 | 136 | Not sure why */ |
aoqi@0 | 137 | /* merge */ |
aoqi@0 | 138 | for (int i=0; i < forwardMeta.size(); i++){ |
aoqi@0 | 139 | try { |
aoqi@0 | 140 | Object obj = forwardMeta.elementAt(i); |
aoqi@0 | 141 | interfaceMeta.addElement(obj); |
aoqi@0 | 142 | } catch (Exception e){}; |
aoqi@0 | 143 | } |
aoqi@0 | 144 | } |
aoqi@0 | 145 | } |
aoqi@0 | 146 | } |
aoqi@0 | 147 | |
aoqi@0 | 148 | /** |
aoqi@0 | 149 | * parse pragma message and place into vector v. |
aoqi@0 | 150 | * @param v: vector to add message |
aoqi@0 | 151 | * @param msg: string of comma separated message, perhaps with comment. |
aoqi@0 | 152 | * This is implemented as a state machine as follows: |
aoqi@0 | 153 | * |
aoqi@0 | 154 | * State token next action |
aoqi@0 | 155 | * ----------------------------------------------------- |
aoqi@0 | 156 | * initial whitespace initial |
aoqi@0 | 157 | * initial SlashStar comment |
aoqi@0 | 158 | * initial SlashSlash final |
aoqi@0 | 159 | * initial no more final |
aoqi@0 | 160 | * initial text text add to text buffer |
aoqi@0 | 161 | * initial StarSlash initial |
aoqi@0 | 162 | * comment StarSlash initial |
aoqi@0 | 163 | * comment SlashStar comment |
aoqi@0 | 164 | * comment whitespace comment |
aoqi@0 | 165 | * comment SlashSlash comment |
aoqi@0 | 166 | * comment text comment |
aoqi@0 | 167 | * comment no more final |
aoqi@0 | 168 | * text text text add to buffer |
aoqi@0 | 169 | * text SlashStar comment put in vector |
aoqi@0 | 170 | * text whitespace initial put in vector |
aoqi@0 | 171 | * text SlashSlash final put in vector |
aoqi@0 | 172 | * text StarSlash initial put in vector |
aoqi@0 | 173 | * text no more final put in vector |
aoqi@0 | 174 | * |
aoqi@0 | 175 | */ |
aoqi@0 | 176 | private static int initialState = 0; |
aoqi@0 | 177 | private static int commentState = 1; |
aoqi@0 | 178 | private static int textState = 2; |
aoqi@0 | 179 | private static int finalState =3; |
aoqi@0 | 180 | |
aoqi@0 | 181 | private void parseMsg(Vector v, String msg){ |
aoqi@0 | 182 | int state = initialState; |
aoqi@0 | 183 | String text = ""; |
aoqi@0 | 184 | int index = 0; |
aoqi@0 | 185 | while ( state != finalState ){ |
aoqi@0 | 186 | boolean isNoMore = index >= msg.length(); |
aoqi@0 | 187 | char ch = ' '; |
aoqi@0 | 188 | boolean isSlashStar = false; |
aoqi@0 | 189 | boolean isSlashSlash = false; |
aoqi@0 | 190 | boolean isWhiteSpace = false; |
aoqi@0 | 191 | boolean isStarSlash = false; |
aoqi@0 | 192 | boolean isText = false; |
aoqi@0 | 193 | if (!isNoMore ){ |
aoqi@0 | 194 | ch = msg.charAt(index); |
aoqi@0 | 195 | if (ch == '/' && index+1 < msg.length()){ |
aoqi@0 | 196 | if (msg.charAt(index+1) == '/'){ |
aoqi@0 | 197 | isSlashSlash = true; |
aoqi@0 | 198 | index++; |
aoqi@0 | 199 | } |
aoqi@0 | 200 | else if (msg.charAt(index+1) == '*'){ |
aoqi@0 | 201 | isSlashStar= true; |
aoqi@0 | 202 | index++; |
aoqi@0 | 203 | } else isText = true; |
aoqi@0 | 204 | } |
aoqi@0 | 205 | else if (ch == '*' && index+1 < msg.length() ){ |
aoqi@0 | 206 | if (msg.charAt(index+1) == '/'){ |
aoqi@0 | 207 | isStarSlash = true; |
aoqi@0 | 208 | index++; |
aoqi@0 | 209 | } else isText = true; |
aoqi@0 | 210 | } |
aoqi@0 | 211 | else if ( Character.isSpace(ch) || (ch == ',') // 59601 |
aoqi@0 | 212 | || (ch == ';') ) // 59683 |
aoqi@0 | 213 | isWhiteSpace = true; |
aoqi@0 | 214 | else isText = true; |
aoqi@0 | 215 | } |
aoqi@0 | 216 | |
aoqi@0 | 217 | if (state == initialState){ |
aoqi@0 | 218 | if (isSlashStar){ |
aoqi@0 | 219 | state = commentState; |
aoqi@0 | 220 | } |
aoqi@0 | 221 | else if (isSlashSlash || isNoMore){ |
aoqi@0 | 222 | state = finalState; |
aoqi@0 | 223 | } |
aoqi@0 | 224 | else if (isText){ |
aoqi@0 | 225 | state = textState; |
aoqi@0 | 226 | text = text+ ch; |
aoqi@0 | 227 | } |
aoqi@0 | 228 | } |
aoqi@0 | 229 | else if (state == commentState){ |
aoqi@0 | 230 | if (isNoMore){ |
aoqi@0 | 231 | state = finalState; |
aoqi@0 | 232 | } |
aoqi@0 | 233 | else if ( isStarSlash){ |
aoqi@0 | 234 | state = initialState; |
aoqi@0 | 235 | } |
aoqi@0 | 236 | } |
aoqi@0 | 237 | else if (state == textState){ |
aoqi@0 | 238 | if (isNoMore || isStarSlash || isSlashSlash || |
aoqi@0 | 239 | isSlashStar || isWhiteSpace ){ |
aoqi@0 | 240 | if (!text.equals("")) { |
aoqi@0 | 241 | v.addElement(text); |
aoqi@0 | 242 | // System.err.println("adding " + text); |
aoqi@0 | 243 | text = ""; |
aoqi@0 | 244 | } |
aoqi@0 | 245 | if (isNoMore) |
aoqi@0 | 246 | state = finalState; |
aoqi@0 | 247 | else if (isSlashStar) |
aoqi@0 | 248 | state = commentState; |
aoqi@0 | 249 | else state = initialState; |
aoqi@0 | 250 | } |
aoqi@0 | 251 | else if (isText){ |
aoqi@0 | 252 | text = text+ch; |
aoqi@0 | 253 | } |
aoqi@0 | 254 | } |
aoqi@0 | 255 | index++; |
aoqi@0 | 256 | } |
aoqi@0 | 257 | } |
aoqi@0 | 258 | |
aoqi@0 | 259 | } |