Return-Path: X-Original-To: apmail-flex-commits-archive@www.apache.org Delivered-To: apmail-flex-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2ED581182E for ; Sat, 26 Apr 2014 03:39:52 +0000 (UTC) Received: (qmail 15726 invoked by uid 500); 26 Apr 2014 03:39:41 -0000 Delivered-To: apmail-flex-commits-archive@flex.apache.org Received: (qmail 15616 invoked by uid 500); 26 Apr 2014 03:39:40 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 14662 invoked by uid 99); 26 Apr 2014 03:39:25 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Apr 2014 03:39:25 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 443B5952BF8; Sat, 26 Apr 2014 03:39:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aharui@apache.org To: commits@flex.apache.org Date: Sat, 26 Apr 2014 03:39:38 -0000 Message-Id: <510f3690c18d4d599d71759d9ebc9e92@git.apache.org> In-Reply-To: <58ce79a5cbca406baaab33a2abd79292@git.apache.org> References: <58ce79a5cbca406baaab33a2abd79292@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [17/27] fdb with worker support http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/AS3DebuggerRules.jbg ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/AS3DebuggerRules.jbg b/modules/fdbworkers/src/flash/tools/debugger/expression/AS3DebuggerRules.jbg new file mode 100644 index 0000000..65e0622 --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/AS3DebuggerRules.jbg @@ -0,0 +1,734 @@ +/* + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ +Pattern foldedExpressionPattern +FoldedExpressionID(void); + +foldedExpression = Pattern foldedExpressionPattern: 1 +JBurg.Reduction reducer.reduceLazyExpression(__p); + +Pattern logicalAndExprLazy +Op_LogicalAndID(expression l, foldedExpression r); + +Pattern logicalOrExprLazy +Op_LogicalOrID(expression l, foldedExpression r); + +/* + * AS3DebuggerRules.jbg holds the rewrite rules for debugger support. + * @see AS3Patterns.jbg, which holds the corresponding patterns. + */ + +/* + * Assignment to a simple name. + */ +expression = Pattern assignToNameExpr: 2 +JBurg.Reduction reducer.reduce_assignToNameExpr_to_expression(__p, lval,r); + +/* + * Assignment to a more general lvalue. + */ +expression = Pattern assignToMemberExpr : 10 +JBurg.Reduction reducer.reduce_assignToMemberExpr_to_expression(__p, stem, member, r); + +/* + * Assignment to a[i] type lvalue. + */ +expression = Pattern assignToBracketExpr: 1 +JBurg.Reduction reducer.reduce_assignToBracketExpr_to_expression(__p, stem, index, r, false); + +expression = Pattern assignToSuperBracketExpr: 1 +JBurg.Reduction reducer.reduce_assignToBracketExpr_to_expression(__p, null, index, r, true); + +/* + * Assignment to qualified names and attributes. + */ +expression = Pattern assignToQualifiedMemberExpr : 1 +JBurg.Reduction reducer.reduce_assignToQualifiedMemberExpr(__p, stem, qualifier, member, r, NEED_VALUE); + +expression = Pattern assignToQualifiedRuntimeMemberExpr : 1 +JBurg.Reduction reducer.reduce_assignToQualifiedRuntimeMemberExpr(__p, stem, qualifier, member, r, NEED_VALUE); + +expression = Pattern assignToQualifiedAttributeExpr : 1 +JBurg.Reduction reducer.reduce_assignToQualifiedAttributeExpr(__p, stem, qualifier, attribute, r, NEED_VALUE); + +expression = Pattern assignToUnqualifiedRuntimeAttributeExpr : 1 +JBurg.Reduction reducer.reduce_assignToUnqualifiedRuntimeAttributeExpr(__p, stem, rt_attr_name, r, NEED_VALUE); + +expression = Pattern assignToUnqualifiedRuntimeDescendantsAttributeExpr : 1 +JBurg.Reduction reducer.reduce_assignToUnqualifiedRuntimeAttributeExpr(__p, stem, rt_attr_name, r, NEED_VALUE); + +/* + * Assignment to descendants. + */ +expression = Pattern assignToDescendantsExpr : 1 +JBurg.Reduction reducer.reduce_assignToDescendantsExpr(__p, stem, member, r, NEED_VALUE); + +/* + * Error trap for diagnosing parser/CG mismatches. + * The cost is unfeasibly high for a normal reduction, + * so this will only be chosen if no other reduction works. + */ +expression = Op_AssignId(expression non_lvalue, expression rvalue ) : ERROR_TRAP +JBurg.Reduction reducer.error_reduce_Op_AssignId(__p, non_lvalue, rvalue); + +/* + * Miscellaneous void expressions. + */ +expression = Pattern nilExpr : 1 +JBurg.Reduction reducer.reduce_nilExpr_to_expression(__p); + +/* + * Binary logical operators. + */ +comparison_expression = Pattern equalExpr : 1 +JBurg.Reduction reducer.binaryOp (__p, l, r, OP_equals); + +comparison_expression = Pattern neqExpr : 1 +JBurg.Reduction reducer.reduce_neqExpr (__p, l, r); + +comparison_expression = Pattern stricteqExpr : 1 +JBurg.Reduction reducer.binaryOp (__p, l, r, OP_strictequals); + +comparison_expression = Pattern strictneqExpr : 1 +JBurg.Reduction reducer.reduce_strictneqExpr (__p, l, r); + +comparison_expression = Pattern greaterThanExpr: 1 +JBurg.Reduction reducer.binaryOp (__p, l, r, OP_greaterthan); + +comparison_expression = Pattern greaterThanEqExpr: 1 +JBurg.Reduction reducer.binaryOp (__p, l, r, OP_greaterequals); + +comparison_expression = Pattern lessExpr : 1 +JBurg.Reduction reducer.binaryOp (__p, l, r, OP_lessthan); + +comparison_expression = Pattern lessEqExpr : 1 +JBurg.Reduction reducer.binaryOp (__p, l, r, OP_lessequals); + +// Closure rule: any comparison_expression +// is also an expression without further conversion. +expression = comparison_expression; + +expression = Pattern logicalAndExprLazy : 5 +JBurg.Reduction reducer.reduce_logicalAndExpr (__p, l, r); + +expression = Pattern logicalOrExprLazy : 5 +JBurg.Reduction reducer.reduce_logicalOrExpr (__p, l, r); + +expression = Pattern logicalNotExpr : 1 +JBurg.Reduction reducer.reduce_logicalNotExpr (__p, expr); + +expression = Pattern ternaryExpr : 1 +JBurg.Reduction reducer.reduce_ternaryExpr (__p, test, when_true, when_false); + +/* + * Binary arithmetic operators. + */ + +expression = Pattern divideExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, l, r, OP_divide); + +expression = Pattern multExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, l, r, OP_multiply); + +expression = Pattern moduloExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, l, r, OP_modulo); + +expression = Pattern addExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, l, r, OP_add); + +expression = Pattern subtractExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, l, r, OP_subtract); + +expression = Pattern bitwiseLeftShiftExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, l, r, OP_lshift); + +expression = Pattern bitwiseRightShiftExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, l, r, OP_rshift); + +expression = Pattern bitwiseUnsignedRightShiftExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, l, r, OP_urshift); + +expression = Pattern bitwiseAndExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, l, r, OP_bitand); + +expression = Pattern bitwiseOrExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, l, r, OP_bitor); + +expression = Pattern bitwiseXorExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, l, r, OP_bitxor); + +/* + * pre/postfix unary operators. + */ + +expression = Pattern postIncNameExpr : 7 +JBurg.Reduction reducer.reduce_postIncNameExpr(__p, unary, true); + +expression = Pattern preIncNameExpr : 7 +JBurg.Reduction reducer.reduce_preIncNameExpr(__p, unary, true); + +expression = Pattern preIncMemberExpr : 8 +JBurg.Reduction reducer.reduce_preIncMemberExpr(__p, stem, field, true); + +expression = Pattern postIncMemberExpr: 8 +JBurg.Reduction reducer.reduce_postIncMemberExpr(__p, stem, field, true); + +expression = Pattern preIncBracketExpr: 8 +JBurg.Reduction reducer.reduce_preIncBracketExpr(__p, stem, index, true); + +expression = Pattern postIncBracketExpr: 8 +JBurg.Reduction reducer.reduce_postIncBracketExpr(__p, stem, index, true); + +expression = Pattern postDecNameExpr : 7 +JBurg.Reduction reducer.reduce_postDecNameExpr(__p, unary, true); + +expression = Pattern preDecNameExpr : 7 +JBurg.Reduction reducer.reduce_preDecNameExpr(__p, unary, true); + +expression = Pattern preDecMemberExpr : 8 +JBurg.Reduction reducer.reduce_preDecMemberExpr(__p, stem, field, true); + +expression = Pattern postDecMemberExpr: 8 +JBurg.Reduction reducer.reduce_postDecMemberExpr(__p, stem, field, true); + +expression = Pattern preDecBracketExpr: 8 +JBurg.Reduction reducer.reduce_preDecBracketExpr(__p, stem, index, true); + +expression = Pattern postDecBracketExpr: 8 +JBurg.Reduction reducer.reduce_postDecBracketExpr(__p, stem, index, true); + +/* + * Unary expressions. + */ +expression = Pattern unaryMinusExpr: 1 +JBurg.Reduction reducer.unaryOp(__p, e, OP_negate); + +expression = Pattern unaryPlusExpr: 0 +{ + return reducer.unaryOp(__p, e, OP_convert_d); +} + +expression = Pattern typeofExpr: 10 +JBurg.Reduction reducer.reduce_typeof_expr(__p, expr); + +expression = Pattern typeofName: 1 +JBurg.Reduction reducer.reduce_typeof_name(__p, n); + +expression = Pattern bitNotExpr: 1 +JBurg.Reduction reducer.unaryOp(__p, unary, OP_bitnot); + +/* + * Miscellaneous binary expressions. + */ +expression = Pattern istypeExprLate : 1 +JBurg.Reduction reducer.binaryOp(__p, expr, typename, OP_istypelate); + +expression = Pattern astypeExprLate : 1 +JBurg.Reduction reducer.binaryOp(__p, expr, typename, OP_astypelate); + +expression = Pattern inExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, needle, haystack, OP_in); + +expression = Pattern instanceofExpr : 1 +JBurg.Reduction reducer.binaryOp(__p, expr, typename, OP_instanceof); + +// lhs += rhs +JBurg.include "AS3DebuggerCompoundAssignmentRules.jbg" \ + Op_COMPOUND_ASSIGN="OP_add" \ + compoundAssignToName="assignPlusToNameExpr" \ + compoundAssignToMember="assignPlusToMemberExpr" \ + compoundAssignToBracket="assignPlusToBracketExpr" + +// lhs *= rhs +JBurg.include "AS3DebuggerCompoundAssignmentRules.jbg" \ + Op_COMPOUND_ASSIGN="OP_multiply" \ + compoundAssignToName="assignMultiplyToNameExpr" \ + compoundAssignToMember="assignMultiplyToMemberExpr" \ + compoundAssignToBracket="assignMultiplyToBracketExpr" + +// lhs -= rhs +JBurg.include "AS3DebuggerCompoundAssignmentRules.jbg" \ + Op_COMPOUND_ASSIGN="OP_subtract" \ + compoundAssignToName="assignMinusToNameExpr" \ + compoundAssignToMember="assignMinusToMemberExpr" \ + compoundAssignToBracket="assignMinusToBracketExpr" + +// lhs /= rhs +JBurg.include "AS3DebuggerCompoundAssignmentRules.jbg" \ + Op_COMPOUND_ASSIGN="OP_divide" \ + compoundAssignToName="assignDivideToNameExpr" \ + compoundAssignToMember="assignDivideToMemberExpr" \ + compoundAssignToBracket="assignDivideToBracketExpr" + +// lhs %= rhs +JBurg.include "AS3DebuggerCompoundAssignmentRules.jbg" \ + Op_COMPOUND_ASSIGN="OP_modulo" \ + compoundAssignToName="assignModuloToNameExpr" \ + compoundAssignToMember="assignModuloToMemberExpr" \ + compoundAssignToBracket="assignModuloToBracketExpr" + +// lhs <<= rhs +JBurg.include "AS3DebuggerCompoundAssignmentRules.jbg" \ + Op_COMPOUND_ASSIGN="OP_lshift" \ + compoundAssignToName="assignLeftShiftToNameExpr" \ + compoundAssignToMember="assignLeftShiftToMemberExpr" \ + compoundAssignToBracket="assignLeftShiftToBracketExpr" + +// lhs <<= rhs +JBurg.include "AS3DebuggerCompoundAssignmentRules.jbg" \ + Op_COMPOUND_ASSIGN="OP_rshift" \ + compoundAssignToName="assignRightShiftToNameExpr" \ + compoundAssignToMember="assignRightShiftToMemberExpr" \ + compoundAssignToBracket="assignRightShiftToBracketExpr" + +// lhs >>>= rhs +JBurg.include "AS3DebuggerCompoundAssignmentRules.jbg" \ + Op_COMPOUND_ASSIGN="OP_urshift" \ + compoundAssignToName="assignUnsignedRightShiftToNameExpr" \ + compoundAssignToMember="assignUnsignedRightShiftToMemberExpr" \ + compoundAssignToBracket="assignUnsignedRightShiftToBracketExpr" + +// lhs &= rhs +JBurg.include "AS3DebuggerCompoundAssignmentRules.jbg" \ + Op_COMPOUND_ASSIGN="OP_bitand" \ + compoundAssignToName="assignBitwiseAndToNameExpr" \ + compoundAssignToMember="assignBitwiseAndToMemberExpr" \ + compoundAssignToBracket="assignBitwiseAndToBracketExpr" + +// lhs |= rhs +JBurg.include "AS3DebuggerCompoundAssignmentRules.jbg" \ + Op_COMPOUND_ASSIGN="OP_bitor" \ + compoundAssignToName="assignBitwiseOrToNameExpr" \ + compoundAssignToMember="assignBitwiseOrToMemberExpr" \ + compoundAssignToBracket="assignBitwiseOrToBracketExpr" + +// lhs ^= rhs +JBurg.include "AS3DebuggerCompoundAssignmentRules.jbg" \ + Op_COMPOUND_ASSIGN="OP_bitxor" \ + compoundAssignToName="assignBitwiseXorToNameExpr" \ + compoundAssignToMember="assignBitwiseXorToMemberExpr" \ + compoundAssignToBracket="assignBitwiseXorToBracketExpr" + +/* + * Primary expressions. + */ +expression = Pattern memberAccessExpr : 10 +JBurg.Reduction reducer.reduce_memberAccessExpr (__p, stem, member, OP_getproperty); + +expression = Pattern qualifiedMemberAccessExpr : 10 +JBurg.Reduction reducer.reduce_qualifiedMemberAccessExpr(__p, stem, qualifier, member, OP_getproperty); + +expression = Pattern qualifiedDescendantsExpr : 10 +JBurg.Reduction reducer.reduce_qualifiedMemberAccessExpr(__p, stem, qualifier, member, OP_getdescendants); + +expression = Pattern qualifiedDescendantsRuntimeExpr : 1 +JBurg.Reduction reducer.reduce_qualifiedAttributeRuntimeMemberExpr(__p, stem, qualifier, runtime_member, OP_getdescendants); + +expression = Pattern qualifiedAttributeExpr : 1 +JBurg.Reduction reducer.reduce_qualifiedAttributeExpr(__p, stem, qualifier, member, OP_getproperty); + +expression = Pattern qualifiedDescendantsAttributeExpr : 1 +JBurg.Reduction reducer.reduce_qualifiedAttributeExpr(__p, stem, qualifier, member, OP_getdescendants); + +expression = Pattern qualifiedAttributeRuntimeMemberExpr : 1 +JBurg.Reduction reducer.reduce_qualifiedAttributeRuntimeMemberExpr(__p, stem, qualifier, runtime_member, OP_getproperty); + +expression = Pattern qualifiedDescendantsRuntimeMemberExpr : 1 +JBurg.Reduction reducer.reduce_qualifiedAttributeRuntimeMemberExpr(__p, stem, qualifier, runtime_member, OP_getdescendants); + +// Prefer the basic memberAccessExpr pattern where feasible. +expression = Pattern qualifiedMemberRuntimeNameExpr : 100 +JBurg.Reduction reducer.reduce_qualifiedMemberRuntimeNameExpr(__p, stem, qualifier, runtime_member); + +expression = Pattern unqualifiedAttributeExpr : 1 +JBurg.Reduction reducer.reduce_unqualifiedAttributeExpr(__p, stem, expr, OP_getproperty); + +expression = Pattern unqualifiedDescendantsAttributeExpr : 1 +JBurg.Reduction reducer.reduce_unqualifiedAttributeExpr(__p, stem, expr, OP_getdescendants); + +expression = Pattern runtimeAttributeExp : 1 +JBurg.Reduction reducer.reduce_runtimeAttributeExp(__p, expr); + +expression = Pattern arrayIndexExpr : 1 +JBurg.Reduction reducer.reduce_arrayIndexExpr (__p, stem, false, index); + +expression = Pattern superIndexExpr : 1 +JBurg.Reduction reducer.reduce_arrayIndexExpr (__p, null, true, index); + +expression = Pattern functionCallExpr : 3 // Cost artificially inflated +JBurg.Reduction reducer.reduce_functionCallExpr_to_expression (__p, method_name, args); + +expression = Pattern newVectorLiteral: 0 +JBurg.Reduction reducer.reduce_newVectorLiteral(__p, literal); + +// 'new Whatever(...)' has cost 2, so it gets beaten by the two previous rules. +// Use this reduction if the type is known; +// it allows much better error checking of the constructor call. +expression = Pattern newExpr : 2 +JBurg.Reduction reducer.reduce_newExpr (__p, class_binding, args); + +expression = Pattern newMemberProperty: 10 +JBurg.Reduction reducer.reduce_newMemberProperty(__p, stem, member, args); + +expression = Pattern newAsRandomExpr : 30 +JBurg.Reduction reducer.reduce_newAsRandomExpr (__p, random_expr, args); + +expression = Pattern functionCallOfSuperclassMethod : 2 +JBurg.Reduction reducer.reduce_functionCallOfSuperclassMethod_to_expression (__p, null, method_name, args); + +expression = Pattern functionCallOfExplicitObjectSuperclassMethod : 2 +JBurg.Reduction reducer.reduce_functionCallOfSuperclassMethod_to_expression (__p, stem, method_name, args); + +expression = Pattern functionAsMemberExpr : 4 // Cost inflated to prefer functionCallOfSuperclassMethod +JBurg.Reduction reducer.reduce_functionAsMemberExpr (__p, stem, method_name, args); + +expression = Pattern functionAsBracketExpr : 4 +JBurg.Reduction reducer.reduce_functionAsBracketExpr (__p, stem, index, args); + +expression = Pattern functionAsRandomExpr : 30 +JBurg.Reduction reducer.reduce_functionAsRandomExpr (__p, random_expr, args); + +/* + * Delete expressions. + */ +expression = Pattern deleteNameExpr: 2 +JBurg.Reduction reducer.reduce_deleteNameExpr(__p, n); + +expression = Pattern deleteBracketExpr: 1 +JBurg.Reduction reducer.reduce_deleteBracketExpr(__p, stem, index); + +expression = Pattern deleteAtBracketExpr: 1 +JBurg.Reduction reducer.reduce_deleteAtBracketExpr(__p, stem, index); + +expression = Pattern deleteMemberExpr: 1 +JBurg.Reduction reducer.reduce_deleteMemberExpr(__p, stem, field); + +expression = Pattern deleteRuntimeNameExpr: 1 +JBurg.Reduction reducer.reduce_deleteRuntimeNameExpr(__p, stem, rt_name); + +expression = Pattern deleteDescendantsExpr: 1 +JBurg.Reduction reducer.reduce_deleteDescendantsExpr(__p, stem, field); + +expression = Pattern deleteAnyExprExprExpr: 2000 +JBurg.Reduction reducer.reduce_deleteExprExprExpr(__p, expr); + +/* + * Comma expression. + */ +expression = Pattern commaExpr: 0 +JBurg.Reduction reducer.reduce_commaExpr(__p, payload_expr, exprs); + +/* + * Names and reference expressions built from names. + */ +name = Pattern simpleName : 0 +JBurg.Reduction reducer.reduce_simpleName (__p); + +qualifiedNamePart = Pattern simpleName: 0 +JBurg.Reduction reducer.getIdentifierContent(__p); + +name = Pattern typedVariableExpression : 0 +JBurg.Reduction reducer.reduce_typedVariableExpression (__p, var_name, var_type); + +dottedNamePart = Pattern dottedName : 0 +JBurg.Reduction reducer.reduce_by_concatenation (__p, first, second); + +dottedNamePart = qualifiedNamePart; + +name = Pattern dottedName : isDottedName() +JBurg.Reduction reducer.dottedName (__p, first, second); + +name = Pattern dottedName : isPackageName() +JBurg.Reduction reducer.errorPackageName(__p, first, second); + +// This reduction handles an entire dotted name subtree. +name = Pattern fullName : 0 +JBurg.Reduction reducer.dottedName(__p, first, second); + +// qualified namespace is the same as a full name, +// it's just what gets produced when we're in a use namespace directive +// use namespace a.b.Foo; +name = Pattern qualifiedNamespaceName : 0 +JBurg.Reduction reducer.dottedName(__p, first, second); + +// This reduction handles the bar.T part of foo.bar.T +dottedNamePart = Pattern fullName : 0 +JBurg.Reduction reducer.reduce_by_concatenation (__p, first, second); + +name = Pattern superAccess : 0 +JBurg.Reduction reducer.reduce_superAccess (__p, qualified_name); + +// A bare parameterized type name can only be +// used as a type annotation. In code it's necessary +// to expand it into an expression that calls applytype. +// Note: this reduction gets an error-trapping cost if +// the parameter type is not constant; this forces +// expression-oriented reductions to try and reduce +// the type parameter as an expression. +type_name = Pattern parameterizedName : parameterTypeIsConstant() +JBurg.Reduction reducer.reduce_parameterizedTypeName (__p, base, param); + +// A name can be a type_name, which in combination with +// the reduction above yields the set of possible type_names: +// identifiers and * +type_name = name : 1 +JBurg.Reduction reducer.reduce_nameToTypeName(name, true); + +// The 'new' expression takes a pseduo-type name: +// when it can be resolved, the semantic analysis +// code can check the constructor. When it can't +// be resolved, it's a generalized expression. +new_type_name = name; + +// Inflate this cost so it's only selected +// if the type_name isn't a name. +new_type_name = type_name : 20 +JBurg.Reduction reducer.reduce_nameToTypeName(type_name, false); + +// The parameter of a parameterized type expression may be an expression +// or a type name; if it resolves to a type, it's a type name. +type_param_expression = name: isKnownType() +JBurg.Reduction reducer.reduce_typeNameParameterAsType(__p, name); + +// any expression can be used as a type param name in an expression context. +type_param_expression = expression; + +expression = Pattern parameterizedTypeExpression : 1 +JBurg.Reduction reducer.reduce_parameterizedTypeExpression (__p, base, param); + +expression = name: 2000 +JBurg.Reduction reducer.transform_name_to_expression(__p, name); + +type_name = Pattern voidExpr : 0 +JBurg.Reduction reducer.reduce_voidExpr_to_type_name(__p); + +name = Pattern attributeName : 0 +JBurg.Reduction reducer.reduce_attributeName (__p, attr_name); + +// ns1::foo and rt_ns::foo look alike to +// the parser, so they must be disambiguated +// by checking their semantic annotations. +name = Pattern namespaceAccess : qualifierIsCompileTimeConstant() +JBurg.Reduction reducer.reduce_namespaceAccess (__p, qualifier, qualified_name); + +// Error trap for an unresolved namespace in a context +// where it must be declared. +name = Pattern namespaceAccess: ERROR_TRAP +JBurg.Reduction reducer.error_namespaceAccess(__p, qualifier, qualified_name); + +// A namespace-qualified name reference whose name +// is a runtime expression, e.g., ns1::[foo]. +// The parser doesn't know the difference between +// ns1::[foo] and rt_ns::[foo], so we need a cost +// function to disambiguate the tree. +runtime_name_expression = Pattern namespaceMultinameL: qualifierIsCompileTimeConstant() +JBurg.Reduction reducer.reduce_namespaceMultinameL(__p, qualifier, expr); + +runtime_name_expression = Pattern namespaceRTQName : 2000 +JBurg.Reduction reducer.reduce_namespaceRTQName (__p, qualifier, qualfied_name); + +expression = Pattern embedExpression : 2 +JBurg.Reduction reducer.reduce_embed(__p); + +/* + * E4X expressions (except literals) + */ + +expression = Pattern e4xFilter : 3 +JBurg.Reduction reducer.reduce_e4xFilter (__p, stem, filter); + +runtime_name_expression = Pattern namespaceRTQNameL : 2000 +JBurg.Reduction reducer.reduce_namespaceRTQNameL (__p, qualifier, expr); + +expression = runtime_name_expression : 1 +JBurg.Reduction reducer.transform_runtime_name_expression(__p, runtime_name_expression); + +expression = Pattern runtimeNameExpression: 1 +JBurg.Reduction reducer.reduce_runtimeNameExpression(__p, expr); + +name = Pattern namespaceAsName: 1 +JBurg.Reduction reducer.reduce_namespaceAsName_to_name(__p); + +expression = Pattern namespaceAsName: 1 +JBurg.Reduction reducer.reduce_namespaceAsName_to_expression(__p); + +void_expression = Pattern assignToRuntimeNameExpr: 1 +JBurg.Reduction reducer.reduce_assignToRuntimeNameExpr(__p, lval, r, DISCARD_VALUE); + +expression = Pattern assignToRuntimeNameExpr: 1 +JBurg.Reduction reducer.reduce_assignToRuntimeNameExpr(__p, lval, r, NEED_VALUE); + +expression = Pattern descendantsExpression : 1 +JBurg.Reduction reducer.reduce_memberAccessExpr(__p, stem, descendants, OP_getdescendants); + +/* + * Literals. + */ +e4x_literal = Pattern XMLLiteral : 0 +JBurg.Reduction reducer.getStringLiteralContent (__p); + +string_constant = e4x_literal; + +expression = Pattern XMLContent: 1 +JBurg.Reduction reducer.reduce_XMLContent(__p, exprs); + +expression = Pattern XMLList: 2 +JBurg.Reduction reducer.reduce_XMLList(__p, exprs); + +expression = Pattern XMLListConst: 1 +JBurg.Reduction reducer.reduce_XMLListConst(__p, elements); + +expression = literal; +literal = object_literal; +literal = boolean_literal; +literal = array_literal; + +expression = string_constant : 1 +JBurg.Reduction reducer.transform_string_constant(__p, string_constant); + +integer_constant = Pattern numericLiteral: isIntLiteral() +JBurg.Reduction reducer.getIntegerContent(__p); + +expression = integer_constant : 1 +JBurg.Reduction reducer.transform_integer_constant(__p, integer_constant); + +uint_constant = Pattern numericLiteral: isIntLiteral() +JBurg.Reduction reducer.getUintContent(__p); + +expression = uint_constant : 1 +JBurg.Reduction reducer.transform_uint_constant(__p, uint_constant); + +expression = boolean_constant : 1 +JBurg.Reduction reducer.transform_boolean_constant(__p, boolean_constant); + + +/** + * Constant values + */ +// Error trap for non-constant expressions +// used in a context where only a constant is valid, +// e.g., foo() in function needsConstantInit(x = foo()). +required_constant_value = expression : ERROR_TRAP +JBurg.Reduction reducer.transform_expression_to_constant_value(__p, expression); + +// A name can be used as a constant in some contexts, +// e.g., if it's a Namespace or otherwise known to be +// a compile-time constant. + +integer_constant = LiteralIntegerZeroID(void) : 1 +JBurg.Reduction reducer.getIntegerZeroContent(__p); + +uint_constant = LiteralIntegerZeroID(void) : 1 +JBurg.Reduction reducer.getIntegerZeroContentAsLong(__p); + +float_constant = Pattern numericLiteral : isFloatLiteral() +JBurg.Reduction reducer.getFloatContent(__p); + +constant_value = Pattern nullLiteral : 0 +JBurg.Reduction reducer.reduce_nullLiteral_to_constant_value (__p); + +constant_value = Pattern void0Literal: 0 +JBurg.Reduction reducer.reduce_void0Literal_to_constant_value(__p); + +constant_value = Pattern voidConstant: 0 +JBurg.Reduction reducer.reduce_voidOperator_to_constant_value(__p, value); + +boolean_constant = Pattern booleanLiteral: 0 +JBurg.Reduction reducer.reduce_booleanLiteral(__p); + +string_constant = Pattern stringLiteral : 0 +JBurg.Reduction reducer.getStringLiteralContent (__p); + +numeric_constant = integer_constant; +numeric_constant = uint_constant; +numeric_constant = double_constant; +numeric_constant = float_constant; + + +constant_value = string_constant : 1 +JBurg.Reduction reducer.transform_string_constant_to_constant(__p, string_constant); + +constant_value = boolean_constant : 1 +JBurg.Reduction reducer.transform_boolean_constant_to_constant(__p, boolean_constant); + +constant_value = numeric_constant : 1 +JBurg.Reduction reducer.transform_numeric_constant_to_constant(__p, numeric_constant); + +required_constant_value = constant_value; + +double_constant = Pattern numericLiteral : isDoubleLiteral() +JBurg.Reduction reducer.getDoubleContent(__p); + +// Fallback code-gen choice if conversion to +// double failed in LiteralNumberNode.getNodeID(). +// It's not likely to work better here, +// but the BURM will emit some diagnostics. +double_constant = Pattern numericLiteral : 3 +JBurg.Reduction reducer.getDoubleContent(__p); + +expression = double_constant : 5 +JBurg.Reduction reducer.transform_double_constant(__p, double_constant); + +expression = numeric_constant : 5 +JBurg.Reduction reducer.transform_numeric_constant(__p, numeric_constant); + +expression = float_constant : 5 +JBurg.Reduction reducer.transform_float_constant(__p, float_constant); + +expression = constant_value : 0 +JBurg.Reduction reducer.transform_constant_value(__p, constant_value); + +object_literal = Pattern nullLiteral : 1 +JBurg.Reduction reducer.reduce_nullLiteral_to_object_literal (__p); + +object_literal = Pattern objectLiteral : 3 +JBurg.Reduction reducer.reduce_objectLiteral (__p, elements); + +object_literal_element = Pattern objectLiteralElement : 0 +JBurg.Reduction reducer.reduce_objectLiteralElement (__p, id, value); + +non_resolving_identifier = Pattern nonResolvingIdentifier : 0 +JBurg.Reduction reducer.getIdentifierContent(__p); + +expression = non_resolving_identifier : 1 +JBurg.Reduction reducer.transform_non_resolving_identifier(__p, non_resolving_identifier); + +object_literal = Pattern regexLiteral: 5 +JBurg.Reduction reducer.reduce_regexLiteral(__p); + +object_literal = Pattern void0Literal: 1 +JBurg.Reduction reducer.reduce_void0Literal_to_object_literal(__p); + +object_literal = Pattern void0Operator: 1 +JBurg.Reduction reducer.reduce_void0Operator(__p); + +expression = Pattern voidOperator : 1 +JBurg.Reduction reducer.reduce_voidOperator_to_expression (__p, expr); + +boolean_literal = boolean_constant: 1 +JBurg.Reduction reducer.transform_boolean_constant(__p, boolean_constant); + +array_literal = Pattern arrayLiteral : 1 +JBurg.Reduction reducer.reduce_arrayLiteral (__p, elements); + +vector_literal = Pattern vectorLiteral: 1 +JBurg.Reduction reducer.reduce_vectorLiteral(__p, type_param, elements); + +decl_name = Pattern simpleName : 0 +JBurg.Reduction reducer.reduce_declName(__p); + http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/ASTBuilder.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/ASTBuilder.java b/modules/fdbworkers/src/flash/tools/debugger/expression/ASTBuilder.java new file mode 100644 index 0000000..1b52772 --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/ASTBuilder.java @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package flash.tools.debugger.expression; + +import java.io.IOException; +import java.io.Reader; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; + +import com.adobe.flash.compiler.problems.ICompilerProblem; +import com.adobe.flash.compiler.tree.as.IASNode; + +import flash.localization.LocalizationManager; +import flash.tools.debugger.DebuggerLocalizer; + +/** + * ASTBuilder.java + * + * This class creates an abstract syntax tree representation + * of an expression given a sequence of tokens. + * + * The tree is built by calling the ActionScript compiler and + * having it parse the expression, then converting the result + * to a form we prefer. + * + * No compression is performed on the tree, thus expressions + * such as (3*4) will result in 3 nodes. + * + */ +public class ASTBuilder implements IASTBuilder +{ + private static LocalizationManager s_localizationManager; + + /** + * whether the fdb indirection operators are allowed, e.g. asterisk (*x) or + * trailing dot (x.) + */ + private boolean m_isIndirectionOperatorAllowed = true; + + static + { + // set up for localizing messages + s_localizationManager = new LocalizationManager(); + s_localizationManager.addLocalizer( new DebuggerLocalizer("flash.tools.debugger.expression.expression.") ); //$NON-NLS-1$ + } + + /** + * @param isIndirectionOperatorAllowed + * whether the fdb indirection operators are allowed, e.g. + * asterisk (*x) or trailing dot (x.) + */ + public ASTBuilder(boolean isIndirectionOperatorAllowed) + { + m_isIndirectionOperatorAllowed = isIndirectionOperatorAllowed; + } + + /** + * @return whether the fdb indirection operators are allowed, e.g. asterisk + * (*x) or trailing dot (x.) + */ + public boolean isIndirectionOperatorAllowed() + { + return m_isIndirectionOperatorAllowed; + } + + + /* + * @see flash.tools.debugger.expression.IASTBuilder#parse(java.io.Reader) + */ + public ValueExp parse(Reader in) throws IOException, ParseException + { + DebuggerExpression retval = new DebuggerExpression(); + + StringBuilder sb = new StringBuilder(); + int ch; + while ( (ch=in.read()) != -1 ) + sb.append((char)ch); + + String s = sb.toString(); + + // FB-16879: If expression begins with "#N" where N is a number, + // replace that with "$obj(N)". For example, "#3" would become + // "$obj(3)". Later, in PlayerSession.callFunction(), we will + // detect the $obj() function and handle it. + s = s.replaceFirst("^#([0-9]+)", "\\$obj($1)"); //$NON-NLS-1$ //$NON-NLS-2$ + + if (isIndirectionOperatorAllowed()) { + if (s.endsWith(".")) { //$NON-NLS-1$ + retval.setLookupMembers(true); + s = s.substring(0, s.length() - 1); + } else if (s.startsWith("*")) { //$NON-NLS-1$ + retval.setLookupMembers(true); + s = s.substring(1); + } + } + + // Enclose the expression in parentheses, in order to ensure that the + // parser considers it to be an expression. For example, "{x:3}" would + // be considered to be a block with label "x" and value "3", but, + // "({x:3})" is considered to be an inline object with field "x" that + // has value 3. + s = "(" + s + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + + final List errors = new ArrayList(); +// CompilerHandler newHandler = new CompilerHandler() { +// @Override +// public void error(final String filename, int ln, int col, String msg, String source) { +// ErrorInfo ei = new ErrorInfo(); +// ei.filename = filename; +// ei.ln = ln; +// ei.col = col; +// ei.msg = msg; +// ei.source = source; +// errors.add(ei); +// } +// }; +// cx.setHandler(newHandler); +// cx.scriptAssistParsing = true; + // Parser parser = new Parser(cx, s, "Expression"); //$NON-NLS-1$ + IASNode programNode = DebuggerUtil.parseExpression(s, errors); + //ProgramNode programNode = parser.parseProgram(); + + if (errors.size() > 0) { + ICompilerProblem firstError = errors.get(0); + throw new ParseException(firstError.toString(), firstError.getColumn()); + } + + retval.setProgramNode(programNode); + return retval; + } + + + static LocalizationManager getLocalizationManager() + { + return s_localizationManager; + } +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/Context.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/Context.java b/modules/fdbworkers/src/flash/tools/debugger/expression/Context.java new file mode 100644 index 0000000..0088ac3 --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/Context.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package flash.tools.debugger.expression; + +import flash.tools.debugger.Session; +import flash.tools.debugger.Value; + +/** + * An object which returns a value given a name and + * appropriate context information. + */ +public interface Context +{ + /** + * Looks for an object of the given name in this context -- for example, a member variable. + * + * The returned Object can be of any type at all. For example, it could be: + * + *
    + *
  • a flash.tools.debugger.Variable
  • + *
  • your own wrapper around Variable
  • + *
  • a flash.tools.debugger.Value
  • + *
  • any built-in Java primitive such as Long, Integer, + * Double, Boolean, or String
  • + *
  • any other type you want which has a good toString(); see below
  • + *
