001    package escjava.vcGeneration;
002    
003    import java.io.IOException;
004    
005    public class TName extends TVariable {
006    
007        /*@ non_null @*/public String name;
008    
009        /**
010         * type is supposed to be one of the object that is statically
011         * initialized in TNode, like _Reference, _Type etc...
012         */
013        protected TName(/*@ non_null @*/String name) {
014            this.name = name;
015        }
016    
017        public void accept(/*@ non_null @*/TVisitor v) throws IOException {
018            v.visitTName(this);
019        }
020        protected void typeTree(){
021            // lets try to fetch our type...
022            if(type == null) {
023                    VariableInfo vi = TNode.getVariableInfo(name);
024                    type = vi.type;
025            }
026        }
027        
028        protected void setType(TypeInfo type, boolean sure){
029            
030                TName m = (TName)this;
031                //@ assert m.type == null;
032    
033                // retrieve current type;
034                if(!variablesName.containsKey(m.name)) {
035                    TDisplay.err(this, "setType(TypeInfo, boolean)", "You're manipulating a TName ("+m.name+") node, yet the name isn't in the global map 'variablesName'");
036                }
037                // take care no else here
038                
039                VariableInfo vi = (VariableInfo)variablesName.get(m.name);
040                
041                if(vi.type == null) {// we set it
042                    vi.type = type;
043                }
044                else {
045                            if(!vi.type.equals(type)) {// inconsistency
046                                if(vi.typeSure) // we don't change it
047                                    TDisplay.err(this, "setType(TypeInfo, boolean)", "Variable named "+m.name+", has type "+vi.type.old+" yet you try to change it to "+type.old);
048                                else {
049                                    if(type == _Reference) {
050                                            // no we won't change it !!!
051                                            TDisplay.warn(this, "setType(TypeInfo, boolean)", "I won't change the type of "+m.name+" (which was "+vi.type.old+") to this silly type : "+type.old);
052                                    }
053                                    else {
054                                            TDisplay.warn(this, "setType(TypeInfo, boolean)", "Changing type of "+m.name+" (which was "+vi.type.old+") to "+type.old);
055                                            vi.type = type;
056                                    }
057                                }
058                            }           
059                }
060                this.type = vi.type;
061       }
062    }
063    
064    
065