@@ -38,8 +38,6 @@ class AstNode extends TAstNode {
38
38
result = node .getLocation ( )
39
39
)
40
40
or
41
- result = toGenerateYaml ( this ) .getLocation ( )
42
- or
43
41
result = toDbscheme ( this ) .getLocation ( )
44
42
}
45
43
@@ -2573,126 +2571,49 @@ class BindingSet extends Annotation {
2573
2571
* Classes modeling YAML AST nodes.
2574
2572
*/
2575
2573
module YAML {
2576
- /** A node in a YAML file */
2577
- class YamlNode extends TYamlNode , AstNode {
2578
- /** Holds if the predicate is a root node (has no parent) */
2579
- predicate isRoot ( ) { not exists ( this .getParent ( ) ) }
2580
-
2581
- override AstNode getParent ( ) { toGenerateYaml ( result ) = toGenerateYaml ( this ) .getParent ( ) }
2582
- }
2574
+ private import codeql.yaml.Yaml as LibYaml
2583
2575
2584
- /** DEPRECATED: Alias for YamlNode */
2585
- deprecated class YAMLNode = YamlNode ;
2576
+ private module YamlSig implements LibYaml :: InputSig {
2577
+ import codeql.Locations
2586
2578
2587
- /** A YAML comment. */
2588
- class YamlComment extends TYamlComment , YamlNode {
2589
- Yaml:: Comment yamlcomment ;
2579
+ class LocatableBase extends @yaml_locatable {
2580
+ Location getLocation ( ) { yaml_locations ( this , result ) }
2590
2581
2591
- YamlComment ( ) { this = TYamlComment ( yamlcomment ) }
2592
-
2593
- override string getAPrimaryQlClass ( ) { result = "YamlComment" }
2594
- }
2582
+ string toString ( ) { none ( ) }
2583
+ }
2595
2584
2596
- /** DEPRECATED: Alias for YamlComment */
2597
- deprecated class YAMLComment = YamlComment ;
2585
+ class NodeBase extends LocatableBase , @yaml_node {
2586
+ NodeBase getChildNode ( int i ) { yaml ( result , _ , this , i , _ , _ ) }
2598
2587
2599
- /** A YAML entry. */
2600
- class YamlEntry extends TYamlEntry , YamlNode {
2601
- Yaml:: Entry yamle ;
2588
+ string getTag ( ) { yaml ( this , _, _, _, result , _) }
2602
2589
2603
- YamlEntry ( ) { this = TYamlEntry ( yamle ) }
2590
+ string getAnchor ( ) { yaml_anchors ( this , result ) }
2604
2591
2605
- /** Gets the key of this YAML entry. */
2606
- YamlKey getKey ( ) {
2607
- exists ( Yaml:: Keyvaluepair pair |
2608
- pair .getParent ( ) = yamle and
2609
- result = TYamlKey ( pair .getKey ( ) )
2610
- )
2592
+ override string toString ( ) { yaml ( this , _, _, _, _, result ) }
2611
2593
}
2612
2594
2613
- YamlListItem getListItem ( ) { toGenerateYaml ( result ) .getParent ( ) = yamle }
2595
+ class ScalarNodeBase extends NodeBase , @yaml_scalar_node {
2596
+ int getStyle ( ) { yaml_scalars ( this , result , _) }
2614
2597
2615
- /** Gets the value of this YAML entry. */
2616
- YamlValue getValue ( ) {
2617
- exists ( Yaml:: Keyvaluepair pair |
2618
- pair .getParent ( ) = yamle and
2619
- result = TYamlValue ( pair .getValue ( ) )
2620
- )
2598
+ string getValue ( ) { yaml_scalars ( this , _, result ) }
2621
2599
}
2622
2600
2623
- override string getAPrimaryQlClass ( ) { result = "YamlEntry" }
2624
- }
2625
-
2626
- /** DEPRECATED: Alias for YamlEntry */
2627
- deprecated class YAMLEntry = YamlEntry ;
2628
-
2629
- /** A YAML key. */
2630
- class YamlKey extends TYamlKey , YamlNode {
2631
- Yaml:: Key yamlkey ;
2601
+ class CollectionNodeBase extends NodeBase , @yaml_collection_node { }
2632
2602
2633
- YamlKey ( ) { this = TYamlKey ( yamlkey ) }
2603
+ class MappingNodeBase extends CollectionNodeBase , @yaml_mapping_node { }
2634
2604
2635
- /**
2636
- * Gets the value of this YAML key.
2637
- */
2638
- YamlValue getValue ( ) {
2639
- exists ( Yaml:: Keyvaluepair pair |
2640
- pair .getKey ( ) = yamlkey and result = TYamlValue ( pair .getValue ( ) )
2641
- )
2642
- }
2643
-
2644
- override string getAPrimaryQlClass ( ) { result = "YamlKey" }
2605
+ class SequenceNodeBase extends CollectionNodeBase , @yaml_sequence_node { }
2645
2606
2646
- /** Gets the value of this YAML value. */
2647
- string getNamePart ( int i ) {
2648
- i = 0 and result = yamlkey .getChild ( 0 ) .( Yaml:: SimpleId ) .getValue ( )
2649
- or
2650
- exists ( YamlKey child |
2651
- child = TYamlKey ( yamlkey .getChild ( 1 ) ) and
2652
- result = child .getNamePart ( i - 1 )
2653
- )
2607
+ class AliasNodeBase extends NodeBase , @yaml_alias_node {
2608
+ string getTarget ( ) { yaml_aliases ( this , result ) }
2654
2609
}
2655
2610
2656
- /**
2657
- * Gets all the name parts of this YAML key concatenated with `/`.
2658
- * Dashes are replaced with `/` (because we don't have that information in the generated AST).
2659
- */
2660
- string getQualifiedName ( ) {
2661
- result = concat ( string part , int i | part = this .getNamePart ( i ) | part , "/" order by i )
2611
+ class ParseErrorBase extends LocatableBase , @yaml_error {
2612
+ string getMessage ( ) { yaml_errors ( this , result ) }
2662
2613
}
2663
2614
}
2664
2615
2665
- /** DEPRECATED: Alias for YamlKey */
2666
- deprecated class YAMLKey = YamlKey ;
2667
-
2668
- /** A YAML list item. */
2669
- class YamlListItem extends TYamlListitem , YamlNode {
2670
- Yaml:: Listitem yamllistitem ;
2671
-
2672
- YamlListItem ( ) { this = TYamlListitem ( yamllistitem ) }
2673
-
2674
- /**
2675
- * Gets the value of this YAML list item.
2676
- */
2677
- YamlValue getValue ( ) { result = TYamlValue ( yamllistitem .getChild ( ) ) }
2678
-
2679
- override string getAPrimaryQlClass ( ) { result = "YamlListItem" }
2680
- }
2681
-
2682
- /** DEPRECATED: Alias for YamlListItem */
2683
- deprecated class YAMLListItem = YamlListItem ;
2684
-
2685
- /** A YAML value. */
2686
- class YamlValue extends TYamlValue , YamlNode {
2687
- Yaml:: Value yamlvalue ;
2688
-
2689
- YamlValue ( ) { this = TYamlValue ( yamlvalue ) }
2690
-
2691
- override string getAPrimaryQlClass ( ) { result = "YamlValue" }
2692
-
2693
- /** Gets the value of this YAML value. */
2694
- string getValue ( ) { result = yamlvalue .getValue ( ) }
2695
- }
2616
+ import LibYaml:: Make< YamlSig >
2696
2617
2697
2618
// to not expose the entire `File` API on `QlPack`.
2698
2619
private newtype TQLPack = MKQlPack ( File file ) { file .getBaseName ( ) = "qlpack.yml" }
@@ -2705,15 +2626,16 @@ module YAML {
2705
2626
2706
2627
QLPack ( ) { this = MKQlPack ( file ) }
2707
2628
2708
- private string getProperty ( string name ) {
2709
- exists ( YamlEntry entry |
2710
- entry .isRoot ( ) and
2711
- entry .getKey ( ) .getQualifiedName ( ) = name and
2712
- result = entry .getValue ( ) .getValue ( ) .trim ( ) and
2713
- entry .getLocation ( ) .getFile ( ) = file
2629
+ private YamlValue get ( string name ) {
2630
+ exists ( YamlMapping m |
2631
+ m instanceof YamlDocument and
2632
+ m .getFile ( ) = file and
2633
+ result = m .lookup ( name )
2714
2634
)
2715
2635
}
2716
2636
2637
+ private string getProperty ( string name ) { result = this .get ( name ) .( YamlScalar ) .getValue ( ) }
2638
+
2717
2639
/** Gets the name of this qlpack */
2718
2640
string getName ( ) { result = this .getProperty ( "name" ) }
2719
2641
@@ -2728,32 +2650,12 @@ module YAML {
2728
2650
/** Gets the file that this `QLPack` represents. */
2729
2651
File getFile ( ) { result = file }
2730
2652
2731
- private predicate isADependency ( YamlEntry entry ) {
2732
- exists ( YamlEntry deps |
2733
- deps .getLocation ( ) .getFile ( ) = file and entry .getLocation ( ) .getFile ( ) = file
2734
- |
2735
- deps .isRoot ( ) and
2736
- deps .getKey ( ) .getQualifiedName ( ) = [ "dependencies" , "libraryPathDependencies" ] and
2737
- entry .getLocation ( ) .getStartLine ( ) = 1 + deps .getLocation ( ) .getStartLine ( ) and
2738
- entry .getLocation ( ) .getStartColumn ( ) > deps .getLocation ( ) .getStartColumn ( )
2739
- )
2740
- or
2741
- exists ( YamlEntry prev | this .isADependency ( prev ) |
2742
- prev .getLocation ( ) .getFile ( ) = file and
2743
- entry .getLocation ( ) .getFile ( ) = file and
2744
- entry .getLocation ( ) .getStartLine ( ) = 1 + prev .getLocation ( ) .getStartLine ( ) and
2745
- entry .getLocation ( ) .getStartColumn ( ) = prev .getLocation ( ) .getStartColumn ( )
2746
- )
2747
- }
2748
-
2749
2653
predicate hasDependency ( string name , string version ) {
2750
- exists ( YamlEntry entry | this .isADependency ( entry ) |
2751
- entry .getKey ( ) .getQualifiedName ( ) .trim ( ) = name and
2752
- entry .getValue ( ) .getValue ( ) = version
2753
- or
2754
- name = entry .getListItem ( ) .getValue ( ) .getValue ( ) .trim ( ) and
2755
- version = "\"*\""
2756
- )
2654
+ version = this .get ( "dependencies" ) .( YamlMapping ) .lookup ( name ) .( YamlScalar ) .getValue ( )
2655
+ or
2656
+ name =
2657
+ this .get ( "libraryPathDependencies" ) .( YamlCollection ) .getAChild ( ) .( YamlScalar ) .getValue ( ) and
2658
+ version = "\"*\""
2757
2659
or
2758
2660
name = this .getProperty ( "libraryPathDependencies" ) and
2759
2661
version = "\"*\""
0 commit comments