Changeset 14185


Ignore:
Timestamp:
Nov 26, 2019 7:12:28 PM (2 weeks ago)
Author:
amartensen
Message:

#5879 performing lookup after parsing anonymous class

Location:
branches/dev-2559/Compiler/ModelicaFrontEnd/src/jastadd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-2559/Compiler/ModelicaFrontEnd/src/jastadd/instance/InstanceTree.jrag

    r13621 r14185  
    893893    private Map<String,SrcClassDecl> Program.anonymousClassMap = null;
    894894
    895     syn SrcClassDecl Program.anonymousClass(String code, SrcRestriction restriction, String targetName) {
     895    syn SrcClassDecl Program.anonymousClass(String code) {
    896896        if (anonymousClassMap == null)
    897897            anonymousClassMap = new HashMap<String,SrcClassDecl>();
     
    899899        if (res == null) {
    900900            try {
    901                 addAnonymousClass(root().getUtilInterface().getParserHandler().parseAnonymousClassString(code, restriction, targetName));
     901                SrcShortClassDecl anonymousClass = (SrcShortClassDecl) root().getUtilInterface().getParserHandler() .parseAnonymousClassString(code);
     902                String targetName = anonymousClass.getSrcExtendsClauseShortClass().getSuper().name();
     903                InstLookupResult<InstClassDecl> icd = getInstProgramRoot().lookupInstClassQualified(targetName);
     904                if (!icd.successful()) {
     905                    return null;
     906                }
     907                anonymousClass.setName(new SrcIdDecl(targetName));
     908                SrcRestriction restriction = ((SrcBaseClassDecl) icd.target().actualInstClass().getSrcClassDecl()).getSrcRestriction();
     909                anonymousClass.setSrcRestriction(restriction);
     910                addAnonymousClass(anonymousClass);
    902911                res = getAnonymousClass(getNumAnonymousClass() - 1);
    903912                anonymousClassMap.put(code, res);
     
    922931        int p = className.indexOf('(');
    923932        if (p >= 0) {
    924             String targetName = className.substring(0, p);
    925             InstLookupResult<InstClassDecl> icd = lookupInstClassQualified(targetName);
    926             if (icd.successful()) {
    927                 SrcRestriction restriction = ((SrcBaseClassDecl) icd.target().actualInstClass().getSrcClassDecl()).getSrcRestriction();
    928                 SrcClassDecl cl = sourceRoot().getProgram().anonymousClass(className, restriction, targetName);
    929                 if (cl != null) {
    930                     addInstAnonymousClass(createInstClassDecl(cl));
    931                     return getInstAnonymousClass(getNumInstAnonymousClass() - 1);
     933                SrcClassDecl cl = sourceRoot().getProgram().anonymousClass(className);
     934                if (cl == null) {
     935                    return unknownInstClassDecl();
    932936                }
    933             }
    934             return unknownInstClassDecl();
     937                addInstAnonymousClass(createInstClassDecl(cl));
     938                return getInstAnonymousClass(getNumInstAnonymousClass() - 1);
    935939        } else {
    936940            InstLookupResult<InstClassDecl> icd = lookupInstClassQualified(className);
  • branches/dev-2559/Compiler/ModelicaFrontEnd/src/jastadd/source/Parser.jrag

    r13901 r14185  
    212212    }
    213213
    214     public SrcBaseClassDecl ParserHandler.parseAnonymousClassString(String code, SrcRestriction restriction, String targetName)
    215             throws ParserException, beaver.Parser.Exception, IOException {
    216         return parseModelicaAnonymousClassString(code, restriction, targetName);
     214    public SrcBaseClassDecl ParserHandler.parseAnonymousClassString(String code)
     215            throws ParserException, beaver.Parser.Exception, IOException {
     216        return parseModelicaAnonymousClassString(code);
    217217    }
    218218
     
    269269    public static final LoadInfo ParserHandler.ANONYMOUS_CLASS_FILENAME = LoadInfo.create("<command line argument>");
    270270
    271     public SrcBaseClassDecl ParserHandler.parseModelicaAnonymousClassString(String code, SrcRestriction restriction, String targetName)
     271    public SrcBaseClassDecl ParserHandler.parseModelicaAnonymousClassString(String code)
    272272            throws ParserException, beaver.Parser.Exception, IOException {
    273273        AbstractModelicaScanner scanner = createModelicaScanner(new StringReader(code));
    274274        beaver.Parser parser = createModelicaParser(scanner, ANONYMOUS_CLASS_FILENAME);
    275275        SrcBaseClassDecl cl = (SrcBaseClassDecl) parser.parse(scanner, anonymousClassModelicaGoal());
    276         cl.setSrcRestriction(restriction);
    277         cl.setName(new SrcIdDecl(targetName));
    278276        return cl;
    279277    }
Note: See TracChangeset for help on using the changeset viewer.