Changeset 1227
- Timestamp:
- 07/13/08 01:25:33 (2 months ago)
- Files:
-
- trunk/descent.core/src/descent/core/Flags.java (modified) (2 diffs)
- trunk/descent.core/src/descent/core/dom/ASTConverter.java (modified) (2 diffs)
- trunk/descent.core/src/descent/core/dom/Declaration.java (modified) (1 diff)
- trunk/descent.core/src/descent/core/dom/FunctionDeclaration.java (modified) (7 diffs)
- trunk/descent.core/src/descent/core/dom/Modifier.java (modified) (3 diffs)
- trunk/descent.core/src/descent/internal/compiler/SourceElementParser.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/FuncDeclaration.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/Modifier.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/Parser.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/TypeFunction.java (modified) (3 diffs)
- trunk/descent.tests/descent/tests/mars/Function_Test.java (modified) (2 diffs)
- trunk/descent.ui/icons/full/ovr16/const_co.gif (modified) (previous)
- trunk/descent.ui/icons/full/ovr16/invariant_co.gif (modified) (previous)
- trunk/descent.ui/icons/full/ovr16/native_co.gif (deleted)
- trunk/descent.ui/icons/full/ovr16/nothrow_co.gif (added)
- trunk/descent.ui/icons/full/ovr16/pure_co.gif (added)
- trunk/descent.ui/src/descent/internal/ui/JavaPluginImages.java (modified) (1 diff)
- trunk/descent.ui/src/descent/internal/ui/viewsupport/JavaElementImageProvider.java (modified) (1 diff)
- trunk/descent.ui/src/descent/ui/JavaElementImageDescriptor.java (modified) (2 diffs)
- trunk/descent.ui/src/descent/ui/text/java/CompletionProposalLabelProvider.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/descent.core/src/descent/core/Flags.java
r1222 r1227 249 249 250 250 /** 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 /** 251 263 * Invariant property flag. 252 264 * @since 2.0 … … 658 670 public static boolean isInvariant(long flags) { 659 671 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; 660 692 } 661 693 trunk/descent.core/src/descent/core/dom/ASTConverter.java
r1222 r1227 1654 1654 } 1655 1655 convertArguments(b.arguments(), ty.sourceParameters); 1656 convertModifiers(b.postModifiers(), ty.postModifiers); 1656 1657 fillFunction(b, a); 1657 1658 fillDeclaration(b, a); … … 3294 3295 case TOKref: b.setModifierKeyword(descent.core.dom.Modifier.ModifierKeyword.REF_KEYWORD); break; 3295 3296 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; 3296 3299 default: 3297 3300 throw new IllegalStateException("Invalid modifier: " + a.tok); trunk/descent.core/src/descent/core/dom/Declaration.java
r927 r1227 156 156 * declaration. 157 157 * 158 * @return the live list of alias declaration158 * @return the live list of modifiers 159 159 * (element type: <code>Modifier</code>) 160 160 */ trunk/descent.core/src/descent/core/dom/FunctionDeclaration.java
r441 r1227 2 2 3 3 import java.util.ArrayList; 4 import java.util.Iterator; 4 5 import java.util.List; 5 6 … … 12 13 * Type SimpleName [ <b>(</b> TemplateParameter { <b>,</b> TemplateParameter } <b>)</b> ] 13 14 * <b>(</b> [ Argument { <b>,</b> Argument } ] <b>)</b> 15 * { Modifiers } 14 16 * [ <b>in</b> Block ] 15 17 * [ <b>out</b> [ <b>(</b> SimpleName <b>)</b> ] Block ] … … 30 32 public static final ChildListPropertyDescriptor MODIFIERS_PROPERTY = 31 33 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$ 32 40 33 41 /** … … 148 156 private ASTNode.NodeList templateParameters = 149 157 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); 150 166 151 167 /** … … 462 478 return this.templateParameters; 463 479 } 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 } 464 509 465 510 /* (omit javadoc for this method) … … 467 512 */ 468 513 int memSize() { 469 return BASE_NODE_SIZE + 1 2* 4;514 return BASE_NODE_SIZE + 13 * 4; 470 515 } 471 516 … … 478 523 + (this.preDDocs.listSize()) 479 524 + (this.modifiers.listSize()) 525 + (this.postModifiers.listSize()) 480 526 + (this.returnType == null ? 0 : getReturnType().treeSize()) 481 527 + (this.name == null ? 0 : getName().treeSize()) trunk/descent.core/src/descent/core/dom/Modifier.java
r1222 r1227 33 33 * <b>ref</b> 34 34 * <b>enum</b> 35 * <b>pure</b> 36 * <b>nothrow</b> 35 37 * </pre> 36 38 */ … … 64 66 REF_KEYWORD("ref", REF), 65 67 ENUM_KEYWORD("enum", ENUM), 68 PURE_KEYWORD("pure", PURE), 69 NOTHROW_KEYWORD("nothrow", NOTHROW), 66 70 ; 67 71 … … 257 261 258 262 /** 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 /** 259 273 * The "modifierKeyword" structural property of this node type. 260 274 */ trunk/descent.core/src/descent/internal/compiler/SourceElementParser.java
r1199 r1227 519 519 info.returnType = getSignature(ty.next); 520 520 info.signature = getSignature(ty); 521 if (ty.postModifiers != null) { 522 for(Modifier modifier : ty.postModifiers) { 523 info.modifiers |= modifier.getFlags(); 524 } 525 } 521 526 } 522 527 if (templateDeclaration != null) { trunk/descent.core/src/descent/internal/compiler/parser/FuncDeclaration.java
r1223 r1227 52 52 import org.eclipse.core.runtime.Assert; 53 53 54 import descent.core.Flags; 54 55 import descent.core.IMethod; 55 56 import descent.core.JavaModelException; … … 2563 2564 return javaElement; 2564 2565 } 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 } 2565 2579 2566 2580 } trunk/descent.core/src/descent/internal/compiler/parser/Modifier.java
r1160 r1227 11 11 12 12 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; 16 20 this.lineNumber = lineNumber; 17 21 } … … 65 69 case TOKscope: return Flags.AccScope; 66 70 case TOKinvariant: return Flags.AccInvariant; 71 case TOKenum: return Flags.AccEnum; 72 case TOKnothrow: return Flags.AccNothrow; 73 case TOKpure: return Flags.AccPure; 67 74 case TOKin: return 0; 68 75 case TOKout: return 0; trunk/descent.core/src/descent/internal/compiler/parser/Parser.java
r1226 r1227 1066 1066 } 1067 1067 1068 private Dsymbols parseBlock(boolean thinksItsD2) {1069 return parseBlock(null, thinksItsD2);1070 }1071 1072 1068 private Dsymbols parseBlock(boolean[] isSingle) { 1073 1069 return parseBlock(isSingle, false); … … 3216 3212 continue; 3217 3213 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)); 3220 3221 nextToken(); 3221 3222 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)); 3225 3232 nextToken(); 3226 3233 continue; 3234 } 3227 3235 } 3228 3236 break; trunk/descent.core/src/descent/internal/compiler/parser/TypeFunction.java
r1201 r1227 1 1 package descent.internal.compiler.parser; 2 3 import java.util.ArrayList; 4 import java.util.List; 2 5 3 6 import melnorme.miscutil.Assert; … … 30 33 public boolean ispure; 31 34 public boolean isnothrow; 35 36 public List<Modifier> postModifiers; 32 37 33 38 public TypeFunction(Arguments parameters, Type treturn, int varargs, … … 653 658 } 654 659 } 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 } 655 680 656 681 @SuppressWarnings("serial") trunk/descent.tests/descent/tests/mars/Function_Test.java
r606 r1227 11 11 import descent.core.dom.FunctionDeclaration; 12 12 import descent.core.dom.ModifiedType; 13 import descent.core.dom.Modifier; 13 14 import descent.core.dom.NumberLiteral; 14 15 import descent.core.dom.UnitTestDeclaration; … … 333 334 assertEquals("scope", argument.modifiers().get(1).toString()); 334 335 } 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 } 335 408 336 409 } trunk/descent.ui/src/descent/internal/ui/JavaPluginImages.java
r1226 r1227 449 449 public static final ImageDescriptor DESC_OVR_CONST= createUnManagedCached(T_OVR, "const_co.gif"); //$NON-NLS-1$ 450 450 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$ 451 453 public static final ImageDescriptor DESC_OVR_SYNCH= createUnManagedCached(T_OVR, "synch_co.gif"); //$NON-NLS-1$ 452 454 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 380 380 } 381 381 382 if (Flags.isNothrow(modifiers)) { 383 flags |= JavaElementImageDescriptor.NOTHROW; 384 } 385 386 if (Flags.isPure(modifiers)) { 387 flags |= JavaElementImageDescriptor.PURE; 388 } 389 382 390 if (Flags.isDeprecated(modifiers)) 383 391 flags |= JavaElementImageDescriptor.DEPRECATED; trunk/descent.ui/src/descent/ui/JavaElementImageDescriptor.java
r1226 r1227 76 76 /** Flag to render the invariant adornment. */ 77 77 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; 78 84 79 85 private ImageDescriptor fBaseImage; … … 229 235 x-= data.width; 230 236 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 } 232 248 } 233 249 trunk/descent.ui/src/descent/ui/text/java/CompletionProposalLabelProvider.java
r1226 r1227 841 841 adornments |= JavaElementImageDescriptor.CONST; 842 842 } 843 if (Flags.isNothrow(flags)) { 844 adornments |= JavaElementImageDescriptor.NOTHROW; 845 } 846 if (Flags.isPure(flags)) { 847 adornments |= JavaElementImageDescriptor.PURE; 848 } 843 849 } 844 850
