@@ -38,8 +38,6 @@ class AstNode extends TAstNode {
3838 result = node .getLocation ( )
3939 )
4040 or
41- result = toGenerateYaml ( this ) .getLocation ( )
42- or
4341 result = toDbscheme ( this ) .getLocation ( )
4442 }
4543
@@ -2573,126 +2571,49 @@ class BindingSet extends Annotation {
25732571 * Classes modeling YAML AST nodes.
25742572 */
25752573module 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
25832575
2584- /** DEPRECATED: Alias for YamlNode */
2585- deprecated class YAMLNode = YamlNode ;
2576+ private module YamlSig implements LibYaml :: InputSig {
2577+ import codeql.Locations
25862578
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 ) }
25902581
2591- YamlComment ( ) { this = TYamlComment ( yamlcomment ) }
2592-
2593- override string getAPrimaryQlClass ( ) { result = "YamlComment" }
2594- }
2582+ string toString ( ) { none ( ) }
2583+ }
25952584
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 , _ , _ ) }
25982587
2599- /** A YAML entry. */
2600- class YamlEntry extends TYamlEntry , YamlNode {
2601- Yaml:: Entry yamle ;
2588+ string getTag ( ) { yaml ( this , _, _, _, result , _) }
26022589
2603- YamlEntry ( ) { this = TYamlEntry ( yamle ) }
2590+ string getAnchor ( ) { yaml_anchors ( this , result ) }
26042591
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 ) }
26112593 }
26122594
2613- YamlListItem getListItem ( ) { toGenerateYaml ( result ) .getParent ( ) = yamle }
2595+ class ScalarNodeBase extends NodeBase , @yaml_scalar_node {
2596+ int getStyle ( ) { yaml_scalars ( this , result , _) }
26142597
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 ) }
26212599 }
26222600
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 { }
26322602
2633- YamlKey ( ) { this = TYamlKey ( yamlkey ) }
2603+ class MappingNodeBase extends CollectionNodeBase , @yaml_mapping_node { }
26342604
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 { }
26452606
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 ) }
26542609 }
26552610
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 ) }
26622613 }
26632614 }
26642615
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 >
26962617
26972618 // to not expose the entire `File` API on `QlPack`.
26982619 private newtype TQLPack = MKQlPack ( File file ) { file .getBaseName ( ) = "qlpack.yml" }
@@ -2705,15 +2626,16 @@ module YAML {
27052626
27062627 QLPack ( ) { this = MKQlPack ( file ) }
27072628
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 )
27142634 )
27152635 }
27162636
2637+ private string getProperty ( string name ) { result = this .get ( name ) .( YamlScalar ) .getValue ( ) }
2638+
27172639 /** Gets the name of this qlpack */
27182640 string getName ( ) { result = this .getProperty ( "name" ) }
27192641
@@ -2728,32 +2650,12 @@ module YAML {
27282650 /** Gets the file that this `QLPack` represents. */
27292651 File getFile ( ) { result = file }
27302652
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-
27492653 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 = "\"*\""
27572659 or
27582660 name = this .getProperty ( "libraryPathDependencies" ) and
27592661 version = "\"*\""
0 commit comments