Changeset 13442


Ignore:
Timestamp:
Sep 10, 2019 5:18:44 PM (3 months ago)
Author:
molsson
Message:

#5827 Fixed errors when variable with same name as instream variable already exists.

Location:
branches/dev-mo-2267/Compiler
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-mo-2267/Compiler/ModelicaFlatTree/src/jastadd/FlatAPI/FlatAPI.jrag

    r13425 r13442  
    31723172    ASTNode implements CausalPortsEvaluator;
    31733173    syn boolean ASTNode.useCausalPorts() = myOptions().causal_ports.getValue();
    3174    
    3175     syn boolean FAbstractVariable.isInStream() = false;
    3176     eq FVariable.isInStream() = getCausalityConnectorPrefix().isInStream();
    31773174}
    31783175
  • branches/dev-mo-2267/Compiler/ModelicaFrontEnd/src/jastadd/flattening/Flattening.jrag

    r13411 r13442  
    12201220    }
    12211221
    1222     public FVariable InstAssignable.flatten(Flattener f, FlattenBindingExp binding, int level, boolean global) {
     1222    public void InstAssignable.flatten(Flattener f, FlattenBindingExp binding, int level, boolean global) {
    12231223        if (useInFlattening() && (global || !flattenAsGlobalVariable())) {
    12241224            if (hasBindingFExp()) {
     
    12381238                f.addFVariable(fv);
    12391239            }
     1240            if (fv.getCausalityConnectorPrefix().isStream() && useCausalPorts()) {
     1241                FVariable inStream = fv.treeCopy();
     1242                FAccess inStreamAccess = createInStreamAccess(inStream.getFAccess());
     1243                inStream.setFAccess(inStreamAccess);
     1244                inStream.setCausalityConnectorPrefix(CausalityConnectorPrefix.INSTREAM);
     1245                fv.annotation().vendorNode().forPath("internal/instream").setValue(new FStringLitExp(inStreamAccess.name()));
     1246                f.addFVariable(inStream);
     1247            }
    12401248            flattenMyType(f);
    12411249            clearModificationLevel(oldLevels);
    1242             return fv;
    1243         }
    1244         return null;
     1250        }
     1251    }
     1252   
     1253    inh FAccess InstAssignable.createInStreamAccess(FAccess streamAccess);
     1254    eq InstClassDecl.getChild().createInStreamAccess(FAccess streamAccess) {
     1255        FAccess lastPart = streamAccess.copyLastSuffix();
     1256        String streamName = lastPart.name();
     1257        String end = "";
     1258        if (streamName.endsWith("]")) {
     1259            int index = streamName.lastIndexOf("[");
     1260            end = streamName.substring(index);
     1261            streamName = streamName.substring(0, index);
     1262        }
     1263        if (streamName.endsWith("'")) {
     1264            streamName = streamName.substring(0, streamName.length() - 1);
     1265            end = "'" + end;
     1266        }
     1267        FAccess result = streamAccess.copyPrefix().append(streamName + "__instream_" + end, lastPart.getFArraySubscripts());
     1268        int i = 2;
     1269        while (componentExists(new QualifiedName(result.name()))) {
     1270            result = streamAccess.copyPrefix().append(streamName + "__instream_" + i + end, lastPart.getFArraySubscripts());
     1271            i++;
     1272        }
     1273        return result;
    12451274    }
    12461275   
  • branches/dev-mo-2267/Compiler/ModelicaFrontEnd/src/jastadd/flattening/FlatteningStatements.jrag

    r12184 r13442  
    245245    eq Root.getChild().breakCondName() = null;
    246246
    247     public boolean InstClassDecl.componentExists(String name) {
     247    public boolean InstNode.componentExists(String name) {
    248248        for (InstComponentDecl decl : allInstComponentDecls()) {
    249249            if (decl.name().equals(name)) {
    250250                return true;
    251251            }
     252        }
     253        return false;
     254    }
     255   
     256    public boolean InstNode.componentExists(Iterator<String> qualifiedName) {
     257        if (!qualifiedName.hasNext()) {
     258            return true;
     259        }
     260        String name = qualifiedName.next();
     261        if (componentExists(name)) {
     262            return memberInstComponent(name).targetOrNull().componentExists(qualifiedName);
    252263        }
    253264        return false;
  • branches/dev-mo-2267/Compiler/ModelicaFrontEnd/src/jastadd/flattening/connections/Connections.jrag

    r13411 r13442  
    576576                }
    577577            }
    578 
    579             ConnectionSetEntry fst = first();
    580             InstAssignable fstVar = (InstAssignable) fst.getVar();
    581             if (size() == 1 && fst.isInside() && fstVar.isTopLevelCausalOrConnector()
    582                     && (fstVar.isInput() || fstVar.isOutput() || fstVar.useCausalPorts())) {
    583                 FVariable fv = fstVar.flatten(f, FlattenBindingExp.NONE, 1, false);
    584                 FAccess inStreamAccess = createInStreamAccess(fv.getFAccess());
    585                 fv.setFAccess(inStreamAccess);
    586                 fv.setCausalityConnectorPrefix(CausalityConnectorPrefix.INSTREAM);
    587             }
    588578        }
    589579
     
    597587            String name = access.name();
    598588            ConnectionSetEntry e = getConnectionSetEntry(name, false);
    599             String nameWithSuffix = nameWithSuffix(name);
    600             if (access.useCausalPorts() && !access.lookupFV(nameWithSuffix).isUnknown()) {
    601                 access = new FAccessString(nameWithSuffix);
     589            if (access.useCausalPorts()) {
     590                AnnotationNode instreamAnnotation = access.myFV().annotation().vendorNode().forPath("internal/instream");
     591                if (instreamAnnotation.exists()) {
     592                    String instreamName = instreamAnnotation.ceval().stringValue();
     593                    access = nameWithSubscripts(instreamName, name);
     594                }
    602595            }
    603596            FExp exp = expandInStreamExp(e, name, new FAccessExp(access));
     
    606599        }
    607600       
    608         public String nameWithSuffix(String access) {
    609             String name = access;
    610             String subscripts = "";
    611             if (name.endsWith("]")) {
    612                 int subscriptsIndex = access.lastIndexOf("[");
    613                 name = access.substring(0, subscriptsIndex);
    614                 subscripts = access.substring(subscriptsIndex);
    615             }
    616             return name + inStreamSuffix + subscripts;
     601        public FAccess nameWithSubscripts(String name, String access) {
     602            String subscripts = (access.endsWith("]")) ? access.substring(access.lastIndexOf("[")) : "";
     603            return new FAccessString(name + subscripts);
    617604       }
    618605
     
    647634            }
    648635        }
    649        
    650         private FAccess createInStreamAccess(FAccess access) {
    651             FAccess lastPart = access.copyLastSuffix();
    652             return access.copyPrefix().append(lastPart.name() + inStreamSuffix, lastPart.getFArraySubscripts());
    653         }
    654636    }
    655637
  • branches/dev-mo-2267/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/ast/prefixes/CausalityConnectorPrefix.java

    r13425 r13442  
    2222    }
    2323   
    24     public boolean isInStream() {
    25         return this == INSTREAM;
     24    public boolean isStream() {
     25        return this == STREAM;
    2626    }
    2727   
  • branches/dev-mo-2267/Compiler/ModelicaMiddleEnd/test/modelica/CausalPorts.mo

    r13411 r13442  
    105105 potential Real c.p;
    106106 flow Real c.f;
    107  stream Real c.s;
     107 stream Real c.s annotation(__Modelon(internal(instream = \"c.s__instream_\")));
    108108 inStream Real c.s__instream_;
    109109equation
     
    120120 potential Real c.p;
    121121 flow Real c.f;
    122  stream Real c.s;
     122 stream Real c.s annotation(__Modelon(internal(instream = \"c.s__instream_\")));
    123123 inStream Real c.s__instream_;
    124124equation
     
    173173 potential Real c.p;
    174174 flow Real c.f;
    175  stream Real c.s;
     175 stream Real c.s annotation(__Modelon(internal(instream = \"c.s__instream_\")));
     176 inStream Real c.s__instream_;
    176177 Real a1.c.p;
    177178 Real a1.c.f;
     
    180181 Real a2.c.f;
    181182 Real a2.c.s;
    182  inStream Real c.s__instream_;
    183183equation
    184184 c.p = time;
     
    217217 potential Real c.p;
    218218 flow Real c.f;
    219  stream Real c.s1[0];
    220  stream Real c.s2[2];
     219 stream Real c.s1[0] annotation(__Modelon(internal(instream = \"c.s1__instream_\")));
    221220 inStream Real c.s1__instream_[0];
     221 stream Real c.s2[2] annotation(__Modelon(internal(instream = \"c.s2__instream_\")));
    222222 inStream Real c.s2__instream_[2];
    223223equation
     
    235235 potential Real c.p;
    236236 flow Real c.f;
    237  stream Real c.s2[1];
    238  stream Real c.s2[2];
     237 stream Real c.s2[1] annotation(__Modelon(internal(instream = \"c.s2__instream_\")));
     238 stream Real c.s2[2] annotation(__Modelon(internal(instream = \"c.s2__instream_\")));
    239239 inStream Real c.s2__instream_[1];
    240240 inStream Real c.s2__instream_[2];
     
    248248
    249249
     250model Stream4
     251    connector C
     252        Real p;
     253        flow Real f;
     254        stream Real 's.s';
     255        stream Real 's.s__instream_';
     256    end C;
     257    C 'c.c';
     258equation
     259    'c.c'.p = time;
     260    'c.c'.'s.s' = inStream('c.c'.'s.s');
     261    'c.c'.'s.s__instream_' = inStream('c.c'.'s.s__instream_');
     262annotation(__JModelica(UnitTesting(tests={
     263    FlatteningTestCase(
     264        description="Instream variable name is already used",
     265        causal_ports=true,
     266        eliminate_alias_variables=false,
     267        variability_propagation=false,
     268        flatModel="
     269fclass CausalPorts.Stream4
     270 potential Real 'c.c'.p;
     271 flow Real 'c.c'.f;
     272 stream Real 'c.c'.'s.s' annotation(__Modelon(internal(instream = \"'c.c'.'s.s__instream_2'\")));
     273 inStream Real 'c.c'.'s.s__instream_2';
     274 stream Real 'c.c'.'s.s__instream_' annotation(__Modelon(internal(instream = \"'c.c'.'s.s__instream___instream_'\")));
     275 inStream Real 'c.c'.'s.s__instream___instream_';
     276equation
     277 'c.c'.p = time;
     278 'c.c'.'s.s' = inStream('c.c'.'s.s');
     279 'c.c'.'s.s__instream_' = inStream('c.c'.'s.s__instream_');
     280end CausalPorts.Stream4;
     281"), TransformCanonicalTestCase(
     282        description="Instream variable name is already used",
     283        causal_ports=true,
     284        eliminate_alias_variables=false,
     285        variability_propagation=false,
     286        flatModel="
     287fclass CausalPorts.Stream4
     288 potential Real 'c.c'.p;
     289 flow Real 'c.c'.f;
     290 stream Real 'c.c'.'s.s' annotation(__Modelon(internal(instream = \"'c.c'.'s.s__instream_2'\")));
     291 inStream Real 'c.c'.'s.s__instream_2';
     292 stream Real 'c.c'.'s.s__instream_' annotation(__Modelon(internal(instream = \"'c.c'.'s.s__instream___instream_'\")));
     293 inStream Real 'c.c'.'s.s__instream___instream_';
     294equation
     295 'c.c'.p = time;
     296 'c.c'.'s.s' = 'c.c'.'s.s__instream_2';
     297 'c.c'.'s.s__instream_' = 'c.c'.'s.s__instream___instream_';
     298end CausalPorts.Stream4;
     299")})));
     300end Stream4;
     301
     302
    250303end CausalPorts;
Note: See TracChangeset for help on using the changeset viewer.