+ * + * Since the return type is just Object, the returned value is only meaningful when + * passed to other functions this interface. For example, the returned Object can be + * passed to createContext(), assign(), or toValue(). + * + * @param o the object to look up; most commonly a string representing the name of + * a member variable. + */ + public Object lookup(Object o) throws NoSuchVariableException, PlayerFaultException; + + /** + * Looks for the members of an object. + * + * @param o + * A variable whose members we want to look up + * @return Some object which represents the members; could even be just a + * string. See lookup() for more information about the returned + * type. + * @see #lookup(Object) + */ + public Object lookupMembers(Object o) throws NoSuchVariableException; + + /** + * Creates a new context object by combining the current one and o. + * For example, if the user typed "myVariable.myMember", then this function + * will get called with o equal to the object which represents "myVariable". + * This function should return a new context which, when called with + * lookup("myMember"), will return an object for that member. + * + * @param o any object which may have been returned by this class's lookup() function + */ + public Context createContext(Object o); + + /** + * Assign the object o, the value v. + * + * @param o + * a variable to assign to -- this should be some value returned + * by an earlier call to lookup(). + * @param v + * a value, such as a Boolean, Long, String, etc. + */ + public void assign(Object o, Value v) throws NoSuchVariableException, PlayerFaultException; + + /** + * Enables/disables the creation of variables during lookup calls. + * This is ONLY used by AssignmentExp for creating a assigning a value + * to a property which currently does not exist. + */ + public void createPseudoVariables(boolean oui); + + /** + * Converts the object to a Value. + * + * @param o + * Either object that was returned by an earlier call to + * lookup(), or one of the raw types that can be + * returned by Value.getValueAsObject(). + * @return the corresponding Value, or null. + * @see Value#getValueAsObject() + */ + public Value toValue(Object o); + + /** + * Converts the context to a Value. Very similar to + * toValue(Object o), except that the object being converted + * is the object that was used to initialize this context. + * + * @return the corresponding Value, or null. + */ + public Value toValue(); + + /** + * Returns the session associated with this context, or null. + * This can legitimately be null; for example, in fdb, you are + * allowed to do things like "set $columnwidth = 120" before + * beginning a debugging session. + */ + public Session getSession(); + + /** + * The worker id to which this context object belongs. + */ + public int getIsolateId(); +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerExpression.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerExpression.java b/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerExpression.java new file mode 100644 index 0000000..a552082 --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerExpression.java @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package flash.tools.debugger.expression; + +import java.util.HashSet; + +import com.adobe.flash.compiler.internal.projects.ASCProject; +import com.adobe.flash.compiler.internal.tree.as.BinaryOperatorLogicalAndNode; +import com.adobe.flash.compiler.internal.tree.as.ExpressionNodeBase; +import com.adobe.flash.compiler.internal.workspaces.Workspace; +import com.adobe.flash.compiler.projects.ICompilerProject; +import com.adobe.flash.compiler.tree.ASTNodeID; +import com.adobe.flash.compiler.tree.as.IASNode; +import com.adobe.flash.compiler.tree.as.IExpressionNode; +import com.adobe.flash.compiler.workspaces.IWorkspace; + +import flash.tools.debugger.PlayerDebugException; + +/** + * A wrapper around an abstract syntax tree (AST) that was provided by the + * ActionScript Compiler (ASC), suitable for use by the debugger. + * + * When {@link #evaluate(Context)} is called, this will walk the AST and return + * a value. But please note that this class's implementation of expression + * evaluation should not be taken as a model of 100% perfect ActionScript + * evaluation. While this implementation handles all the cases the debugger is + * likely to run into, there are many edge cases that this class can't handle. + * For most cases where you need an on-the-fly expression evaluator, you would + * be better off using the code from the "esc" project. + * + * @author Mike Morearty + */ +class DebuggerExpression implements ValueExp { + + private final static HashSet ASSIGN_OPRATORS = new HashSet(); + static { + ASSIGN_OPRATORS.add(ASTNodeID.Op_AssignId); + ASSIGN_OPRATORS.add(ASTNodeID.Op_LeftShiftAssignID); + ASSIGN_OPRATORS.add(ASTNodeID.Op_RightShiftAssignID); + ASSIGN_OPRATORS.add(ASTNodeID.Op_UnsignedRightShiftAssignID); + ASSIGN_OPRATORS.add(ASTNodeID.Op_MultiplyAssignID); + ASSIGN_OPRATORS.add(ASTNodeID.Op_DivideAssignID); + ASSIGN_OPRATORS.add(ASTNodeID.Op_ModuloAssignID); + ASSIGN_OPRATORS.add(ASTNodeID.Op_BitwiseAndAssignID); + ASSIGN_OPRATORS.add(ASTNodeID.Op_BitwiseXorAssignID); + ASSIGN_OPRATORS.add(ASTNodeID.Op_BitwiseOrAssignID); + ASSIGN_OPRATORS.add(ASTNodeID.Op_AddAssignID); + ASSIGN_OPRATORS.add(ASTNodeID.Op_SubtractAssignID); + ASSIGN_OPRATORS.add(ASTNodeID.Op_LogicalAndAssignID); + ASSIGN_OPRATORS.add(ASTNodeID.Op_LogicalOrAssignID); + } + /** + * The AST representing the expression. + */ + private IASNode m_programNode; + + /** + * @see #isLookupMembers() + */ + private boolean m_lookupMembers = false; + + /** + * @return the AST representing the expression. + */ + public IASNode getProgramNode() { + return m_programNode; + } + + /** + * Sets the AST representing the expression. + */ + public void setProgramNode(IASNode programNode) { + m_programNode = programNode; + } + + /* + * @see flash.tools.debugger.expression.ValueExp#isLookupMembers() + */ + public boolean isLookupMembers() { + return m_lookupMembers; + } + + /** + * @see #isLookupMembers() + */ + public void setLookupMembers(boolean value) { + m_lookupMembers = value; + } + + /* + * @see flash.tools.debugger.expression.ValueExp#containsAssignment() + */ + public boolean containsAssignment() { + return containsAssignment(m_programNode); + } + + /** + * @param containsAssignment + */ + private boolean containsAssignment(IASNode node) { + if (ASSIGN_OPRATORS.contains(node.getNodeID())) { + return true; + } + for (int i = 0; i < node.getChildCount(); i++) { + if (containsAssignment(node.getChild(i))) { + return true; + } + } + return false; + } + + /* + * @see + * flash.tools.debugger.expression.ValueExp#evaluate(flash.tools.debugger + * .expression.Context) + */ + public Object evaluate(Context context) throws NumberFormatException, + NoSuchVariableException, PlayerFaultException, PlayerDebugException { + // assert m_cx.getScopeDepth() == 0; + // m_cx.pushScope(new ExpressionEvaluatorScope(context)); + try { + IExpressionEvaluator eval = new DebuggerExpressionEvaluator(); + DebuggerValue value = eval.evaluate(context, m_programNode); + + if (isLookupMembers()) { + return context.lookupMembers(value.debuggerValue); + } else { + return value.debuggerValue; + } + } catch (Exception e) { + // e.printStackTrace();//TODO : ASC3 : remove + if (e.getCause() instanceof NumberFormatException) { + throw (NumberFormatException) e.getCause(); + } else if (e.getCause() instanceof NoSuchVariableException) { + throw (NoSuchVariableException) e.getCause(); + } else if (e.getCause() instanceof PlayerFaultException) { + throw (PlayerFaultException) e.getCause(); + } else if (e.getCause() instanceof PlayerDebugException) { + throw (PlayerDebugException) e.getCause(); + } else { + e.printStackTrace(); + throw new PlayerDebugException(e.getLocalizedMessage()); + } + } finally { + // m_cx.popScope(); + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerExpressionEvaluator.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerExpressionEvaluator.java b/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerExpressionEvaluator.java new file mode 100644 index 0000000..aaa73c0 --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerExpressionEvaluator.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package flash.tools.debugger.expression; + +import com.adobe.flash.compiler.internal.projects.ASCProject; +import com.adobe.flash.compiler.internal.workspaces.Workspace; +import com.adobe.flash.compiler.projects.ICompilerProject; +import com.adobe.flash.compiler.tree.as.IASNode; + +/** + * @author ggv + * + */ +public class DebuggerExpressionEvaluator implements IExpressionEvaluator { + + private final ICompilerProject project; + private final IASTFolder logicalOperatorFolder; + + /** + * + */ + public DebuggerExpressionEvaluator() { + project = new ASCProject(new Workspace(), true); + logicalOperatorFolder = new LogicalOperatorsFolder(); + + } + + /** + * @param project2 + */ + public DebuggerExpressionEvaluator(ICompilerProject project2) { + logicalOperatorFolder = new LogicalOperatorsFolder(); + this.project = project2; + } + + @Override + public DebuggerValue evaluate(Context context, IASNode node) + throws Exception { + + if (node instanceof FoldedExpressionNode) { + /* + * Unfold the folded node, and if the unfolded subtree has a logical + * operator, fold the RHS of that + */ + node = logicalOperatorFolder + .unfoldOneLevel((FoldedExpressionNode) node); + } else { + /* + * Where ever it finds a logical operator, fold the rhs of that. + */ + node = logicalOperatorFolder.fold(node); + } + AS3DebuggerBURM burm = new AS3DebuggerBURM(); + burm.reducer = new AS3DebuggerReducer(context, project); + + burm.burm(node, AS3DebuggerBURM.__expression_NT); + DebuggerValue value = (DebuggerValue) burm.getResult(); + return value; + } + +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerUtil.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerUtil.java b/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerUtil.java new file mode 100644 index 0000000..87d8fce --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerUtil.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package flash.tools.debugger.expression; + +import java.io.StringReader; +import java.util.EnumSet; +import java.util.List; + +import com.adobe.flash.compiler.common.SourceLocation; +import com.adobe.flash.compiler.internal.parsing.as.FrontEnd; +import com.adobe.flash.compiler.internal.scopes.ASFileScope; +import com.adobe.flash.compiler.internal.semantics.PostProcessStep; +import com.adobe.flash.compiler.internal.tree.as.NodeBase; +import com.adobe.flash.compiler.internal.tree.as.ScopedBlockNode; +import com.adobe.flash.compiler.internal.workspaces.Workspace; +import com.adobe.flash.compiler.problems.ICompilerProblem; +import com.adobe.flash.compiler.projects.ASDialect; +import com.adobe.flash.compiler.tree.as.IASNode; +import com.adobe.flash.compiler.workspaces.IWorkspace; + +/** + * + * @author ggv + */ +public class DebuggerUtil +{ + + /** + * + * @param code + * @param problems + * @return + */ + public static IASNode parseExpression(String code, List problems) + { + IWorkspace workspace = new Workspace(); + IASNode exprAST = FrontEnd.parseExpression(ASDialect.AS30, workspace, new StringReader(code), problems, null, new SourceLocation("", -1, -1, -1, -1)); + + // Have to create a fake ScopedBlockNode so the expression can do things + // like resolve, which means it has to be able to find a scope. + // For parsing an expression in a file, one would hook up the expression + // AST to whatever the real scope was. + ScopedBlockNode scopedNode = new ScopedBlockNode(); + scopedNode.addChild((NodeBase)exprAST); + scopedNode.setScope(new ASFileScope(workspace, "fake", ASDialect.AS30)); + scopedNode.runPostProcess(EnumSet.of(PostProcessStep.CALCULATE_OFFSETS)); + + return exprAST; + } + + + +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerValue.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerValue.java b/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerValue.java new file mode 100644 index 0000000..cd647bc --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/DebuggerValue.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package flash.tools.debugger.expression; + +public class DebuggerValue { + public Object debuggerValue; + + public DebuggerValue(Object v) + { + debuggerValue = v; + } +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/ECMA.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/ECMA.java b/modules/fdbworkers/src/flash/tools/debugger/expression/ECMA.java new file mode 100644 index 0000000..39c3308 --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/ECMA.java @@ -0,0 +1,430 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package flash.tools.debugger.expression; + +import flash.tools.debugger.Isolate; +import flash.tools.debugger.PlayerDebugException; +import flash.tools.debugger.Session; +import flash.tools.debugger.Value; +import flash.tools.debugger.VariableType; +import flash.tools.debugger.concrete.DValue; +import flash.tools.debugger.events.ExceptionFault; + +/** + * Implementations of some of the conversion functions defined by + * the ECMAScript spec ( http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf ). + * Please note, these conversion functions should not be considered to + * be 100% accurate; they handle all the cases the debugger's expression + * evaluator is likely to run into, but there are some edge cases that + * fall through the cracks. + * + * @author Mike Morearty + */ +public class ECMA +{ + /** Used by defaultValue() etc. */ + private enum PreferredType { NUMBER, STRING } + + /** + * ECMA 4.3.2 + */ + public static boolean isPrimitive(Value v) + { + v = safeValue(v, Isolate.DEFAULT_ID); + Object o = v.getValueAsObject(); + return (o == Value.UNDEFINED || o == null || o instanceof Boolean + || o instanceof Double || o instanceof String); + } + + private static Value callFunction(Session session, Value v, String functionName, Value[] args, int isolateId) + { + v = safeValue(v, isolateId); + + try + { + return session.getWorkerSession(isolateId).callFunction(v, functionName, args); + } + catch (PlayerDebugException e) + { + throw new ExpressionEvaluatorException(e); + } + } + + /** + * Calls the valueOf() function of an object. + */ + private static Value callValueOf(Session session, Value v, int isolateId) + { + v = safeValue(v, isolateId); + return callFunction(session, v, "valueOf", new Value[0], isolateId); //$NON-NLS-1$ + } + + /** + * Do not confuse this with toString()! toString() represents the official + * ECMA definition of [[ToString]], as defined in ECMA section 9.8. This + * function, on the other hand, represents calling the toString() function + * of an object. + */ + private static Value callToString(Session session, Value v, int isolateId) + { + v = safeValue(v, isolateId); + return callFunction(session, v, "toString", new Value[0], isolateId); //$NON-NLS-1$ + } + + /** + * ECMA 8.6.2.6 + * + * @param v + * @param optionalPreferredType + * either NUMBER, STRING, or null. + */ + public static Value defaultValue(Session session, Value v, + PreferredType optionalPreferredType, + int isolateId) + { + v = safeValue(v, isolateId); + String typename = v.getTypeName(); + int at = typename.indexOf('@'); + if (at != -1) + typename = typename.substring(0, at); + + if (optionalPreferredType == null) + { + if (typename.equals("Date")) //$NON-NLS-1$ + optionalPreferredType = PreferredType.STRING; + else + optionalPreferredType = PreferredType.NUMBER; + } + + if (optionalPreferredType == PreferredType.NUMBER) + { + Value result = callValueOf(session, v, isolateId); + if (isPrimitive(result)) + return result; + result = callToString(session, v, isolateId); + if (isPrimitive(result)) + return result; + throw new RuntimeException(new PlayerFaultException(new ExceptionFault(ASTBuilder.getLocalizationManager().getLocalizedTextString("typeError"), false, null, isolateId))); //$NON-NLS-1$ + } + else + { + Value result = callToString(session, v, isolateId); + if (isPrimitive(result)) + return result; + result = callValueOf(session, v, isolateId); + if (isPrimitive(result)) + return result; + throw new RuntimeException(new PlayerFaultException(new ExceptionFault(ASTBuilder.getLocalizationManager().getLocalizedTextString("typeError"), false, null, isolateId))); //$NON-NLS-1$ + } + } + + /** + * ECMA 9.1 + * + * @param v + * @param optionalPreferredType + * either NUMBER_TYPE, STRING_TYPE, or null. + * @return + */ + public static Value toPrimitive(Session session, Value v, + PreferredType optionalPreferredType, int isolateId) + { + v = safeValue(v, isolateId); + switch (v.getType()) + { + case VariableType.UNDEFINED: + case VariableType.NULL: + case VariableType.BOOLEAN: + case VariableType.NUMBER: + case VariableType.STRING: + return v; + + default: + return defaultValue(session, v, optionalPreferredType, isolateId); + } + } + + /** ECMA 9.2 */ + public static boolean toBoolean(Value v) + { + v = safeValue(v, Isolate.DEFAULT_ID); + switch (v.getType()) + { + case VariableType.UNDEFINED: + case VariableType.NULL: + return false; + case VariableType.BOOLEAN: + return ((Boolean) v.getValueAsObject()).booleanValue(); + case VariableType.NUMBER: + { + double d = ((Double) v.getValueAsObject()).doubleValue(); + if (d == 0 || Double.isNaN(d)) + { + return false; + } + else + { + return true; + } + } + case VariableType.STRING: + return ((String) v.getValueAsObject()).length() != 0; + default: + return true; + } + } + + /** ECMA 9.3 */ + public static double toNumber(Session session, Value v) + { + v = safeValue(v, Isolate.DEFAULT_ID); + switch (v.getType()) + { + case VariableType.UNDEFINED: + return Double.NaN; + case VariableType.NULL: + return 0; + case VariableType.BOOLEAN: + return ((Boolean) v.getValueAsObject()).booleanValue() ? 1 : 0; + case VariableType.NUMBER: + return ((Double) v.getValueAsObject()).doubleValue(); + case VariableType.STRING: + { + String s = (String) v.getValueAsObject(); + if (s.length() == 0) + { + return 0; + } + else + { + try + { + return Double.parseDouble(s); + } + catch (NumberFormatException e) + { + return Double.NaN; + } + } + } + default: + return toNumber(session, toPrimitive(session, v, PreferredType.NUMBER, v.getIsolateId())); + } + } + + private static final double _2pow31 = Math.pow(2, 31); + private static final double _2pow32 = Math.pow(2, 32); + + /** ECMA 9.5 */ + public static int toInt32(Session session, Value v) + { + v = safeValue(v, Isolate.DEFAULT_ID); + double d = toNumber(session, v); + if (d == Double.POSITIVE_INFINITY || d == Double.NEGATIVE_INFINITY) + { + return 0; + } + else + { + double sign = Math.signum(d); + d = Math.floor(Math.abs(d)); + d %= _2pow32; + while (d >= _2pow31) + d -= _2pow32; + return (int) (sign*d); + } + } + + /** ECMA 9.6 */ + public static long toUint32(Session session, Value v) + { + v = safeValue(v, Isolate.DEFAULT_ID); + long n = toInt32(session, v); + if (n < 0) + n = n + (long) 0x10000 * (long) 0x10000; + return n; + } + + /** ECMA 9.8 */ + public static String toString(Session session, Value v) + { + v = safeValue(v, Isolate.DEFAULT_ID); + switch (v.getType()) + { + case VariableType.UNDEFINED: + case VariableType.NULL: + case VariableType.BOOLEAN: + case VariableType.STRING: + return v.getValueAsString(); + case VariableType.NUMBER: + { + double d = ((Double) v.getValueAsObject()).doubleValue(); + if (d == (long) d) + { + return Long.toString((long) d); // avoid the ".0" on the end + } + else + { + return v.toString(); + } + } + default: + return toString(session, toPrimitive(session, v, PreferredType.STRING, v.getIsolateId())); + } + } + + /** ECMA 11.8.5. Returns true, false, or undefined. */ + public static Value lessThan(Session session, Value x, Value y) + { + x = safeValue(x, Isolate.DEFAULT_ID); + y = safeValue(y, Isolate.DEFAULT_ID); + Value px = toPrimitive(session, x, PreferredType.NUMBER, x.getIsolateId()); + Value py = toPrimitive(session, y, PreferredType.NUMBER, y.getIsolateId()); + if (px.getType() == VariableType.STRING + && py.getType() == VariableType.STRING) + { + String sx = px.getValueAsString(); + String sy = py.getValueAsString(); + return DValue.forPrimitive(new Boolean(sx.compareTo(sy) < 0), x.getIsolateId()); + } + else + { + double dx = toNumber(session, px); + double dy = toNumber(session, py); + if (Double.isNaN(dx) || Double.isNaN(dy)) + return DValue.forPrimitive(Value.UNDEFINED, x.getIsolateId()); + return DValue.forPrimitive(new Boolean(dx < dy), x.getIsolateId()); + } + } + + /** ECMA 11.9.3 */ + public static boolean equals(Session session, Value xv, Value yv) + { + xv = safeValue(xv, Isolate.DEFAULT_ID); + yv = safeValue(yv, Isolate.DEFAULT_ID); + + Object x = xv.getValueAsObject(); + Object y = yv.getValueAsObject(); + + if (xv.getType() == yv.getType()) + { + if (x == Value.UNDEFINED) + return true; + if (x == null) + return true; + if (x instanceof Double) + { + double dx = ((Double) x).doubleValue(); + double dy = ((Double) y).doubleValue(); + return dx == dy; + } + if (x instanceof String || x instanceof Boolean) + return x.equals(y); + + // see if they are the same object + if (xv.getId() != -1 || yv.getId() != -1) + return xv.getId() == yv.getId(); + return false; + } + else + { + if (x == null && y == Value.UNDEFINED) + return true; + if (x == Value.UNDEFINED && y == null) + return true; + if (x instanceof Double && y instanceof String) + { + double dx = ((Double) x).doubleValue(); + double dy = toNumber(session, yv); + return dx == dy; + } + if (x instanceof String && y instanceof Double) + { + double dx = toNumber(session, xv); + double dy = ((Double) y).doubleValue(); + return dx == dy; + } + if (x instanceof Boolean) + return equals(session, DValue.forPrimitive(new Double(toNumber(session, xv)), xv.getIsolateId()), yv); + if (y instanceof Boolean) + return equals(session, xv, DValue.forPrimitive(new Double(toNumber(session, yv)), xv.getIsolateId())); + if ((x instanceof String || x instanceof Double) && yv.getType() == VariableType.OBJECT) + { + return equals(session, xv, toPrimitive(session, yv, null, yv.getIsolateId())); + } + if (xv.getType() == VariableType.OBJECT && (y instanceof String || y instanceof Double)) + { + return equals(session, toPrimitive(session, xv, null, xv.getIsolateId()), yv); + } + return false; + } + } + + /** ECMA 11.9.6 */ + public static boolean strictEquals(Value xv, Value yv) + { + xv = safeValue(xv, Isolate.DEFAULT_ID); + yv = safeValue(yv, Isolate.DEFAULT_ID); + + Object x = xv.getValueAsObject(); + Object y = yv.getValueAsObject(); + + if (xv.getType() == yv.getType()) + { + if (x == Value.UNDEFINED) + return true; + if (x == null) + return true; + if (x instanceof Double) + { + double dx = ((Double) x).doubleValue(); + double dy = ((Double) y).doubleValue(); + return dx == dy; + } + if (x instanceof String || x instanceof Boolean) + return x.equals(y); + + // see if they are the same object + if (xv.getId() != -1 || yv.getId() != -1) + return xv.getId() == yv.getId(); + return false; + } + else + { + return false; + } + } + + /** + * Returns a "safe" (non-null) form of the specified Value -- that is, if + * the specified Value is null, returns a non-null Value that *represents* + * null. + * + * @param v + * any Value, possibly null + * @return a non-null Value + */ + public static Value safeValue(Value v, int isolateId) + { + if (v == null) + { + v = DValue.forPrimitive(null, isolateId); + assert v != null; + } + return v; + } +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/ExpressionEvaluatorException.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/ExpressionEvaluatorException.java b/modules/fdbworkers/src/flash/tools/debugger/expression/ExpressionEvaluatorException.java new file mode 100644 index 0000000..d10485d --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/ExpressionEvaluatorException.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package flash.tools.debugger.expression; + +/** + * An exception raised while evaluating an expression. This is a bit + * of a hack -- we need this to extend RuntimeException + * because the functions in the Evaluator interface don't + * throw anything, but our DebuggerEvaluator has many + * places where it needs to bail out. + * + * @author Mike Morearty + */ +public class ExpressionEvaluatorException extends RuntimeException { + private static final long serialVersionUID = -7005526599250035578L; + + public ExpressionEvaluatorException(String message) { + super(message); + } + + public ExpressionEvaluatorException(Throwable cause) { + super(cause); + } +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/FoldedExpressionNode.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/FoldedExpressionNode.java b/modules/fdbworkers/src/flash/tools/debugger/expression/FoldedExpressionNode.java new file mode 100644 index 0000000..31cb380 --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/FoldedExpressionNode.java @@ -0,0 +1,252 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package flash.tools.debugger.expression; + +import com.adobe.flash.compiler.filespecs.IFileSpecification; +import com.adobe.flash.compiler.internal.tree.as.ExpressionNodeBase; +import com.adobe.flash.compiler.tree.ASTNodeID; +import com.adobe.flash.compiler.tree.as.IASNode; +import com.adobe.flash.compiler.tree.as.IExpressionNode; +import com.adobe.flash.compiler.tree.as.IScopedNode; + +/** + * @author ggv + * + */ +public class FoldedExpressionNode extends ExpressionNodeBase implements + IExpressionNode { + + private final IASNode rootNode; + + /** + * + */ + public FoldedExpressionNode(IASNode rootNode) { + this.rootNode = rootNode; + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.common.ISourceLocation#getStart() + */ + @Override + public int getStart() { + return getUnderLyingNode().getStart(); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.common.ISourceLocation#getEnd() + */ + @Override + public int getEnd() { + return getUnderLyingNode().getEnd(); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.common.ISourceLocation#getLine() + */ + @Override + public int getLine() { + return getUnderLyingNode().getLine(); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.common.ISourceLocation#getColumn() + */ + @Override + public int getColumn() { + return 0; + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.common.ISourceLocation#getAbsoluteStart() + */ + @Override + public int getAbsoluteStart() { + return getUnderLyingNode().getAbsoluteStart(); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.common.ISourceLocation#getAbsoluteEnd() + */ + @Override + public int getAbsoluteEnd() { + return getUnderLyingNode().getAbsoluteEnd(); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.tree.as.IASNode#getNodeID() + */ + @Override + public ASTNodeID getNodeID() { + return ASTNodeID.FoldedExpressionID; + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.tree.as.IASNode#contains(int) + */ + @Override + public boolean contains(int offset) { + return getUnderLyingNode().contains(offset); + } + + /* + * (non-Javadoc) + * + * @see + * com.adobe.flash.compiler.tree.as.IASNode#getAncestorOfType(java.lang. + * Class) + */ + @Override + public IASNode getAncestorOfType(Class nodeType) { + return getUnderLyingNode().getAncestorOfType(nodeType); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.tree.as.IASNode#getChild(int) + */ + @Override + public IASNode getChild(int i) { + return null; + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.tree.as.IASNode#getChildCount() + */ + @Override + public int getChildCount() { + return 0; + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.tree.as.IASNode#getContainingNode(int) + */ + @Override + public IASNode getContainingNode(int offset) { + return getUnderLyingNode().getContainingNode(offset); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.tree.as.IASNode#getContainingScope() + */ + @Override + public IScopedNode getContainingScope() { + return getUnderLyingNode().getContainingScope(); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.tree.as.IASNode#getPackageName() + */ + @Override + public String getPackageName() { + return getUnderLyingNode().getPackageName(); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.tree.as.IASNode#getParent() + */ + @Override + public IASNode getParent() { + return getUnderLyingNode().getParent(); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.tree.as.IASNode#getFileSpecification() + */ + @Override + public IFileSpecification getFileSpecification() { + return getUnderLyingNode().getFileSpecification(); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.tree.as.IASNode#getSpanningStart() + */ + @Override + public int getSpanningStart() { + return getUnderLyingNode().getSpanningStart(); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.tree.as.IASNode#getSucceedingNode(int) + */ + @Override + public IASNode getSucceedingNode(int offset) { + return getUnderLyingNode().getSucceedingNode(offset); + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.tree.as.IASNode#isTerminal() + */ + @Override + public boolean isTerminal() { + return true; + } + + /** + * @return the rootNode + */ + public IASNode getUnderLyingNode() { + return rootNode; + } + + /* + * (non-Javadoc) + * + * @see com.adobe.flash.compiler.internal.tree.as.ExpressionNodeBase#copy() + */ + @Override + protected ExpressionNodeBase copy() { + return null; + } + +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/IASTBuilder.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/IASTBuilder.java b/modules/fdbworkers/src/flash/tools/debugger/expression/IASTBuilder.java new file mode 100644 index 0000000..ba4bb72 --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/IASTBuilder.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package flash.tools.debugger.expression; + +import java.io.IOException; +import java.io.Reader; +import java.text.ParseException; + +public interface IASTBuilder +{ + /** + * A parser that should do a fairly good job at + * parsing a general expression string. + * + * Exceptions: + * ParseException - a general parsing error occurred. + * + */ + public ValueExp parse(Reader in) throws IOException, ParseException; +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/IASTFolder.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/IASTFolder.java b/modules/fdbworkers/src/flash/tools/debugger/expression/IASTFolder.java new file mode 100644 index 0000000..462708b --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/IASTFolder.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package flash.tools.debugger.expression; + +import com.adobe.flash.compiler.tree.as.IASNode; + +/** + * @author ggv + * + */ +public interface IASTFolder { + + /** + * This will perform folding of certain nodes, based on implementation + * + * @param rootNode + * @return + */ + public IASNode fold(IASNode rootNode); + + /** + * Unfolds onlevel, if required will fold the children + * + * @param rootNode + * @return + */ + public IASNode unfoldOneLevel(FoldedExpressionNode rootNode); +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/IExpressionEvaluator.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/IExpressionEvaluator.java b/modules/fdbworkers/src/flash/tools/debugger/expression/IExpressionEvaluator.java new file mode 100644 index 0000000..47ef20a --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/IExpressionEvaluator.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package flash.tools.debugger.expression; + +import com.adobe.flash.compiler.tree.as.IASNode; + +/** + * @author ggv + * + */ +public interface IExpressionEvaluator { + + public abstract DebuggerValue evaluate(Context context, IASNode node) throws Exception; + +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/LogicalOperatorsFolder.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/LogicalOperatorsFolder.java b/modules/fdbworkers/src/flash/tools/debugger/expression/LogicalOperatorsFolder.java new file mode 100644 index 0000000..23555a2 --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/LogicalOperatorsFolder.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package flash.tools.debugger.expression; + +import com.adobe.flash.compiler.internal.tree.as.BinaryOperatorLogicalAndAssignmentNode; +import com.adobe.flash.compiler.internal.tree.as.BinaryOperatorLogicalAndNode; +import com.adobe.flash.compiler.internal.tree.as.BinaryOperatorLogicalOrAssignmentNode; +import com.adobe.flash.compiler.internal.tree.as.BinaryOperatorLogicalOrNode; +import com.adobe.flash.compiler.internal.tree.as.ExpressionNodeBase; +import com.adobe.flash.compiler.tree.as.IASNode; +import com.adobe.flash.compiler.tree.as.IExpressionNode; + +/** + * The logical operator's right hand operands are folded into + * FoldedExperessionNode, so that they are not evaluated by the burm. + * + * This is required for shortcircuit evaluation + * + * @author ggv + * + */ +public class LogicalOperatorsFolder implements IASTFolder { + + /* + * (non-Javadoc) + * + * @see + * flash.tools.debugger.expression.IASTFolder#fold(com.adobe.flash.compiler + * .tree.as.IASNode) + */ + @Override + public IASNode fold(IASNode rootNode) { + foldLazyRHSOperandsForLogicalOperators(rootNode); + return rootNode; + } + + /** + * @param node + */ + private void foldLazyRHSOperandsForLogicalOperators(IASNode node) { + + if (node instanceof BinaryOperatorLogicalAndNode + || node instanceof BinaryOperatorLogicalAndAssignmentNode) { + + BinaryOperatorLogicalAndNode opNode = ((BinaryOperatorLogicalAndNode) node); + opNode.setRightOperandNode(fold(opNode.getRightOperandNode())); + foldLazyRHSOperandsForLogicalOperators(opNode.getLeftOperandNode()); + + } else if (node instanceof BinaryOperatorLogicalOrNode + || node instanceof BinaryOperatorLogicalOrAssignmentNode) { + + BinaryOperatorLogicalOrNode opNode = ((BinaryOperatorLogicalOrNode) node); + opNode.setRightOperandNode(fold(opNode.getRightOperandNode())); + foldLazyRHSOperandsForLogicalOperators(opNode.getLeftOperandNode()); + + } else { + int chCount = node.getChildCount(); + for (int i = 0; i < chCount; i++) { + IASNode childNode = node.getChild(i); + foldLazyRHSOperandsForLogicalOperators(childNode); + } + } + } + + /** + * @param rightOperandNode + * @return + */ + private ExpressionNodeBase fold(IExpressionNode rightOperandNode) { + return new FoldedExpressionNode(rightOperandNode); + } + + /* + * (non-Javadoc) + * + * @see + * flash.tools.debugger.expression.IASTFolder#unfoldOneLevel(flash.tools + * .debugger.expression.FoldedExpressionNode) + */ + @Override + public IASNode unfoldOneLevel(FoldedExpressionNode foldedExpressionNode) { + IASNode node = foldedExpressionNode.getUnderLyingNode(); + fold(node); + return node; + } + +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/NoSuchVariableException.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/NoSuchVariableException.java b/modules/fdbworkers/src/flash/tools/debugger/expression/NoSuchVariableException.java new file mode 100644 index 0000000..05e69ca --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/NoSuchVariableException.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package flash.tools.debugger.expression; + +import java.util.HashMap; +import java.util.Map; + +/** + * Thrown when a variable name cannot be resolved in the current scope + */ +public class NoSuchVariableException extends Exception +{ + private static final long serialVersionUID = -400396588945206074L; + + public NoSuchVariableException(String s) { super(s); } + public NoSuchVariableException(Object o) { super(o.toString()); } + + @Override + public String getLocalizedMessage() + { + Map args = new HashMap(); + args.put("arg2", getMessage() ); //$NON-NLS-1$ + return ASTBuilder.getLocalizationManager().getLocalizedTextString("noSuchVariable", args); //$NON-NLS-1$ + } +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a3765ae5/modules/fdbworkers/src/flash/tools/debugger/expression/PlayerFaultException.java ---------------------------------------------------------------------- diff --git a/modules/fdbworkers/src/flash/tools/debugger/expression/PlayerFaultException.java b/modules/fdbworkers/src/flash/tools/debugger/expression/PlayerFaultException.java new file mode 100644 index 0000000..5cec3a1 --- /dev/null +++ b/modules/fdbworkers/src/flash/tools/debugger/expression/PlayerFaultException.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package flash.tools.debugger.expression; + +import flash.tools.debugger.events.FaultEvent; + +/** + * Thrown when the player generates a fault. For example, if + * an attempt to assign a value to a variable results in the player + * generating a fault because that value has no setter, or because + * the setter throws an exception for any other reason, then this + * exception will be generated. + */ +public class PlayerFaultException extends Exception { + private static final long serialVersionUID = 7754580337597815207L; + private FaultEvent m_event; + + public PlayerFaultException(FaultEvent event) + { + m_event = event; + } + + public FaultEvent getFaultEvent() + { + return m_event; + } + + @Override + public String getMessage() + { + return m_event.information; + } +}