Changeset 3078

Show
Ignore:
Timestamp:
11/18/08 12:54:36 (12 months ago)
Author:
sukyoungryu
Message:

[ast] Eliminated the Export node.

Location:
trunk
Files:
19 modified

Legend:

Unmodified
Added
Removed
  • trunk/Library/FortressSyntax.fsi

    r3077 r3078  
    2929    Component : Component 
    3030    Api : Api 
    31     Exports : List[\Export\] 
    32     Export : Export 
     31    Exports : List[\APIName\] 
    3332    Imports : List[\Import\] 
    3433    Import : Import 
  • trunk/ProjectFortress/astgen/Fortress.ast

    r3077 r3078  
    162162             * component declaration 
    163163             * Component ::= native? component APIName Imports? Exports Decls? end 
     164             * Export ::= export APINames 
    164165             * e.g.) component Hello 
    165166             *         export Executable 
     
    168169             */ 
    169170            Component(boolean _native = false, APIName name, List<Import> imports, 
    170                       List<Export> exports, List<Decl> decls, 
     171                      List<APIName> exports, List<Decl> decls, 
    171172                      List<_RewriteObjectExpr> objectExprs = 
    172173                           Collections.<_RewriteObjectExpr>emptyList(), 
     
    226227        AliasedAPIName(APIName api, 
    227228                       Option<Id> alias = Option.<Id>none()); 
    228         /** 
    229          * export statement 
    230          * Export ::= export APINames 
    231          * e.g.) export Executable 
    232          */ 
    233         Export(List<APIName> apis); 
    234229        /** 
    235230         * trait or object declaration in components or APIs 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/ObjectExpressionVisitor.java

    r3077 r3078  
    170170    public Node forComponentOnly(Component that, APIName name_result, 
    171171                                     List<Import> imports_result, 
    172                                      List<Export> exports_result, 
     172                                     List<APIName> exports_result, 
    173173                                     List<Decl> decls_result, 
    174174                                     List<_RewriteObjectExpr> objectExprs) { 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/TopLevelEnv.java

    r3071 r3078  
    4646import com.sun.fortress.nodes.Component; 
    4747import com.sun.fortress.nodes.Enclosing; 
    48 import com.sun.fortress.nodes.Export; 
    4948import com.sun.fortress.nodes.Id; 
    5049import com.sun.fortress.nodes.IdOrOpName; 
     
    7675public class TopLevelEnv extends NameEnv { 
    7776    private static final Set<String> WELL_KNOWN_APIS = Useful.set(WellKnownNames.fortressLibrary, WellKnownNames.fortressBuiltin, WellKnownNames.anyTypeName); 
    78      
     77 
    7978    private final GlobalEnvironment _originalGlobalEnv; // environment as it is created by the compiler 
    8079    private final GlobalEnvironment _filteredGlobalEnv; // environment that only includes "imported" names 
     
    9594        _current = current; 
    9695        _errors = errors; 
    97          
     96 
    9897        GlobalEnvironment filtered_global_env; 
    9998        if( current instanceof ApiIndex ) { 
     
    105104            //  Filter env based on what this component imports 
    106105            Map<APIName,ApiIndex> filtered = filterApis(globalEnv.apis(), ((Component)current.ast())); 
    107             filtered_global_env = new GlobalEnvironment.FromMap(filtered);             
     106            filtered_global_env = new GlobalEnvironment.FromMap(filtered); 
    108107        } 
    109108        else { 
     
    111110        } 
    112111        _filteredGlobalEnv = filtered_global_env; 
    113          
     112 
    114113        _onDemandImportedApis = Collections.unmodifiableMap(initializeOnDemandImportedApis(filtered_global_env, current)); 
    115114        _onDemandTypeConsNames = Collections.unmodifiableMap(initializeOnDemandTypeConsNames(_onDemandImportedApis)); 
     
    123122 
    124123    /** 
    125      * Initializes the map of imported API names to ApiIndices.  
     124     * Initializes the map of imported API names to ApiIndices. 
    126125     * Adds all imported and implicitly imported 
    127126     * Apis to a map that it returns. 
     
    131130        // TODO: Fix to support other kinds of imports. 
    132131        Set<APIName> imports = current.imports(); 
    133         Map<APIName, ApiIndex> result = new HashMap<APIName, ApiIndex>();  
     132        Map<APIName, ApiIndex> result = new HashMap<APIName, ApiIndex>(); 
    134133 
    135134        // The following APIs are always imported, provided they exist. 
     
    184183        // TODO: Fix to support explicit imports and api imports. I don't think this is still a 'to-do' 
    185184        Map<Id, Set<Id>> result = new HashMap<Id, Set<Id>>(); 
    186          
     185 
    187186        for (Map.Entry<APIName, ApiIndex> apiEntry: imported_apis.entrySet()) { 
    188187            for (Map.Entry<Id, TypeConsIndex> typeEntry: apiEntry.getValue().typeConses().entrySet()) { 
     
    216215 
    217216    private static OpName copyOpNameWithNewAPIName(OpName op, final APIName api) { 
    218         OpName result =  
     217        OpName result = 
    219218                op.accept(new NodeDepthFirstVisitor<OpName>(){ 
    220219                        @Override 
     
    232231        return result; 
    233232    } 
    234      
     233 
    235234    private static Pair<Map<Id, Set<Id>>, Map<OpName, Set<OpName>>> initializeOnDemandFunctionNames(Map<APIName, ApiIndex> imported_apis) { 
    236235        Map<Id, Set<Id>> fun_result = new HashMap<Id, Set<Id>>(); 
    237236        Map<OpName, Set<OpName>> ops_result =  new HashMap<OpName, Set<OpName>>(); 
    238          
     237 
    239238        for (Map.Entry<APIName, ApiIndex> apiEntry: imported_apis.entrySet()) { 
    240239            for (IdOrOpOrAnonymousName fnName: apiEntry.getValue().functions().firstSet()) { 
     
    253252                        fun_result.put(_fnName, matches); 
    254253                    } 
    255                 }  
     254                } 
    256255                else { // fnName instanceof OpName 
    257256                    OpName _opName = (OpName)fnName; 
     
    299298        } 
    300299    } 
    301      
     300 
    302301    @Override 
    303302    public Option<StaticParam> hasTypeParam(IdOrOpName name) { 
     
    321320                _current.units().containsKey(name)) { 
    322321 
    323             // A name defined in this CU should only be qualified if this is an API  
     322            // A name defined in this CU should only be qualified if this is an API 
    324323            Id result_id; 
    325324            if( _current instanceof ApiIndex ) 
     
    327326            else if( _current instanceof ComponentIndex ) 
    328327                result_id = apiQualifyIfComponentExports(((ComponentIndex)_current), name); 
    329             else  
     328            else 
    330329                result_id = name; 
    331330 
     
    345344    private Id apiQualifyIfComponentExports(ComponentIndex comp, Id name) { 
    346345        Option<Id> result_ = Option.none(); 
    347          
     346 
    348347        for( APIName api_name : comp.exports() ) { 
    349              
     348 
    350349            // TODO: We don't really need this, but for now since there is no Executable... 
    351350            if( !_originalGlobalEnv.definesApi(api_name) ) continue; 
    352              
     351 
    353352            ApiIndex api = _originalGlobalEnv.api(api_name); 
    354              
     353 
    355354            if( api.typeConses().containsKey(name) ) { 
    356                 if( result_.isSome() )  
     355                if( result_.isSome() ) 
    357356                    return NI.nyi("Disambiguator cannot yet handle the same Component providing the implementation for multiple APIs: " + name); 
    358                  
     357 
    359358                result_ = Option.some(NodeFactory.makeId(api_name, name, name.getSpan())); 
    360359            } 
    361360        } 
    362          
     361 
    363362        if( result_.isNone() ) 
    364363            return name; 
     
    367366    } 
    368367 
    369     public Set<Id> explicitVariableNames(Id name) {      
     368    public Set<Id> explicitVariableNames(Id name) { 
    370369        Set<Id> result = Collections.emptySet(); 
    371370        if (_current.variables().containsKey(name) || 
    372371                _current.units().containsKey(name)) { 
    373              
     372 
    374373            // A name defined in this CU should only be qualified if this is an API 
    375374            Id result_id; 
     
    394393    public Set<Id> explicitFunctionNames(Id name) { 
    395394        Set<Id> result = Collections.emptySet(); 
    396          
     395 
    397396        // Add fns from this component 
    398397        if (_current.functions().containsFirst(name)) { 
     
    403402            else 
    404403                result_id = name; 
    405              
     404 
    406405            result = CollectUtil.union(result, Collections.singleton(result_id)); 
    407406        } 
    408          
     407 
    409408        // Also add imports 
    410409        result = CollectUtil.union(result, this.onDemandFunctionNames(name)); 
     
    424423            else 
    425424                result_id = name; 
    426                  
     425 
    427426            result = CollectUtil.union(result, Collections.singleton(result_id)); 
    428427        } 
     
    584583        } 
    585584    } 
    586      
     585 
    587586    /** 
    588587     * Returns API names in the given list of exports that can be imported implicitly. 
    589588     * This helps, for example, when compiling FortressLibrary, since that is one API that 
    590      * is normally imported implicitly.  
     589     * is normally imported implicitly. 
    591590     */ 
    592     private static Set<APIName> findWellKnownExports(List<Export> exports) { 
    593         return IterUtil.fold(exports, new HashSet<APIName>(),new Lambda2<HashSet<APIName>,Export, HashSet<APIName>>(){ 
    594             public HashSet<APIName> value(HashSet<APIName> arg0, Export arg1) { 
    595                 for( APIName api : arg1.getApis() ) { 
    596                     if( WELL_KNOWN_APIS.contains(api.getText()) ) { 
    597                         arg0.add(api); 
    598                     } 
     591    private static Set<APIName> findWellKnownExports(List<APIName> exports) { 
     592        return IterUtil.fold(exports, new HashSet<APIName>(),new Lambda2<HashSet<APIName>,APIName, HashSet<APIName>>(){ 
     593            public HashSet<APIName> value(HashSet<APIName> arg0, APIName api) { 
     594                if( WELL_KNOWN_APIS.contains(api.getText()) ) { 
     595                    arg0.add(api); 
    599596                } 
    600597                return arg0; 
    601598            }}); 
    602599    } 
    603      
     600 
    604601    private static  Map<APIName, ApiIndex> filterApis(Map<APIName,ApiIndex> apis, Component comp) { 
    605602        Set<APIName> dont_import = findWellKnownExports(comp.getExports()); 
     
    611608        // need them at a minimum. 
    612609        Import this_api_import = new ImportStar(NodeFactory.makeSpan("implicit import, TopLevelEnv"), api.getName(), Collections.<IdOrOpOrAnonymousName>emptyList()); 
    613         return filterApis(Collections.unmodifiableMap(apis),  
    614                 Useful.concat(Collections.singletonList(this_api_import),  
     610        return filterApis(Collections.unmodifiableMap(apis), 
     611                Useful.concat(Collections.singletonList(this_api_import), 
    615612                        api.getImports() 
    616613                        ) 
     
    618615    } 
    619616 
    620     private static <K, T> Map<K,T> filterMap(Map<K,T> map, Set<? super K> set,  
     617    private static <K, T> Map<K,T> filterMap(Map<K,T> map, Set<? super K> set, 
    621618            Predicate<K> pred) { 
    622          
     619 
    623620        Map<K,T> result = new HashMap<K,T>(); 
    624621        for( Map.Entry<K, T> entry : map.entrySet() ) { 
     
    629626        return result; 
    630627    } 
    631      
     628 
    632629    private static <K, T> Map<K,T> removeHelper(Map<K,T> map, final Set<? super K> set) { 
    633630        Predicate<K> pred = new Predicate<K>() { 
     
    635632                return !set.contains(arg1); 
    636633            }}; 
    637          
     634 
    638635        return filterMap(map, set, pred); 
    639636    } 
    640      
     637 
    641638    private static ApiIndex remove(ApiIndex index, 
    642639            final Set<IdOrOpOrAnonymousName> exceptions_) { 
    643          
     640 
    644641        Predicate2<IdOrOpOrAnonymousName,Function> pred = new Predicate2<IdOrOpOrAnonymousName,Function>(){ 
    645642 
     
    647644                return !exceptions_.contains(arg0); 
    648645            } 
    649              
     646 
    650647        }; 
    651          
     648 
    652649        return new ApiIndex((Api)index.ast(), 
    653650                            removeHelper(index.variables(), exceptions_), 
     
    659656                            index.modifiedDate()); 
    660657    } 
    661      
     658 
    662659    private static <K, T> Map<K,T> keepHelper(Map<K,T> map, final Set<? super K> set) { 
    663660        Predicate<K> pred = new Predicate<K>() { 
     
    665662                return set.contains(arg1); 
    666663            }}; 
    667          
     664 
    668665        return filterMap(map, set, pred); 
    669666    } 
    670      
     667 
    671668    private static ApiIndex keep(ApiIndex index, 
    672669            final Set<IdOrOpOrAnonymousName> allowed_) { 
    673          
     670 
    674671        Predicate2<IdOrOpOrAnonymousName,Function> pred = new Predicate2<IdOrOpOrAnonymousName,Function>(){ 
    675672 
     
    677674                return allowed_.contains(arg0); 
    678675            } 
    679              
     676 
    680677        }; 
    681          
     678 
    682679        return new ApiIndex((Api)index.ast(), 
    683680                keepHelper(index.variables(), allowed_), 
     
    689686                index.modifiedDate()); 
    690687    } 
    691      
     688 
    692689    /** 
    693690     * Filter out whole apis or parts of apis based on the imports of a component or 
    694      * api. FortressBuiltin and AnyType are always imported, and FortressLibrary is only  
     691     * api. FortressBuiltin and AnyType are always imported, and FortressLibrary is only 
    695692     * imported implicitly if it is not imported explicitly. If {@code do_not_import} contains 
    696693     * api names, those apis will not beimported no matter what. 
    697694     */ 
    698     private static Map<APIName,ApiIndex> filterApis(Map<APIName, ApiIndex> apis, List<Import> imports, Set<APIName> do_not_import) {  
     695    private static Map<APIName,ApiIndex> filterApis(Map<APIName, ApiIndex> apis, List<Import> imports, Set<APIName> do_not_import) { 
    699696        final Map<APIName, Set<IdOrOpOrAnonymousName>> exceptions = new HashMap<APIName, Set<IdOrOpOrAnonymousName>>(); 
    700697        final Map<APIName, Set<IdOrOpOrAnonymousName>> allowed = new HashMap<APIName, Set<IdOrOpOrAnonymousName>>(); 
     
    722719 
    723720                // TODO Handle these aliased names more thoroughly 
    724                 List<IdOrOpOrAnonymousName> names = CollectUtil.makeList(IterUtil.map(that.getAliasedNames(),  
     721                List<IdOrOpOrAnonymousName> names = CollectUtil.makeList(IterUtil.map(that.getAliasedNames(), 
    725722                        new Lambda<AliasedSimpleName,IdOrOpOrAnonymousName>(){ 
    726723                    public IdOrOpOrAnonymousName value( 
     
    772769                Set<IdOrOpOrAnonymousName> allowed_ = allowed.get(name); 
    773770                result.put(name, keep(index, allowed_)); 
    774             }  
     771            } 
    775772            else if( name.getText().equals(WellKnownNames.fortressBuiltin) ) { 
    776773                // Fortress builtin is always implicitly imported 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/environments/TopLevelEnvGen.java

    r2773 r3078  
    7878 
    7979    public static String mangleClassIdentifier(String identifier) { 
    80         String mangledString = identifier.replaceAll("\\.", "\\$");   
    81         return mangledString;          
    82     } 
    83      
     80        String mangledString = identifier.replaceAll("\\.", "\\$"); 
     81        return mangledString; 
     82    } 
     83 
    8484    /** 
    8585     * http://blogs.sun.com/jrose/entry/symbolic_freedom_in_the_vm 
     
    115115            mangledString = "\\=" + mangledString; 
    116116        } 
    117         return mangledString;  
     117        return mangledString; 
    118118    } 
    119119 
     
    146146        return new CompilationUnitResult(compiledApis, errors); 
    147147    } 
    148   
     148 
    149149    /** 
    150150     * Given a list of components, generate a Java bytecode compiled environment 
     
    232232                ImportApi importApi = (ImportApi) imports; 
    233233                for (AliasedAPIName api : importApi.getApis()) { 
    234                     importedApiNames.add(NodeUtil.nameString(api.getApi()));                     
     234                    importedApiNames.add(NodeUtil.nameString(api.getApi())); 
    235235                } 
    236236            } else if (imports instanceof ImportedNames) { 
     
    241241            } 
    242242        } 
    243          
     243 
    244244        // XXX: SUPER DUPER HACKY 
    245245        // Rewrite the AST to include these builtin imports! 
    246246        for(String builtinLib : WellKnownNames.defaultLibrary) { 
    247             importedApiNames.add(builtinLib);             
    248         } 
    249          
     247            importedApiNames.add(builtinLib); 
     248        } 
     249 
    250250        // Any names that are exported, are also "imported", which is to say, 
    251251        // the disambiguator will generate references to them, so we had better 
     
    253253        if (comp instanceof Component) { 
    254254            Component ccomp = (Component) comp; 
    255             for (Export e : ccomp.getExports()) { 
    256                 for (APIName api : e.getApis()) { 
    257                     importedApiNames.add(NodeUtil.nameString(api)); 
    258                 } 
    259             } 
    260         } 
    261          
    262         namesToFields(EnvironmentClass.ENVIRONMENT, cw, symbolNames, importedApiNames);         
     255            for (APIName api : ccomp.getExports()) { 
     256                importedApiNames.add(NodeUtil.nameString(api)); 
     257            } 
     258        } 
     259 
     260        namesToFields(EnvironmentClass.ENVIRONMENT, cw, symbolNames, importedApiNames); 
    263261    } 
    264262 
     
    271269        // Create all variables as fields in the environment 
    272270        Set<String> idStringSet = new HashSet<String>(); 
    273         for(Id id : compUnitIndex.variables().keySet()) {                         
     271        for(Id id : compUnitIndex.variables().keySet()) { 
    274272            String idString = NodeUtil.nameString(id); 
    275273            if (idString.equals("_")) { 
     
    285283                // apply further mangling. 
    286284            } 
    287             idStringSet.add(idString);             
    288         } 
    289         namesToFields(EnvironmentClass.FVALUE, cw, symbolNames, idStringSet);         
     285            idStringSet.add(idString); 
     286        } 
     287        namesToFields(EnvironmentClass.FVALUE, cw, symbolNames, idStringSet); 
    290288 
    291289        // Create all functions as fields in the environment 
     
    293291        for(IdOrOpOrAnonymousName id : compUnitIndex.functions().firstSet()) { 
    294292            String idString = NodeUtil.nameString(id); 
    295             idStringSet.add(idString);             
    296         }         
    297         namesToFields(EnvironmentClass.FVALUE, cw, symbolNames, idStringSet);         
     293            idStringSet.add(idString); 
     294        } 
     295        namesToFields(EnvironmentClass.FVALUE, cw, symbolNames, idStringSet); 
    298296 
    299297        // Create all types as fields in the environment 
     
    303301            idStringSet.add(idString); 
    304302        } 
    305         namesToFields(EnvironmentClass.FTYPE, cw, symbolNames, idStringSet);  
     303        namesToFields(EnvironmentClass.FTYPE, cw, symbolNames, idStringSet); 
    306304 
    307305        // Special case for singleton objects; get to the object through 
     
    314312                if (oti.constructor().isNone()) { 
    315313                    String idString = WellKnownNames.obfuscatedSingletonConstructorName(NodeUtil.nameString(id), id); 
    316                     idStringSet.add(idString);                     
     314                    idStringSet.add(idString); 
    317315                } 
    318316            } 
    319317        } 
    320         namesToFields(EnvironmentClass.FVALUE, cw, symbolNames, idStringSet);         
    321          
     318        namesToFields(EnvironmentClass.FVALUE, cw, symbolNames, idStringSet); 
     319 
    322320        handleWeirdToplevelDecls(cw, compUnitIndex, symbolNames); 
    323          
     321 
    324322        writeImportFields(cw, compUnitIndex, symbolNames); 
    325323    } 
    326      
     324 
    327325    /** 
    328326     * Emits additional names for overloaded functions, 
    329327     * for temporaries generated by multiple assignment/init, 
    330328     * and for object expressions. 
    331      *  
     329     * 
    332330     * @param cw 
    333331     * @param compUnitIndex 
     
    355353                } 
    356354            } 
    357          
     355 
    358356        // Scan for all object exprs in a component; the interpreter will 
    359357        // promote those to top level. 
     
    373371            compUnit.accept(visitor); 
    374372        } 
    375     }     
    376      
     373    } 
     374 
    377375    private static void namesToFields(EnvironmentClass nameSpace, 
    378376            ClassWriter cw, EnvSymbolNames symbolNames, Set<String> idStringSet) { 
     
    388386        cw.visitField(Opcodes.ACC_PUBLIC, mangleIdentifier(idString), nameSpace.descriptor(), null, null).visitEnd(); 
    389387        return; 
    390     }     
     388    } 
    391389 
    392390    /** 
     
    394392     * This constructors calls the method setToplevel(). 
    395393     * If this environment is not a top-level environment, then a default 
    396      * constructor does not need to be created.  (ASM will generate a  
     394     * constructor does not need to be created.  (ASM will generate a 
    397395     * default constructor). 
    398396     */ 
     
    414412    /** 
    415413     * Implementing "static reflection" for the method getFooRaw so the 
    416      * interpreter uses a switch instruction for ***GetRaw  
     414     * interpreter uses a switch instruction for ***GetRaw 
    417415     * based on the hash values of String names in this namespace. 
    418416     */ 
     
    439437        Collections.sort(sortedCodes); 
    440438        Label returnNull = new Label(); 
    441          
     439 
    442440        getRawHelper(mv, className, hashCodeRelation, environmentClass, sortedCodes, returnNull); 
    443441 
    444442        mv.visitLabel(returnNull); 
    445443        mv.visitInsn(Opcodes.ACONST_NULL); 
    446         mv.visitInsn(Opcodes.ARETURN);         
    447          
     444        mv.visitInsn(Opcodes.ARETURN); 
     445 
    448446        Label endFunction = new Label(); 
    449447        mv.visitLabel(endFunction); 
     
    451449        mv.visitLocalVariable("queryString", "Ljava/lang/String;", null, beginFunction, endFunction, 1); 
    452450        mv.visitLocalVariable("queryHashCode", "I", null, beginLoop, endFunction, 2); 
    453         // See comment above on ClassWriter.COMPUTE_FRAMES         
     451        // See comment above on ClassWriter.COMPUTE_FRAMES 
    454452        mv.visitMaxs(2, 3); 
    455453        mv.visitEnd(); 
     
    505503    /** 
    506504     * Implementing "static reflection" for the method putRaw so the 
    507      * interpreter uses a switch instruction for ***PutRaw  
     505     * interpreter uses a switch instruction for ***PutRaw 
    508506     * based on the hash values of String names in this namespace. 
    509507     */ 
     
    524522        mv.visitLabel(beginLoop); 
    525523 
    526         Relation<String, Integer> hashCodeRelation = symbolNames.makeHashCodeRelation(environmentClass);         
     524        Relation<String, Integer> hashCodeRelation = symbolNames.makeHashCodeRelation(environmentClass); 
    527525        ArrayList<Integer> sortedCodes = new ArrayList<Integer>(hashCodeRelation.secondSet()); 
    528526        Collections.sort(sortedCodes); 
     
    530528        putRawHelper(mv, className, environmentClass, hashCodeRelation, sortedCodes, notFound); 
    531529        mv.visitLabel(notFound); 
    532         mv.visitInsn(Opcodes.RETURN);         
    533         Label endFunction = new Label();                 
     530        mv.visitInsn(Opcodes.RETURN); 
     531        Label endFunction = new Label(); 
    534532        mv.visitLabel(endFunction); 
    535533        mv.visitLocalVariable("this", "L" + className + ";", null, 
     
    539537        mv.visitLocalVariable("value", environmentClass.descriptor(), null, beginFunction, endFunction, 2); 
    540538        mv.visitLocalVariable("queryHashCode", "I", null, beginLoop, endFunction, 3); 
    541         // See comment above on ClassWriter.COMPUTE_FRAMES         
     539        // See comment above on ClassWriter.COMPUTE_FRAMES 
    542540        mv.visitMaxs(2, 4); 
    543541        mv.visitEnd(); 
     
    560558            mv.visitLabel(labels[i]); 
    561559            putRawBaseCase(mv, className, hashCodeRelation, environmentClass, codes[i], notFound); 
    562         }         
    563          
     560        } 
     561 
    564562    } 
    565563 
    566564    private static void putRawBaseCase(MethodVisitor mv, String className, 
    567             Relation<String, Integer> hashCodeRelation, EnvironmentClass environmentClass,  
     565            Relation<String, Integer> hashCodeRelation, EnvironmentClass environmentClass, 
    568566            int code, Label notFound ) { 
    569567 
     
    603601        mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0); 
    604602        mv.visitLocalVariable("str", "Ljava/lang/String;", null, l0, l1, 1); 
    605         // See comment above on ClassWriter.COMPUTE_FRAMES         
     603        // See comment above on ClassWriter.COMPUTE_FRAMES 
    606604        mv.visitMaxs(1, 2); 
    607605        mv.visitEnd(); 
     
    619617        mv.visitLocalVariable("str", "Ljava/lang/String;", null, l0, l1, 1); 
    620618        mv.visitLocalVariable("f2", "Ljava/lang/Number;", null, l0, l1, 2); 
    621         // See comment above on ClassWriter.COMPUTE_FRAMES         
     619        // See comment above on ClassWriter.COMPUTE_FRAMES 
    622620        mv.visitMaxs(0, 3); 
    623621        mv.visitEnd(); 
     
    642640        mv.visitLocalVariable("this", "L" + className + ";", null, l0, l2, 0); 
    643641        mv.visitLocalVariable("name", "Ljava/lang/String;", null, l0, l2, 1); 
    644         // See comment above on ClassWriter.COMPUTE_FRAMES         
     642        // See comment above on ClassWriter.COMPUTE_FRAMES 
    645643        mv.visitMaxs(3, 2); 
    646644        mv.visitEnd(); 
     
    714712        mv.visitLocalVariable("this", "L" + className + ";", null, l0, l9, 0); 
    715713        mv.visitLocalVariable("a", "Ljava/lang/Appendable;", null, l0, l9, 1); 
    716         // See comment above on ClassWriter.COMPUTE_FRAMES         
     714        // See comment above on ClassWriter.COMPUTE_FRAMES 
    717715        mv.visitMaxs(2, 2); 
    718716        mv.visitEnd(); 
     
    783781            Pair<String,byte[]> compOutput = compiledCompUnits.get(componentName); 
    784782            String fileName = ProjectProperties.BYTECODE_CACHE_DIR + File.separator + compOutput.getA() + ".class"; 
    785              outputClassFile(compOutput.getB(), fileName, errors);  
     783             outputClassFile(compOutput.getB(), fileName, errors); 
    786784        } 
    787785    } 
     
    811809 
    812810} 
    813  
    814  
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/ComponentIndex.java

    r2699 r3078  
    2626import com.sun.fortress.nodes.APIName; 
    2727import com.sun.fortress.nodes.Component; 
    28 import com.sun.fortress.nodes.Export; 
    2928import com.sun.fortress.nodes.Id; 
    3029import com.sun.fortress.nodes.IdOrOpOrAnonymousName; 
     
    4544                          Map<Id, Unit> units, 
    4645                          long modifiedDate) { 
    47         super(ast, variables, functions, typeConses,  
     46        super(ast, variables, functions, typeConses, 
    4847              dimensions, units, modifiedDate); 
    4948        _initializers = initializers; 
     
    5554 
    5655    @Override 
    57     public Set<APIName> exports() {  
    58         List<Export> exports = ((Component)ast()).getExports(); 
     56    public Set<APIName> exports() { 
     57        List<APIName> exports = ((Component)ast()).getExports(); 
    5958        Set<APIName> result = new HashSet<APIName>(); 
    6059 
    61         for( Export export : exports ) { 
    62             result.addAll(export.getApis()); 
    63         } 
     60        result.addAll(exports); 
    6461        return result; 
    6562    } 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/SubtypeCheckerJUTest.java

    r3071 r3078  
    356356        Component ast = new Component(span, NodeFactory.makeAPIName(span, name), 
    357357                                      Collections.<Import>emptyList(), 
    358                                       Collections.<Export>emptyList(), 
     358                                      Collections.<APIName>emptyList(), 
    359359                                      traitDecls); 
    360360        return new ComponentIndex(ast, 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeAnalyzerJUTest.java

    r3071 r3078  
    4141 
    4242    static Span span = NodeFactory.makeSpan("TypeAnalyzerJUTest"); 
    43      
     43 
    4444    public static void main(String... args) { 
    4545      junit.textui.TestRunner.run(TypeAnalyzerJUTest.class); 
     
    429429        Component ast = new Component(span, NodeFactory.makeAPIName(name), 
    430430                                      Collections.<Import>emptyList(), 
    431                                       Collections.<Export>emptyList(), 
     431                                      Collections.<APIName>emptyList(), 
    432432                                      traitDecls); 
    433433        return new ComponentIndex(ast, 
     
    514514        s = s.trim(); 
    515515        int opIndex; 
    516   
     516 
    517517        opIndex = findAtTop(s, "->"); 
    518518        if (opIndex >= 0) { 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java

    r3077 r3078  
    20422042                                        (APIName)name_result.ast(), 
    20432043                                        (List<Import>)TypeCheckerResult.astFromResults(imports_result), 
    2044                                         (List<Export>)TypeCheckerResult.astFromResults(exports_result), 
     2044                                        (List<APIName>)TypeCheckerResult.astFromResults(exports_result), 
    20452045                                        (List<Decl>)TypeCheckerResult.astFromResults(decls_result)); 
    20462046 
     
    22092209 
    22102210                return TypeCheckerResult.compose(new_node, Types.BOTTOM, subtypeChecker, withResult); 
    2211         } 
    2212  
    2213         @Override 
    2214         public TypeCheckerResult forExportOnly(Export that, List<TypeCheckerResult> apis_result) { 
    2215                 return new TypeCheckerResult(that); 
    22162211        } 
    22172212 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/Driver.java

    r3077 r3078  
    7070import com.sun.fortress.nodes.Component; 
    7171import com.sun.fortress.nodes.Decl; 
    72 import com.sun.fortress.nodes.Export; 
    7372import com.sun.fortress.nodes.FnAbsDeclOrDecl; 
    7473import com.sun.fortress.nodes.FnDecl; 
     
    510509 
    511510            List<APIWrapper> exports_list = new ArrayList<APIWrapper>(1); 
    512             for (Export ex : comp.getExports()) 
    513                 for (APIName ex_apiname : ex.getApis()) { 
    514                     String ex_name = NodeUtil.nameString(ex_apiname); 
    515                     Api newapi = readTreeOrSourceApi(ex_name, ex_name, fr); 
    516                     exports_list.add( new APIWrapper(newapi, linker, WellKnownNames.defaultLibrary) ); 
    517                 } 
     511            for (APIName ex_apiname : comp.getExports()) { 
     512                String ex_name = NodeUtil.nameString(ex_apiname); 
     513                Api newapi = readTreeOrSourceApi(ex_name, ex_name, fr); 
     514                exports_list.add( new APIWrapper(newapi, linker, WellKnownNames.defaultLibrary) ); 
     515            } 
    518516 
    519517            comp_wrapper = new ComponentWrapper(comp_index, exports_list, linker, WellKnownNames.defaultLibrary); 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/env/CUWrapper.java

    r2994 r3078  
    4242import com.sun.fortress.nodes.CompilationUnit; 
    4343import com.sun.fortress.nodes.Component; 
    44 import com.sun.fortress.nodes.Export; 
    4544import com.sun.fortress.nodes.Import; 
    4645import com.sun.fortress.nodes_util.NodeUtil; 
     
    5352 
    5453public class CUWrapper { 
    55      
     54 
    5655    private final static boolean loadCompiledEnvs = 
    5756        ProjectProperties.getBoolean("fortress.test.compiled.environments", true); 
    58      
     57 
    5958    CompilationUnit comp_unit; 
    6059 
     
    6867     */ 
    6968    protected String[]  implicitLibs; 
    70      
     69 
    7170    public BASet<String> ownNames = new BASet<String>(com.sun.fortress.useful.StringHashComparer.V); 
    7271    public BASet<String> excludedImportNames = new BASet<String>(com.sun.fortress.useful.StringHashComparer.V); 
    7372 
    7473    /** 
    75      * If a variable/value/function name is missing when an API is initialized,  
    76      * store it here, in case it is found later (that is, imported into the  
     74     * If a variable/value/function name is missing when an API is initialized, 
     75     * store it here, in case it is found later (that is, imported into the 
    7776     * component through some other API). 
    7877     */ 
     
    8988     */ 
    9089    //public BASet<String> missingExportedTypes = new BASet<String>(com.sun.fortress.useful.StringHashComparer.V); 
    91      
     90 
    9291    public Set<AbstractNode> unresolvedExports = new HashSet<AbstractNode>(); 
    93         
     92 
    9493    protected DesugarerVisitor desugarer; 
    9594 
     
    105104            } 
    106105        this.exports = null; 
    107          
    108     } 
    109      
     106 
     107    } 
     108 
    110109    Visitor2<String, Object> nameCollector = new Visitor2<String, Object>() { 
    111110 
    112111        @Override 
    113112        public void visit(String t, Object u) { 
    114              
     113 
    115114            ownNames.add(t); 
    116115        } 
     
    122121       if (comp == null) 
    123122            throw new NullPointerException("Null component (1st parameter to constructor) not allowed"); 
    124         
     123 
    125124         comp_unit = comp; 
    126          
     125 
    127126         String fortressFileName = comp_unit.getName().getText(); 
    128          
     127 
    129128         try { 
    130              
     129 
    131130                Environment e = loadCompiledEnvs ? 
    132131                    SimpleClassLoader.loadEnvironment(fortressFileName, false) : 
     
    136135                        new BuildNativeEnvironment(e, linker) : 
    137136                        new BuildTopLevelEnvironments(e, linker)); 
    138                 List<Export> component_exports = comp.getExports(); 
    139                 for (Export exp : component_exports) { 
     137                List<APIName> component_exports = comp.getExports(); 
     138                for (APIName exp : component_exports) { 
    140139                    // TODO work in progress, this might not be the best place 
    141140                } 
    142              
     141 
    143142        } catch (IOException ex) { 
    144143            bug("Failed to load class (" + ex + ") for " + comp); 
     
    154153        if (api == null) 
    155154            throw new NullPointerException("Null api (1st parameter to constructor) not allowed"); 
    156          
     155 
    157156         //comp_unit = (Api) RewriteInPresenceOfTypeInfoVisitor.Only.visit(api); 
    158157        comp_unit = api; // do nothing? 
    159          
     158 
    160159         String fortressFileName = comp_unit.getName().getText(); 
    161          
     160 
    162161         try { 
    163162                Environment e = loadCompiledEnvs ? 
     
    166165                e.setTopLevel(); 
    167166                be = new BuildApiEnvironment(e, linker); 
    168              
     167 
    169168        } catch (IOException ex) { 
    170169            bug("Failed to load class (" + ex + ") for " + api); 
     
    189188    public CUWrapper(Component comp, List<APIWrapper> api_list, HashMap<String, ComponentWrapper> linker, String[] implicitLibs) { 
    190189        this(comp, linker, implicitLibs); 
    191         for (APIWrapper api : api_list)  
     190        for (APIWrapper api : api_list) 
    192191            exports.put(NodeUtil.nameString(api.getCompilationUnit().getName()), api); 
    193192    } 
    194      
     193 
    195194 
    196195 
     
    219218        return exports.values(); 
    220219    } 
    221      
     220 
    222221    public void touchExports(boolean suppressDebugDump) { 
    223222        if (visitState != UNVISITED) 
     
    258257        return desugarer.injectAtTopLevel(putName, getName, getFrom.desugarer, excluded); 
    259258    } 
    260      
    261   
    262  
    263   
     259 
     260 
     261 
     262 
    264263    public void initTypes() { 
    265264        if (visitState == POPULATED) { 
     
    303302 
    304303    protected void registerObjectExprs(Environment environment) { 
    305          
     304 
    306305    } 
    307306 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/env/ComponentWrapper.java

    r3047 r3078  
    3535import com.sun.fortress.nodes.CompilationUnit; 
    3636import com.sun.fortress.nodes.Component; 
    37 import com.sun.fortress.nodes.Export; 
    3837import com.sun.fortress.nodes.Param; 
    3938import com.sun.fortress.nodes.StaticParam; 
     
    5352public class ComponentWrapper extends CUWrapper { 
    5453 
    55     /*  
     54    /* 
    5655     * Next three lines are for the "cache" of rewritten ASTs 
    5756     */ 
     
    6059        public String apply(APIName x) { 
    6160            return ProjectProperties.compFileName(ProjectProperties.INTERPRETER_CACHE_DIR, CacheBasedRepository.deCaseName(x)); 
    62         }  
     61        } 
    6362    }; 
    6463    private static IOAst componentReaderWriter = new IOAst(toCompFileName); 
    65     private static DerivedFiles<CompilationUnit> componentCache =  
     64    private static DerivedFiles<CompilationUnit> componentCache = 
    6665        new DerivedFiles<CompilationUnit>(componentReaderWriter); 
    67      
     66 
    6867    public static boolean noCache; 
    69      
     68 
    7069    Component transformed; 
    7170    boolean cacheDisabled; 
    72      
    73      
     71 
     72 
    7473    private Component getCached(ComponentIndex comp) { 
    7574        if (cacheDisabled) 
     
    7877            return  (Component) componentCache.get(comp.ast().getName(), comp.modifiedDate()); 
    7978    } 
    80      
     79 
    8180    public ComponentWrapper(ComponentIndex comp, HashMap<String, ComponentWrapper> linker, 
    8281            String[] implicitLibs) { 
    8382        super((Component) comp.ast(), linker, implicitLibs); 
    8483        cacheDisabled = noCache; 
    85          
     84 
    8685        transformed = getCached(comp); 
    8786        // TODO Auto-generated constructor stub 
     
    125124            } 
    126125        } 
    127          
     126 
    128127        if (!cacheDisabled && exportsMain(transformed)) { 
    129128            // It's not a library, no point keeping this copy in memory. 
     
    136135        be.getEnvironment().visit(nameCollector); 
    137136        comp_unit = cu; 
    138           
     137 
    139138        for (String implicitLibraryName : implicitLibs) { 
    140139            be.importAPIName(implicitLibraryName); 
    141140        } 
    142          
     141 
    143142        for (CUWrapper api: exports.values()) { 
    144143            be.importAPIName(api.name()); 
    145144        } 
    146          
     145 
    147146        for (APIWrapper api: exports.values()) { 
    148147            api.populateOne(this); 
     
    151150        return cu; 
    152151    } 
    153      
     152 
    154153    private boolean exportsMain(Component transformed2) { 
    155         List<Export> exports = transformed2.getExports(); 
    156         for (Export e : exports) { 
    157             List<APIName> apis = e.getApis(); 
    158             for (APIName a : apis) 
    159                 if (a.getText().equals("Executable")) 
    160                     return true; 
     154        List<APIName> exports = transformed2.getExports(); 
     155        for (APIName a : exports) { 
     156            if (a.getText().equals("Executable")) 
     157                return true; 
    161158        } 
    162159        return false; 
     
    170167    protected void registerObjectExprs(Environment env) { 
    171168        Component comp = (Component) comp_unit; 
    172          
     169 
    173170            for (_RewriteObjectExpr oe : comp.getObjectExprs()) { 
    174171                String name = oe.getGenSymName(); 
     
    196193                } 
    197194            } 
    198          
     195 
    199196    } 
    200197    public Set<String> getTopLevelRewriteNames() { 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java

    r3077 r3078  
    6666import com.sun.fortress.nodes.DoFront; 
    6767import com.sun.fortress.nodes.EnsuresClause; 
    68 import com.sun.fortress.nodes.Export; 
    6968import com.sun.fortress.nodes.Expr; 
    7069import com.sun.fortress.nodes.ExprMI; 
     
    655654        APIName name_result = (APIName) recur(com.getName()); 
    656655        List<Import> imports_result = recurOnListOfImport(com.getImports()); 
    657         List<Export> exports_result = recurOnListOfExport(com.getExports()); 
     656        List<APIName> exports_result = recurOnListOfAPIName(com.getExports()); 
    658657        List<Decl> decls_result = recurOnListOfDecl(com.getDecls()); 
    659658 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeUtil.java

    r3077 r3078  
    9393 
    9494                @Override 
    95                 public void forExport(Export that){ 
    96                     Debug.debug(Debug.Type.SYNTAX, 2, "Add export api ", that.getApis()); 
    97                     all.addAll(that.getApis()); 
    98                 } 
    99  
    100                 @Override 
    10195                public void forImportApi(ImportApi that){ 
    10296                    for (AliasedAPIName api : that.getApis()){ 
     
    106100                } 
    107101            }); 
     102        for (APIName api : comp.getExports()) { 
     103            all.add(api); 
     104        } 
    108105        return removeExecutableApi(all); 
    109106    } 
  • trunk/ProjectFortress/src/com/sun/fortress/parser/Compilation.rats

    r3019 r3078  
    296296 
    297297/* Exports ::= Export (br Export)* */ 
    298 private List<Export> Exports = a1:Export a2s:(br Export)* 
    299      { yyValue = FortressUtil.mkList(a1, a2s.list()); }; 
     298private List<APIName> Exports = a1:Export a2s:(br Export)* 
     299     { yyValue = a1; 
     300       for (List<APIName> export : a2s.list()) { 
     301           a1.addAll(export); 
     302       } 
     303     }; 
    300304 
    301305/* Export ::= export w APINames */ 
    302 private Export Export = export w a1:APINames 
    303      { yyValue = new Export(createSpan(yyStart,yyCount), a1); }; 
     306private List<APIName> Export = export w APINames ; 
    304307 
    305308/* APINames ::= 
  • trunk/ProjectFortress/src/com/sun/fortress/parser/preparser/PreCompilation.rats

    r2249 r3078  
    9393   / a1:(native w)? component w a2:APIName a3:(w yyValue:Imports w semicolon?)? w a4:Exports w (_)* 
    9494     { if (a3 == null) a3 = Collections.<Import>emptyList(); 
    95        // List<Export> a4 = Collections.<Export>emptyList(); 
    9695       List<Decl> a5 = Collections.<Decl>emptyList(); 
    9796       Span span = createSpan(yyStart,yyCount); 
     
    263262 
    264263/* Exports ::= Export (br Export)* */ 
    265 private List<Export> Exports = a1:Export a2s:(br Export)* 
    266      { yyValue = FortressUtil.mkList(a1, a2s.list()); }; 
     264private List<APIName> Exports = a1:Export a2s:(br Export)* 
     265     { yyValue = a1; 
     266       for (List<APIName> export : a2s.list()) { 
     267           a1.addAll(export); 
     268       } 
     269     }; 
    267270 
    268271/* Export ::= export w APINames */ 
    269 private Export Export = export w a1:APINames 
    270      { yyValue = new Export(createSpan(yyStart,yyCount), a1); }; 
     272private List<APIName> Export = export w APINames; 
    271273 
    272274/* APINames ::= 
  • trunk/ProjectFortress/src/com/sun/fortress/syntax_abstractions/parser/PreParser.java

    r3073 r3078  
    3434import com.sun.fortress.nodes.CompilationUnit; 
    3535import com.sun.fortress.nodes.Component; 
    36 import com.sun.fortress.nodes.Export; 
    3736import com.sun.fortress.nodes.Id; 
    3837import com.sun.fortress.nodes.Import; 
  • trunk/ProjectFortress/src/com/sun/fortress/tests/unit_tests/ConstructorsJUTest.java

    r2650 r3078  
    2424 
    2525import com.sun.fortress.nodes.APIName; 
    26 import com.sun.fortress.nodes.Export; 
    2726import com.sun.fortress.nodes.Expr; 
    2827import com.sun.fortress.nodes.FloatLiteralExpr; 
     
    126125    } 
    127126 
    128     public void testExport() { 
    129         Span span1 = newSpan("cat", 1, 2, 3); 
    130         Export e1 = new Export(span1, FortressUtil.mkList(newAPIName("some", "exported", "apiname"))); 
    131         Export e2 = new Export(span1, FortressUtil.mkList(newAPIName("some", "exported", "apiname"))); 
    132         Export e3 = new Export(span1, FortressUtil.mkList(newAPIName("an", "exported", "apiname"))); 
    133  
    134         een(e1, e2, e3); 
    135     } 
    136  
    137127    /** 
    138128     * @param e1 
  • trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java

    r3077 r3078  
    287287            s.append( import_ ).append( "\n" ); 
    288288        } 
    289         for ( String export_ : exports_result ){ 
    290             s.append( export_ ).append( "\n" ); 
    291         } 
     289        if (exports_result.size() == 0) 
     290            return bug(that, "A component should have at least one export statement."); 
     291        else 
     292            s = optCurlyBraces(s,"export ", exports_result, ""); 
     293        s.append( "\n" ); 
    292294        for ( String decl_ : decls_result ){ 
    293295            s.append( decl_ ).append( "\n\n" ); 
     
    373375        } 
    374376        return s.toString(); 
    375     } 
    376  
    377     @Override public String forExportOnly(Export that, List<String> apis_result) { 
    378         StringBuilder s = new StringBuilder(); 
    379         if (apis_result.size() == 0) 
    380             return bug(that, "An export statement should have at least one API name."); 
    381         else 
    382             return optCurlyBraces(s,"export ", apis_result, "").toString(); 
    383377    } 
    384378