@@ -3699,7 +3699,9 @@ private void emitPatternNotImplemented(String kind) {
3699
3699
}
3700
3700
3701
3701
/**
3702
- * Saves subject of the pattern context into BytecodeLocal variable, to be restored eventually.
3702
+ * Saves subject of the pattern context into BytecodeLocal variable, to be restored
3703
+ * eventually.
3704
+ *
3703
3705
* @param pc Pattern context, which subject needs to be saved.
3704
3706
* @return Subject saved in local variable.
3705
3707
*/
@@ -3713,6 +3715,7 @@ private BytecodeLocal patternContextSubjectSave(PatternContext pc) {
3713
3715
3714
3716
/**
3715
3717
* Loads pattern context subject back into pattern context.
3718
+ *
3716
3719
* @param pcSave Variable to restore pattern context subject from.
3717
3720
* @param pc Pattern context into which the subject should be restored.
3718
3721
*/
@@ -3723,8 +3726,9 @@ private void patternContextSubjectLoad(BytecodeLocal pcSave, PatternContext pc)
3723
3726
}
3724
3727
3725
3728
/**
3726
- * Check if attribute and keyword attribute lengths match, or if there isn't too much patterns or attributes.
3727
- * Throws error on fail.
3729
+ * Check if attribute and keyword attribute lengths match, or if there isn't too much
3730
+ * patterns or attributes. Throws error on fail.
3731
+ *
3728
3732
* @param patLen Patterns count
3729
3733
* @param attrsLen Attributes count
3730
3734
* @param kwdPatLen Keyword attributes count
@@ -3742,9 +3746,11 @@ private void classMatchLengthChecks(int patLen, int attrsLen, int kwdPatLen, Pat
3742
3746
}
3743
3747
3744
3748
/**
3745
- * Visits sub-patterns for class pattern matching. Regular, positional patterns are handled first, then the
3746
- * keyword patterns (e.g. the "class.attribute = [keyword] pattern"). Generates boolean value based on
3747
- * results of the subpatterns; values are evaluated using the AND operator.
3749
+ * Visits sub-patterns for class pattern matching. Regular, positional patterns are handled
3750
+ * first, then the keyword patterns (e.g. the "class.attribute = [keyword] pattern").
3751
+ * Generates boolean value based on results of the subpatterns; values are evaluated using
3752
+ * the AND operator.
3753
+ *
3748
3754
* @param patterns Patterns to check as subpatterns.
3749
3755
* @param kwdPatterns Keyword patterns to check as subpatterns.
3750
3756
* @param attrsValueUnpacked Values to use as `pc.subject` in sub-pattern check.
@@ -3760,31 +3766,31 @@ private void classMatchVisitSubpatterns(PatternTy[] patterns, PatternTy[] kwdPat
3760
3766
} else {
3761
3767
BytecodeLocal temp = b .createLocal ();
3762
3768
b .beginStoreLocal (temp );
3763
- b .beginPrimitiveBoolAnd ();
3764
- for (int i = 0 ; i < patLen ; i ++) {
3765
- b .beginBlock ();
3766
- b .beginStoreLocal (pc .subject );
3767
- b .beginArrayIndex (i );
3768
- b .emitLoadLocal (attrsValueUnpacked );
3769
- b .endArrayIndex ();
3770
- b .endStoreLocal ();
3769
+ b .beginPrimitiveBoolAnd ();
3770
+ for (int i = 0 ; i < patLen ; i ++) {
3771
+ b .beginBlock ();
3772
+ b .beginStoreLocal (pc .subject );
3773
+ b .beginArrayIndex (i );
3774
+ b .emitLoadLocal (attrsValueUnpacked );
3775
+ b .endArrayIndex ();
3776
+ b .endStoreLocal ();
3771
3777
3772
- visitSubpattern (patterns [i ], pc );
3773
- b .endBlock ();
3774
- }
3778
+ visitSubpattern (patterns [i ], pc );
3779
+ b .endBlock ();
3780
+ }
3775
3781
3776
- for (int i = 0 , j = patLen ; i < attrsLen ; i ++, j ++) {
3777
- b .beginBlock ();
3778
- b .beginStoreLocal (pc .subject );
3779
- b .beginArrayIndex (j );
3780
- b .emitLoadLocal (attrsValueUnpacked );
3781
- b .endArrayIndex ();
3782
- b .endStoreLocal ();
3782
+ for (int i = 0 , j = patLen ; i < attrsLen ; i ++, j ++) {
3783
+ b .beginBlock ();
3784
+ b .beginStoreLocal (pc .subject );
3785
+ b .beginArrayIndex (j );
3786
+ b .emitLoadLocal (attrsValueUnpacked );
3787
+ b .endArrayIndex ();
3788
+ b .endStoreLocal ();
3783
3789
3784
- visitSubpattern (kwdPatterns [i ], pc );
3785
- b .endBlock ();
3786
- }
3787
- b .endPrimitiveBoolAnd ();
3790
+ visitSubpattern (kwdPatterns [i ], pc );
3791
+ b .endBlock ();
3792
+ }
3793
+ b .endPrimitiveBoolAnd ();
3788
3794
b .endStoreLocal ();
3789
3795
3790
3796
patternContextSubjectLoad (pcSave , pc );
@@ -3866,7 +3872,9 @@ private void doVisitPattern(PatternTy.MatchClass node, PatternContext pc) {
3866
3872
}
3867
3873
3868
3874
/**
3869
- * Checks if keyword argument names aren't the same or if their name isn't forbidden. Raises error at fail.
3875
+ * Checks if keyword argument names aren't the same or if their name isn't forbidden. Raises
3876
+ * error at fail.
3877
+ *
3870
3878
* @param attrs Attributes to check.
3871
3879
* @param patterns Patterns for error source range.
3872
3880
*/
@@ -3891,8 +3899,8 @@ private static int lengthOrZero(Object[] p) {
3891
3899
}
3892
3900
3893
3901
/**
3894
- * Checks if keys in pattern are, if present, longer than keys in subject. If yes, pattern should fail,
3895
- * otherwise, we should continue with evaluation.
3902
+ * Checks if keys in pattern are, if present, longer than keys in subject. If yes, pattern
3903
+ * should fail, otherwise, we should continue with evaluation.
3896
3904
*
3897
3905
* Generates result of the comparison (boolean).
3898
3906
*
@@ -3909,8 +3917,8 @@ private void checkPatternKeysLength(int keyLen, PatternContext pc) {
3909
3917
}
3910
3918
3911
3919
/**
3912
- * Will process pattern keys: Attributes evaluation and constant folding. Checks for duplicate keys and
3913
- * that only literals and attributes lookups are being matched.
3920
+ * Will process pattern keys: Attributes evaluation and constant folding. Checks for
3921
+ * duplicate keys and that only literals and attributes lookups are being matched.
3914
3922
*
3915
3923
* Generates array.
3916
3924
*
@@ -3962,56 +3970,56 @@ private void mappingVisitSubpatterns(PatternTy[] patterns, BytecodeLocal values,
3962
3970
int patLen = patterns .length ;
3963
3971
3964
3972
b .beginBlock ();
3965
- // unpack values from pc.subject
3966
- BytecodeLocal valuesUnpacked = b .createLocal ();
3967
- b .beginStoreLocal (valuesUnpacked );
3968
- b .beginUnpackSequence (patLen );
3969
- b .emitLoadLocal (values );
3970
- b .endUnpackSequence ();
3971
- b .endStoreLocal ();
3972
-
3973
- // backup pc.subject, it will get replaced for sub-patterns
3974
- BytecodeLocal pcSave = patternContextSubjectSave (pc );
3973
+ // unpack values from pc.subject
3974
+ BytecodeLocal valuesUnpacked = b .createLocal ();
3975
+ b .beginStoreLocal (valuesUnpacked );
3976
+ b .beginUnpackSequence (patLen );
3977
+ b .emitLoadLocal (values );
3978
+ b .endUnpackSequence ();
3979
+ b .endStoreLocal ();
3975
3980
3976
- BytecodeLocal temp = b .createLocal ();
3977
- b .beginStoreLocal (temp );
3978
- b .beginPrimitiveBoolAnd ();
3979
- boolean hadNonWildcardPattern = false ;
3980
- for (int i = 0 ; i < patLen ; i ++) {
3981
- if (wildcardCheck (patterns [i ])) {
3982
- continue ;
3983
- }
3984
- hadNonWildcardPattern = true ;
3985
- b .beginBlock ();
3986
- b .beginStoreLocal (pc .subject );
3987
- b .beginArrayIndex (i );
3988
- b .emitLoadLocal (valuesUnpacked );
3989
- b .endArrayIndex ();
3990
- b .endStoreLocal ();
3981
+ // backup pc.subject, it will get replaced for sub-patterns
3982
+ BytecodeLocal pcSave = patternContextSubjectSave (pc );
3991
3983
3992
- visitSubpattern (patterns [i ], pc );
3993
- b .endBlock ();
3994
- }
3995
- if (!hadNonWildcardPattern ) {
3996
- b .emitLoadConstant (true );
3997
- }
3998
- b .endPrimitiveBoolAnd ();
3984
+ BytecodeLocal temp = b .createLocal ();
3985
+ b .beginStoreLocal (temp );
3986
+ b .beginPrimitiveBoolAnd ();
3987
+ boolean hadNonWildcardPattern = false ;
3988
+ for (int i = 0 ; i < patLen ; i ++) {
3989
+ if (wildcardCheck (patterns [i ])) {
3990
+ continue ;
3991
+ }
3992
+ hadNonWildcardPattern = true ;
3993
+ b .beginBlock ();
3994
+ b .beginStoreLocal (pc .subject );
3995
+ b .beginArrayIndex (i );
3996
+ b .emitLoadLocal (valuesUnpacked );
3997
+ b .endArrayIndex ();
3999
3998
b .endStoreLocal ();
4000
3999
4001
- patternContextSubjectLoad (pcSave , pc );
4000
+ visitSubpattern (patterns [i ], pc );
4001
+ b .endBlock ();
4002
+ }
4003
+ if (!hadNonWildcardPattern ) {
4004
+ b .emitLoadConstant (true );
4005
+ }
4006
+ b .endPrimitiveBoolAnd ();
4007
+ b .endStoreLocal ();
4002
4008
4003
- b .emitLoadLocal (temp );
4009
+ patternContextSubjectLoad (pcSave , pc );
4010
+
4011
+ b .emitLoadLocal (temp );
4004
4012
b .endBlock ();
4005
4013
}
4006
4014
4007
4015
private void doVisitPattern (PatternTy .MatchMapping node , PatternContext pc ) {
4008
4016
/**
4009
- * Mapping pattern match will take the keys and check, whether the keys in the pattern are
4010
- * present in the subject. This is good enough, since the pattern needs only to be a subset of the subject.
4011
- * Keys aren't evaluated as subpatterns.
4017
+ * Mapping pattern match will take the keys and check, whether the keys in the pattern
4018
+ * are present in the subject. This is good enough, since the pattern needs only to be a
4019
+ * subset of the subject. Keys aren't evaluated as subpatterns.
4012
4020
*
4013
- * After the key check, the values of the pattern are patterns as well and are evaluated as sub-patterns
4014
- * with values in the subject used as separate respective subjects.
4021
+ * After the key check, the values of the pattern are patterns as well and are evaluated
4022
+ * as sub-patterns with values in the subject used as separate respective subjects.
4015
4023
*/
4016
4024
ExprTy [] keys = node .keys ;
4017
4025
PatternTy [] patterns = node .patterns ;
0 commit comments