Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
| (...skipping 2852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2863 } | 2863 } |
| 2864 | 2864 |
| 2865 | 2865 |
| 2866 // Consumes exactly one right angle bracket. If the current token is a single | 2866 // Consumes exactly one right angle bracket. If the current token is a single |
| 2867 // bracket token, it is consumed normally. However, if it is a double or triple | 2867 // bracket token, it is consumed normally. However, if it is a double or triple |
| 2868 // bracket, it is replaced by a single or double bracket token without | 2868 // bracket, it is replaced by a single or double bracket token without |
| 2869 // incrementing the token index. | 2869 // incrementing the token index. |
| 2870 void Parser::ConsumeRightAngleBracket() { | 2870 void Parser::ConsumeRightAngleBracket() { |
| 2871 if (token_kind_ == Token::kGT) { | 2871 if (token_kind_ == Token::kGT) { |
| 2872 ConsumeToken(); | 2872 ConsumeToken(); |
| 2873 } else if (token_kind_ == Token::kSAR) { | 2873 } else if (token_kind_ == Token::kSHR) { |
| 2874 token_kind_ = Token::kGT; | 2874 token_kind_ = Token::kGT; |
| 2875 } else if (token_kind_ == Token::kSHR) { | |
| 2876 token_kind_ = Token::kSAR; | |
| 2877 } else { | 2875 } else { |
| 2878 UNREACHABLE(); | 2876 UNREACHABLE(); |
| 2879 } | 2877 } |
| 2880 } | 2878 } |
| 2881 | 2879 |
| 2882 | 2880 |
| 2883 void Parser::SkipTypeArguments() { | 2881 void Parser::SkipTypeArguments() { |
| 2884 if (CurrentToken() == Token::kLT) { | 2882 if (CurrentToken() == Token::kLT) { |
| 2885 do { | 2883 do { |
| 2886 ConsumeToken(); | 2884 ConsumeToken(); |
| 2887 SkipType(false); | 2885 SkipType(false); |
| 2888 } while (CurrentToken() == Token::kCOMMA); | 2886 } while (CurrentToken() == Token::kCOMMA); |
| 2889 Token::Kind token = CurrentToken(); | 2887 Token::Kind token = CurrentToken(); |
| 2890 if ((token == Token::kGT) || | 2888 if ((token == Token::kGT) || |
| 2891 (token == Token::kSAR) || | |
| 2892 (token == Token::kSHR)) { | 2889 (token == Token::kSHR)) { |
| 2893 ConsumeRightAngleBracket(); | 2890 ConsumeRightAngleBracket(); |
| 2894 } else { | 2891 } else { |
| 2895 ErrorMsg("right angle bracket expected"); | 2892 ErrorMsg("right angle bracket expected"); |
| 2896 } | 2893 } |
| 2897 } | 2894 } |
| 2898 } | 2895 } |
| 2899 | 2896 |
| 2900 | 2897 |
| 2901 void Parser::SkipType(bool allow_void) { | 2898 void Parser::SkipType(bool allow_void) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 2930 AbstractType& type_extends = Type::ZoneHandle(Type::DynamicType()); | 2927 AbstractType& type_extends = Type::ZoneHandle(Type::DynamicType()); |
| 2931 if (CurrentToken() == Token::kEXTENDS) { | 2928 if (CurrentToken() == Token::kEXTENDS) { |
| 2932 ConsumeToken(); | 2929 ConsumeToken(); |
| 2933 type_extends = ParseType(kCanResolve); | 2930 type_extends = ParseType(kCanResolve); |
| 2934 } | 2931 } |
| 2935 type_parameters.Add(&type_parameter_name); | 2932 type_parameters.Add(&type_parameter_name); |
| 2936 type_parameter_extends.Add(&type_extends); | 2933 type_parameter_extends.Add(&type_extends); |
| 2937 } while (CurrentToken() == Token::kCOMMA); | 2934 } while (CurrentToken() == Token::kCOMMA); |
| 2938 Token::Kind token = CurrentToken(); | 2935 Token::Kind token = CurrentToken(); |
| 2939 if ((token == Token::kGT) || | 2936 if ((token == Token::kGT) || |
| 2940 (token == Token::kSAR) || | |
| 2941 (token == Token::kSHR)) { | 2937 (token == Token::kSHR)) { |
|
hausner
2012/01/13 07:22:53
Probably fits on one line now. Also in other place
Ivan Posva
2012/01/13 09:04:18
Done.
| |
| 2942 ConsumeRightAngleBracket(); | 2938 ConsumeRightAngleBracket(); |
| 2943 } else { | 2939 } else { |
| 2944 ErrorMsg("right angle bracket expected"); | 2940 ErrorMsg("right angle bracket expected"); |
| 2945 } | 2941 } |
| 2946 cls.set_type_parameters(Array::Handle(NewArray<String>(type_parameters))); | 2942 cls.set_type_parameters(Array::Handle(NewArray<String>(type_parameters))); |
| 2947 const TypeArguments& extends_array = | 2943 const TypeArguments& extends_array = |
| 2948 TypeArguments::Handle(NewTypeArguments(type_parameter_extends)); | 2944 TypeArguments::Handle(NewTypeArguments(type_parameter_extends)); |
| 2949 cls.set_type_parameter_extends(extends_array); | 2945 cls.set_type_parameter_extends(extends_array); |
| 2950 // Try to resolve the upper bounds, which will at least resolve the | 2946 // Try to resolve the upper bounds, which will at least resolve the |
| 2951 // referenced type parameters. | 2947 // referenced type parameters. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2964 TypeResolution type_resolution) { | 2960 TypeResolution type_resolution) { |
| 2965 if (CurrentToken() == Token::kLT) { | 2961 if (CurrentToken() == Token::kLT) { |
| 2966 GrowableArray<AbstractType*> types; | 2962 GrowableArray<AbstractType*> types; |
| 2967 do { | 2963 do { |
| 2968 ConsumeToken(); | 2964 ConsumeToken(); |
| 2969 AbstractType& type = AbstractType::ZoneHandle(ParseType(type_resolution)); | 2965 AbstractType& type = AbstractType::ZoneHandle(ParseType(type_resolution)); |
| 2970 types.Add(&type); | 2966 types.Add(&type); |
| 2971 } while (CurrentToken() == Token::kCOMMA); | 2967 } while (CurrentToken() == Token::kCOMMA); |
| 2972 Token::Kind token = CurrentToken(); | 2968 Token::Kind token = CurrentToken(); |
| 2973 if ((token == Token::kGT) || | 2969 if ((token == Token::kGT) || |
| 2974 (token == Token::kSAR) || | |
| 2975 (token == Token::kSHR)) { | 2970 (token == Token::kSHR)) { |
| 2976 ConsumeRightAngleBracket(); | 2971 ConsumeRightAngleBracket(); |
| 2977 } else { | 2972 } else { |
| 2978 ErrorMsg("right angle bracket expected"); | 2973 ErrorMsg("right angle bracket expected"); |
| 2979 } | 2974 } |
| 2980 return NewTypeArguments(types); | 2975 return NewTypeArguments(types); |
| 2981 } | 2976 } |
| 2982 return TypeArguments::null(); | 2977 return TypeArguments::null(); |
| 2983 } | 2978 } |
| 2984 | 2979 |
| (...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3904 // parameters. Current token position is not saved and restored. | 3899 // parameters. Current token position is not saved and restored. |
| 3905 bool Parser::IsTypeParameter() { | 3900 bool Parser::IsTypeParameter() { |
| 3906 if (CurrentToken() == Token::kLT) { | 3901 if (CurrentToken() == Token::kLT) { |
| 3907 // We are possibly looking at type parameters. Find closing ">". | 3902 // We are possibly looking at type parameters. Find closing ">". |
| 3908 int nesting_level = 0; | 3903 int nesting_level = 0; |
| 3909 do { | 3904 do { |
| 3910 if (CurrentToken() == Token::kLT) { | 3905 if (CurrentToken() == Token::kLT) { |
| 3911 nesting_level++; | 3906 nesting_level++; |
| 3912 } else if (CurrentToken() == Token::kGT) { | 3907 } else if (CurrentToken() == Token::kGT) { |
| 3913 nesting_level--; | 3908 nesting_level--; |
| 3914 } else if (CurrentToken() == Token::kSAR) { | 3909 } else if (CurrentToken() == Token::kSHR) { |
| 3915 nesting_level -= 2; | 3910 nesting_level -= 2; |
| 3916 } else if (CurrentToken() == Token::kSHR) { | |
| 3917 nesting_level -= 3; | |
| 3918 } else if (CurrentToken() == Token::kIDENT) { | 3911 } else if (CurrentToken() == Token::kIDENT) { |
| 3919 // Check to see if it is a qualified identifier. | 3912 // Check to see if it is a qualified identifier. |
| 3920 if (LookaheadToken(1) == Token::kPERIOD) { | 3913 if (LookaheadToken(1) == Token::kPERIOD) { |
| 3921 // Consume the identifier, the period will be consumed below. | 3914 // Consume the identifier, the period will be consumed below. |
| 3922 ConsumeToken(); | 3915 ConsumeToken(); |
| 3923 } | 3916 } |
| 3924 } else if (CurrentToken() != Token::kCOMMA && | 3917 } else if (CurrentToken() != Token::kCOMMA && |
| 3925 CurrentToken() != Token::kEXTENDS) { | 3918 CurrentToken() != Token::kEXTENDS) { |
| 3926 // We are looking at something other than type parameters. | 3919 // We are looking at something other than type parameters. |
| 3927 return false; | 3920 return false; |
| (...skipping 1642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5570 case Token::kASSIGN_SUB: | 5563 case Token::kASSIGN_SUB: |
| 5571 return new BinaryOpNode(op_pos, Token::kSUB, lhs, rhs); | 5564 return new BinaryOpNode(op_pos, Token::kSUB, lhs, rhs); |
| 5572 case Token::kASSIGN_MUL: | 5565 case Token::kASSIGN_MUL: |
| 5573 return new BinaryOpNode(op_pos, Token::kMUL, lhs, rhs); | 5566 return new BinaryOpNode(op_pos, Token::kMUL, lhs, rhs); |
| 5574 case Token::kASSIGN_TRUNCDIV: | 5567 case Token::kASSIGN_TRUNCDIV: |
| 5575 return new BinaryOpNode(op_pos, Token::kTRUNCDIV, lhs, rhs); | 5568 return new BinaryOpNode(op_pos, Token::kTRUNCDIV, lhs, rhs); |
| 5576 case Token::kASSIGN_DIV: | 5569 case Token::kASSIGN_DIV: |
| 5577 return new BinaryOpNode(op_pos, Token::kDIV, lhs, rhs); | 5570 return new BinaryOpNode(op_pos, Token::kDIV, lhs, rhs); |
| 5578 case Token::kASSIGN_MOD: | 5571 case Token::kASSIGN_MOD: |
| 5579 return new BinaryOpNode(op_pos, Token::kMOD, lhs, rhs); | 5572 return new BinaryOpNode(op_pos, Token::kMOD, lhs, rhs); |
| 5580 case Token::kASSIGN_SAR: | 5573 case Token::kASSIGN_SHR: |
| 5581 return new BinaryOpNode(op_pos, Token::kSAR, lhs, rhs); | 5574 return new BinaryOpNode(op_pos, Token::kSHR, lhs, rhs); |
| 5582 case Token::kASSIGN_SHL: | 5575 case Token::kASSIGN_SHL: |
| 5583 return new BinaryOpNode(op_pos, Token::kSHL, lhs, rhs); | 5576 return new BinaryOpNode(op_pos, Token::kSHL, lhs, rhs); |
| 5584 case Token::kASSIGN_SHR: | |
| 5585 return new BinaryOpNode(op_pos, Token::kSHR, lhs, rhs); | |
| 5586 case Token::kASSIGN_OR: | 5577 case Token::kASSIGN_OR: |
| 5587 return new BinaryOpNode(op_pos, Token::kBIT_OR, lhs, rhs); | 5578 return new BinaryOpNode(op_pos, Token::kBIT_OR, lhs, rhs); |
| 5588 case Token::kASSIGN_AND: | 5579 case Token::kASSIGN_AND: |
| 5589 return new BinaryOpNode(op_pos, Token::kBIT_AND, lhs, rhs); | 5580 return new BinaryOpNode(op_pos, Token::kBIT_AND, lhs, rhs); |
| 5590 case Token::kASSIGN_XOR: | 5581 case Token::kASSIGN_XOR: |
| 5591 return new BinaryOpNode(op_pos, Token::kBIT_XOR, lhs, rhs); | 5582 return new BinaryOpNode(op_pos, Token::kBIT_XOR, lhs, rhs); |
| 5592 default: | 5583 default: |
| 5593 ErrorMsg(op_pos, "internal error: ExpandAssignableOp '%s' unimplemented", | 5584 ErrorMsg(op_pos, "internal error: ExpandAssignableOp '%s' unimplemented", |
| 5594 Token::Name(assignment_op)); | 5585 Token::Name(assignment_op)); |
| 5595 UNIMPLEMENTED(); | 5586 UNIMPLEMENTED(); |
| (...skipping 2130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7726 } | 7717 } |
| 7727 | 7718 |
| 7728 | 7719 |
| 7729 void Parser::SkipNestedExpr() { | 7720 void Parser::SkipNestedExpr() { |
| 7730 const bool saved_mode = SetAllowFunctionLiterals(true); | 7721 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7731 SkipExpr(); | 7722 SkipExpr(); |
| 7732 SetAllowFunctionLiterals(saved_mode); | 7723 SetAllowFunctionLiterals(saved_mode); |
| 7733 } | 7724 } |
| 7734 | 7725 |
| 7735 } // namespace dart | 7726 } // namespace dart |
| OLD | NEW |