@appthreat/atom 1.8.1 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/phpastgen.js +7 -1
- package/plugins/autoload.php +1 -1
- package/plugins/bin/atom +1 -1
- package/plugins/bin/atom.bat +1 -1
- package/plugins/composer/autoload_classmap.php +18 -18
- package/plugins/composer/autoload_real.php +4 -4
- package/plugins/composer/autoload_static.php +22 -22
- package/plugins/composer/installed.json +10 -12
- package/plugins/composer/installed.php +9 -9
- package/plugins/lib/io.appthreat.atom-1.8.2-classpath.jar +0 -0
- package/plugins/lib/{io.appthreat.atom-1.8.1.jar → io.appthreat.atom-1.8.2.jar} +0 -0
- package/plugins/lib/{io.appthreat.c2cpg_3-1.1.3.jar → io.appthreat.c2cpg_3-1.1.4.jar} +0 -0
- package/plugins/lib/{io.appthreat.dataflowengineoss_3-1.1.3.jar → io.appthreat.dataflowengineoss_3-1.1.4.jar} +0 -0
- package/plugins/lib/{io.appthreat.javasrc2cpg_3-1.1.3.jar → io.appthreat.javasrc2cpg_3-1.1.4.jar} +0 -0
- package/plugins/lib/{io.appthreat.jimple2cpg_3-1.1.3.jar → io.appthreat.jimple2cpg_3-1.1.4.jar} +0 -0
- package/plugins/lib/{io.appthreat.jssrc2cpg_3-1.1.3.jar → io.appthreat.jssrc2cpg_3-1.1.4.jar} +0 -0
- package/plugins/lib/{io.appthreat.php2atom_3-1.1.3.jar → io.appthreat.php2atom_3-1.1.4.jar} +0 -0
- package/plugins/lib/{io.appthreat.pysrc2cpg_3-1.1.3.jar → io.appthreat.pysrc2cpg_3-1.1.4.jar} +0 -0
- package/plugins/lib/{io.appthreat.semanticcpg_3-1.1.3.jar → io.appthreat.semanticcpg_3-1.1.4.jar} +0 -0
- package/plugins/lib/{io.appthreat.x2cpg_3-1.1.3.jar → io.appthreat.x2cpg_3-1.1.4.jar} +0 -0
- package/plugins/nikic/php-parser/README.md +12 -20
- package/plugins/nikic/php-parser/bin/php-parse +10 -11
- package/plugins/nikic/php-parser/composer.json +4 -6
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/ClassConst.php +15 -17
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/Class_.php +30 -35
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/Declaration.php +4 -11
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/EnumCase.php +7 -9
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/Enum_.php +27 -26
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/FunctionLike.php +7 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/Function_.php +7 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/Interface_.php +10 -11
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/Method.php +15 -16
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/Namespace_.php +5 -5
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/Param.php +35 -16
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/Property.php +19 -19
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/TraitUse.php +5 -6
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/TraitUseAdaptation.php +28 -25
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/Trait_.php +11 -16
- package/plugins/nikic/php-parser/lib/PhpParser/Builder/Use_.php +8 -8
- package/plugins/nikic/php-parser/lib/PhpParser/Builder.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/BuilderFactory.php +69 -45
- package/plugins/nikic/php-parser/lib/PhpParser/BuilderHelpers.php +19 -17
- package/plugins/nikic/php-parser/lib/PhpParser/Comment/Doc.php +2 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Comment.php +67 -35
- package/plugins/nikic/php-parser/lib/PhpParser/ConstExprEvaluationException.php +3 -3
- package/plugins/nikic/php-parser/lib/PhpParser/ConstExprEvaluator.php +10 -15
- package/plugins/nikic/php-parser/lib/PhpParser/Error.php +33 -24
- package/plugins/nikic/php-parser/lib/PhpParser/ErrorHandler/Collecting.php +9 -6
- package/plugins/nikic/php-parser/lib/PhpParser/ErrorHandler/Throwing.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/ErrorHandler.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Internal/DiffElem.php +7 -11
- package/plugins/nikic/php-parser/lib/PhpParser/Internal/Differ.php +22 -36
- package/plugins/nikic/php-parser/lib/PhpParser/Internal/PrintableNewAnonClassNode.php +13 -20
- package/plugins/nikic/php-parser/lib/PhpParser/Internal/TokenStream.php +70 -55
- package/plugins/nikic/php-parser/lib/PhpParser/JsonDecoder.php +10 -15
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/Emulative.php +93 -68
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php +18 -11
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/CoaleseEqualTokenEmulator.php +47 -0
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/EnumTokenEmulator.php +15 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ExplicitOctalEmulator.php +11 -12
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/FlexibleDocStringEmulator.php +76 -0
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/FnTokenEmulator.php +23 -0
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/KeywordEmulator.php +25 -19
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php +10 -6
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NullsafeTokenEmulator.php +29 -22
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NumericLiteralSeparatorEmulator.php +105 -0
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyFunctionTokenEmulator.php +3 -3
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyTokenEmulator.php +15 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php +5 -6
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php +5 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Lexer.php +513 -69
- package/plugins/nikic/php-parser/lib/PhpParser/NameContext.php +24 -23
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Arg.php +15 -13
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Attribute.php +10 -9
- package/plugins/nikic/php-parser/lib/PhpParser/Node/AttributeGroup.php +7 -5
- package/plugins/nikic/php-parser/lib/PhpParser/Node/ComplexType.php +2 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Const_.php +10 -9
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayDimFetch.php +11 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayItem.php +39 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Array_.php +11 -11
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ArrowFunction.php +28 -33
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Assign.php +10 -9
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/BitwiseAnd.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/BitwiseOr.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/BitwiseXor.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Coalesce.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Concat.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Div.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Minus.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Mod.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Mul.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Plus.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Pow.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/ShiftLeft.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/ShiftRight.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignRef.php +10 -9
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BitwiseAnd.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BitwiseOr.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BitwiseXor.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BooleanAnd.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BooleanOr.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Coalesce.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Concat.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Div.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Equal.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Greater.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/GreaterOrEqual.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Identical.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/LogicalAnd.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/LogicalOr.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/LogicalXor.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Minus.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Mod.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Mul.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/NotEqual.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/NotIdentical.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Plus.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Pow.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/ShiftLeft.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/ShiftRight.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Smaller.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/SmallerOrEqual.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Spaceship.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp.php +11 -8
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BitwiseNot.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BooleanNot.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/CallLike.php +7 -3
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Array_.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Bool_.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Double.php +6 -5
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Int_.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Object_.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/String_.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Unset_.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast.php +6 -5
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ClassConstFetch.php +10 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Clone_.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Closure.php +26 -33
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ClosureUse.php +32 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ConstFetch.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Empty_.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Error.php +6 -5
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ErrorSuppress.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Eval_.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Exit_.php +11 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/FuncCall.php +11 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Include_.php +14 -13
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Instanceof_.php +11 -11
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Isset_.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/List_.php +8 -12
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Match_.php +7 -8
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/MethodCall.php +12 -12
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/New_.php +11 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/NullsafeMethodCall.php +12 -12
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/NullsafePropertyFetch.php +10 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/PostDec.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/PostInc.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/PreDec.php +7 -6
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/PreInc.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Print_.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/PropertyFetch.php +10 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ShellExec.php +9 -9
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/StaticCall.php +13 -12
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/StaticPropertyFetch.php +11 -11
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Ternary.php +13 -12
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Throw_.php +7 -6
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/UnaryMinus.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/UnaryPlus.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Variable.php +7 -6
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/YieldFrom.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Yield_.php +11 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr.php +2 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/FunctionLike.php +8 -5
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Identifier.php +13 -13
- package/plugins/nikic/php-parser/lib/PhpParser/Node/IntersectionType.php +9 -6
- package/plugins/nikic/php-parser/lib/PhpParser/Node/MatchArm.php +9 -8
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Name/FullyQualified.php +9 -8
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Name/Relative.php +9 -8
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Name.php +56 -71
- package/plugins/nikic/php-parser/lib/PhpParser/Node/NullableType.php +10 -11
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Param.php +22 -46
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php +75 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/Encapsed.php +29 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/EncapsedStringPart.php +28 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/LNumber.php +78 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Class_.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Dir.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/File.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Function_.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Line.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Method.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Trait_.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/String_.php +26 -30
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar.php +2 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Break_.php +9 -8
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Case_.php +11 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Catch_.php +12 -11
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassConst.php +32 -24
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassLike.php +13 -13
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassMethod.php +54 -47
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Class_.php +89 -46
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Const_.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Continue_.php +9 -8
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/DeclareDeclare.php +32 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Declare_.php +12 -12
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Do_.php +10 -9
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Echo_.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/ElseIf_.php +10 -9
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Else_.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/EnumCase.php +12 -11
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Enum_.php +13 -17
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Expression.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Finally_.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/For_.php +15 -19
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Foreach_.php +17 -20
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Function_.php +24 -28
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Global_.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Goto_.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/GroupUse.php +14 -16
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/HaltCompiler.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/If_.php +15 -18
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/InlineHTML.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Interface_.php +10 -13
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Label.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Namespace_.php +12 -11
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Nop.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Property.php +37 -28
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/PropertyProperty.php +32 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Return_.php +9 -8
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/StaticVar.php +35 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Static_.php +8 -8
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Switch_.php +10 -9
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Throw_.php +30 -0
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUse.php +9 -8
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Alias.php +13 -12
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Precedence.php +10 -9
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation.php +4 -3
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Trait_.php +8 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/TryCatch.php +12 -11
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Unset_.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/UseUse.php +50 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Use_.php +16 -16
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/While_.php +10 -9
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt.php +2 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Node/UnionType.php +8 -7
- package/plugins/nikic/php-parser/lib/PhpParser/Node/VarLikeIdentifier.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node/VariadicPlaceholder.php +2 -2
- package/plugins/nikic/php-parser/lib/PhpParser/Node.php +29 -24
- package/plugins/nikic/php-parser/lib/PhpParser/NodeAbstract.php +20 -20
- package/plugins/nikic/php-parser/lib/PhpParser/NodeDumper.php +84 -168
- package/plugins/nikic/php-parser/lib/PhpParser/NodeFinder.php +19 -28
- package/plugins/nikic/php-parser/lib/PhpParser/NodeTraverser.php +84 -71
- package/plugins/nikic/php-parser/lib/PhpParser/NodeTraverserInterface.php +7 -4
- package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/CloningVisitor.php +2 -1
- package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/FindingVisitor.php +5 -4
- package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php +7 -6
- package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/NameResolver.php +28 -30
- package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php +3 -2
- package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php +11 -8
- package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor.php +7 -59
- package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitorAbstract.php +2 -1
- package/plugins/nikic/php-parser/lib/PhpParser/Parser/Multiple.php +55 -0
- package/plugins/nikic/php-parser/lib/PhpParser/Parser/Php5.php +2682 -0
- package/plugins/nikic/php-parser/lib/PhpParser/Parser/Php7.php +1522 -1323
- package/plugins/nikic/php-parser/lib/PhpParser/Parser/Tokens.php +148 -0
- package/plugins/nikic/php-parser/lib/PhpParser/Parser.php +3 -9
- package/plugins/nikic/php-parser/lib/PhpParser/ParserAbstract.php +252 -433
- package/plugins/nikic/php-parser/lib/PhpParser/ParserFactory.php +49 -15
- package/plugins/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php +335 -386
- package/plugins/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php +438 -517
- package/plugins/lib/io.appthreat.atom-1.8.1-classpath.jar +0 -0
- package/plugins/nikic/php-parser/.php-cs-fixer.dist.php +0 -31
- package/plugins/nikic/php-parser/Makefile +0 -10
- package/plugins/nikic/php-parser/lib/PhpParser/Internal/TokenPolyfill.php +0 -237
- package/plugins/nikic/php-parser/lib/PhpParser/Modifiers.php +0 -69
- package/plugins/nikic/php-parser/lib/PhpParser/Node/ArrayItem.php +0 -43
- package/plugins/nikic/php-parser/lib/PhpParser/Node/ClosureUse.php +0 -36
- package/plugins/nikic/php-parser/lib/PhpParser/Node/DeclareItem.php +0 -37
- package/plugins/nikic/php-parser/lib/PhpParser/Node/InterpolatedStringPart.php +0 -32
- package/plugins/nikic/php-parser/lib/PhpParser/Node/PropertyItem.php +0 -37
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/Float_.php +0 -78
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/Int_.php +0 -82
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/InterpolatedString.php +0 -34
- package/plugins/nikic/php-parser/lib/PhpParser/Node/StaticVar.php +0 -39
- package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Block.php +0 -29
- package/plugins/nikic/php-parser/lib/PhpParser/Node/UseItem.php +0 -55
- package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/CommentAnnotatingVisitor.php +0 -82
- package/plugins/nikic/php-parser/lib/PhpParser/Parser/Php8.php +0 -2717
- package/plugins/nikic/php-parser/lib/PhpParser/PhpVersion.php +0 -164
- package/plugins/nikic/php-parser/lib/PhpParser/PrettyPrinter.php +0 -51
- package/plugins/nikic/php-parser/lib/PhpParser/Token.php +0 -18
- package/plugins/nikic/php-parser/lib/PhpParser/compatibility_tokens.php +0 -56
- package/plugins/nikic/php-parser/phpstan-baseline.neon +0 -236
- package/plugins/nikic/php-parser/phpstan.neon.dist +0 -8
|
@@ -3,200 +3,162 @@
|
|
|
3
3
|
namespace PhpParser;
|
|
4
4
|
|
|
5
5
|
use PhpParser\Internal\DiffElem;
|
|
6
|
-
use PhpParser\Internal\Differ;
|
|
7
6
|
use PhpParser\Internal\PrintableNewAnonClassNode;
|
|
8
7
|
use PhpParser\Internal\TokenStream;
|
|
9
|
-
use PhpParser\Node\AttributeGroup;
|
|
10
8
|
use PhpParser\Node\Expr;
|
|
11
9
|
use PhpParser\Node\Expr\AssignOp;
|
|
12
10
|
use PhpParser\Node\Expr\BinaryOp;
|
|
13
11
|
use PhpParser\Node\Expr\Cast;
|
|
14
|
-
use PhpParser\Node\IntersectionType;
|
|
15
|
-
use PhpParser\Node\MatchArm;
|
|
16
|
-
use PhpParser\Node\Param;
|
|
17
12
|
use PhpParser\Node\Scalar;
|
|
18
13
|
use PhpParser\Node\Stmt;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Expr\
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Cast\
|
|
47
|
-
Cast\
|
|
48
|
-
Cast\
|
|
49
|
-
Cast\
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
BinaryOp\
|
|
57
|
-
BinaryOp\
|
|
58
|
-
BinaryOp\
|
|
59
|
-
BinaryOp\
|
|
60
|
-
BinaryOp\
|
|
61
|
-
BinaryOp\
|
|
62
|
-
BinaryOp\
|
|
63
|
-
BinaryOp\
|
|
64
|
-
BinaryOp\
|
|
65
|
-
BinaryOp\
|
|
66
|
-
BinaryOp\
|
|
67
|
-
BinaryOp\
|
|
68
|
-
BinaryOp\
|
|
69
|
-
BinaryOp\
|
|
70
|
-
BinaryOp\
|
|
71
|
-
BinaryOp\
|
|
72
|
-
BinaryOp\
|
|
73
|
-
BinaryOp\
|
|
74
|
-
BinaryOp\
|
|
75
|
-
BinaryOp\
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
Expr\
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
AssignOp\
|
|
83
|
-
AssignOp\
|
|
84
|
-
AssignOp\
|
|
85
|
-
AssignOp\
|
|
86
|
-
AssignOp\
|
|
87
|
-
AssignOp\
|
|
88
|
-
AssignOp\
|
|
89
|
-
AssignOp\
|
|
90
|
-
AssignOp\
|
|
91
|
-
AssignOp\
|
|
92
|
-
AssignOp\
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
BinaryOp\LogicalXor::class => [200, 201, 200],
|
|
100
|
-
BinaryOp\LogicalOr::class => [210, 211, 210],
|
|
101
|
-
Expr\Include_::class => [220, -1, -1],
|
|
102
|
-
Expr\ArrowFunction::class => [230, -1, -1],
|
|
103
|
-
Expr\Throw_::class => [240, -1, -1],
|
|
14
|
+
|
|
15
|
+
abstract class PrettyPrinterAbstract
|
|
16
|
+
{
|
|
17
|
+
const FIXUP_PREC_LEFT = 0; // LHS operand affected by precedence
|
|
18
|
+
const FIXUP_PREC_RIGHT = 1; // RHS operand affected by precedence
|
|
19
|
+
const FIXUP_CALL_LHS = 2; // LHS of call
|
|
20
|
+
const FIXUP_DEREF_LHS = 3; // LHS of dereferencing operation
|
|
21
|
+
const FIXUP_BRACED_NAME = 4; // Name operand that may require bracing
|
|
22
|
+
const FIXUP_VAR_BRACED_NAME = 5; // Name operand that may require ${} bracing
|
|
23
|
+
const FIXUP_ENCAPSED = 6; // Encapsed string part
|
|
24
|
+
const FIXUP_NEW = 7; // New/instanceof operand
|
|
25
|
+
const FIXUP_STATIC_DEREF_LHS = 8; // LHS of static dereferencing operation
|
|
26
|
+
|
|
27
|
+
protected $precedenceMap = [
|
|
28
|
+
// [precedence, associativity]
|
|
29
|
+
// where for precedence -1 is %left, 0 is %nonassoc and 1 is %right
|
|
30
|
+
BinaryOp\Pow::class => [ 0, 1],
|
|
31
|
+
Expr\BitwiseNot::class => [ 10, 1],
|
|
32
|
+
Expr\PreInc::class => [ 10, 1],
|
|
33
|
+
Expr\PreDec::class => [ 10, 1],
|
|
34
|
+
Expr\PostInc::class => [ 10, -1],
|
|
35
|
+
Expr\PostDec::class => [ 10, -1],
|
|
36
|
+
Expr\UnaryPlus::class => [ 10, 1],
|
|
37
|
+
Expr\UnaryMinus::class => [ 10, 1],
|
|
38
|
+
Cast\Int_::class => [ 10, 1],
|
|
39
|
+
Cast\Double::class => [ 10, 1],
|
|
40
|
+
Cast\String_::class => [ 10, 1],
|
|
41
|
+
Cast\Array_::class => [ 10, 1],
|
|
42
|
+
Cast\Object_::class => [ 10, 1],
|
|
43
|
+
Cast\Bool_::class => [ 10, 1],
|
|
44
|
+
Cast\Unset_::class => [ 10, 1],
|
|
45
|
+
Expr\ErrorSuppress::class => [ 10, 1],
|
|
46
|
+
Expr\Instanceof_::class => [ 20, 0],
|
|
47
|
+
Expr\BooleanNot::class => [ 30, 1],
|
|
48
|
+
BinaryOp\Mul::class => [ 40, -1],
|
|
49
|
+
BinaryOp\Div::class => [ 40, -1],
|
|
50
|
+
BinaryOp\Mod::class => [ 40, -1],
|
|
51
|
+
BinaryOp\Plus::class => [ 50, -1],
|
|
52
|
+
BinaryOp\Minus::class => [ 50, -1],
|
|
53
|
+
BinaryOp\Concat::class => [ 50, -1],
|
|
54
|
+
BinaryOp\ShiftLeft::class => [ 60, -1],
|
|
55
|
+
BinaryOp\ShiftRight::class => [ 60, -1],
|
|
56
|
+
BinaryOp\Smaller::class => [ 70, 0],
|
|
57
|
+
BinaryOp\SmallerOrEqual::class => [ 70, 0],
|
|
58
|
+
BinaryOp\Greater::class => [ 70, 0],
|
|
59
|
+
BinaryOp\GreaterOrEqual::class => [ 70, 0],
|
|
60
|
+
BinaryOp\Equal::class => [ 80, 0],
|
|
61
|
+
BinaryOp\NotEqual::class => [ 80, 0],
|
|
62
|
+
BinaryOp\Identical::class => [ 80, 0],
|
|
63
|
+
BinaryOp\NotIdentical::class => [ 80, 0],
|
|
64
|
+
BinaryOp\Spaceship::class => [ 80, 0],
|
|
65
|
+
BinaryOp\BitwiseAnd::class => [ 90, -1],
|
|
66
|
+
BinaryOp\BitwiseXor::class => [100, -1],
|
|
67
|
+
BinaryOp\BitwiseOr::class => [110, -1],
|
|
68
|
+
BinaryOp\BooleanAnd::class => [120, -1],
|
|
69
|
+
BinaryOp\BooleanOr::class => [130, -1],
|
|
70
|
+
BinaryOp\Coalesce::class => [140, 1],
|
|
71
|
+
Expr\Ternary::class => [150, 0],
|
|
72
|
+
// parser uses %left for assignments, but they really behave as %right
|
|
73
|
+
Expr\Assign::class => [160, 1],
|
|
74
|
+
Expr\AssignRef::class => [160, 1],
|
|
75
|
+
AssignOp\Plus::class => [160, 1],
|
|
76
|
+
AssignOp\Minus::class => [160, 1],
|
|
77
|
+
AssignOp\Mul::class => [160, 1],
|
|
78
|
+
AssignOp\Div::class => [160, 1],
|
|
79
|
+
AssignOp\Concat::class => [160, 1],
|
|
80
|
+
AssignOp\Mod::class => [160, 1],
|
|
81
|
+
AssignOp\BitwiseAnd::class => [160, 1],
|
|
82
|
+
AssignOp\BitwiseOr::class => [160, 1],
|
|
83
|
+
AssignOp\BitwiseXor::class => [160, 1],
|
|
84
|
+
AssignOp\ShiftLeft::class => [160, 1],
|
|
85
|
+
AssignOp\ShiftRight::class => [160, 1],
|
|
86
|
+
AssignOp\Pow::class => [160, 1],
|
|
87
|
+
AssignOp\Coalesce::class => [160, 1],
|
|
88
|
+
Expr\YieldFrom::class => [165, 1],
|
|
89
|
+
Expr\Print_::class => [168, 1],
|
|
90
|
+
BinaryOp\LogicalAnd::class => [170, -1],
|
|
91
|
+
BinaryOp\LogicalXor::class => [180, -1],
|
|
92
|
+
BinaryOp\LogicalOr::class => [190, -1],
|
|
93
|
+
Expr\Include_::class => [200, -1],
|
|
104
94
|
];
|
|
105
95
|
|
|
106
96
|
/** @var int Current indentation level. */
|
|
107
|
-
protected
|
|
108
|
-
/** @var string Newline style. Does not include current indentation. */
|
|
109
|
-
protected string $newline;
|
|
97
|
+
protected $indentLevel;
|
|
110
98
|
/** @var string Newline including current indentation. */
|
|
111
|
-
protected
|
|
112
|
-
/** @var string
|
|
113
|
-
|
|
114
|
-
protected ?string $docStringEndToken;
|
|
99
|
+
protected $nl;
|
|
100
|
+
/** @var string Token placed at end of doc string to ensure it is followed by a newline. */
|
|
101
|
+
protected $docStringEndToken;
|
|
115
102
|
/** @var bool Whether semicolon namespaces can be used (i.e. no global namespace is used) */
|
|
116
|
-
protected
|
|
117
|
-
/** @var
|
|
118
|
-
protected
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
/** @var
|
|
123
|
-
protected
|
|
124
|
-
/** @var
|
|
125
|
-
protected
|
|
126
|
-
/** @var array<string, bool> Map determining whether a certain character is a label character */
|
|
127
|
-
protected array $labelCharMap;
|
|
103
|
+
protected $canUseSemicolonNamespaces;
|
|
104
|
+
/** @var array Pretty printer options */
|
|
105
|
+
protected $options;
|
|
106
|
+
|
|
107
|
+
/** @var TokenStream Original tokens for use in format-preserving pretty print */
|
|
108
|
+
protected $origTokens;
|
|
109
|
+
/** @var Internal\Differ Differ for node lists */
|
|
110
|
+
protected $nodeListDiffer;
|
|
111
|
+
/** @var bool[] Map determining whether a certain character is a label character */
|
|
112
|
+
protected $labelCharMap;
|
|
128
113
|
/**
|
|
129
|
-
* @var
|
|
130
|
-
*
|
|
114
|
+
* @var int[][] Map from token classes and subnode names to FIXUP_* constants. This is used
|
|
115
|
+
* during format-preserving prints to place additional parens/braces if necessary.
|
|
131
116
|
*/
|
|
132
|
-
protected
|
|
117
|
+
protected $fixupMap;
|
|
133
118
|
/**
|
|
134
|
-
* @var
|
|
135
|
-
*
|
|
136
|
-
*
|
|
119
|
+
* @var int[][] Map from "{$node->getType()}->{$subNode}" to ['left' => $l, 'right' => $r],
|
|
120
|
+
* where $l and $r specify the token type that needs to be stripped when removing
|
|
121
|
+
* this node.
|
|
137
122
|
*/
|
|
138
|
-
protected
|
|
123
|
+
protected $removalMap;
|
|
139
124
|
/**
|
|
140
|
-
* @var
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* are optionally added before/after the main insertions.
|
|
125
|
+
* @var mixed[] Map from "{$node->getType()}->{$subNode}" to [$find, $beforeToken, $extraLeft, $extraRight].
|
|
126
|
+
* $find is an optional token after which the insertion occurs. $extraLeft/Right
|
|
127
|
+
* are optionally added before/after the main insertions.
|
|
144
128
|
*/
|
|
145
|
-
protected
|
|
129
|
+
protected $insertionMap;
|
|
146
130
|
/**
|
|
147
|
-
* @var
|
|
148
|
-
*
|
|
131
|
+
* @var string[] Map From "{$node->getType()}->{$subNode}" to string that should be inserted
|
|
132
|
+
* between elements of this list subnode.
|
|
149
133
|
*/
|
|
150
|
-
protected
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
*
|
|
154
|
-
|
|
155
|
-
protected array $emptyListInsertionMap;
|
|
156
|
-
/** @var array<string, array{string, int}> Map from "{$class}->{$subNode}" to [$printFn, $token]
|
|
157
|
-
* where $printFn is the function to print the modifiers and $token is the token before which
|
|
158
|
-
* the modifiers should be reprinted. */
|
|
159
|
-
protected array $modifierChangeMap;
|
|
134
|
+
protected $listInsertionMap;
|
|
135
|
+
protected $emptyListInsertionMap;
|
|
136
|
+
/** @var int[] Map from "{$node->getType()}->{$subNode}" to token before which the modifiers
|
|
137
|
+
* should be reprinted. */
|
|
138
|
+
protected $modifierChangeMap;
|
|
160
139
|
|
|
161
140
|
/**
|
|
162
141
|
* Creates a pretty printer instance using the given options.
|
|
163
142
|
*
|
|
164
143
|
* Supported options:
|
|
165
|
-
* *
|
|
166
|
-
*
|
|
167
|
-
* versions in cases where a simple stylistic choice exists (e.g.
|
|
168
|
-
* array() vs []). It is safe to pretty-print an AST for a newer
|
|
169
|
-
* PHP version while specifying an older target (but the result will
|
|
170
|
-
* of course not be compatible with the older version in that case).
|
|
171
|
-
* * string $newline: The newline style to use. Should be "\n" (default) or "\r\n".
|
|
172
|
-
* * bool $shortArraySyntax: Whether to use [] instead of array() as the default array
|
|
173
|
-
* syntax, if the node does not specify a format. Defaults to whether
|
|
174
|
-
* the phpVersion support short array syntax.
|
|
144
|
+
* * bool $shortArraySyntax = false: Whether to use [] instead of array() as the default array
|
|
145
|
+
* syntax, if the node does not specify a format.
|
|
175
146
|
*
|
|
176
|
-
* @param array
|
|
177
|
-
* phpVersion?: PhpVersion, newline?: string, shortArraySyntax?: bool
|
|
178
|
-
* } $options Dictionary of formatting options
|
|
147
|
+
* @param array $options Dictionary of formatting options
|
|
179
148
|
*/
|
|
180
149
|
public function __construct(array $options = []) {
|
|
181
|
-
$this->
|
|
150
|
+
$this->docStringEndToken = '_DOC_STRING_END_' . mt_rand();
|
|
182
151
|
|
|
183
|
-
$
|
|
184
|
-
|
|
185
|
-
throw new \LogicException('Option "newline" must be one of "\n" or "\r\n"');
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
$this->shortArraySyntax =
|
|
189
|
-
$options['shortArraySyntax'] ?? $this->phpVersion->supportsShortArraySyntax();
|
|
190
|
-
$this->docStringEndToken =
|
|
191
|
-
$this->phpVersion->supportsFlexibleHeredoc() ? null : '_DOC_STRING_END_' . mt_rand();
|
|
152
|
+
$defaultOptions = ['shortArraySyntax' => false];
|
|
153
|
+
$this->options = $options + $defaultOptions;
|
|
192
154
|
}
|
|
193
155
|
|
|
194
156
|
/**
|
|
195
157
|
* Reset pretty printing state.
|
|
196
158
|
*/
|
|
197
|
-
protected function resetState()
|
|
159
|
+
protected function resetState() {
|
|
198
160
|
$this->indentLevel = 0;
|
|
199
|
-
$this->nl =
|
|
161
|
+
$this->nl = "\n";
|
|
200
162
|
$this->origTokens = null;
|
|
201
163
|
}
|
|
202
164
|
|
|
@@ -205,15 +167,15 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
205
167
|
*
|
|
206
168
|
* @param int $level Level in number of spaces
|
|
207
169
|
*/
|
|
208
|
-
protected function setIndentLevel(int $level)
|
|
170
|
+
protected function setIndentLevel(int $level) {
|
|
209
171
|
$this->indentLevel = $level;
|
|
210
|
-
$this->nl =
|
|
172
|
+
$this->nl = "\n" . \str_repeat(' ', $level);
|
|
211
173
|
}
|
|
212
174
|
|
|
213
175
|
/**
|
|
214
176
|
* Increase indentation level.
|
|
215
177
|
*/
|
|
216
|
-
protected function indent()
|
|
178
|
+
protected function indent() {
|
|
217
179
|
$this->indentLevel += 4;
|
|
218
180
|
$this->nl .= ' ';
|
|
219
181
|
}
|
|
@@ -221,10 +183,10 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
221
183
|
/**
|
|
222
184
|
* Decrease indentation level.
|
|
223
185
|
*/
|
|
224
|
-
protected function outdent()
|
|
186
|
+
protected function outdent() {
|
|
225
187
|
assert($this->indentLevel >= 4);
|
|
226
188
|
$this->indentLevel -= 4;
|
|
227
|
-
$this->nl =
|
|
189
|
+
$this->nl = "\n" . str_repeat(' ', $this->indentLevel);
|
|
228
190
|
}
|
|
229
191
|
|
|
230
192
|
/**
|
|
@@ -234,7 +196,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
234
196
|
*
|
|
235
197
|
* @return string Pretty printed statements
|
|
236
198
|
*/
|
|
237
|
-
public function prettyPrint(array $stmts): string {
|
|
199
|
+
public function prettyPrint(array $stmts) : string {
|
|
238
200
|
$this->resetState();
|
|
239
201
|
$this->preprocessNodes($stmts);
|
|
240
202
|
|
|
@@ -248,7 +210,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
248
210
|
*
|
|
249
211
|
* @return string Pretty printed node
|
|
250
212
|
*/
|
|
251
|
-
public function prettyPrintExpr(Expr $node): string {
|
|
213
|
+
public function prettyPrintExpr(Expr $node) : string {
|
|
252
214
|
$this->resetState();
|
|
253
215
|
return $this->handleMagicTokens($this->p($node));
|
|
254
216
|
}
|
|
@@ -260,15 +222,15 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
260
222
|
*
|
|
261
223
|
* @return string Pretty printed statements
|
|
262
224
|
*/
|
|
263
|
-
public function prettyPrintFile(array $stmts): string {
|
|
225
|
+
public function prettyPrintFile(array $stmts) : string {
|
|
264
226
|
if (!$stmts) {
|
|
265
|
-
return "<?php"
|
|
227
|
+
return "<?php\n\n";
|
|
266
228
|
}
|
|
267
229
|
|
|
268
|
-
$p = "<?php" . $this->
|
|
230
|
+
$p = "<?php\n\n" . $this->prettyPrint($stmts);
|
|
269
231
|
|
|
270
232
|
if ($stmts[0] instanceof Stmt\InlineHTML) {
|
|
271
|
-
$p = preg_replace('/^<\?php\s+\?>\
|
|
233
|
+
$p = preg_replace('/^<\?php\s+\?>\n?/', '', $p);
|
|
272
234
|
}
|
|
273
235
|
if ($stmts[count($stmts) - 1] instanceof Stmt\InlineHTML) {
|
|
274
236
|
$p = preg_replace('/<\?php$/', '', rtrim($p));
|
|
@@ -282,7 +244,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
282
244
|
*
|
|
283
245
|
* @param Node[] $nodes Array of nodes
|
|
284
246
|
*/
|
|
285
|
-
protected function preprocessNodes(array $nodes)
|
|
247
|
+
protected function preprocessNodes(array $nodes) {
|
|
286
248
|
/* We can use semicolon-namespaces unless there is a global namespace declaration */
|
|
287
249
|
$this->canUseSemicolonNamespaces = true;
|
|
288
250
|
foreach ($nodes as $node) {
|
|
@@ -294,17 +256,15 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
294
256
|
}
|
|
295
257
|
|
|
296
258
|
/**
|
|
297
|
-
* Handles (and removes) doc-string-end tokens.
|
|
259
|
+
* Handles (and removes) no-indent and doc-string-end tokens.
|
|
260
|
+
*
|
|
261
|
+
* @param string $str
|
|
262
|
+
* @return string
|
|
298
263
|
*/
|
|
299
|
-
protected function handleMagicTokens(string $str): string {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
$this->docStringEndToken . ';' . $this->newline,
|
|
304
|
-
';' . $this->newline,
|
|
305
|
-
$str);
|
|
306
|
-
$str = str_replace($this->docStringEndToken, $this->newline, $str);
|
|
307
|
-
}
|
|
264
|
+
protected function handleMagicTokens(string $str) : string {
|
|
265
|
+
// Replace doc-string-end tokens with nothing or a newline
|
|
266
|
+
$str = str_replace($this->docStringEndToken . ";\n", ";\n", $str);
|
|
267
|
+
$str = str_replace($this->docStringEndToken, "\n", $str);
|
|
308
268
|
|
|
309
269
|
return $str;
|
|
310
270
|
}
|
|
@@ -312,12 +272,12 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
312
272
|
/**
|
|
313
273
|
* Pretty prints an array of nodes (statements) and indents them optionally.
|
|
314
274
|
*
|
|
315
|
-
* @param Node[] $nodes
|
|
316
|
-
* @param bool
|
|
275
|
+
* @param Node[] $nodes Array of nodes
|
|
276
|
+
* @param bool $indent Whether to indent the printed nodes
|
|
317
277
|
*
|
|
318
278
|
* @return string Pretty printed statements
|
|
319
279
|
*/
|
|
320
|
-
protected function pStmts(array $nodes, bool $indent = true): string {
|
|
280
|
+
protected function pStmts(array $nodes, bool $indent = true) : string {
|
|
321
281
|
if ($indent) {
|
|
322
282
|
$this->indent();
|
|
323
283
|
}
|
|
@@ -345,96 +305,84 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
345
305
|
/**
|
|
346
306
|
* Pretty-print an infix operation while taking precedence into account.
|
|
347
307
|
*
|
|
348
|
-
* @param string $class
|
|
349
|
-
* @param Node
|
|
308
|
+
* @param string $class Node class of operator
|
|
309
|
+
* @param Node $leftNode Left-hand side node
|
|
350
310
|
* @param string $operatorString String representation of the operator
|
|
351
|
-
* @param Node
|
|
352
|
-
* @param int $precedence Precedence of parent operator
|
|
353
|
-
* @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator
|
|
311
|
+
* @param Node $rightNode Right-hand side node
|
|
354
312
|
*
|
|
355
313
|
* @return string Pretty printed infix operation
|
|
356
314
|
*/
|
|
357
|
-
protected function pInfixOp(
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
$suffix = '';
|
|
364
|
-
if ($opPrecedence >= $precedence) {
|
|
365
|
-
$prefix = '(';
|
|
366
|
-
$suffix = ')';
|
|
367
|
-
$lhsPrecedence = self::MAX_PRECEDENCE;
|
|
368
|
-
}
|
|
369
|
-
return $prefix . $this->p($leftNode, $newPrecedenceLHS, $newPrecedenceLHS)
|
|
370
|
-
. $operatorString . $this->p($rightNode, $newPrecedenceRHS, $lhsPrecedence) . $suffix;
|
|
315
|
+
protected function pInfixOp(string $class, Node $leftNode, string $operatorString, Node $rightNode) : string {
|
|
316
|
+
list($precedence, $associativity) = $this->precedenceMap[$class];
|
|
317
|
+
|
|
318
|
+
return $this->pPrec($leftNode, $precedence, $associativity, -1)
|
|
319
|
+
. $operatorString
|
|
320
|
+
. $this->pPrec($rightNode, $precedence, $associativity, 1);
|
|
371
321
|
}
|
|
372
322
|
|
|
373
323
|
/**
|
|
374
324
|
* Pretty-print a prefix operation while taking precedence into account.
|
|
375
325
|
*
|
|
376
|
-
* @param string $class
|
|
326
|
+
* @param string $class Node class of operator
|
|
377
327
|
* @param string $operatorString String representation of the operator
|
|
378
|
-
* @param Node
|
|
379
|
-
* @param int $precedence Precedence of parent operator
|
|
380
|
-
* @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator
|
|
328
|
+
* @param Node $node Node
|
|
381
329
|
*
|
|
382
330
|
* @return string Pretty printed prefix operation
|
|
383
331
|
*/
|
|
384
|
-
protected function pPrefixOp(string $class, string $operatorString, Node $node
|
|
385
|
-
$
|
|
386
|
-
$
|
|
387
|
-
$suffix = '';
|
|
388
|
-
if ($opPrecedence >= $lhsPrecedence) {
|
|
389
|
-
$prefix = '(';
|
|
390
|
-
$suffix = ')';
|
|
391
|
-
$lhsPrecedence = self::MAX_PRECEDENCE;
|
|
392
|
-
}
|
|
393
|
-
$printedArg = $this->p($node, $opPrecedence, $lhsPrecedence);
|
|
394
|
-
if (($operatorString === '+' && $printedArg[0] === '+') ||
|
|
395
|
-
($operatorString === '-' && $printedArg[0] === '-')
|
|
396
|
-
) {
|
|
397
|
-
// Avoid printing +(+$a) as ++$a and similar.
|
|
398
|
-
$printedArg = '(' . $printedArg . ')';
|
|
399
|
-
}
|
|
400
|
-
return $prefix . $operatorString . $printedArg . $suffix;
|
|
332
|
+
protected function pPrefixOp(string $class, string $operatorString, Node $node) : string {
|
|
333
|
+
list($precedence, $associativity) = $this->precedenceMap[$class];
|
|
334
|
+
return $operatorString . $this->pPrec($node, $precedence, $associativity, 1);
|
|
401
335
|
}
|
|
402
336
|
|
|
403
337
|
/**
|
|
404
338
|
* Pretty-print a postfix operation while taking precedence into account.
|
|
405
339
|
*
|
|
406
|
-
* @param string $class
|
|
340
|
+
* @param string $class Node class of operator
|
|
407
341
|
* @param string $operatorString String representation of the operator
|
|
408
|
-
* @param Node
|
|
409
|
-
* @param int $precedence Precedence of parent operator
|
|
410
|
-
* @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator
|
|
342
|
+
* @param Node $node Node
|
|
411
343
|
*
|
|
412
344
|
* @return string Pretty printed postfix operation
|
|
413
345
|
*/
|
|
414
|
-
protected function pPostfixOp(string $class, Node $node, string $operatorString
|
|
415
|
-
$
|
|
416
|
-
$
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
346
|
+
protected function pPostfixOp(string $class, Node $node, string $operatorString) : string {
|
|
347
|
+
list($precedence, $associativity) = $this->precedenceMap[$class];
|
|
348
|
+
return $this->pPrec($node, $precedence, $associativity, -1) . $operatorString;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Prints an expression node with the least amount of parentheses necessary to preserve the meaning.
|
|
353
|
+
*
|
|
354
|
+
* @param Node $node Node to pretty print
|
|
355
|
+
* @param int $parentPrecedence Precedence of the parent operator
|
|
356
|
+
* @param int $parentAssociativity Associativity of parent operator
|
|
357
|
+
* (-1 is left, 0 is nonassoc, 1 is right)
|
|
358
|
+
* @param int $childPosition Position of the node relative to the operator
|
|
359
|
+
* (-1 is left, 1 is right)
|
|
360
|
+
*
|
|
361
|
+
* @return string The pretty printed node
|
|
362
|
+
*/
|
|
363
|
+
protected function pPrec(Node $node, int $parentPrecedence, int $parentAssociativity, int $childPosition) : string {
|
|
364
|
+
$class = \get_class($node);
|
|
365
|
+
if (isset($this->precedenceMap[$class])) {
|
|
366
|
+
$childPrecedence = $this->precedenceMap[$class][0];
|
|
367
|
+
if ($childPrecedence > $parentPrecedence
|
|
368
|
+
|| ($parentPrecedence === $childPrecedence && $parentAssociativity !== $childPosition)
|
|
369
|
+
) {
|
|
370
|
+
return '(' . $this->p($node) . ')';
|
|
371
|
+
}
|
|
425
372
|
}
|
|
426
|
-
|
|
373
|
+
|
|
374
|
+
return $this->p($node);
|
|
427
375
|
}
|
|
428
376
|
|
|
429
377
|
/**
|
|
430
378
|
* Pretty prints an array of nodes and implodes the printed values.
|
|
431
379
|
*
|
|
432
380
|
* @param Node[] $nodes Array of Nodes to be printed
|
|
433
|
-
* @param string $glue
|
|
381
|
+
* @param string $glue Character to implode with
|
|
434
382
|
*
|
|
435
|
-
* @return string Imploded pretty printed nodes
|
|
383
|
+
* @return string Imploded pretty printed nodes
|
|
436
384
|
*/
|
|
437
|
-
protected function pImplode(array $nodes, string $glue = ''): string {
|
|
385
|
+
protected function pImplode(array $nodes, string $glue = '') : string {
|
|
438
386
|
$pNodes = [];
|
|
439
387
|
foreach ($nodes as $node) {
|
|
440
388
|
if (null === $node) {
|
|
@@ -454,7 +402,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
454
402
|
*
|
|
455
403
|
* @return string Comma separated pretty printed nodes
|
|
456
404
|
*/
|
|
457
|
-
protected function pCommaSeparated(array $nodes): string {
|
|
405
|
+
protected function pCommaSeparated(array $nodes) : string {
|
|
458
406
|
return $this->pImplode($nodes, ', ');
|
|
459
407
|
}
|
|
460
408
|
|
|
@@ -463,12 +411,12 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
463
411
|
*
|
|
464
412
|
* The result includes a leading newline and one level of indentation (same as pStmts).
|
|
465
413
|
*
|
|
466
|
-
* @param Node[] $nodes
|
|
467
|
-
* @param bool
|
|
414
|
+
* @param Node[] $nodes Array of Nodes to be printed
|
|
415
|
+
* @param bool $trailingComma Whether to use a trailing comma
|
|
468
416
|
*
|
|
469
417
|
* @return string Comma separated pretty printed nodes in multiline style
|
|
470
418
|
*/
|
|
471
|
-
protected function pCommaSeparatedMultiline(array $nodes, bool $trailingComma): string {
|
|
419
|
+
protected function pCommaSeparatedMultiline(array $nodes, bool $trailingComma) : string {
|
|
472
420
|
$this->indent();
|
|
473
421
|
|
|
474
422
|
$result = '';
|
|
@@ -500,7 +448,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
500
448
|
*
|
|
501
449
|
* @return string Reformatted text of comments
|
|
502
450
|
*/
|
|
503
|
-
protected function pComments(array $comments): string {
|
|
451
|
+
protected function pComments(array $comments) : string {
|
|
504
452
|
$formattedComments = [];
|
|
505
453
|
|
|
506
454
|
foreach ($comments as $comment) {
|
|
@@ -521,11 +469,13 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
521
469
|
* * The CloningVisitor must be run on the AST prior to modification.
|
|
522
470
|
* * The original tokens must be provided, using the getTokens() method on the lexer.
|
|
523
471
|
*
|
|
524
|
-
* @param Node[] $stmts
|
|
525
|
-
* @param Node[] $origStmts
|
|
526
|
-
* @param
|
|
472
|
+
* @param Node[] $stmts Modified AST with links to original AST
|
|
473
|
+
* @param Node[] $origStmts Original AST with token offset information
|
|
474
|
+
* @param array $origTokens Tokens of the original code
|
|
475
|
+
*
|
|
476
|
+
* @return string
|
|
527
477
|
*/
|
|
528
|
-
public function printFormatPreserving(array $stmts, array $origStmts, array $origTokens): string {
|
|
478
|
+
public function printFormatPreserving(array $stmts, array $origStmts, array $origTokens) : string {
|
|
529
479
|
$this->initializeNodeListDiffer();
|
|
530
480
|
$this->initializeLabelCharMap();
|
|
531
481
|
$this->initializeFixupMap();
|
|
@@ -543,18 +493,18 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
543
493
|
$pos = 0;
|
|
544
494
|
$result = $this->pArray($stmts, $origStmts, $pos, 0, 'File', 'stmts', null);
|
|
545
495
|
if (null !== $result) {
|
|
546
|
-
$result .= $this->origTokens->getTokenCode($pos, count($origTokens)
|
|
496
|
+
$result .= $this->origTokens->getTokenCode($pos, count($origTokens), 0);
|
|
547
497
|
} else {
|
|
548
498
|
// Fallback
|
|
549
499
|
// TODO Add <?php properly
|
|
550
|
-
$result = "<?php" . $this->
|
|
500
|
+
$result = "<?php\n" . $this->pStmts($stmts, false);
|
|
551
501
|
}
|
|
552
502
|
|
|
553
|
-
return $this->handleMagicTokens($result);
|
|
503
|
+
return ltrim($this->handleMagicTokens($result));
|
|
554
504
|
}
|
|
555
505
|
|
|
556
|
-
protected function pFallback(Node $node
|
|
557
|
-
return $this->{'p' . $node->getType()}($node
|
|
506
|
+
protected function pFallback(Node $node) {
|
|
507
|
+
return $this->{'p' . $node->getType()}($node);
|
|
558
508
|
}
|
|
559
509
|
|
|
560
510
|
/**
|
|
@@ -563,25 +513,20 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
563
513
|
* This method also handles formatting preservation for nodes.
|
|
564
514
|
*
|
|
565
515
|
* @param Node $node Node to be pretty printed
|
|
566
|
-
* @param int $precedence Precedence of parent operator
|
|
567
|
-
* @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator
|
|
568
516
|
* @param bool $parentFormatPreserved Whether parent node has preserved formatting
|
|
569
517
|
*
|
|
570
518
|
* @return string Pretty printed node
|
|
571
519
|
*/
|
|
572
|
-
protected function p(
|
|
573
|
-
Node $node, int $precedence = self::MAX_PRECEDENCE, int $lhsPrecedence = self::MAX_PRECEDENCE,
|
|
574
|
-
bool $parentFormatPreserved = false
|
|
575
|
-
): string {
|
|
520
|
+
protected function p(Node $node, $parentFormatPreserved = false) : string {
|
|
576
521
|
// No orig tokens means this is a normal pretty print without preservation of formatting
|
|
577
522
|
if (!$this->origTokens) {
|
|
578
|
-
return $this->{'p' . $node->getType()}($node
|
|
523
|
+
return $this->{'p' . $node->getType()}($node);
|
|
579
524
|
}
|
|
580
525
|
|
|
581
|
-
/** @var Node
|
|
526
|
+
/** @var Node $origNode */
|
|
582
527
|
$origNode = $node->getAttribute('origNode');
|
|
583
528
|
if (null === $origNode) {
|
|
584
|
-
return $this->pFallback($node
|
|
529
|
+
return $this->pFallback($node);
|
|
585
530
|
}
|
|
586
531
|
|
|
587
532
|
$class = \get_class($node);
|
|
@@ -594,17 +539,15 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
594
539
|
$fallbackNode = $node;
|
|
595
540
|
if ($node instanceof Expr\New_ && $node->class instanceof Stmt\Class_) {
|
|
596
541
|
// Normalize node structure of anonymous classes
|
|
597
|
-
assert($origNode instanceof Expr\New_);
|
|
598
542
|
$node = PrintableNewAnonClassNode::fromNewNode($node);
|
|
599
543
|
$origNode = PrintableNewAnonClassNode::fromNewNode($origNode);
|
|
600
|
-
$class = PrintableNewAnonClassNode::class;
|
|
601
544
|
}
|
|
602
545
|
|
|
603
546
|
// InlineHTML node does not contain closing and opening PHP tags. If the parent formatting
|
|
604
547
|
// is not preserved, then we need to use the fallback code to make sure the tags are
|
|
605
548
|
// printed.
|
|
606
549
|
if ($node instanceof Stmt\InlineHTML && !$parentFormatPreserved) {
|
|
607
|
-
return $this->pFallback($fallbackNode
|
|
550
|
+
return $this->pFallback($fallbackNode);
|
|
608
551
|
}
|
|
609
552
|
|
|
610
553
|
$indentAdjustment = $this->indentLevel - $this->origTokens->getIndentationBefore($startPos);
|
|
@@ -629,27 +572,34 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
629
572
|
if (is_array($subNode) && is_array($origSubNode)) {
|
|
630
573
|
// Array subnode changed, we might be able to reconstruct it
|
|
631
574
|
$listResult = $this->pArray(
|
|
632
|
-
$subNode, $origSubNode, $pos, $indentAdjustment, $
|
|
575
|
+
$subNode, $origSubNode, $pos, $indentAdjustment, $type, $subNodeName,
|
|
633
576
|
$fixupInfo[$subNodeName] ?? null
|
|
634
577
|
);
|
|
635
578
|
if (null === $listResult) {
|
|
636
|
-
return $this->pFallback($fallbackNode
|
|
579
|
+
return $this->pFallback($fallbackNode);
|
|
637
580
|
}
|
|
638
581
|
|
|
639
582
|
$result .= $listResult;
|
|
640
583
|
continue;
|
|
641
584
|
}
|
|
642
585
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
586
|
+
if (is_int($subNode) && is_int($origSubNode)) {
|
|
587
|
+
// Check if this is a modifier change
|
|
588
|
+
$key = $type . '->' . $subNodeName;
|
|
589
|
+
if (!isset($this->modifierChangeMap[$key])) {
|
|
590
|
+
return $this->pFallback($fallbackNode);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
$findToken = $this->modifierChangeMap[$key];
|
|
594
|
+
$result .= $this->pModifiers($subNode);
|
|
595
|
+
$pos = $this->origTokens->findRight($pos, $findToken);
|
|
596
|
+
continue;
|
|
647
597
|
}
|
|
648
598
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
599
|
+
// If a non-node, non-array subnode changed, we don't be able to do a partial
|
|
600
|
+
// reconstructions, as we don't have enough offset information. Pretty print the
|
|
601
|
+
// whole node instead.
|
|
602
|
+
return $this->pFallback($fallbackNode);
|
|
653
603
|
}
|
|
654
604
|
|
|
655
605
|
$extraLeft = '';
|
|
@@ -667,7 +617,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
667
617
|
// A node has been inserted, check if we have insertion information for it
|
|
668
618
|
$key = $type . '->' . $subNodeName;
|
|
669
619
|
if (!isset($this->insertionMap[$key])) {
|
|
670
|
-
return $this->pFallback($fallbackNode
|
|
620
|
+
return $this->pFallback($fallbackNode);
|
|
671
621
|
}
|
|
672
622
|
|
|
673
623
|
list($findToken, $beforeToken, $extraLeft, $extraRight) = $this->insertionMap[$key];
|
|
@@ -689,7 +639,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
689
639
|
// A node has been removed, check if we have removal information for it
|
|
690
640
|
$key = $type . '->' . $subNodeName;
|
|
691
641
|
if (!isset($this->removalMap[$key])) {
|
|
692
|
-
return $this->pFallback($fallbackNode
|
|
642
|
+
return $this->pFallback($fallbackNode);
|
|
693
643
|
}
|
|
694
644
|
|
|
695
645
|
// Adjust positions to account for additional tokens that must be skipped
|
|
@@ -719,7 +669,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
719
669
|
$fixup = $fixupInfo[$subNodeName];
|
|
720
670
|
$res = $this->pFixup($fixup, $subNode, $class, $subStartPos, $subEndPos);
|
|
721
671
|
} else {
|
|
722
|
-
$res = $this->p($subNode,
|
|
672
|
+
$res = $this->p($subNode, true);
|
|
723
673
|
}
|
|
724
674
|
|
|
725
675
|
$this->safeAppend($result, $res);
|
|
@@ -738,23 +688,23 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
738
688
|
/**
|
|
739
689
|
* Perform a format-preserving pretty print of an array.
|
|
740
690
|
*
|
|
741
|
-
* @param
|
|
742
|
-
* @param
|
|
743
|
-
* @param int
|
|
744
|
-
* @param int
|
|
745
|
-
* @param string
|
|
746
|
-
* @param string
|
|
747
|
-
* @param null|int
|
|
691
|
+
* @param array $nodes New nodes
|
|
692
|
+
* @param array $origNodes Original nodes
|
|
693
|
+
* @param int $pos Current token position (updated by reference)
|
|
694
|
+
* @param int $indentAdjustment Adjustment for indentation
|
|
695
|
+
* @param string $parentNodeType Type of the containing node.
|
|
696
|
+
* @param string $subNodeName Name of array subnode.
|
|
697
|
+
* @param null|int $fixup Fixup information for array item nodes
|
|
748
698
|
*
|
|
749
699
|
* @return null|string Result of pretty print or null if cannot preserve formatting
|
|
750
700
|
*/
|
|
751
701
|
protected function pArray(
|
|
752
|
-
array
|
|
753
|
-
string $
|
|
754
|
-
)
|
|
702
|
+
array $nodes, array $origNodes, int &$pos, int $indentAdjustment,
|
|
703
|
+
string $parentNodeType, string $subNodeName, $fixup
|
|
704
|
+
) {
|
|
755
705
|
$diff = $this->nodeListDiffer->diffWithReplacements($origNodes, $nodes);
|
|
756
706
|
|
|
757
|
-
$mapKey = $
|
|
707
|
+
$mapKey = $parentNodeType . '->' . $subNodeName;
|
|
758
708
|
$insertStr = $this->listInsertionMap[$mapKey] ?? null;
|
|
759
709
|
$isStmtList = $subNodeName === 'stmts';
|
|
760
710
|
|
|
@@ -785,9 +735,9 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
785
735
|
$result = '';
|
|
786
736
|
foreach ($diff as $i => $diffElem) {
|
|
787
737
|
$diffType = $diffElem->type;
|
|
788
|
-
/** @var Node|
|
|
738
|
+
/** @var Node|null $arrItem */
|
|
789
739
|
$arrItem = $diffElem->new;
|
|
790
|
-
/** @var Node|
|
|
740
|
+
/** @var Node|null $origArrItem */
|
|
791
741
|
$origArrItem = $diffElem->old;
|
|
792
742
|
|
|
793
743
|
if ($diffType === DiffElem::TYPE_KEEP || $diffType === DiffElem::TYPE_REPLACE) {
|
|
@@ -826,8 +776,9 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
826
776
|
}
|
|
827
777
|
|
|
828
778
|
if ($skipRemovedNode) {
|
|
829
|
-
if ($isStmtList && $this->origTokens->
|
|
830
|
-
|
|
779
|
+
if ($isStmtList && ($this->origTokens->haveBracesInRange($pos, $itemStartPos) ||
|
|
780
|
+
$this->origTokens->haveTagInRange($pos, $itemStartPos))) {
|
|
781
|
+
// We'd remove the brace of a code block.
|
|
831
782
|
// TODO: Preserve formatting.
|
|
832
783
|
$this->setIndentLevel($origIndentLevel);
|
|
833
784
|
return null;
|
|
@@ -847,7 +798,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
847
798
|
}
|
|
848
799
|
}
|
|
849
800
|
|
|
850
|
-
$this->safeAppend($result, $this->p($delayedAddNode,
|
|
801
|
+
$this->safeAppend($result, $this->p($delayedAddNode, true));
|
|
851
802
|
|
|
852
803
|
if ($insertNewline) {
|
|
853
804
|
$result .= $insertStr . $this->nl;
|
|
@@ -876,17 +827,10 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
876
827
|
return null;
|
|
877
828
|
}
|
|
878
829
|
|
|
879
|
-
if (!$arrItem instanceof Node) {
|
|
880
|
-
// We only support list insertion of nodes.
|
|
881
|
-
return null;
|
|
882
|
-
}
|
|
883
|
-
|
|
884
830
|
// We go multiline if the original code was multiline,
|
|
885
831
|
// or if it's an array item with a comment above it.
|
|
886
|
-
// Match always uses multiline formatting.
|
|
887
832
|
if ($insertStr === ', ' &&
|
|
888
|
-
($this->isMultiline($origNodes) || $arrItem->getComments()
|
|
889
|
-
$parentNodeClass === Expr\Match_::class)
|
|
833
|
+
($this->isMultiline($origNodes) || $arrItem->getComments())
|
|
890
834
|
) {
|
|
891
835
|
$insertStr = ',';
|
|
892
836
|
$insertNewline = true;
|
|
@@ -936,8 +880,9 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
936
880
|
$pos, $itemStartPos, $indentAdjustment);
|
|
937
881
|
$skipRemovedNode = true;
|
|
938
882
|
} else {
|
|
939
|
-
if ($isStmtList && $this->origTokens->
|
|
940
|
-
|
|
883
|
+
if ($isStmtList && ($this->origTokens->haveBracesInRange($pos, $itemStartPos) ||
|
|
884
|
+
$this->origTokens->haveTagInRange($pos, $itemStartPos))) {
|
|
885
|
+
// We'd remove the brace of a code block.
|
|
941
886
|
// TODO: Preserve formatting.
|
|
942
887
|
return null;
|
|
943
888
|
}
|
|
@@ -952,7 +897,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
952
897
|
if (null !== $fixup && $arrItem->getAttribute('origNode') !== $origArrItem) {
|
|
953
898
|
$res = $this->pFixup($fixup, $arrItem, null, $itemStartPos, $itemEndPos);
|
|
954
899
|
} else {
|
|
955
|
-
$res = $this->p($arrItem,
|
|
900
|
+
$res = $this->p($arrItem, true);
|
|
956
901
|
}
|
|
957
902
|
$this->safeAppend($result, $res);
|
|
958
903
|
|
|
@@ -986,7 +931,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
986
931
|
$result .= $this->nl;
|
|
987
932
|
}
|
|
988
933
|
}
|
|
989
|
-
$result .= $this->p($delayedAddNode,
|
|
934
|
+
$result .= $this->p($delayedAddNode, true);
|
|
990
935
|
$first = false;
|
|
991
936
|
}
|
|
992
937
|
$result .= $extraRight === "\n" ? $this->nl : $extraRight;
|
|
@@ -1002,33 +947,22 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1002
947
|
* are required to preserve program semantics in a certain context (e.g. to maintain precedence
|
|
1003
948
|
* or because only certain expressions are allowed in certain places).
|
|
1004
949
|
*
|
|
1005
|
-
* @param int
|
|
1006
|
-
* @param Node
|
|
950
|
+
* @param int $fixup Fixup type
|
|
951
|
+
* @param Node $subNode Subnode to print
|
|
1007
952
|
* @param string|null $parentClass Class of parent node
|
|
1008
|
-
* @param int
|
|
1009
|
-
* @param int
|
|
953
|
+
* @param int $subStartPos Original start pos of subnode
|
|
954
|
+
* @param int $subEndPos Original end pos of subnode
|
|
1010
955
|
*
|
|
1011
956
|
* @return string Result of fixed-up print of subnode
|
|
1012
957
|
*/
|
|
1013
|
-
protected function pFixup(int $fixup, Node $subNode,
|
|
958
|
+
protected function pFixup(int $fixup, Node $subNode, $parentClass, int $subStartPos, int $subEndPos) : string {
|
|
1014
959
|
switch ($fixup) {
|
|
1015
960
|
case self::FIXUP_PREC_LEFT:
|
|
1016
|
-
// We use a conservative approximation where lhsPrecedence == precedence.
|
|
1017
|
-
if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) {
|
|
1018
|
-
$precedence = $this->precedenceMap[$parentClass][1];
|
|
1019
|
-
return $this->p($subNode, $precedence, $precedence);
|
|
1020
|
-
}
|
|
1021
|
-
break;
|
|
1022
961
|
case self::FIXUP_PREC_RIGHT:
|
|
1023
962
|
if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) {
|
|
1024
|
-
$precedence = $this->precedenceMap[$parentClass]
|
|
1025
|
-
return $this->
|
|
1026
|
-
|
|
1027
|
-
break;
|
|
1028
|
-
case self::FIXUP_PREC_UNARY:
|
|
1029
|
-
if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) {
|
|
1030
|
-
$precedence = $this->precedenceMap[$parentClass][0];
|
|
1031
|
-
return $this->p($subNode, $precedence, $precedence);
|
|
963
|
+
list($precedence, $associativity) = $this->precedenceMap[$parentClass];
|
|
964
|
+
return $this->pPrec($subNode, $precedence, $associativity,
|
|
965
|
+
$fixup === self::FIXUP_PREC_LEFT ? -1 : 1);
|
|
1032
966
|
}
|
|
1033
967
|
break;
|
|
1034
968
|
case self::FIXUP_CALL_LHS:
|
|
@@ -1068,7 +1002,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1068
1002
|
}
|
|
1069
1003
|
break;
|
|
1070
1004
|
case self::FIXUP_ENCAPSED:
|
|
1071
|
-
if (!$subNode instanceof
|
|
1005
|
+
if (!$subNode instanceof Scalar\EncapsedStringPart
|
|
1072
1006
|
&& !$this->origTokens->haveBraces($subStartPos, $subEndPos)
|
|
1073
1007
|
) {
|
|
1074
1008
|
return '{' . $this->p($subNode) . '}';
|
|
@@ -1087,8 +1021,11 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1087
1021
|
*
|
|
1088
1022
|
* Example: "echo" and "$x" result in "echo$x", but "echo" and "x" result in "echo x".
|
|
1089
1023
|
* Without safeAppend the result would be "echox", which does not preserve semantics.
|
|
1024
|
+
*
|
|
1025
|
+
* @param string $str
|
|
1026
|
+
* @param string $append
|
|
1090
1027
|
*/
|
|
1091
|
-
protected function safeAppend(string &$str, string $append)
|
|
1028
|
+
protected function safeAppend(string &$str, string $append) {
|
|
1092
1029
|
if ($str === "") {
|
|
1093
1030
|
$str = $append;
|
|
1094
1031
|
return;
|
|
@@ -1113,7 +1050,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1113
1050
|
*
|
|
1114
1051
|
* @return bool Whether parentheses are required
|
|
1115
1052
|
*/
|
|
1116
|
-
protected function callLhsRequiresParens(Node $node): bool {
|
|
1053
|
+
protected function callLhsRequiresParens(Node $node) : bool {
|
|
1117
1054
|
return !($node instanceof Node\Name
|
|
1118
1055
|
|| $node instanceof Expr\Variable
|
|
1119
1056
|
|| $node instanceof Expr\ArrayDimFetch
|
|
@@ -1131,7 +1068,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1131
1068
|
*
|
|
1132
1069
|
* @return bool Whether parentheses are required
|
|
1133
1070
|
*/
|
|
1134
|
-
protected function dereferenceLhsRequiresParens(Node $node): bool {
|
|
1071
|
+
protected function dereferenceLhsRequiresParens(Node $node) : bool {
|
|
1135
1072
|
// A constant can occur on the LHS of an array/object deref, but not a static deref.
|
|
1136
1073
|
return $this->staticDereferenceLhsRequiresParens($node)
|
|
1137
1074
|
&& !$node instanceof Expr\ConstFetch;
|
|
@@ -1189,18 +1126,14 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1189
1126
|
*
|
|
1190
1127
|
* @return string Printed modifiers
|
|
1191
1128
|
*/
|
|
1192
|
-
protected function pModifiers(int $modifiers)
|
|
1193
|
-
return ($modifiers &
|
|
1194
|
-
. ($modifiers &
|
|
1195
|
-
. ($modifiers &
|
|
1196
|
-
. ($modifiers &
|
|
1197
|
-
. ($modifiers &
|
|
1198
|
-
. ($modifiers &
|
|
1199
|
-
. ($modifiers &
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
protected function pStatic(bool $static): string {
|
|
1203
|
-
return $static ? 'static ' : '';
|
|
1129
|
+
protected function pModifiers(int $modifiers) {
|
|
1130
|
+
return ($modifiers & Stmt\Class_::MODIFIER_PUBLIC ? 'public ' : '')
|
|
1131
|
+
. ($modifiers & Stmt\Class_::MODIFIER_PROTECTED ? 'protected ' : '')
|
|
1132
|
+
. ($modifiers & Stmt\Class_::MODIFIER_PRIVATE ? 'private ' : '')
|
|
1133
|
+
. ($modifiers & Stmt\Class_::MODIFIER_STATIC ? 'static ' : '')
|
|
1134
|
+
. ($modifiers & Stmt\Class_::MODIFIER_ABSTRACT ? 'abstract ' : '')
|
|
1135
|
+
. ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : '')
|
|
1136
|
+
. ($modifiers & Stmt\Class_::MODIFIER_READONLY ? 'readonly ' : '');
|
|
1204
1137
|
}
|
|
1205
1138
|
|
|
1206
1139
|
/**
|
|
@@ -1210,7 +1143,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1210
1143
|
*
|
|
1211
1144
|
* @return bool Whether multiline formatting is used
|
|
1212
1145
|
*/
|
|
1213
|
-
protected function isMultiline(array $nodes): bool {
|
|
1146
|
+
protected function isMultiline(array $nodes) : bool {
|
|
1214
1147
|
if (\count($nodes) < 2) {
|
|
1215
1148
|
return false;
|
|
1216
1149
|
}
|
|
@@ -1242,19 +1175,15 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1242
1175
|
*
|
|
1243
1176
|
* The label char map determines whether a certain character may occur in a label.
|
|
1244
1177
|
*/
|
|
1245
|
-
protected function initializeLabelCharMap()
|
|
1246
|
-
if (
|
|
1247
|
-
return;
|
|
1248
|
-
}
|
|
1178
|
+
protected function initializeLabelCharMap() {
|
|
1179
|
+
if ($this->labelCharMap) return;
|
|
1249
1180
|
|
|
1250
1181
|
$this->labelCharMap = [];
|
|
1251
1182
|
for ($i = 0; $i < 256; $i++) {
|
|
1183
|
+
// Since PHP 7.1 The lower range is 0x80. However, we also want to support code for
|
|
1184
|
+
// older versions.
|
|
1252
1185
|
$chr = chr($i);
|
|
1253
|
-
$this->labelCharMap[$chr] = $i >=
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
if ($this->phpVersion->allowsDelInIdentifiers()) {
|
|
1257
|
-
$this->labelCharMap["\x7f"] = true;
|
|
1186
|
+
$this->labelCharMap[$chr] = $i >= 0x7f || ctype_alnum($chr);
|
|
1258
1187
|
}
|
|
1259
1188
|
}
|
|
1260
1189
|
|
|
@@ -1263,10 +1192,8 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1263
1192
|
*
|
|
1264
1193
|
* The node list differ is used to determine differences between two array subnodes.
|
|
1265
1194
|
*/
|
|
1266
|
-
protected function initializeNodeListDiffer()
|
|
1267
|
-
if (
|
|
1268
|
-
return;
|
|
1269
|
-
}
|
|
1195
|
+
protected function initializeNodeListDiffer() {
|
|
1196
|
+
if ($this->nodeListDiffer) return;
|
|
1270
1197
|
|
|
1271
1198
|
$this->nodeListDiffer = new Internal\Differ(function ($a, $b) {
|
|
1272
1199
|
if ($a instanceof Node && $b instanceof Node) {
|
|
@@ -1283,21 +1210,22 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1283
1210
|
* The fixup map is used to determine whether a certain subnode of a certain node may require
|
|
1284
1211
|
* some kind of "fixup" operation, e.g. the addition of parenthesis or braces.
|
|
1285
1212
|
*/
|
|
1286
|
-
protected function initializeFixupMap()
|
|
1287
|
-
if (
|
|
1288
|
-
return;
|
|
1289
|
-
}
|
|
1213
|
+
protected function initializeFixupMap() {
|
|
1214
|
+
if ($this->fixupMap) return;
|
|
1290
1215
|
|
|
1291
1216
|
$this->fixupMap = [
|
|
1217
|
+
Expr\PreInc::class => ['var' => self::FIXUP_PREC_RIGHT],
|
|
1218
|
+
Expr\PreDec::class => ['var' => self::FIXUP_PREC_RIGHT],
|
|
1219
|
+
Expr\PostInc::class => ['var' => self::FIXUP_PREC_LEFT],
|
|
1220
|
+
Expr\PostDec::class => ['var' => self::FIXUP_PREC_LEFT],
|
|
1292
1221
|
Expr\Instanceof_::class => [
|
|
1293
|
-
'expr' => self::
|
|
1222
|
+
'expr' => self::FIXUP_PREC_LEFT,
|
|
1294
1223
|
'class' => self::FIXUP_NEW,
|
|
1295
1224
|
],
|
|
1296
1225
|
Expr\Ternary::class => [
|
|
1297
1226
|
'cond' => self::FIXUP_PREC_LEFT,
|
|
1298
1227
|
'else' => self::FIXUP_PREC_RIGHT,
|
|
1299
1228
|
],
|
|
1300
|
-
Expr\Yield_::class => ['value' => self::FIXUP_PREC_UNARY],
|
|
1301
1229
|
|
|
1302
1230
|
Expr\FuncCall::class => ['name' => self::FIXUP_CALL_LHS],
|
|
1303
1231
|
Expr\StaticCall::class => ['class' => self::FIXUP_STATIC_DEREF_LHS],
|
|
@@ -1327,7 +1255,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1327
1255
|
'var' => self::FIXUP_DEREF_LHS,
|
|
1328
1256
|
'name' => self::FIXUP_BRACED_NAME,
|
|
1329
1257
|
],
|
|
1330
|
-
Scalar\
|
|
1258
|
+
Scalar\Encapsed::class => [
|
|
1331
1259
|
'parts' => self::FIXUP_ENCAPSED,
|
|
1332
1260
|
],
|
|
1333
1261
|
];
|
|
@@ -1350,19 +1278,27 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1350
1278
|
];
|
|
1351
1279
|
}
|
|
1352
1280
|
|
|
1281
|
+
$assignOps = [
|
|
1282
|
+
Expr\Assign::class, Expr\AssignRef::class, AssignOp\Plus::class, AssignOp\Minus::class,
|
|
1283
|
+
AssignOp\Mul::class, AssignOp\Div::class, AssignOp\Concat::class, AssignOp\Mod::class,
|
|
1284
|
+
AssignOp\BitwiseAnd::class, AssignOp\BitwiseOr::class, AssignOp\BitwiseXor::class,
|
|
1285
|
+
AssignOp\ShiftLeft::class, AssignOp\ShiftRight::class, AssignOp\Pow::class, AssignOp\Coalesce::class
|
|
1286
|
+
];
|
|
1287
|
+
foreach ($assignOps as $assignOp) {
|
|
1288
|
+
$this->fixupMap[$assignOp] = [
|
|
1289
|
+
'var' => self::FIXUP_PREC_LEFT,
|
|
1290
|
+
'expr' => self::FIXUP_PREC_RIGHT,
|
|
1291
|
+
];
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1353
1294
|
$prefixOps = [
|
|
1354
|
-
Expr\
|
|
1295
|
+
Expr\BitwiseNot::class, Expr\BooleanNot::class, Expr\UnaryPlus::class, Expr\UnaryMinus::class,
|
|
1355
1296
|
Cast\Int_::class, Cast\Double::class, Cast\String_::class, Cast\Array_::class,
|
|
1356
1297
|
Cast\Object_::class, Cast\Bool_::class, Cast\Unset_::class, Expr\ErrorSuppress::class,
|
|
1357
1298
|
Expr\YieldFrom::class, Expr\Print_::class, Expr\Include_::class,
|
|
1358
|
-
Expr\Assign::class, Expr\AssignRef::class, AssignOp\Plus::class, AssignOp\Minus::class,
|
|
1359
|
-
AssignOp\Mul::class, AssignOp\Div::class, AssignOp\Concat::class, AssignOp\Mod::class,
|
|
1360
|
-
AssignOp\BitwiseAnd::class, AssignOp\BitwiseOr::class, AssignOp\BitwiseXor::class,
|
|
1361
|
-
AssignOp\ShiftLeft::class, AssignOp\ShiftRight::class, AssignOp\Pow::class, AssignOp\Coalesce::class,
|
|
1362
|
-
Expr\ArrowFunction::class, Expr\Throw_::class,
|
|
1363
1299
|
];
|
|
1364
1300
|
foreach ($prefixOps as $prefixOp) {
|
|
1365
|
-
$this->fixupMap[$prefixOp] = ['expr' => self::
|
|
1301
|
+
$this->fixupMap[$prefixOp] = ['expr' => self::FIXUP_PREC_RIGHT];
|
|
1366
1302
|
}
|
|
1367
1303
|
}
|
|
1368
1304
|
|
|
@@ -1372,10 +1308,8 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1372
1308
|
* The removal map is used to determine which additional tokens should be removed when a
|
|
1373
1309
|
* certain node is replaced by null.
|
|
1374
1310
|
*/
|
|
1375
|
-
protected function initializeRemovalMap()
|
|
1376
|
-
if (
|
|
1377
|
-
return;
|
|
1378
|
-
}
|
|
1311
|
+
protected function initializeRemovalMap() {
|
|
1312
|
+
if ($this->removalMap) return;
|
|
1379
1313
|
|
|
1380
1314
|
$stripBoth = ['left' => \T_WHITESPACE, 'right' => \T_WHITESPACE];
|
|
1381
1315
|
$stripLeft = ['left' => \T_WHITESPACE];
|
|
@@ -1385,7 +1319,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1385
1319
|
$stripEquals = ['left' => '='];
|
|
1386
1320
|
$this->removalMap = [
|
|
1387
1321
|
'Expr_ArrayDimFetch->dim' => $stripBoth,
|
|
1388
|
-
'
|
|
1322
|
+
'Expr_ArrayItem->key' => $stripDoubleArrow,
|
|
1389
1323
|
'Expr_ArrowFunction->returnType' => $stripColon,
|
|
1390
1324
|
'Expr_Closure->returnType' => $stripColon,
|
|
1391
1325
|
'Expr_Exit->expr' => $stripBoth,
|
|
@@ -1408,7 +1342,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1408
1342
|
'Stmt_If->else' => $stripLeft,
|
|
1409
1343
|
'Stmt_Namespace->name' => $stripLeft,
|
|
1410
1344
|
'Stmt_Property->type' => $stripRight,
|
|
1411
|
-
'
|
|
1345
|
+
'Stmt_PropertyProperty->default' => $stripEquals,
|
|
1412
1346
|
'Stmt_Return->expr' => $stripBoth,
|
|
1413
1347
|
'Stmt_StaticVar->default' => $stripEquals,
|
|
1414
1348
|
'Stmt_TraitUseAdaptation_Alias->newName' => $stripLeft,
|
|
@@ -1420,18 +1354,16 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1420
1354
|
];
|
|
1421
1355
|
}
|
|
1422
1356
|
|
|
1423
|
-
protected function initializeInsertionMap()
|
|
1424
|
-
if (
|
|
1425
|
-
return;
|
|
1426
|
-
}
|
|
1357
|
+
protected function initializeInsertionMap() {
|
|
1358
|
+
if ($this->insertionMap) return;
|
|
1427
1359
|
|
|
1428
1360
|
// TODO: "yield" where both key and value are inserted doesn't work
|
|
1429
1361
|
// [$find, $beforeToken, $extraLeft, $extraRight]
|
|
1430
1362
|
$this->insertionMap = [
|
|
1431
1363
|
'Expr_ArrayDimFetch->dim' => ['[', false, null, null],
|
|
1432
|
-
'
|
|
1433
|
-
'Expr_ArrowFunction->returnType' => [')', false, ': ', null],
|
|
1434
|
-
'Expr_Closure->returnType' => [')', false, ': ', null],
|
|
1364
|
+
'Expr_ArrayItem->key' => [null, false, null, ' => '],
|
|
1365
|
+
'Expr_ArrowFunction->returnType' => [')', false, ' : ', null],
|
|
1366
|
+
'Expr_Closure->returnType' => [')', false, ' : ', null],
|
|
1435
1367
|
'Expr_Ternary->if' => ['?', false, ' ', ' '],
|
|
1436
1368
|
'Expr_Yield->key' => [\T_YIELD, false, null, ' => '],
|
|
1437
1369
|
'Expr_Yield->value' => [\T_YIELD, false, ' ', null],
|
|
@@ -1439,19 +1371,19 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1439
1371
|
'Param->default' => [null, false, ' = ', null],
|
|
1440
1372
|
'Stmt_Break->num' => [\T_BREAK, false, ' ', null],
|
|
1441
1373
|
'Stmt_Catch->var' => [null, false, ' ', null],
|
|
1442
|
-
'Stmt_ClassMethod->returnType' => [')', false, ': ', null],
|
|
1374
|
+
'Stmt_ClassMethod->returnType' => [')', false, ' : ', null],
|
|
1443
1375
|
'Stmt_ClassConst->type' => [\T_CONST, false, ' ', null],
|
|
1444
1376
|
'Stmt_Class->extends' => [null, false, ' extends ', null],
|
|
1445
1377
|
'Stmt_Enum->scalarType' => [null, false, ' : ', null],
|
|
1446
1378
|
'Stmt_EnumCase->expr' => [null, false, ' = ', null],
|
|
1447
|
-
'Expr_PrintableNewAnonClass->extends' => [null,
|
|
1379
|
+
'Expr_PrintableNewAnonClass->extends' => [null, ' extends ', null],
|
|
1448
1380
|
'Stmt_Continue->num' => [\T_CONTINUE, false, ' ', null],
|
|
1449
1381
|
'Stmt_Foreach->keyVar' => [\T_AS, false, null, ' => '],
|
|
1450
|
-
'Stmt_Function->returnType' => [')', false, ': ', null],
|
|
1382
|
+
'Stmt_Function->returnType' => [')', false, ' : ', null],
|
|
1451
1383
|
'Stmt_If->else' => [null, false, ' ', null],
|
|
1452
1384
|
'Stmt_Namespace->name' => [\T_NAMESPACE, false, ' ', null],
|
|
1453
1385
|
'Stmt_Property->type' => [\T_VARIABLE, true, null, ' '],
|
|
1454
|
-
'
|
|
1386
|
+
'Stmt_PropertyProperty->default' => [null, false, ' = ', null],
|
|
1455
1387
|
'Stmt_Return->expr' => [\T_RETURN, false, ' ', null],
|
|
1456
1388
|
'Stmt_StaticVar->default' => [null, false, ' = ', null],
|
|
1457
1389
|
//'Stmt_TraitUseAdaptation_Alias->newName' => [T_AS, false, ' ', null], // TODO
|
|
@@ -1465,139 +1397,132 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1465
1397
|
];
|
|
1466
1398
|
}
|
|
1467
1399
|
|
|
1468
|
-
protected function initializeListInsertionMap()
|
|
1469
|
-
if (
|
|
1470
|
-
return;
|
|
1471
|
-
}
|
|
1400
|
+
protected function initializeListInsertionMap() {
|
|
1401
|
+
if ($this->listInsertionMap) return;
|
|
1472
1402
|
|
|
1473
1403
|
$this->listInsertionMap = [
|
|
1474
1404
|
// special
|
|
1475
1405
|
//'Expr_ShellExec->parts' => '', // TODO These need to be treated more carefully
|
|
1476
|
-
//'
|
|
1477
|
-
|
|
1478
|
-
UnionType
|
|
1479
|
-
IntersectionType
|
|
1480
|
-
|
|
1481
|
-
|
|
1406
|
+
//'Scalar_Encapsed->parts' => '',
|
|
1407
|
+
'Stmt_Catch->types' => '|',
|
|
1408
|
+
'UnionType->types' => '|',
|
|
1409
|
+
'IntersectionType->types' => '&',
|
|
1410
|
+
'Stmt_If->elseifs' => ' ',
|
|
1411
|
+
'Stmt_TryCatch->catches' => ' ',
|
|
1482
1412
|
|
|
1483
1413
|
// comma-separated lists
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
MatchArm
|
|
1519
|
-
AttributeGroup
|
|
1414
|
+
'Expr_Array->items' => ', ',
|
|
1415
|
+
'Expr_ArrowFunction->params' => ', ',
|
|
1416
|
+
'Expr_Closure->params' => ', ',
|
|
1417
|
+
'Expr_Closure->uses' => ', ',
|
|
1418
|
+
'Expr_FuncCall->args' => ', ',
|
|
1419
|
+
'Expr_Isset->vars' => ', ',
|
|
1420
|
+
'Expr_List->items' => ', ',
|
|
1421
|
+
'Expr_MethodCall->args' => ', ',
|
|
1422
|
+
'Expr_NullsafeMethodCall->args' => ', ',
|
|
1423
|
+
'Expr_New->args' => ', ',
|
|
1424
|
+
'Expr_PrintableNewAnonClass->args' => ', ',
|
|
1425
|
+
'Expr_StaticCall->args' => ', ',
|
|
1426
|
+
'Stmt_ClassConst->consts' => ', ',
|
|
1427
|
+
'Stmt_ClassMethod->params' => ', ',
|
|
1428
|
+
'Stmt_Class->implements' => ', ',
|
|
1429
|
+
'Stmt_Enum->implements' => ', ',
|
|
1430
|
+
'Expr_PrintableNewAnonClass->implements' => ', ',
|
|
1431
|
+
'Stmt_Const->consts' => ', ',
|
|
1432
|
+
'Stmt_Declare->declares' => ', ',
|
|
1433
|
+
'Stmt_Echo->exprs' => ', ',
|
|
1434
|
+
'Stmt_For->init' => ', ',
|
|
1435
|
+
'Stmt_For->cond' => ', ',
|
|
1436
|
+
'Stmt_For->loop' => ', ',
|
|
1437
|
+
'Stmt_Function->params' => ', ',
|
|
1438
|
+
'Stmt_Global->vars' => ', ',
|
|
1439
|
+
'Stmt_GroupUse->uses' => ', ',
|
|
1440
|
+
'Stmt_Interface->extends' => ', ',
|
|
1441
|
+
'Stmt_Match->arms' => ', ',
|
|
1442
|
+
'Stmt_Property->props' => ', ',
|
|
1443
|
+
'Stmt_StaticVar->vars' => ', ',
|
|
1444
|
+
'Stmt_TraitUse->traits' => ', ',
|
|
1445
|
+
'Stmt_TraitUseAdaptation_Precedence->insteadof' => ', ',
|
|
1446
|
+
'Stmt_Unset->vars' => ', ',
|
|
1447
|
+
'Stmt_Use->uses' => ', ',
|
|
1448
|
+
'MatchArm->conds' => ', ',
|
|
1449
|
+
'AttributeGroup->attrs' => ', ',
|
|
1520
1450
|
|
|
1521
1451
|
// statement lists
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
Stmt\TraitUse::class . '->adaptations' => "\n",
|
|
1559
|
-
Stmt\TryCatch::class . '->stmts' => "\n",
|
|
1560
|
-
Stmt\While_::class . '->stmts' => "\n",
|
|
1452
|
+
'Expr_Closure->stmts' => "\n",
|
|
1453
|
+
'Stmt_Case->stmts' => "\n",
|
|
1454
|
+
'Stmt_Catch->stmts' => "\n",
|
|
1455
|
+
'Stmt_Class->stmts' => "\n",
|
|
1456
|
+
'Stmt_Enum->stmts' => "\n",
|
|
1457
|
+
'Expr_PrintableNewAnonClass->stmts' => "\n",
|
|
1458
|
+
'Stmt_Interface->stmts' => "\n",
|
|
1459
|
+
'Stmt_Trait->stmts' => "\n",
|
|
1460
|
+
'Stmt_ClassMethod->stmts' => "\n",
|
|
1461
|
+
'Stmt_Declare->stmts' => "\n",
|
|
1462
|
+
'Stmt_Do->stmts' => "\n",
|
|
1463
|
+
'Stmt_ElseIf->stmts' => "\n",
|
|
1464
|
+
'Stmt_Else->stmts' => "\n",
|
|
1465
|
+
'Stmt_Finally->stmts' => "\n",
|
|
1466
|
+
'Stmt_Foreach->stmts' => "\n",
|
|
1467
|
+
'Stmt_For->stmts' => "\n",
|
|
1468
|
+
'Stmt_Function->stmts' => "\n",
|
|
1469
|
+
'Stmt_If->stmts' => "\n",
|
|
1470
|
+
'Stmt_Namespace->stmts' => "\n",
|
|
1471
|
+
'Stmt_Class->attrGroups' => "\n",
|
|
1472
|
+
'Stmt_Enum->attrGroups' => "\n",
|
|
1473
|
+
'Stmt_EnumCase->attrGroups' => "\n",
|
|
1474
|
+
'Stmt_Interface->attrGroups' => "\n",
|
|
1475
|
+
'Stmt_Trait->attrGroups' => "\n",
|
|
1476
|
+
'Stmt_Function->attrGroups' => "\n",
|
|
1477
|
+
'Stmt_ClassMethod->attrGroups' => "\n",
|
|
1478
|
+
'Stmt_ClassConst->attrGroups' => "\n",
|
|
1479
|
+
'Stmt_Property->attrGroups' => "\n",
|
|
1480
|
+
'Expr_PrintableNewAnonClass->attrGroups' => ' ',
|
|
1481
|
+
'Expr_Closure->attrGroups' => ' ',
|
|
1482
|
+
'Expr_ArrowFunction->attrGroups' => ' ',
|
|
1483
|
+
'Param->attrGroups' => ' ',
|
|
1484
|
+
'Stmt_Switch->cases' => "\n",
|
|
1485
|
+
'Stmt_TraitUse->adaptations' => "\n",
|
|
1486
|
+
'Stmt_TryCatch->stmts' => "\n",
|
|
1487
|
+
'Stmt_While->stmts' => "\n",
|
|
1561
1488
|
|
|
1562
1489
|
// dummy for top-level context
|
|
1563
1490
|
'File->stmts' => "\n",
|
|
1564
1491
|
];
|
|
1565
1492
|
}
|
|
1566
1493
|
|
|
1567
|
-
protected function initializeEmptyListInsertionMap()
|
|
1568
|
-
if (
|
|
1569
|
-
return;
|
|
1570
|
-
}
|
|
1494
|
+
protected function initializeEmptyListInsertionMap() {
|
|
1495
|
+
if ($this->emptyListInsertionMap) return;
|
|
1571
1496
|
|
|
1572
1497
|
// TODO Insertion into empty statement lists.
|
|
1573
1498
|
|
|
1574
1499
|
// [$find, $extraLeft, $extraRight]
|
|
1575
1500
|
$this->emptyListInsertionMap = [
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1501
|
+
'Expr_ArrowFunction->params' => ['(', '', ''],
|
|
1502
|
+
'Expr_Closure->uses' => [')', ' use(', ')'],
|
|
1503
|
+
'Expr_Closure->params' => ['(', '', ''],
|
|
1504
|
+
'Expr_FuncCall->args' => ['(', '', ''],
|
|
1505
|
+
'Expr_MethodCall->args' => ['(', '', ''],
|
|
1506
|
+
'Expr_NullsafeMethodCall->args' => ['(', '', ''],
|
|
1507
|
+
'Expr_New->args' => ['(', '', ''],
|
|
1508
|
+
'Expr_PrintableNewAnonClass->args' => ['(', '', ''],
|
|
1509
|
+
'Expr_PrintableNewAnonClass->implements' => [null, ' implements ', ''],
|
|
1510
|
+
'Expr_StaticCall->args' => ['(', '', ''],
|
|
1511
|
+
'Stmt_Class->implements' => [null, ' implements ', ''],
|
|
1512
|
+
'Stmt_Enum->implements' => [null, ' implements ', ''],
|
|
1513
|
+
'Stmt_ClassMethod->params' => ['(', '', ''],
|
|
1514
|
+
'Stmt_Interface->extends' => [null, ' extends ', ''],
|
|
1515
|
+
'Stmt_Function->params' => ['(', '', ''],
|
|
1516
|
+
'Stmt_Interface->attrGroups' => [null, '', "\n"],
|
|
1517
|
+
'Stmt_Class->attrGroups' => [null, '', "\n"],
|
|
1518
|
+
'Stmt_ClassConst->attrGroups' => [null, '', "\n"],
|
|
1519
|
+
'Stmt_ClassMethod->attrGroups' => [null, '', "\n"],
|
|
1520
|
+
'Stmt_Function->attrGroups' => [null, '', "\n"],
|
|
1521
|
+
'Stmt_Property->attrGroups' => [null, '', "\n"],
|
|
1522
|
+
'Stmt_Trait->attrGroups' => [null, '', "\n"],
|
|
1523
|
+
'Expr_ArrowFunction->attrGroups' => [null, '', ' '],
|
|
1524
|
+
'Expr_Closure->attrGroups' => [null, '', ' '],
|
|
1525
|
+
'Expr_PrintableNewAnonClass->attrGroups' => [\T_NEW, ' ', ''],
|
|
1601
1526
|
|
|
1602
1527
|
/* These cannot be empty to start with:
|
|
1603
1528
|
* Expr_Isset->vars
|
|
@@ -1629,27 +1554,23 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
|
|
1629
1554
|
];
|
|
1630
1555
|
}
|
|
1631
1556
|
|
|
1632
|
-
protected function initializeModifierChangeMap()
|
|
1633
|
-
if (
|
|
1634
|
-
return;
|
|
1635
|
-
}
|
|
1557
|
+
protected function initializeModifierChangeMap() {
|
|
1558
|
+
if ($this->modifierChangeMap) return;
|
|
1636
1559
|
|
|
1637
1560
|
$this->modifierChangeMap = [
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
Param
|
|
1644
|
-
|
|
1645
|
-
Expr\ArrowFunction::class . '->static' => ['pStatic', \T_FN],
|
|
1646
|
-
//Stmt\TraitUseAdaptation\Alias::class . '->newModifier' => 0, // TODO
|
|
1561
|
+
'Stmt_ClassConst->flags' => \T_CONST,
|
|
1562
|
+
'Stmt_ClassMethod->flags' => \T_FUNCTION,
|
|
1563
|
+
'Stmt_Class->flags' => \T_CLASS,
|
|
1564
|
+
'Stmt_Property->flags' => \T_VARIABLE,
|
|
1565
|
+
'Expr_PrintableNewAnonClass->flags' => \T_CLASS,
|
|
1566
|
+
'Param->flags' => \T_VARIABLE,
|
|
1567
|
+
//'Stmt_TraitUseAdaptation_Alias->newModifier' => 0, // TODO
|
|
1647
1568
|
];
|
|
1648
1569
|
|
|
1649
1570
|
// List of integer subnodes that are not modifiers:
|
|
1650
1571
|
// Expr_Include->type
|
|
1651
1572
|
// Stmt_GroupUse->type
|
|
1652
1573
|
// Stmt_Use->type
|
|
1653
|
-
//
|
|
1574
|
+
// Stmt_UseUse->type
|
|
1654
1575
|
}
|
|
1655
1576
|
}
|