Changeset 1227

Show
Ignore:
Timestamp:
07/13/08 01:25:33 (2 months ago)
Author:
asterite
Message:

Now the UI and the dom understands function post modifiers, and pure and nothrow

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.core/src/descent/core/Flags.java

    r1222 r1227  
    249249     
    250250    /** 
     251     * Nothrow property flag. 
     252     * @since 2.0 
     253     */ 
     254    public static final int AccNothrow = 0x10000000; 
     255     
     256    /** 
     257     * Pure property flag. 
     258     * @since 2.0 
     259     */ 
     260    public static final int AccPure = 0x20000000; 
     261     
     262    /** 
    251263     * Invariant property flag. 
    252264     * @since 2.0 
     
    658670    public static boolean isInvariant(long flags) { 
    659671        return (flags & AccInvariant) != 0; 
     672    } 
     673     
     674    /** 
     675     * Returns whether the given integer includes the <code>nothrow</code> modifier. 
     676     * 
     677     * @param flags the flags 
     678     * @return <code>true</code> if the <code>nothrow</code> modifier is included 
     679     */ 
     680    public static boolean isNothrow(long flags) { 
     681        return (flags & AccNothrow) != 0; 
     682    } 
     683     
     684    /** 
     685     * Returns whether the given integer includes the <code>pure</code> modifier. 
     686     * 
     687     * @param flags the flags 
     688     * @return <code>true</code> if the <code>pure</code> modifier is included 
     689     */ 
     690    public static boolean isPure(long flags) { 
     691        return (flags & AccPure) != 0; 
    660692    } 
    661693     
  • trunk/descent.core/src/descent/core/dom/ASTConverter.java

    r1222 r1227  
    16541654        } 
    16551655        convertArguments(b.arguments(), ty.sourceParameters); 
     1656        convertModifiers(b.postModifiers(), ty.postModifiers); 
    16561657        fillFunction(b, a); 
    16571658        fillDeclaration(b, a); 
     
    32943295        case TOKref: b.setModifierKeyword(descent.core.dom.Modifier.ModifierKeyword.REF_KEYWORD); break; 
    32953296        case TOKenum: b.setModifierKeyword(descent.core.dom.Modifier.ModifierKeyword.ENUM_KEYWORD); break; 
     3297        case TOKpure: b.setModifierKeyword(descent.core.dom.Modifier.ModifierKeyword.PURE_KEYWORD); break; 
     3298        case TOKnothrow: b.setModifierKeyword(descent.core.dom.Modifier.ModifierKeyword.NOTHROW_KEYWORD); break; 
    32963299        default: 
    32973300            throw new IllegalStateException("Invalid modifier: " + a.tok); 
  • trunk/descent.core/src/descent/core/dom/Declaration.java

    r927 r1227  
    156156     * declaration. 
    157157     *  
    158      * @return the live list of alias declaration 
     158     * @return the live list of modifiers 
    159159     *    (element type: <code>Modifier</code>) 
    160160     */  
  • trunk/descent.core/src/descent/core/dom/FunctionDeclaration.java

    r441 r1227  
    22 
    33import java.util.ArrayList; 
     4import java.util.Iterator; 
    45import java.util.List; 
    56 
     
    1213 *    Type SimpleName [ <b>(</b> TemplateParameter { <b>,</b> TemplateParameter } <b>)</b> ] 
    1314 *       <b>(</b> [ Argument { <b>,</b> Argument } ] <b>)</b> 
     15 *       { Modifiers } 
    1416 *       [ <b>in</b> Block ] 
    1517 *       [ <b>out</b> [ <b>(</b> SimpleName <b>)</b> ] Block ] 
     
    3032    public static final ChildListPropertyDescriptor MODIFIERS_PROPERTY = 
    3133    internalModifiersPropertyFactory(FunctionDeclaration.class); //$NON-NLS-1$ 
     34     
     35    /** 
     36     * The "postModifiers" structural property of this node type. 
     37     */ 
     38    public static final ChildListPropertyDescriptor POST_MODIFIERS_PROPERTY = 
     39        new ChildListPropertyDescriptor(FunctionDeclaration.class, "postModifiers", Modifier.class, NO_CYCLE_RISK); //$NON-NLS-1$ 
    3240 
    3341    /** 
     
    148156    private ASTNode.NodeList templateParameters = 
    149157        new ASTNode.NodeList(TEMPLATE_PARAMETERS_PROPERTY); 
     158     
     159    /** 
     160     * The post modifiers 
     161     * (element type: <code>Modifier</code>). 
     162     * Defaults to an empty list. 
     163     */ 
     164    final ASTNode.NodeList postModifiers = 
     165        new ASTNode.NodeList(POST_MODIFIERS_PROPERTY); 
    150166 
    151167    /** 
     
    462478        return this.templateParameters; 
    463479    } 
     480     
     481    /** 
     482     * Returns the live ordered list of post modifiers for this 
     483     * declaration. 
     484     *  
     485     * @return the live list of post modifiers 
     486     *    (element type: <code>Modifier</code>) 
     487     */  
     488    public final List<Modifier> postModifiers() { 
     489        return this.postModifiers; 
     490    } 
     491     
     492    /** 
     493     * Returns the modifiers explicitly specified on this declaration. 
     494     *  
     495     * @return the bit-wise or of <code>Modifier</code> constants 
     496     * @see Modifier 
     497     */ 
     498    @Override 
     499    public int getModifiers() { 
     500        int computedmodifierFlags = super.getModifiers(); 
     501        for (Iterator it = postModifiers().iterator(); it.hasNext(); ) { 
     502            Object x = it.next(); 
     503            if (x instanceof Modifier) { 
     504                computedmodifierFlags |= ((Modifier) x).getModifierKeyword().toFlagValue(); 
     505            } 
     506        } 
     507        return computedmodifierFlags; 
     508    } 
    464509 
    465510    /* (omit javadoc for this method) 
     
    467512     */ 
    468513    int memSize() { 
    469         return BASE_NODE_SIZE + 12 * 4; 
     514        return BASE_NODE_SIZE + 13 * 4; 
    470515    } 
    471516 
     
    478523            + (this.preDDocs.listSize()) 
    479524            + (this.modifiers.listSize()) 
     525            + (this.postModifiers.listSize()) 
    480526            + (this.returnType == null ? 0 : getReturnType().treeSize()) 
    481527            + (this.name == null ? 0 : getName().treeSize()) 
  • trunk/descent.core/src/descent/core/dom/Modifier.java

    r1222 r1227  
    3333 *    <b>ref</b> 
    3434 *    <b>enum</b> 
     35 *    <b>pure</b> 
     36 *    <b>nothrow</b> 
    3537 * </pre> 
    3638 */ 
     
    6466        REF_KEYWORD("ref", REF), 
    6567        ENUM_KEYWORD("enum", ENUM), 
     68        PURE_KEYWORD("pure", PURE), 
     69        NOTHROW_KEYWORD("nothrow", NOTHROW), 
    6670        ; 
    6771         
     
    257261     
    258262    /** 
     263     * "pure" modifier constant (bit mask). 
     264     */ 
     265    public static final int PURE = Flags.AccPure; 
     266     
     267    /** 
     268     * "nothrow" modifier constant (bit mask). 
     269     */ 
     270    public static final int NOTHROW = Flags.AccNothrow; 
     271     
     272    /** 
    259273     * The "modifierKeyword" structural property of this node type. 
    260274     */ 
  • trunk/descent.core/src/descent/internal/compiler/SourceElementParser.java

    r1199 r1227  
    519519            info.returnType = getSignature(ty.next); 
    520520            info.signature = getSignature(ty); 
     521            if (ty.postModifiers != null) { 
     522                for(Modifier modifier : ty.postModifiers) { 
     523                    info.modifiers |= modifier.getFlags(); 
     524                } 
     525            } 
    521526        } 
    522527        if (templateDeclaration != null) { 
  • trunk/descent.core/src/descent/internal/compiler/parser/FuncDeclaration.java

    r1223 r1227  
    5252import org.eclipse.core.runtime.Assert; 
    5353 
     54import descent.core.Flags; 
    5455import descent.core.IMethod; 
    5556import descent.core.JavaModelException; 
     
    25632564        return javaElement; 
    25642565    } 
     2566     
     2567    @Override 
     2568    public long getFlags() { 
     2569        long flags = super.getFlags(); 
     2570        TypeFunction ty = (TypeFunction) type; 
     2571        if (ty.isnothrow) { 
     2572            flags |= Flags.AccNothrow; 
     2573        } 
     2574        if (ty.ispure) { 
     2575            flags |= Flags.AccPure; 
     2576        } 
     2577        return flags; 
     2578    } 
    25652579 
    25662580} 
  • trunk/descent.core/src/descent/internal/compiler/parser/Modifier.java

    r1160 r1227  
    1111 
    1212    public Modifier(Token token, int lineNumber) { 
    13         this.tok = token.value; 
    14         this.start = token.ptr; 
    15         this.length = token.sourceLen; 
     13        this(token.value, token.ptr, token.sourceLen, lineNumber); 
     14    } 
     15     
     16    public Modifier(TOK tok, int start, int length, int lineNumber) { 
     17        this.tok = tok; 
     18        this.start = start; 
     19        this.length = length; 
    1620        this.lineNumber = lineNumber; 
    1721    } 
     
    6569        case TOKscope: return Flags.AccScope; 
    6670        case TOKinvariant: return  Flags.AccInvariant; 
     71        case TOKenum: return Flags.AccEnum; 
     72        case TOKnothrow: return Flags.AccNothrow; 
     73        case TOKpure: return Flags.AccPure; 
    6774        case TOKin: return 0; 
    6875        case TOKout: return 0; 
  • trunk/descent.core/src/descent/internal/compiler/parser/Parser.java

    r1226 r1227  
    10661066    } 
    10671067     
    1068     private Dsymbols parseBlock(boolean thinksItsD2) { 
    1069         return parseBlock(null, thinksItsD2); 
    1070     } 
    1071      
    10721068    private Dsymbols parseBlock(boolean[] isSingle) { 
    10731069        return parseBlock(isSingle, false); 
     
    32163212                            continue; 
    32173213 
    3218                         case TOKnothrow: 
    3219                             ((TypeFunction) ta).isnothrow = true; 
     3214                        case TOKnothrow: { 
     3215                            TypeFunction tf = (TypeFunction) ta; 
     3216                            tf.isnothrow = true; 
     3217                            if (tf.postModifiers == null) { 
     3218                                tf.postModifiers = new ArrayList<Modifier>(); 
     3219                            } 
     3220                            tf.postModifiers.add(new Modifier(token, linnum)); 
    32203221                            nextToken(); 
    32213222                            continue; 
    3222  
    3223                         case TOKpure: 
    3224                             ((TypeFunction) ta).ispure = true; 
     3223                        } 
     3224 
     3225                        case TOKpure: { 
     3226                            TypeFunction tf = (TypeFunction) ta; 
     3227                            tf.ispure = true; 
     3228                            if (tf.postModifiers == null) { 
     3229                                tf.postModifiers = new ArrayList<Modifier>(); 
     3230                            } 
     3231                            tf.postModifiers.add(new Modifier(token, linnum)); 
    32253232                            nextToken(); 
    32263233                            continue; 
     3234                        } 
    32273235                        } 
    32283236                        break; 
  • trunk/descent.core/src/descent/internal/compiler/parser/TypeFunction.java

    r1201 r1227  
    11package descent.internal.compiler.parser; 
     2 
     3import java.util.ArrayList; 
     4import java.util.List; 
    25 
    36import melnorme.miscutil.Assert; 
     
    3033    public boolean ispure; 
    3134    public boolean isnothrow; 
     35     
     36    public List<Modifier> postModifiers; 
    3237 
    3338    public TypeFunction(Arguments parameters, Type treturn, int varargs, 
     
    653658        } 
    654659    } 
     660     
     661    @Override 
     662    public Type makeConst(int startPosition, int length) { 
     663        TypeFunction tf = (TypeFunction) super.makeConst(startPosition, length); 
     664        if (tf.postModifiers == null) { 
     665            tf.postModifiers = new ArrayList<Modifier>(); 
     666        } 
     667        tf.postModifiers.add(new Modifier(TOK.TOKconst, startPosition, length, 0)); 
     668        return tf; 
     669    } 
     670     
     671    @Override 
     672    public Type makeInvariant(int startPosition, int length) { 
     673        TypeFunction tf = (TypeFunction) super.makeInvariant(startPosition, length); 
     674        if (tf.postModifiers == null) { 
     675            tf.postModifiers = new ArrayList<Modifier>(); 
     676        } 
     677        tf.postModifiers.add(new Modifier(TOK.TOKinvariant, startPosition, length, 0)); 
     678        return tf; 
     679    } 
    655680 
    656681    @SuppressWarnings("serial") 
  • trunk/descent.tests/descent/tests/mars/Function_Test.java

    r606 r1227  
    1111import descent.core.dom.FunctionDeclaration; 
    1212import descent.core.dom.ModifiedType; 
     13import descent.core.dom.Modifier; 
    1314import descent.core.dom.NumberLiteral; 
    1415import descent.core.dom.UnitTestDeclaration; 
     
    333334        assertEquals("scope", argument.modifiers().get(1).toString()); 
    334335    } 
     336     
     337    public void testConstFunction() { 
     338        String s = " const void func() { }"; 
     339        FunctionDeclaration f = (FunctionDeclaration) getSingleDeclarationNoProblems(s, AST.D2); 
     340        assertEquals(1, f.modifiers().size()); 
     341        assertEquals("const", f.modifiers().get(0).toString()); 
     342    } 
     343     
     344    public void testInvariantFunction() { 
     345        String s = " invariant void func() { }"; 
     346        FunctionDeclaration f = (FunctionDeclaration) getSingleDeclarationNoProblems(s, AST.D2); 
     347        assertEquals(1, f.modifiers().size()); 
     348        assertEquals("invariant", f.modifiers().get(0).toString()); 
     349    } 
     350     
     351    public void testPureFunction() { 
     352        String s = " pure void func() { }"; 
     353        FunctionDeclaration f = (FunctionDeclaration) getSingleDeclarationNoProblems(s, AST.D2); 
     354        assertEquals(1, f.modifiers().size()); 
     355        assertEquals("pure", f.modifiers().get(0).toString()); 
     356    } 
     357     
     358    public void testNothrowFunction() { 
     359        String s = " nothrow void func() { }"; 
     360        FunctionDeclaration f = (FunctionDeclaration) getSingleDeclarationNoProblems(s, AST.D2); 
     361        assertEquals(1, f.modifiers().size()); 
     362        assertEquals("nothrow", f.modifiers().get(0).toString()); 
     363    } 
     364     
     365    public void testPostConstFunction() { 
     366        String s = " void func() const { }"; 
     367        FunctionDeclaration f = (FunctionDeclaration) getSingleDeclarationNoProblems(s, AST.D2); 
     368        assertEquals(0, f.modifiers().size()); 
     369        assertEquals(1, f.postModifiers().size()); 
     370         
     371        Modifier modifier = f.postModifiers().get(0); 
     372        assertPosition(modifier, 13, 5); 
     373        assertEquals("const", modifier.toString()); 
     374    } 
     375     
     376    public void testPostInvariantFunction() { 
     377        String s = " void func() invariant { }"; 
     378        FunctionDeclaration f = (FunctionDeclaration) getSingleDeclarationNoProblems(s, AST.D2); 
     379        assertEquals(0, f.modifiers().size()); 
     380        assertEquals(1, f.postModifiers().size()); 
     381         
     382        Modifier modifier = f.postModifiers().get(0); 
     383        assertPosition(modifier, 13, 9); 
     384        assertEquals("invariant", modifier.toString()); 
     385    } 
     386     
     387    public void testPostNothrowFunction() { 
     388        String s = " void func() nothrow { }"; 
     389        FunctionDeclaration f = (FunctionDeclaration) getSingleDeclarationNoProblems(s, AST.D2); 
     390        assertEquals(0, f.modifiers().size()); 
     391        assertEquals(1, f.postModifiers().size()); 
     392         
     393        Modifier modifier = f.postModifiers().get(0); 
     394        assertPosition(modifier, 13, 7); 
     395        assertEquals("nothrow", modifier.toString()); 
     396    } 
     397     
     398    public void testPostPureFunction() { 
     399        String s = " void func() pure { }"; 
     400        FunctionDeclaration f = (FunctionDeclaration) getSingleDeclarationNoProblems(s, AST.D2); 
     401        assertEquals(0, f.modifiers().size()); 
     402        assertEquals(1, f.postModifiers().size()); 
     403         
     404        Modifier modifier = f.postModifiers().get(0); 
     405        assertPosition(modifier, 13, 4); 
     406        assertEquals("pure", modifier.toString()); 
     407    } 
    335408 
    336409} 
  • trunk/descent.ui/src/descent/internal/ui/JavaPluginImages.java

    r1226 r1227  
    449449    public static final ImageDescriptor DESC_OVR_CONST= createUnManagedCached(T_OVR, "const_co.gif");                   //$NON-NLS-1$ 
    450450    public static final ImageDescriptor DESC_OVR_INVARIANT= createUnManagedCached(T_OVR, "invariant_co.gif");                   //$NON-NLS-1$ 
     451    public static final ImageDescriptor DESC_OVR_PURE= createUnManagedCached(T_OVR, "pure_co.gif");                     //$NON-NLS-1$ 
     452    public static final ImageDescriptor DESC_OVR_NOTHROW= createUnManagedCached(T_OVR, "nothrow_co.gif");                   //$NON-NLS-1$ 
    451453    public static final ImageDescriptor DESC_OVR_SYNCH= createUnManagedCached(T_OVR, "synch_co.gif");                       //$NON-NLS-1$ 
    452454    public static final ImageDescriptor DESC_OVR_RUN= createUnManagedCached(T_OVR, "run_co.gif");                           //$NON-NLS-1$ 
  • trunk/descent.ui/src/descent/internal/ui/viewsupport/JavaElementImageProvider.java

    r1226 r1227  
    380380                } 
    381381                 
     382                if (Flags.isNothrow(modifiers)) { 
     383                    flags |= JavaElementImageDescriptor.NOTHROW; 
     384                } 
     385                 
     386                if (Flags.isPure(modifiers)) { 
     387                    flags |= JavaElementImageDescriptor.PURE; 
     388                } 
     389                 
    382390                if (Flags.isDeprecated(modifiers)) 
    383391                    flags |= JavaElementImageDescriptor.DEPRECATED; 
  • trunk/descent.ui/src/descent/ui/JavaElementImageDescriptor.java

    r1226 r1227  
    7676    /** Flag to render the invariant adornment. */ 
    7777    public final static int INVARIANT=          0x1000; 
     78     
     79    /** Flag to render the nothrow adornment. */ 
     80    public final static int NOTHROW=            0x2000; 
     81     
     82    /** Flag to render the pure adornment. */ 
     83    public final static int PURE=           0x4000; 
    7884 
    7985    private ImageDescriptor fBaseImage; 
     
    229235            x-= data.width; 
    230236            drawImage(data, x, 0); 
    231         }  
     237        } 
     238        if ((fFlags & NOTHROW) != 0) { 
     239            ImageData data= getImageData(JavaPluginImages.DESC_OVR_NOTHROW); 
     240            x-= data.width; 
     241            drawImage(data, x, 0); 
     242        } 
     243        if ((fFlags & PURE) != 0) { 
     244            ImageData data= getImageData(JavaPluginImages.DESC_OVR_PURE); 
     245            x-= data.width; 
     246            drawImage(data, x, 0); 
     247        } 
    232248    }        
    233249     
  • trunk/descent.ui/src/descent/ui/text/java/CompletionProposalLabelProvider.java

    r1226 r1227  
    841841                adornments |= JavaElementImageDescriptor.CONST; 
    842842            } 
     843            if (Flags.isNothrow(flags)) { 
     844                adornments |= JavaElementImageDescriptor.NOTHROW; 
     845            } 
     846            if (Flags.isPure(flags)) { 
     847                adornments |= JavaElementImageDescriptor.PURE; 
     848            } 
    843849        } 
    844850