| Home >> All |
Source code: engine/ConnectionDescription.java
1 2 /* ********************************** 3 File:ConnectionDescription.java 4 Author: Alec(panovici@elcom.pub.ro) 5 Created on Mon Jul 19 08:13:29 EEST 1999 6 Comments: Part of the vIDE Project 7 Copyright 1999 the vIDE Team. 8 ***********************************/ 9 10 package engine; 11 12 import middle.*; 13 import java.util.*; 14 15 /** 16 * A connection from inside a module to the outside world. 17 * It may contain a selection of ports bundled together under a 18 * single name visible from outside or an expression to be assigned to 19 * the port designated by the name (in a named parameter list). 20 */ 21 22 class ConnectionDescription extends Symbol{ 23 24 /** 25 * The in/out/both type of the connection 26 */ 27 int type; 28 29 /** 30 * The ports bundled inside this name 31 */ 32 ExpressionDescription portExpDesc; 33 34 boolean preparedForContSelection; 35 36 ConnectionDescription(String name, int lineNo, 37 ExpressionDescription portExpDesc){ 38 super(name, lineNo); 39 this.portExpDesc = portExpDesc; 40 } 41 42 /** 43 * If this expression is a port selection, computes the overall type: 44 * if all ports have tha same type with the exception of the inuout ones, 45 * the overall type is the same. If all the ports are inout, the 46 * overall is inout. 47 * Note that the if a port identifier is from another module (a fqn with more 48 * than one node), a parse exception is thrown 49 * else, an exception is thrown 50 */ 51 int computeType(DefaultNameSpaceDescription nsd) throws ParseException { 52 // verifies that all the ports have comaptible types 53 PortDescription pd; 54 try{ 55 GenericSelectorDescription gsd = (GenericSelectorDescription) portExpDesc; 56 if((pd = nsd.isPort((String) gsd.fqn.node)) != null) 57 return type = pd.type; 58 throw new ParseException (":error : bad port expression : \"" + 59 gsd.fqn + "\" is not a port"); 60 } catch (ClassCastException cex) {} 61 try { 62 for(Enumeration e = 63 ((SelectionExpressionDescription)portExpDesc).elements() ; 64 e.hasMoreElements() ; ) 65 { 66 GenericSelectorDescription ck = 67 (GenericSelectorDescription)e.nextElement(); 68 if((pd = nsd.isPort((String) ck.fqn.node)) != null){ 69 if(type == PortDescription.none)type = pd.type; 70 else 71 if(!((pd.type == type) || 72 (pd.type == PortDescription.inout) || 73 (type == PortDescription.inout))) 74 throw new ParseException(":error : bad port expression : \"" + 75 pd.name 76 + "\" and \"" + name + 77 "\" types do not match"); 78 }else 79 throw new ParseException(nsd.toString(lineNo) + 80 ":error : bad port expression : \"" + 81 pd.name + "\" is not a port"); 82 } 83 } catch (ClassCastException cex) { 84 throw new ParseException( ":error: bad port expression : not a port selection"); 85 } 86 return type; 87 } 88 89 Object instantiate(NameSpace ns, ScopeNode thisScope)throws ParseException{ 90 Expression exp; 91 92 if (portExpDesc == null) { //fake connection ? 93 type = PortDescription.inout; 94 return null; 95 } 96 97 try{ 98 exp = portExpDesc.instantiate(ns); 99 }catch(ParseException ex){ 100 xConsole.dumpStack(ex); 101 throw new ParseException(ns.desc.toString(lineNo) + ex); 102 } 103 104 return exp; 105 } 106 107 /** 108 * Makes this expression a continuous expression 109 */ 110 void prepareForContSelection()throws ParseException{ 111 if(preparedForContSelection)return; 112 preparedForContSelection = true; 113 try{ 114 ((AssignableSelection)portExpDesc).toContSelection(); 115 }catch(ClassCastException ex){ 116 throw new ParseException(" error: \"" + name + 117 "\" cannot be input"); 118 } 119 } 120 121 public int getType(){ 122 return connType; 123 } 124 } 125 126 127