Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: compiler/java/com/google/dart/compiler/parser/DartParser.java

Issue 8506019: Convert top level factory into method, issue 345 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/CompilerTestCase.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 package com.google.dart.compiler.parser; 5 package com.google.dart.compiler.parser;
6 6
7 import com.google.common.annotations.VisibleForTesting; 7 import com.google.common.annotations.VisibleForTesting;
8 import com.google.common.io.CharStreams; 8 import com.google.common.io.CharStreams;
9 import com.google.dart.compiler.DartCompilationError; 9 import com.google.dart.compiler.DartCompilationError;
10 import com.google.dart.compiler.DartCompilerListener; 10 import com.google.dart.compiler.DartCompilerListener;
(...skipping 27 matching lines...) Expand all
38 import com.google.dart.compiler.ast.DartForStatement; 38 import com.google.dart.compiler.ast.DartForStatement;
39 import com.google.dart.compiler.ast.DartFunction; 39 import com.google.dart.compiler.ast.DartFunction;
40 import com.google.dart.compiler.ast.DartFunctionExpression; 40 import com.google.dart.compiler.ast.DartFunctionExpression;
41 import com.google.dart.compiler.ast.DartFunctionObjectInvocation; 41 import com.google.dart.compiler.ast.DartFunctionObjectInvocation;
42 import com.google.dart.compiler.ast.DartFunctionTypeAlias; 42 import com.google.dart.compiler.ast.DartFunctionTypeAlias;
43 import com.google.dart.compiler.ast.DartIdentifier; 43 import com.google.dart.compiler.ast.DartIdentifier;
44 import com.google.dart.compiler.ast.DartIfStatement; 44 import com.google.dart.compiler.ast.DartIfStatement;
45 import com.google.dart.compiler.ast.DartImportDirective; 45 import com.google.dart.compiler.ast.DartImportDirective;
46 import com.google.dart.compiler.ast.DartInitializer; 46 import com.google.dart.compiler.ast.DartInitializer;
47 import com.google.dart.compiler.ast.DartIntegerLiteral; 47 import com.google.dart.compiler.ast.DartIntegerLiteral;
48 import com.google.dart.compiler.ast.DartInvocation;
49 import com.google.dart.compiler.ast.DartLabel; 48 import com.google.dart.compiler.ast.DartLabel;
50 import com.google.dart.compiler.ast.DartLibraryDirective; 49 import com.google.dart.compiler.ast.DartLibraryDirective;
51 import com.google.dart.compiler.ast.DartMapLiteral; 50 import com.google.dart.compiler.ast.DartMapLiteral;
52 import com.google.dart.compiler.ast.DartMapLiteralEntry; 51 import com.google.dart.compiler.ast.DartMapLiteralEntry;
53 import com.google.dart.compiler.ast.DartMethodDefinition; 52 import com.google.dart.compiler.ast.DartMethodDefinition;
54 import com.google.dart.compiler.ast.DartMethodInvocation; 53 import com.google.dart.compiler.ast.DartMethodInvocation;
55 import com.google.dart.compiler.ast.DartNamedExpression; 54 import com.google.dart.compiler.ast.DartNamedExpression;
56 import com.google.dart.compiler.ast.DartNativeBlock; 55 import com.google.dart.compiler.ast.DartNativeBlock;
57 import com.google.dart.compiler.ast.DartNativeDirective; 56 import com.google.dart.compiler.ast.DartNativeDirective;
58 import com.google.dart.compiler.ast.DartNewExpression; 57 import com.google.dart.compiler.ast.DartNewExpression;
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 767
769 if (match(Token.VAR) || match(Token.FINAL)) { 768 if (match(Token.VAR) || match(Token.FINAL)) {
770 if (modifiers.isAbstract()) { 769 if (modifiers.isAbstract()) {
771 reportError(position(), ParserErrorCode.DISALLOWED_ABSTRACT_KEYWORD); 770 reportError(position(), ParserErrorCode.DISALLOWED_ABSTRACT_KEYWORD);
772 } else if (modifiers.isFactory()) { 771 } else if (modifiers.isFactory()) {
773 reportError(position(), ParserErrorCode.DISALLOWED_FACTORY_KEYWORD); 772 reportError(position(), ParserErrorCode.DISALLOWED_FACTORY_KEYWORD);
774 } 773 }
775 } 774 }
776 775
777 if (modifiers.isFactory()) { 776 if (modifiers.isFactory()) {
778 return done(parseFactory(modifiers)); 777 // Factory is not allowed on top level.
778 if (!allowStatic) {
779 reportError(position(), ParserErrorCode.DISALLOWED_FACTORY_KEYWORD);
780 modifiers = modifiers.removeFactory();
781 }
782 // Do parse factory.
783 DartMethodDefinition factoryNode = parseFactory(modifiers);
784 // If factory is not allowed, ensure that it is valid as method.
785 DartExpression actualName = factoryNode.getName();
786 if (!allowStatic && !(actualName instanceof DartIdentifier)) {
787 DartExpression replacementName = new DartIdentifier(actualName.toString( ));
788 factoryNode.setName(replacementName);
789 }
790 // Done.
791 return done(factoryNode);
779 } 792 }
780 793
781 final DartNode member; 794 final DartNode member;
782 795
783 switch (peek(0)) { 796 switch (peek(0)) {
784 case VAR: { 797 case VAR: {
785 consume(Token.VAR); 798 consume(Token.VAR);
786 member = parseFieldDeclaration(modifiers, null); 799 member = parseFieldDeclaration(modifiers, null);
787 expectStatmentTerminator(); 800 expectStatmentTerminator();
788 break; 801 break;
(...skipping 2678 matching lines...) Expand 10 before | Expand all | Expand 10 after
3467 } else { 3480 } else {
3468 ctx.error(dartError); 3481 ctx.error(dartError);
3469 errorHistory.add(dartError.hashCode()); 3482 errorHistory.add(dartError.hashCode());
3470 } 3483 }
3471 } 3484 }
3472 3485
3473 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen ts) { 3486 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen ts) {
3474 reportError(new DartCompilationError(node, errorCode, arguments)); 3487 reportError(new DartCompilationError(node, errorCode, arguments));
3475 } 3488 }
3476 } 3489 }
OLDNEW
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/CompilerTestCase.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698