Changeset 4311

Show
Ignore:
Timestamp:
11/03/09 21:46:01 (3 weeks ago)
Author:
sukyoungryu
Message:

[self type] Introduced SelfType? and its immediate subclasses, TraitSelfType? and ObjectExprType?.

Location:
trunk/ProjectFortress
Files:
50 modified

Legend:

Unmodified
Added
Removed
  • trunk/ProjectFortress/astgen/Fortress.ast

    r4296 r4311  
    176176                 * it is initialized by compiler.disambiguator.SelfParamDisambiguator. 
    177177                 */ 
    178                 abstract TraitObjectDecl(TraitTypeHeader header, Option<Type> selfType) implements Generic; 
     178                abstract TraitObjectDecl(TraitTypeHeader header, Option<SelfType> selfType) implements Generic; 
    179179                    /** 
    180180                     * trait declaration in components or APIs 
     
    562562                     *        end 
    563563                     */ 
    564                     ObjectExpr(Option<Type> selfType); 
     564                    ObjectExpr(Option<SelfType> selfType); 
    565565                    /** 
    566566                     * object expression rewritten by interpreter.rewrite.Disambiguate 
     
    10331033                    UnknownType(); 
    10341034                    /** 
     1035                     * the type of "self" in a trait or object 
     1036                     * internal node 
     1037                     */ 
     1038                    abstract SelfType(); 
     1039                        /** 
     1040                         * the type of "self" in a trait or object declaration 
     1041                         * internal node 
     1042                         */ 
     1043                        TraitSelfType(BaseType named, List<NamedType> comprised); 
     1044                        /** 
     1045                         * the type of "self" in an object expression 
     1046                         * internal node 
     1047                         */ 
     1048                        ObjectExprType(List<BaseType> extended); 
     1049                    /** 
    10351050                     * named type 
    10361051                     */ 
  • trunk/ProjectFortress/compiler_tests/XXX10d.test

    r4259 r4311  
    2020${STATIC_TESTS_DIR}/Compiled10.d.fss:20:13-17:\n\ 
    2121\ Could not check call to function g\n\ 
    22 \ - O->() is not applicable to an argument of type AND(T,OR(O,P)).\n\ 
     22\ - O->() is not applicable to an argument of type T.\n\ 
    2323File Compiled10.d.fss has 1 error.\n 
    2424compile_out_equals= 
  • trunk/ProjectFortress/compiler_tests/XXX10k.test

    r4286 r4311  
    2020${STATIC_TESTS_DIR}/Compiled10.k.fss:33:5-9:\n\ 
    2121\ Could not check call to function k\n\ 
    22 \ - Q->() is not applicable to an argument of type AND(T[\\U\\],U).\n\ 
     22\ - Q->() is not applicable to an argument of type T[\\U\\].\n\ 
    2323${STATIC_TESTS_DIR}/Compiled10.k.fss:34:5-7:\n\ 
    2424\ Could not check call to function h\n\ 
    25 \ - AND(T[\\U\\],U)->() is not applicable to an argument of type T[\\U\\].\n\ 
     25\ - T[\\U\\]->() is not applicable to an argument of type T[\\U\\].\n\ 
    2626${STATIC_TESTS_DIR}/Compiled10.k.fss:36:5-7:\n\ 
    2727\ Could not check call to function j\n\ 
  • trunk/ProjectFortress/compiler_tests/XXX10s.test

    r4292 r4311  
    2121${STATIC_TESTS_DIR}/Compiled10.s.fss:20:3-33:\n\ 
    2222\ Invalid overloading of f:\n\ 
    23 \ (AND(Bar[\\O,P\\],OR(O,P)), Bar[\\O,P\\]) -> () @ ${STATIC_TESTS_DIR}/Compiled10.s.fss:20:3-33\n\ 
    24 \ and (AND(Bar[\\P,O\\],OR(P,O)), Bar[\\P,O\\]) -> () @ ${STATIC_TESTS_DIR}/Compiled10.s.fss:20:3-33\n\ 
     23\ (Bar[\\O,P\\], Bar[\\O,P\\]) -> () @ ${STATIC_TESTS_DIR}/Compiled10.s.fss:20:3-33\n\ 
     24\ and (Bar[\\P,O\\], Bar[\\P,O\\]) -> () @ ${STATIC_TESTS_DIR}/Compiled10.s.fss:20:3-33\n\ 
    2525File Compiled10.s.fss has 1 error.\n 
    2626compile_out_equals= 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/NamingCzar.java

    r4305 r4311  
    4242import com.sun.fortress.nodes.NamedType; 
    4343import com.sun.fortress.nodes.Param; 
     44import com.sun.fortress.nodes.TraitSelfType; 
    4445import com.sun.fortress.nodes.TraitType; 
    4546import com.sun.fortress.nodes.TraitTypeWhere; 
     
    872873                throw new CompilerError(x,"emitDesc of type "+x+" failed"); 
    873874            } 
     875            @Override 
    874876            public String forArrowType(ArrowType t) { 
    875877                String res = makeArrowDescriptor(t, ifNone); 
     
    878880                return res; 
    879881            } 
    880  
     882            @Override 
    881883            public String forTupleType(TupleType t) { 
    882884                if ( NodeUtil.isVoidType(t) ) 
     
    888890                return jvmTypeDescs(t.getElements(), ifNone); 
    889891            } 
     892            @Override 
    890893            public String forAnyType (AnyType t) { 
    891894                return descFortressAny; 
    892895            } 
     896            @Override 
    893897            public String forVarType (VarType t) { 
    894898                // 
     
    897901                return s; 
    898902            } 
     903            @Override 
     904            public String forTraitSelfType(TraitSelfType t) { 
     905                return t.getNamed().accept(this); 
     906            } 
     907            @Override 
    899908            public String forTraitType(TraitType t) { 
    900909                // I think this is wrong!  What about API names? 
     
    929938            final APIName ifNone)  { 
    930939        return type.accept(new NodeAbstractVisitor<String>() { 
     940            @Override 
    931941            public String defaultCase(Node x) { 
    932942                throw new CompilerError(x,"methodDesc of type "+x+" failed"); 
    933943            } 
    934  
     944            @Override 
    935945            public String forArrowType(ArrowType t) { 
    936946                if (NodeUtil.isVoidType(t.getDomain())) 
     
    941951 
    942952            // TODO CASES BELOW OUGHT TO JUST FAIL, WILL TEST SOON. 
     953            @Override 
    943954            public String forTupleType(TupleType t) { 
    944955                if ( NodeUtil.isVoidType(t) ) 
     
    954965                return res; 
    955966            } 
     967            @Override 
    956968            public String forAnyType (AnyType t) { 
    957969                return descFortressAny; 
    958970            } 
     971            @Override 
     972            public String forTraitSelfType(TraitSelfType t) { 
     973                return t.getNamed().accept(this); 
     974            } 
     975            @Override 
    959976            public String forTraitType(TraitType t) { 
    960977                String result = specialFortressDescriptors.get(t); 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen/CodeGen.java

    r4305 r4311  
    24172417        } 
    24182418 
    2419         return exprType.unwrap(); 
     2419        Type ty = exprType.unwrap(); 
     2420        if (ty instanceof TraitSelfType) 
     2421            ty = ((TraitSelfType)ty).getNamed(); 
     2422 
     2423        return ty; 
    24202424    } 
    24212425    private Option<Type> exprOptType(Expr expr) { 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen/GenericNumberer.java

    r4296 r4311  
    1515    trademarks of Sun Microsystems, Inc. in the U.S. and other countries. 
    1616******************************************************************************/ 
    17 /* 
    18  * Created on Sep 22, 2009 
    19  * 
    20  */ 
     17 
    2118package com.sun.fortress.compiler.codegen; 
    2219 
     
    3835import com.sun.fortress.nodes.StaticParam; 
    3936import com.sun.fortress.nodes.StaticParamKind; 
     37import com.sun.fortress.nodes.TraitSelfType; 
    4038import com.sun.fortress.nodes.TraitType; 
    4139import com.sun.fortress.nodes.Type; 
     
    124122 
    125123    @Override 
     124    public Node forTraitSelfType(TraitSelfType that) { 
     125        return that.getNamed().accept(this); 
     126    } 
     127 
     128    @Override 
    126129    public Node forTraitType(TraitType that) { 
    127130        TypeInfo info_result = (TypeInfo) recur(that.getInfo()); 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/ObjectExpressionVisitor.java

    r4112 r4311  
    647647                                                       staticParams, 
    648648                                                       extendsClauses, 
    649                                                        decls, params, Option.<Type>none()); 
     649                                                       decls, params, Option.<SelfType>none()); 
    650650        if(enclosingSelf != null) { 
    651651            VarRef receiver = makeVarRefFromParam(enclosingSelf); 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/PreDisambiguationDesugaringVisitor.java

    r4275 r4311  
    7474                                      ExprInfo info, 
    7575                                      TraitTypeHeader header, 
    76                                       Option<Type> selfType) { 
     76                                      Option<SelfType> selfType) { 
    7777        Span span = NodeUtil.getSpan(that); 
    7878        List<TraitTypeWhere> extendsClause = rewriteExtendsClause(that, header.getExtendsClause()); 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/VarRefContainer.java

    r4300 r4311  
    2222import java.util.List; 
    2323 
    24 import com.sun.fortress.nodes.ASTNode; 
    25 import com.sun.fortress.nodes.Decl; 
    26 import com.sun.fortress.nodes.Expr; 
    27 import com.sun.fortress.nodes.FnRef; 
    28 import com.sun.fortress.nodes.Id; 
    29 import com.sun.fortress.nodes.IdOrOp; 
    30 import com.sun.fortress.nodes.LValue; 
    31 import com.sun.fortress.nodes.LocalVarDecl; 
    32 import com.sun.fortress.nodes.Node; 
    33 import com.sun.fortress.nodes.ObjectDecl; 
    34 import com.sun.fortress.nodes.Param; 
    35 import com.sun.fortress.nodes.StaticArg; 
    36 import com.sun.fortress.nodes.StaticParam; 
    37 import com.sun.fortress.nodes.TraitTypeWhere; 
    38 import com.sun.fortress.nodes.Type; 
    39 import com.sun.fortress.nodes.VarDecl; 
    40 import com.sun.fortress.nodes.VarRef; 
    41 import com.sun.fortress.nodes.FieldRef; 
    42 import com.sun.fortress.nodes.WhereClause; 
     24import com.sun.fortress.nodes.*; 
    4325import com.sun.fortress.nodes_util.ExprFactory; 
    4426import com.sun.fortress.nodes_util.Modifiers; 
     
    10183        ObjectDecl container = 
    10284            NodeFactory.makeObjectDecl( NodeUtil.getSpan(origDeclNode), containerDeclId(), 
    103                                         Option.<List<Param>>some(params), Option.<Type>none() ); 
     85                                        Option.<List<Param>>some(params), Option.<SelfType>none() ); 
    10486 
    10587        return container; 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/TypeDisambiguator.java

    r4280 r4311  
    101101                                that.getInfo(), 
    102102                                header, 
    103                                 v.recurOnOptionOfType(that.getSelfType()), 
     103                                v.recurOnOptionOfSelfType(that.getSelfType()), 
    104104                                v.recurOnListOfBaseType(NodeUtil.getExcludesClause(that)), 
    105105                                v.recurOnOptionOfListOfNamedType(NodeUtil.getComprisesClause(that))); 
     
    126126                                 that.getInfo(), 
    127127                                 header, 
    128                                  v.recurOnOptionOfType(that.getSelfType()), 
     128                                 v.recurOnOptionOfSelfType(that.getSelfType()), 
    129129                                 v.recurOnOptionOfListOfParam(NodeUtil.getParams(that))); 
    130130    } 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/Coercion.java

    r4291 r4311  
    6565         
    6666        // Return type always a TraitType inserted by CoercionLifter. 
    67         final TraitType returnType = (TraitType) NodeUtil.getReturnType(ast).unwrap(); 
     67        Type returnTy = NodeUtil.getReturnType(ast).unwrap(); 
     68        final TraitType returnType; 
     69        if (returnTy instanceof TraitSelfType) 
     70            returnType = (TraitType)((TraitSelfType)returnTy).getNamed(); 
     71        else returnType = (TraitType) returnTy; 
     72 
    6873         
    6974        _lifted = true; 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/DeclaredMethod.java

    r4291 r4311  
    3535    private final FnDecl _ast; 
    3636    private final Id _declaringTrait; 
    37     private final Option<Type> _selfType; 
     37    private final Option<SelfType> _selfType; 
    3838 
    3939    public DeclaredMethod(FnDecl ast, TraitObjectDecl traitDecl) { 
     
    5252        _ast = (FnDecl) that._ast.accept(visitor); 
    5353        _declaringTrait = that._declaringTrait; 
    54         _selfType = visitor.recurOnOptionOfType(that._selfType); 
     54        _selfType = visitor.recurOnOptionOfSelfType(that._selfType); 
    5555 
    5656        _thunk = that._thunk; 
     
    109109    } 
    110110 
    111     public Option<Type> selfType() { 
     111    public Option<SelfType> selfType() { 
    112112        return _selfType; 
    113113    } 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/FieldGetterOrSetterMethod.java

    r4291 r4311  
    3636    protected final Binding _ast; 
    3737    protected final Id _declaringTrait; 
    38     protected final Option<Type> _selfType; 
     38    protected final Option<SelfType> _selfType; 
    3939    protected final Option<FnDecl> _fnDecl; 
    4040 
     
    6161        _ast = (Binding) that._ast.accept(visitor); 
    6262        _declaringTrait = that._declaringTrait; 
    63         _selfType = visitor.recurOnOptionOfType(that._selfType); 
     63        _selfType = visitor.recurOnOptionOfSelfType(that._selfType); 
    6464        if (that._fnDecl.isSome()) { 
    6565            _fnDecl = Option.some((FnDecl) that._fnDecl.unwrap().accept(visitor)); 
     
    106106    } 
    107107 
    108     public Option<Type> selfType() { 
     108    public Option<SelfType> selfType() { 
    109109        return _selfType; 
    110110    } 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/FunctionalMethod.java

    r4291 r4311  
    4242    protected final Id _declaringTrait; 
    4343    protected final List<StaticParam> _traitParams; 
    44     protected final Option<Type> _selfType; 
     44    protected final Option<SelfType> _selfType; 
    4545    protected final int _selfPosition; 
    4646 
     
    6868        _declaringTrait = that._declaringTrait; 
    6969        _traitParams = visitor.recurOnListOfStaticParam(that._traitParams); 
    70         _selfType = visitor.recurOnOptionOfType(that._selfType); 
     70        _selfType = visitor.recurOnOptionOfSelfType(that._selfType); 
    7171        _selfPosition = that._selfPosition; 
    7272 
     
    169169    } 
    170170 
    171     public Option<Type> selfType() { 
     171    public Option<SelfType> selfType() { 
    172172        return _selfType; 
    173173    } 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/HasSelfType.java

    r4094 r4311  
    1818package com.sun.fortress.compiler.index; 
    1919 
    20 import com.sun.fortress.nodes.Type; 
     20import com.sun.fortress.nodes.SelfType; 
    2121import com.sun.fortress.nodes.Id; 
    2222import edu.rice.cs.plt.tuple.Option; 
     
    2828public interface HasSelfType { 
    2929    public Id declaringTrait(); 
    30     public Option<Type> selfType(); 
     30    public Option<SelfType> selfType(); 
    3131    public int selfPosition(); 
    3232} 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/TraitIndex.java

    r4309 r4311  
    5757    } 
    5858 
    59     public Option<Type> typeOfSelf() { 
     59    public Option<SelfType> typeOfSelf() { 
    6060        if (this.ast() instanceof TraitObjectDecl) { 
    6161            return ((TraitObjectDecl) this.ast()).getSelfType(); 
    6262        } 
    63         return Option.<Type>none(); 
     63        return Option.<SelfType>none(); 
    6464    } 
    6565 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeAnalyzer.java

    r4280 r4311  
    268268        Type outer_result = (Type) outer_t.accept(new NodeUpdateVisitor() { 
    269269 
     270            @Override public BaseType forTraitSelfTypeOnly(TraitSelfType t, 
     271                                                           TypeInfo i, 
     272                                                           BaseType named, 
     273                                                           List<NamedType> comprised) { 
     274                return (BaseType) named.accept(this); 
     275            } 
     276 
     277            @Override public Type forObjectExprTypeOnly(ObjectExprType t, 
     278                                                        TypeInfo i, 
     279                                                        List<BaseType> extended) { 
     280                Type result = mt(extended, history); 
     281                return t.equals(result) ? t : result; 
     282            } 
     283 
    270284            @Override public BaseType forTraitTypeOnly(TraitType t, 
    271285                                                       TypeInfo i, 
     
    607621                result = sub_type.accept(new NodeAbstractVisitor<ConstraintFormula>() { 
    608622                    @Override public ConstraintFormula forType(Type s) { return falseFormula(); } 
     623                    @Override public ConstraintFormula forTraitSelfType(TraitSelfType s) { 
     624                        return s.getNamed().accept(this); 
     625                    } 
     626                    @Override public ConstraintFormula forObjectExprType(ObjectExprType s) { 
     627                        return intersectionSub(NodeFactory.makeIntersectionType(s.getExtended()), 
     628                                               super_type, h); 
     629                    } 
    609630                    @Override public ConstraintFormula forTraitType(TraitType s) { 
    610631                        if (super_type instanceof TraitType) { 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeAnalyzerJUTest.java

    r4280 r4311  
    3838import com.sun.fortress.compiler.index.*; 
    3939import com.sun.fortress.compiler.typechecker.constraints.ConstraintFormula; 
    40 import com.sun.fortress.nodes.APIName; 
    41 import com.sun.fortress.nodes.Api; 
    42 import com.sun.fortress.nodes.BaseType; 
    43 import com.sun.fortress.nodes.Component; 
    44 import com.sun.fortress.nodes.Decl; 
    45 import com.sun.fortress.nodes.Effect; 
    46 import com.sun.fortress.nodes.Id; 
    47 import com.sun.fortress.nodes.IdOrOpOrAnonymousName; 
    48 import com.sun.fortress.nodes.Import; 
    49 import com.sun.fortress.nodes.KeywordType; 
    50 import com.sun.fortress.nodes.StaticParam; 
    51 import com.sun.fortress.nodes.TraitDecl; 
    52 import com.sun.fortress.nodes.TraitTypeWhere; 
    53 import com.sun.fortress.nodes.Type; 
    54 import com.sun.fortress.nodes.VarDecl; 
    55 import com.sun.fortress.nodes.WhereClause; 
     40import com.sun.fortress.nodes.*; 
    5641import com.sun.fortress.nodes_util.NodeFactory; 
    5742import com.sun.fortress.nodes_util.NodeUtil; 
     
    496481            ast = NodeFactory.makeTraitDecl(span, NodeFactory.makeId(span, name), 
    497482                                            Collections.<StaticParam>emptyList(), 
    498                                             extendsClause, Option.<Type>none()); 
     483                                            extendsClause, Option.<SelfType>none()); 
    499484        } 
    500485        else { 
    501486            ast = NodeFactory.makeTraitDecl(span, NodeFactory.makeId(span, name), 
    502487                                            Collections.<StaticParam>emptyList(), 
    503                                             extendsClause, Option.<Type>none()); 
     488                                            extendsClause, Option.<SelfType>none()); 
    504489        } 
    505490        return new ProperTraitIndex(ast, 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeAnalyzerUtil.java

    r4280 r4311  
    191191                return t.getName().getApiName().isNone() && names.contains(t.getName()); 
    192192            } 
     193            @Override public Boolean forTraitSelfType(TraitSelfType t) { 
     194                return t.getNamed().accept(this); 
     195            } 
    193196            @Override public Boolean forTraitType(TraitType t) { 
    194197                for (StaticArg arg : t.getArgs()) { 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeCheckerTestCase.java

    r3963 r4311  
    2828 
    2929import com.sun.fortress.compiler.index.*; 
    30 import com.sun.fortress.nodes.ArrowType; 
    31 import com.sun.fortress.nodes.Decl; 
    32 import com.sun.fortress.nodes.Id; 
    33 import com.sun.fortress.nodes.TraitType; 
    34 import com.sun.fortress.nodes.NodeAbstractVisitor; 
    35 import com.sun.fortress.nodes.Param; 
    36 import com.sun.fortress.nodes.IdOrOpOrAnonymousName; 
    37 import com.sun.fortress.nodes.StaticArg; 
    38 import com.sun.fortress.nodes.StaticParam; 
    39 import com.sun.fortress.nodes.TraitDecl; 
    40 import com.sun.fortress.nodes.BaseType; 
    41 import com.sun.fortress.nodes.TraitTypeWhere; 
    42 import com.sun.fortress.nodes.TupleType; 
    43 import com.sun.fortress.nodes.Type; 
    44 import com.sun.fortress.nodes.WhereClause; 
     30import com.sun.fortress.nodes.*; 
    4531import com.sun.fortress.nodes_util.NodeFactory; 
    4632import com.sun.fortress.nodes_util.Span; 
     
    9076        } 
    9177        TraitDecl ast = NodeFactory.makeTraitDecl(span, NodeFactory.makeId(span, name), sparams, 
    92                                                   extendsClause, Option.<Type>none()); 
     78                                                  extendsClause, Option.<SelfType>none()); 
    9379        return new ProperTraitIndex(ast, 
    9480                                    Collections.<Id, Method>emptyMap(), 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeNormalizer.java

    r4275 r4311  
    5656                                 ASTNodeInfo info, 
    5757                                 TraitTypeHeader header, 
    58                                  Option<Type> selfType, 
     58                                 Option<SelfType> selfType, 
    5959                                 List<BaseType> excludesClause, 
    6060                                 Option<List<NamedType>> comprises) { 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypesUtil.java

    r3928 r4311  
    3232import com.sun.fortress.compiler.Types; 
    3333import com.sun.fortress.compiler.typechecker.constraints.ConstraintFormula; 
    34 import com.sun.fortress.nodes.AnyType; 
    35 import com.sun.fortress.nodes.ArrayType; 
    36 import com.sun.fortress.nodes.ArrowType; 
    37 import com.sun.fortress.nodes.BottomType; 
    38 import com.sun.fortress.nodes.Id; 
    39 import com.sun.fortress.nodes.IdOrOp; 
    40 import com.sun.fortress.nodes.IntersectionType; 
    41 import com.sun.fortress.nodes.KindBool; 
    42 import com.sun.fortress.nodes.KindDim; 
    43 import com.sun.fortress.nodes.KindInt; 
    44 import com.sun.fortress.nodes.KindNat; 
    45 import com.sun.fortress.nodes.KindOp; 
    46 import com.sun.fortress.nodes.KindType; 
    47 import com.sun.fortress.nodes.KindUnit; 
    48 import com.sun.fortress.nodes.MatrixType; 
    49 import com.sun.fortress.nodes.Node; 
    50 import com.sun.fortress.nodes.NodeAbstractVisitor; 
    51 import com.sun.fortress.nodes.NodeDepthFirstVisitor; 
    52 import com.sun.fortress.nodes.NodeDepthFirstVisitor_void; 
    53 import com.sun.fortress.nodes.ObjectExpr; 
    54 import com.sun.fortress.nodes.Op; 
    55 import com.sun.fortress.nodes.OutAfterTypeChecking; 
    56 import com.sun.fortress.nodes.WhereClause; 
    57 import com.sun.fortress.nodes.StaticArg; 
    58 import com.sun.fortress.nodes.StaticParam; 
    59 import com.sun.fortress.nodes.TraitType; 
    60 import com.sun.fortress.nodes.TraitTypeWhere; 
    61 import com.sun.fortress.nodes.Type; 
    62 import com.sun.fortress.nodes.TypeAbstractVisitor; 
    63 import com.sun.fortress.nodes.UnionType; 
     34import com.sun.fortress.nodes.*; 
    6435import com.sun.fortress.nodes._InferenceVarType; 
    6536import com.sun.fortress.nodes_util.ExprFactory; 
     
    477448 
    478449    /** 
    479      * Given an ObjectExpr, returns the Type of the expression. 
    480      * @return 
    481      */ 
    482     public static Type getObjectExprType(ObjectExpr obj) { 
    483         List<Type> extends_types = CollectUtil.makeList(IterUtil.map(NodeUtil.getExtendsClause(obj), 
    484                         new Lambda<TraitTypeWhere,Type>(){ 
    485                 public Type value(TraitTypeWhere arg0) { 
    486                         return arg0.getBaseType(); 
    487                 }})); 
    488         Type self_type = 
    489                 extends_types.isEmpty() ? 
    490                                 Types.OBJECT : 
    491                                 Types.makeIntersection(extends_types); 
    492         return self_type; 
    493     } 
    494  
    495     /** 
    496450     * Take a node with _InferenceVarType, and TypeCheckerResults, which containt 
    497451     * constraints on those inference vars, solve, and replace the inference vars 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/EvalType.java

    r4260 r4311  
    5555    } 
    5656 
     57    public FType evalType(TraitSelfType t) { 
     58        return evalType(t.getNamed()); 
     59    } 
     60 
    5761    // Returns the type that has the same name as the trait, in this 
    5862    // environment (used in unification). 
     
    517521    public FType forAnyType(AnyType a) { 
    518522        return FTypeTop.ONLY; 
     523    } 
     524 
     525    public FType forTraitSelfType(TraitSelfType x) { 
     526        return x.getNamed().accept(this); 
     527    } 
     528 
     529    public FType forObjectExprType(ObjectExprType x) { 
     530        List<BaseType> extended = x.getExtended(); 
     531        if (!extended.isEmpty()) 
     532            return extended.get(0).accept(this); 
     533        else return NI.nyi("Can't interpret an empty intersection type."); 
    519534    } 
    520535 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/ScoutVisitor.java

    r4002 r4311  
    6666        // TODO Auto-generated method stub 
    6767        super.forVarType(that); 
     68    } 
     69 
     70    @Override 
     71    public void forTraitSelfType(TraitSelfType that) { 
     72        // TODO Auto-generated method stub 
     73        super.forTraitSelfType(that); 
    6874    } 
    6975 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/types/FTraitOrObject.java

    r4169 r4311  
    271271                                               BoundingMap<String, FType, TypeLatticeOps> abm, 
    272272                                               Type val) { 
     273        if (val instanceof TraitSelfType) 
     274            val = ((TraitSelfType)val).getNamed(); 
    273275        if (DUMP_UNIFY) System.out.println("unify GT/O  " + this + " and " + val + " abm= " + abm); 
    274276        if (!(val instanceof TraitType)) { 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ErrorMsgMaker.java

    r4296 r4311  
    310310    } 
    311311 
     312    public String forTraitSelfType(TraitSelfType node) { 
     313        //return "SelfType " + node.getNamed().accept(this); 
     314        return node.getNamed().accept(this); 
     315    } 
     316 
     317    public String forObjectExprType(ObjectExprType node) { 
     318        // Could use U+2227 = AND if we supported Unicode output 
     319        //return "AND" + Useful.listInParens(mapSelf(node.getExtended())); 
     320        List<BaseType> extended = node.getExtended(); 
     321        if (extended.size() == 1) 
     322            return extended.get(0).accept(this); 
     323        else 
     324            return "AND" + Useful.listInParens(mapSelf(node.getExtended())); 
     325    } 
     326 
    312327    public String forTraitType(TraitType node) { 
    313328        String constructorName = NodeUtil.shortNameString(node.getName()); 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java

    r4300 r4311  
    948948                                            List<TraitTypeWhere> extendsC, 
    949949                                            List<Decl> decls, 
    950                                             Option<Type> selfType) { 
     950                                            Option<SelfType> selfType) { 
    951951        return makeObjectExpr(span, false, Option.<Type>none(), 
    952952                              extendsC, decls, selfType); 
     
    958958                                            List<TraitTypeWhere> extendsC, 
    959959                                            List<Decl> decls, 
    960                                             Option<Type> selfType) { 
     960                                            Option<SelfType> selfType) { 
    961961        TraitTypeHeader header = NodeFactory.makeTraitTypeHeader(NodeFactory.makeId(span, "_"), 
    962962                                                                 extendsC, decls); 
     
    968968                                            Option<Type> ty, 
    969969                                            TraitTypeHeader header, 
    970                                             Option<Type> selfType) { 
     970                                            Option<SelfType> selfType) { 
    971971        ExprInfo info = NodeFactory.makeExprInfo(span, parenthesized, ty); 
    972972        return new ObjectExpr(info, header, selfType); 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeComparator.java

    r4260 r4311  
    354354    static int compare(OpArg left, OpArg right) { 
    355355        return compare(left.getName().getOriginalName(), right.getName().getOriginalName()); 
     356    } 
     357 
     358    static int compare(TraitSelfType left, TraitSelfType right) { 
     359        int c = compare(left.getNamed(), right.getNamed()); 
     360        if (c != 0) return c; 
     361        return typeListComparer.compare(left.getComprised(), 
     362                                        right.getComprised()); 
     363    } 
     364 
     365    static int compare(ObjectExprType left, ObjectExprType right) { 
     366        return typeListComparer.compare(left.getExtended(), 
     367                                        right.getExtended()); 
    356368    } 
    357369 
     
    410422        if (left instanceof TraitType) { 
    411423            return compare((TraitType) left, (TraitType) right); 
     424        } else if (left instanceof TraitSelfType) { 
     425            return subtypeCompareTo(((TraitSelfType)left).getNamed(), 
     426                                    ((TraitSelfType)right).getNamed()); 
     427        } else if (left instanceof ObjectExprType) { 
     428            int x = typeListComparer.compare(((ObjectExprType)left).getExtended(), 
     429                                             ((ObjectExprType)right).getExtended()); 
     430            return x; 
    412431        } else if (left instanceof TupleType) { 
    413432            if ( NodeUtil.isVoidType((TupleType)left) ) 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeFactory.java

    r4296 r4311  
    295295                             excludesC, 
    296296                             comprisesC, 
    297                              Option.<Type>some(selfType)); 
     297                             Option.<SelfType>some(makeSelfType(selfType))); 
    298298    } 
    299299     
     
    302302                                          List<StaticParam> sparams, 
    303303                                          List<TraitTypeWhere> extendsC, 
    304                                           Option<Type> selfType) { 
     304                                          Option<SelfType> selfType) { 
    305305        return makeTraitDecl(span, Modifiers.None, name, 
    306306                             sparams, extendsC, Option.<WhereClause>none(), 
     
    317317                                          List<BaseType> excludesC, 
    318318                                          Option<List<NamedType>> comprisesC, 
    319                                           Option<Type> selfType) { 
     319                                          Option<SelfType> selfType) { 
    320320        return makeTraitDecl(span, mods, name, sparams, extendsC, whereC, decls, 
    321321                             excludesC, comprisesC, false, selfType); 
     
    330330                                          Option<List<NamedType>> comprisesC, 
    331331                                          boolean comprisesEllipses, 
    332                                           Option<Type> selfType) { 
     332                                          Option<SelfType> selfType) { 
    333333        TraitTypeHeader header = makeTraitTypeHeader(mods, name, sparams, whereC, 
    334334                                                     Option.<List<Type>>none(), 
     
    343343                                          Option<List<NamedType>> comprisesC, 
    344344                                          boolean comprisesEllipses, 
    345                                           Option<Type> selfType) { 
     345                                          Option<SelfType> selfType) { 
    346346        return new TraitDecl(info, header, selfType, excludesC, comprisesC, comprisesEllipses); 
    347347    } 
     
    350350                                            List<TraitTypeWhere> extendsC, 
    351351                                            List<Decl> decls, 
    352                                             Option<Type> selfType) { 
     352                                            Option<SelfType> selfType) { 
    353353        return makeObjectDecl(span, Modifiers.None, name, 
    354354                              Collections.<StaticParam>emptyList(), 
     
    362362    public static ObjectDecl makeObjectDecl(Span span, Id name, 
    363363                                            Option<List<Param>> params, 
    364                                             Option<Type> selfType) { 
     364                                            Option<SelfType> selfType) { 
    365365        return makeObjectDecl(span, Modifiers.None, name, 
    366366                              Collections.<StaticParam>emptyList(), 
     
    378378                                            List<Decl> decls, 
    379379                                            Option<List<Param>> params, 
    380                                             Option<Type> selfType) { 
     380                                            Option<SelfType> selfType) { 
    381381        return makeObjectDecl(span, Modifiers.None, name, 
    382382                              sparams, extendsC, 
     
    390390                                            List<TraitTypeWhere> extendsC) { 
    391391        return makeObjectDecl(NodeUtil.getSpan(selfType), 
    392                 Modifiers.None, 
    393                 selfType.getName(), 
    394                 NodeUtil.getStaticParams(selfType), 
    395                 extendsC, 
    396                 Option.<WhereClause>none(), 
    397                 Collections.<Decl>emptyList(), 
    398                 Option.<List<Param>>none(), 
    399                 Option.<List<Type>>none(), 
    400                 Option.<Contract>none(), 
    401                 Option.<Type>some(selfType)); 
     392                              Modifiers.None, 
     393                              selfType.getName(), 
     394                              NodeUtil.getStaticParams(selfType), 
     395                              extendsC, 
     396                              Option.<WhereClause>none(), 
     397                              Collections.<Decl>emptyList(), 
     398                              Option.<List<Param>>none(), 
     399                              Option.<List<Type>>none(), 
     400                              Option.<Contract>none(), 
     401                              Option.<SelfType>some(makeSelfType(selfType))); 
    402402    } 
    403403     
     
    410410                                            Option<List<Type>> throwsC, 
    411411                                            Option<Contract> contract, 
    412                                             Option<Type> selfType) { 
     412                                            Option<SelfType> selfType) { 
    413413        TraitTypeHeader header = makeTraitTypeHeader(mods, name, sparams, whereC, 
    414414                                                     throwsC, contract, extendsC, 
     
    875875    } 
    876876 
     877    public static ObjectExprType makeObjectExprType(List<BaseType> extended) { 
     878        return makeObjectExprType(NodeUtil.spanAll(extended), false, extended); 
     879    } 
     880 
     881    public static ObjectExprType makeObjectExprType(Span span, boolean parenthesized, 
     882                                                    List<BaseType> extended) { 
     883        TypeInfo info = makeTypeInfo(span, parenthesized); 
     884        return new ObjectExprType(info, extended); 
     885    } 
     886 
     887    public static SelfType makeSelfType(TraitType self) { 
     888        return makeTraitSelfType(NodeUtil.getSpan(self), false, 
     889                                 self, Collections.<NamedType>emptyList()); 
     890    } 
     891 
     892    public static SelfType makeSelfType(TraitType self, List<NamedType> comprised) { 
     893        return makeTraitSelfType(NodeUtil.getSpan(self), false, self, comprised); 
     894    } 
     895 
     896    public static SelfType makeTraitSelfType(Span span, boolean parenthesized, 
     897                                             BaseType self, List<NamedType> comprised) { 
     898        TypeInfo info = makeTypeInfo(span, parenthesized); 
     899        return new TraitSelfType(info, self, comprised); 
     900    } 
     901 
    877902    public static TraitType makeTraitType(TraitType original) { 
    878903        return makeTraitType(NodeUtil.getSpan(original), NodeUtil.isParenthesized(original), 
     
    21442169                return makeMatrixType(NodeUtil.getSpan(t), true, t.getElemType(), 
    21452170                                      t.getDimensions()); 
     2171            } 
     2172            public Type forTraitSelfType(TraitSelfType t) { 
     2173                return  makeTraitSelfType(NodeUtil.getSpan(t), true, 
     2174                                          t.getNamed(), t.getComprised()); 
     2175            } 
     2176            public Type forObjectExprType(ObjectExprType t) { 
     2177                return  makeObjectExprType(NodeUtil.getSpan(t), true, t.getExtended()); 
    21462178            } 
    21472179            public Type forTraitType(TraitType t) { 
  • trunk/ProjectFortress/src/com/sun/fortress/parser/DelimitedExpr.rats

    r4080 r4311  
    5757     { if (a1 == null) a1 = Collections.<TraitTypeWhere>emptyList(); 
    5858       if (a2 == null) a2 = Collections.<Decl>emptyList(); 
    59        yyValue = ExprFactory.makeObjectExpr(createSpan(yyStart,yyCount), a1, a2, Option.<Type>none()); 
     59       yyValue = ExprFactory.makeObjectExpr(createSpan(yyStart,yyCount), 
     60                                            a1, a2, Option.<SelfType>none()); 
    6061     } 
    6162   / Do 
  • trunk/ProjectFortress/src/com/sun/fortress/parser/TraitObject.rats

    r3986 r4311  
    4949                                           a4, a3.getExcludes(), 
    5050                                           a3.getComprises(), a3.getEllipses(), 
    51                                            Option.<Type>none()); 
     51                                           Option.<SelfType>none()); 
    5252     }; 
    5353 
     
    141141                                            fhc.getThrowsClause(), 
    142142                                            fhc.getContractClause(), 
    143                                             Option.<Type>none()); 
     143                                            Option.<SelfType>none()); 
    144144     }; 
    145145 
     
    227227                                           a4, a3.getExcludes(), 
    228228                                           a3.getComprises(), a3.getEllipses(), 
    229                                            Option.<Type>none()); 
     229                                           Option.<SelfType>none()); 
    230230     }; 
    231231 
     
    293293                                            fhc.getThrowsClause(), 
    294294                                            fhc.getContractClause(), 
    295                                             Option.<Type>none()); 
     295                                            Option.<SelfType>none()); 
    296296     }; 
    297297 
  • trunk/ProjectFortress/src/com/sun/fortress/repository/ForeignJava.java

    r4291 r4311  
    395395                                                 excludesC, 
    396396                                                 comprisesC, 
    397                                                  Option.<com.sun.fortress.nodes.Type>none()); 
     397                                                 Option.<com.sun.fortress.nodes.SelfType>none()); 
    398398        // Need to fake up an API for this class, too. 
    399399        classToTraitDecl.put(imported_class, td); 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/disambiguator/SelfParamDisambiguator.scala

    r4259 r4311  
    5252    case SObjectDecl(_, STraitTypeHeader(sparams,_,name,_,_,_,_,_), _, _) => 
    5353      // Add a type to self parameters of methods 
    54       val self_type = NF.makeTraitType(name.asInstanceOf[Id], 
    55                                        TypeEnv.staticParamsToArgs(toJavaList(sparams))) 
     54      val self_type = NF.makeSelfType(NF.makeTraitType(name.asInstanceOf[Id], 
     55                                                       TypeEnv.staticParamsToArgs(toJavaList(sparams)))) 
    5656      replaceSelfParamsWithType(node, self_type).asInstanceOf[ObjectDecl] match { 
    5757        case SObjectDecl(info, header, _, params) => 
     
    7171                    _, _, comprisesC, _) => 
    7272      // Add a type to self parameters of methods 
    73       var self_type: Type = NF.makeTraitType(name.asInstanceOf[Id], 
    74                                              TypeEnv.staticParamsToArgs(toJavaList(sparams))) 
    75       comprisesC match { 
    76         case Some(comprises@_::_) => 
    77           self_type = NF.makeIntersectionType(self_type, 
    78                                               NF.makeMaybeUnionType(toJavaList(comprises))) 
    79         case _ => 
     73      val type_name = NF.makeTraitType(name.asInstanceOf[Id], 
     74                                       TypeEnv.staticParamsToArgs(toJavaList(sparams))) 
     75      val self_type = comprisesC match { 
     76        case Some(comprises@_::_) => NF.makeSelfType(type_name, toJavaList(comprises)) 
     77        case _ => NF.makeSelfType(type_name) 
     78        
    8079      } 
    8180      replaceSelfParamsWithType(node, self_type).asInstanceOf[TraitDecl] match { 
     
    8786    case oe@SObjectExpr(_, STraitTypeHeader(sparams,_,name,_,_,_,_,_), _) => 
    8887      // Add a type to self parameters of methods 
    89       val self_type = TypesUtil.getObjectExprType(oe) 
     88      val self_type = getObjectExprType(oe) 
    9089      replaceSelfParamsWithType(oe, self_type) match { 
    9190        case SObjectExpr(info, header, _) => 
     
    103102   * @param self_type 
    104103   */ 
    105   def replaceSelfParamsWithType(that_node: Any, self_type: Type): Node = { 
     104  def replaceSelfParamsWithType(that_node: Any, self_type: SelfType): Node = { 
    106105    object replacer extends Walker { 
    107106      var traitNestingDepth = 0 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/linker/HygienicRenamer.scala

    r4296 r4311  
    140140             SLValue(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ASTNodeInfo], walk(getName).asInstanceOf[com.sun.fortress.nodes.Id], walk(getMods).asInstanceOf[com.sun.fortress.nodes_util.Modifiers], walk(getIdType).asInstanceOf[Option[com.sun.fortress.nodes.Type]], walk(isMutable).asInstanceOf[Boolean]) 
    141141         case SObjectDecl(getInfo, getHeader, getParams, getSelfType) => 
    142              SObjectDecl(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ASTNodeInfo], walk(getHeader).asInstanceOf[com.sun.fortress.nodes.TraitTypeHeader], walk(getSelfType).asInstanceOf[Option[com.sun.fortress.nodes.Type]], walk(getParams).asInstanceOf[Option[List[com.sun.fortress.nodes.Param]]]) 
     142             SObjectDecl(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ASTNodeInfo], walk(getHeader).asInstanceOf[com.sun.fortress.nodes.TraitTypeHeader], walk(getSelfType).asInstanceOf[Option[com.sun.fortress.nodes.SelfType]], walk(getParams).asInstanceOf[Option[List[com.sun.fortress.nodes.Param]]]) 
    143143         case SObjectExpr(getInfo, getHeader, getSelfType) => 
    144              SObjectExpr(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ExprInfo], walk(getHeader).asInstanceOf[com.sun.fortress.nodes.TraitTypeHeader], walk(getSelfType).asInstanceOf[Option[com.sun.fortress.nodes.Type]]) 
     144             SObjectExpr(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ExprInfo], walk(getHeader).asInstanceOf[com.sun.fortress.nodes.TraitTypeHeader], walk(getSelfType).asInstanceOf[Option[com.sun.fortress.nodes.SelfType]]) 
    145145         case SOp(getInfo, getApiName, getText, getFixity, isEnclosing) => 
    146146             SOp(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ASTNodeInfo], walk(getApiName).asInstanceOf[Option[com.sun.fortress.nodes.APIName]], walk(getText).asInstanceOf[String], walk(getFixity).asInstanceOf[com.sun.fortress.nodes.Fixity], walk(isEnclosing).asInstanceOf[Boolean]) 
     
    202202             STokenSymbol(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ASTNodeInfo], walk(getToken).asInstanceOf[String]) 
    203203         case STraitDecl(getInfo, getHeader, getExcludesClause, getComprisesClause, isComprisesEllipses, getSelfType) => 
    204              STraitDecl(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ASTNodeInfo], walk(getHeader).asInstanceOf[com.sun.fortress.nodes.TraitTypeHeader], walk(getSelfType).asInstanceOf[Option[com.sun.fortress.nodes.Type]], walk(getExcludesClause).asInstanceOf[List[com.sun.fortress.nodes.BaseType]], walk(getComprisesClause).asInstanceOf[Option[List[com.sun.fortress.nodes.NamedType]]], walk(isComprisesEllipses).asInstanceOf[Boolean]) 
     204             STraitDecl(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ASTNodeInfo], walk(getHeader).asInstanceOf[com.sun.fortress.nodes.TraitTypeHeader], walk(getSelfType).asInstanceOf[Option[com.sun.fortress.nodes.SelfType]], walk(getExcludesClause).asInstanceOf[List[com.sun.fortress.nodes.BaseType]], walk(getComprisesClause).asInstanceOf[Option[List[com.sun.fortress.nodes.NamedType]]], walk(isComprisesEllipses).asInstanceOf[Boolean]) 
     205         case STraitSelfType(getInfo, getNamed, getComprised) => 
     206             STraitSelfType(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.TypeInfo], 
     207                            walk(getNamed).asInstanceOf[com.sun.fortress.nodes.BaseType], 
     208                            walk(getComprised).asInstanceOf[List[com.sun.fortress.nodes.NamedType]]) 
     209         case SObjectExprType(getInfo, getExtended) => 
     210             SObjectExprType(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.TypeInfo], 
     211                             walk(getExtended).asInstanceOf[List[com.sun.fortress.nodes.BaseType]]) 
    205212         case STraitType(getInfo, getName, getArgs, getStaticParams) => 
    206213             STraitType(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.TypeInfo], walk(getName).asInstanceOf[com.sun.fortress.nodes.Id], walk(getArgs).asInstanceOf[List[com.sun.fortress.nodes.StaticArg]], walk(getStaticParams).asInstanceOf[List[com.sun.fortress.nodes.StaticParam]]) 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/CoercionOracle.scala

    r4296 r4311  
    8888 
    8989  /** The set of all arrow types for coercions from types T to U. */ 
    90   def getCoercionsTo(u: Type): Set[LiftedCoercion] = { 
     90  def getCoercionsTo(uu: Type): Set[LiftedCoercion] = { 
     91    val u = 
     92      if (uu.isInstanceOf[TraitSelfType] && 
     93          uu.asInstanceOf[TraitSelfType].getNamed.isInstanceOf[TraitType]) 
     94        uu.asInstanceOf[TraitSelfType].getNamed.asInstanceOf[TraitType] 
     95      else uu 
     96 
    9197    if (!u.isInstanceOf[TraitType]) return Set() 
    9298 
     
    144150                            : Option[Option[CoercionInvocation]] = (t, u) match { 
    145151    case (_, u:TraitType) => checkCoercionTrait(t, u, expr) 
     152    case (_, u:TraitSelfType) => checkCoercion(t, u.getNamed, expr) 
    146153    case (t:TupleType, u:TupleType) => checkCoercionTuple(t, u, expr) 
    147154    case (t:ArrowType, u:ArrowType) => checkCoercionArrow(t, u, expr) 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/ExclusionOracle.scala

    r4292 r4311  
    147147      case (_:TupleType ,_) => true 
    148148      case (_, _:TupleType) => true 
     149      case (f:TraitSelfType, s:TraitSelfType) => excludes(f.getNamed, s.getNamed) 
     150      case (f:ObjectExprType, s:ObjectExprType) => true 
    149151      case (f:TraitType, s:TraitType) => 
    150152        ( toOption(typeAnalyzer.traits.typeCons(f.getName)), 
     
    224226        } 
    225227      case STraitType(i,n,a,p) => STraitType(i, n, a.map(saSubst), p.map(spSubst)) 
     228      case STraitSelfType(i,n,ts) => 
     229        STraitSelfType(i, tySubst(n).asInstanceOf[BaseType], 
     230                       ts.map(tySubst).asInstanceOf[List[NamedType]]) 
     231      case SObjectExprType(i,ts) => 
     232        SObjectExprType(i, ts.map(tySubst).asInstanceOf[List[TraitType]]) 
    226233      case STupleType(i,e,v,k) => STupleType(i, e.map(tySubst), v, k) 
    227234      case SArrowType(i,d,r,e,b,m) => SArrowType(i, tySubst(d), tySubst(r), e, b, m.map(miSubst)) 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/ExportChecker.scala

    r4280 r4311  
    433433      case (SVarType(_, nameL, _), SVarType(_, nameR, _)) => 
    434434        equalIds(nameL, nameR) 
     435      case (STraitSelfType(_, namedL, tysL), 
     436            STraitSelfType(_, namedR, tysR)) => 
     437        equalTypes(namedL, namedR) && 
     438        equalListTypes(tysL, tysR) 
     439      case (SObjectExprType(_, tysL), SObjectExprType(_, tysR)) => 
     440        equalListTypes(tysL, tysR) 
    435441      case (STraitType(_, nameL, argsL, paramsL), 
    436442            STraitType(_, nameR, argsR, paramsR)) => 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/IndexBuilder.scala

    r4275 r4311  
    236236                                excludes: List[BaseType], 
    237237                                comprises: Option[List[NamedType]], 
    238                                 self: Option[Type]) = { 
     238                                self: Option[SelfType]) = { 
    239239    val dIndex = typeConses.get(dName).asInstanceOf[ProperTraitIndex] 
    240240    if ( comprises.isDefined ) { 
     
    252252        // add d to t's excludes clause 
    253253        typ = toOption(self) match { 
    254           case Some(ty) if (ty.isInstanceOf[TraitType]) => 
    255             ty.asInstanceOf[TraitType] 
    256           case Some(ty) if (ty.isInstanceOf[IntersectionType]) => 
    257             ty.asInstanceOf[IntersectionType].getElements.get(0).asInstanceOf[TraitType] 
     254          case Some(ty) if (ty.isInstanceOf[TraitSelfType] && 
     255                            ty.asInstanceOf[TraitSelfType].getNamed.isInstanceOf[TraitType]) => 
     256            ty.asInstanceOf[TraitSelfType].getNamed.asInstanceOf[TraitType] 
    258257          case _ => 
    259258            NF.makeTraitType(dName.asInstanceOf[Id], 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/STypeChecker.scala

    r4291 r4311  
    355355  protected def assertTrait(t: BaseType, 
    356356                            msg: String, 
    357                             error_loc: Node) = t match { 
     357                            error_loc: Node): Unit = t match { 
     358    case tt:TraitSelfType => assertTrait(tt.getNamed, msg, error_loc) 
    358359    case tt:TraitType => toOption(traits.typeCons(tt.getName)) match { 
    359360      case Some(ti) if ti.isInstanceOf[ProperTraitIndex] => 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/TypeHierarchyChecker.scala

    r4279 r4311  
    118118          c.parameters.get(0).getIdType.unwrap match { 
    119119            case STraitType(_,name,_,_) => kids = name::kids 
     120            case STraitSelfType(_,STraitType(_,name,_,_),_) => kids = name::kids 
    120121            case _ => 
    121122          } 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/TypeWellFormedChecker.scala

    r4275 r4311  
    9898        if ( ! analyzer.env.contains(name) ) 
    9999          error("Unbound type: " + name, t) 
     100      case t@STraitSelfType(_, named, tys) => walk(named); tys.foreach(walk) 
     101      case t@SObjectExprType(_, tys) => tys.foreach(walk) 
    100102      case t@STraitType(_, name, sargs, _) => 
    101103        getTypes(name) match { 
     
    123125      // Keyword parameters are not yet supported... 
    124126      case STupleType(_, elements, varargs, keywords) => 
    125         elements.foreach((t:Type) => walk(t)) 
     127        elements.foreach(walk) 
    126128        varargs match { 
    127129          case Some(ty) => walk(ty) 
     
    130132      // Effects are not yet supported... 
    131133      case SArrowType(_, domain, range, effect, io, _) => walk(domain); walk(range) 
    132       case SIntersectionType(_, elements) => elements.foreach((t:Type) => walk(t)) 
    133       case SUnionType(_, elements) => elements.foreach((t:Type) => walk(t)) 
     134      case SIntersectionType(_, elements) => elements.foreach(walk) 
     135      case SUnionType(_, elements) => elements.foreach(walk) 
    134136      case _:LabelType => // OK 
    135137      case _:DimBase => // OK 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/impls/Common.scala

    r4309 r4311  
    145145   */ 
    146146  protected def traitTypesCallable(typ: Type): Set[TraitType] = typ match { 
     147    case t:TraitSelfType => traitTypesCallable(t.getNamed) 
     148 
    147149    case t:TraitType => Set(t) 
    148150 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/types/CoveringAnalyzer.scala

    r4285 r4311  
    4444      ta.meet(ts) 
    4545    case SUnionType(_, e) => ta.join(e.map(minimize)) 
     46    case t:TraitSelfType => minimize(t.getNamed) 
     47    case t:ObjectExprType => t 
    4648    case t:TraitType => ta.join(comprisesLeaves(t)) 
    4749    //ToDo: Handle keywords 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/types/TypeAnalyzer.scala

    r4285 r4311  
    2525import com.sun.fortress.nodes._ 
    2626import com.sun.fortress.nodes_util.NodeFactory.typeSpan 
     27import com.sun.fortress.nodes_util.{NodeFactory => NF} 
    2728import com.sun.fortress.scala_src.nodes._ 
    2829import com.sun.fortress.scala_src.typechecker.ConstraintFormula 
     
    5455  def join(x: Iterable[Type]): Type = normalize(makeUnionType(x)) 
    5556 
    56   def subtype(x: Type, y: Type): ConstraintFormula = sub(normalize(x), normalize(y)) 
    57  
    58   private def sub(x: Type, y: Type): ConstraintFormula = (x,y) match { 
     57  private def removeSelf(x: Type) = { 
     58    object remover extends Walker { 
     59      override def walk(y: Any): Any = y match { 
     60        case t:TraitSelfType => 
     61          if (t.getComprised.isEmpty) t.getNamed 
     62          else NF.makeIntersectionType(t.getNamed, 
     63                                       NF.makeMaybeUnionType(t.getComprised)) 
     64        case t:ObjectExprType => NF.makeIntersectionType(t.getExtended) 
     65        case _ => super.walk(y) 
     66      } 
     67    } 
     68    remover(x).asInstanceOf[Type] 
     69  } 
     70 
     71  def subtype(x: Type, y: Type): ConstraintFormula = 
     72    sub(normalize(removeSelf(x)), normalize(removeSelf(y))) 
     73 
     74  private def sub(x: Type, y: Type): ConstraintFormula = (x, y) match { 
    5975    case (s,t) if (s==t) => TRUE 
    6076    case (s: BottomType, _) => TRUE 
     
    151167 
    152168 
    153   def excludes(x: Type, y: Type) = exc(normalize(x), normalize(y)) 
    154  
    155   private def exc(x: Type, y: Type): Boolean = (x,y) match { 
     169  def excludes(x: Type, y: Type) = 
     170    exc(normalize(removeSelf(x)), normalize(removeSelf(y))) 
     171 
     172  private def exc(x: Type, y: Type): Boolean = (x, y) match { 
    156173    case (s: BottomType, _) => true 
    157174    case (_, t: BottomType) => true 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/useful/SNodeUtil.scala

    r4275 r4311  
    184184  def getTraitType(ty: Type): Option[TraitType] = ty match { 
    185185    case tt:TraitType => Some(tt) 
    186     case tt:IntersectionType => getTraitType(tt.getElements.get(0)) 
     186    case tt:TraitSelfType => getTraitType(tt.getNamed) 
    187187    case _ => None 
    188188  } 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/useful/STypesUtil.scala

    r4309 r4311  
    417417  def checkSubtype(subtype: Type, supertype: Type) 
    418418                  (implicit analyzer: TypeAnalyzer): ConstraintFormula = { 
     419 
    419420    val constraint = analyzer.subtype(subtype, supertype) 
     421 
    420422    if (!constraint.isInstanceOf[ConstraintFormula]) { 
    421423      bug("Not a ConstraintFormula.") 
     
    974976      } 
    975977  } 
     978 
     979  /** 
     980   * Given an ObjectExpr, returns the Type of the expression. 
     981   * @return 
     982   */ 
     983  def getObjectExprType(obj: ObjectExpr): SelfType = { 
     984    var extends_types = 
     985      toList(NU.getExtendsClause(obj)).map(_.getBaseType) 
     986    if (extends_types.isEmpty) extends_types = List(Types.OBJECT) 
     987    NF.makeObjectExprType(toJavaList(extends_types)) 
     988  } 
     989 
    976990} 
  • trunk/ProjectFortress/src/com/sun/fortress/syntax_abstractions/util/BaseTypeCollector.java

    r4002 r4311  
    3636 
    3737    @Override 
     38    public String forTraitSelfType(TraitSelfType that) { 
     39        return that.getNamed().accept(this); 
     40    } 
     41 
     42    @Override 
    3843    public String forTraitTypeOnly(TraitType that, 
    3944                                   String info, 
  • trunk/ProjectFortress/src/com/sun/fortress/syntax_abstractions/util/FortressTypeToJavaType.java

    r3998 r4311  
    3838 
    3939            @Override 
     40            public String forTraitSelfType(TraitSelfType that) { 
     41                return that.getNamed().accept(this); 
     42            } 
     43 
     44            @Override 
    4045            public String forTraitType(TraitType that) { 
    4146                if (that.getArgs().size() == 0) { 
  • trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java

    r4296 r4311  
    21222122 
    21232123    @Override 
     2124    public String forTraitSelfTypeOnly(TraitSelfType that, 
     2125                                       String info, 
     2126                                       String named_result, 
     2127                                       List<String> comprised_result) { 
     2128        return named_result; 
     2129    } 
     2130 
     2131    @Override 
     2132    public String forObjectExprTypeOnly(ObjectExprType that, 
     2133                                        String info, 
     2134                                        List<String> extended_result) { 
     2135        return "ObjectExprType"; 
     2136    } 
     2137 
     2138    @Override 
    21242139    public String forArrayTypeOnly(ArrayType that, String info, String type_result, String indices_result) { 
    21252140        StringBuilder s = new StringBuilder();