Skip to content

Commit acd578b

Browse files
committed
Update tests and lib to remove JSON
1 parent 70c34de commit acd578b

File tree

7 files changed

+20
-277
lines changed

7 files changed

+20
-277
lines changed

ql/lib/codeql/iac/ast/Json.qll

Whitespace-only changes.
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
private import TreeSitter
22
import Hcl
33
import Container
4-
import Json
54

65
/**
76
* AST Common Type
87
*/
98
cached
109
newtype TAstNode =
1110
THclAstNode(HCL::AstNode node) or
12-
TContainerAstNode(DOCKERFILE::AstNode node) or
13-
TJsonAstNode(JSON::AstNode node)
11+
TContainerAstNode(DOCKERFILE::AstNode node)

ql/lib/codeql/iac/ast/internal/Json.qll

Lines changed: 0 additions & 45 deletions
This file was deleted.

ql/lib/codeql/iac/ast/internal/TreeSitter.qll

Lines changed: 0 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -620,153 +620,6 @@ module HCL {
620620
}
621621
}
622622

623-
module JSON {
624-
/** The base class for all AST nodes */
625-
class AstNode extends @json_ast_node {
626-
/** Gets a string representation of this element. */
627-
string toString() { result = this.getAPrimaryQlClass() }
628-
629-
/** Gets the location of this element. */
630-
final L::Location getLocation() { json_ast_node_info(this, _, _, result) }
631-
632-
/** Gets the parent of this element. */
633-
final AstNode getParent() { json_ast_node_info(this, result, _, _) }
634-
635-
/** Gets the index of this node among the children of its parent. */
636-
final int getParentIndex() { json_ast_node_info(this, _, result, _) }
637-
638-
/** Gets a field or child node of this node. */
639-
AstNode getAFieldOrChild() { none() }
640-
641-
/** Gets the name of the primary QL class for this element. */
642-
string getAPrimaryQlClass() { result = "???" }
643-
644-
/** Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. */
645-
string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
646-
}
647-
648-
/** A token. */
649-
class Token extends @json_token, AstNode {
650-
/** Gets the value of this token. */
651-
final string getValue() { json_tokeninfo(this, _, result) }
652-
653-
/** Gets a string representation of this element. */
654-
final override string toString() { result = this.getValue() }
655-
656-
/** Gets the name of the primary QL class for this element. */
657-
override string getAPrimaryQlClass() { result = "Token" }
658-
}
659-
660-
/** A reserved word. */
661-
class ReservedWord extends @json_reserved_word, Token {
662-
/** Gets the name of the primary QL class for this element. */
663-
final override string getAPrimaryQlClass() { result = "ReservedWord" }
664-
}
665-
666-
/** A class representing `array` nodes. */
667-
class Array extends @json_array, AstNode {
668-
/** Gets the name of the primary QL class for this element. */
669-
final override string getAPrimaryQlClass() { result = "Array" }
670-
671-
/** Gets the `i`th child of this node. */
672-
final Value getChild(int i) { json_array_child(this, i, result) }
673-
674-
/** Gets a field or child node of this node. */
675-
final override AstNode getAFieldOrChild() { json_array_child(this, _, result) }
676-
}
677-
678-
/** A class representing `comment` tokens. */
679-
class Comment extends @json_token_comment, Token {
680-
/** Gets the name of the primary QL class for this element. */
681-
final override string getAPrimaryQlClass() { result = "Comment" }
682-
}
683-
684-
/** A class representing `document` nodes. */
685-
class Document extends @json_document, AstNode {
686-
/** Gets the name of the primary QL class for this element. */
687-
final override string getAPrimaryQlClass() { result = "Document" }
688-
689-
/** Gets the `i`th child of this node. */
690-
final Value getChild(int i) { json_document_child(this, i, result) }
691-
692-
/** Gets a field or child node of this node. */
693-
final override AstNode getAFieldOrChild() { json_document_child(this, _, result) }
694-
}
695-
696-
/** A class representing `false` tokens. */
697-
class False extends @json_token_false, Token {
698-
/** Gets the name of the primary QL class for this element. */
699-
final override string getAPrimaryQlClass() { result = "False" }
700-
}
701-
702-
/** A class representing `null` tokens. */
703-
class Null extends @json_token_null, Token {
704-
/** Gets the name of the primary QL class for this element. */
705-
final override string getAPrimaryQlClass() { result = "Null" }
706-
}
707-
708-
/** A class representing `number` tokens. */
709-
class Number extends @json_token_number, Token {
710-
/** Gets the name of the primary QL class for this element. */
711-
final override string getAPrimaryQlClass() { result = "Number" }
712-
}
713-
714-
/** A class representing `object` nodes. */
715-
class Object extends @json_object, AstNode {
716-
/** Gets the name of the primary QL class for this element. */
717-
final override string getAPrimaryQlClass() { result = "Object" }
718-
719-
/** Gets the `i`th child of this node. */
720-
final Pair getChild(int i) { json_object_child(this, i, result) }
721-
722-
/** Gets a field or child node of this node. */
723-
final override AstNode getAFieldOrChild() { json_object_child(this, _, result) }
724-
}
725-
726-
/** A class representing `pair` nodes. */
727-
class Pair extends @json_pair, AstNode {
728-
/** Gets the name of the primary QL class for this element. */
729-
final override string getAPrimaryQlClass() { result = "Pair" }
730-
731-
/** Gets the node corresponding to the field `key`. */
732-
final AstNode getKey() { json_pair_def(this, result, _) }
733-
734-
/** Gets the node corresponding to the field `value`. */
735-
final Value getValue() { json_pair_def(this, _, result) }
736-
737-
/** Gets a field or child node of this node. */
738-
final override AstNode getAFieldOrChild() {
739-
json_pair_def(this, result, _) or json_pair_def(this, _, result)
740-
}
741-
}
742-
743-
/** A class representing `string` nodes. */
744-
class String extends @json_string__, AstNode {
745-
/** Gets the name of the primary QL class for this element. */
746-
final override string getAPrimaryQlClass() { result = "String" }
747-
748-
/** Gets the child of this node. */
749-
final StringContent getChild() { json_string_child(this, result) }
750-
751-
/** Gets a field or child node of this node. */
752-
final override AstNode getAFieldOrChild() { json_string_child(this, result) }
753-
}
754-
755-
/** A class representing `string_content` tokens. */
756-
class StringContent extends @json_token_string_content, Token {
757-
/** Gets the name of the primary QL class for this element. */
758-
final override string getAPrimaryQlClass() { result = "StringContent" }
759-
}
760-
761-
/** A class representing `true` tokens. */
762-
class True extends @json_token_true, Token {
763-
/** Gets the name of the primary QL class for this element. */
764-
final override string getAPrimaryQlClass() { result = "True" }
765-
}
766-
767-
class Value extends @json_value, AstNode { }
768-
}
769-
770623
module DOCKERFILE {
771624
/** The base class for all AST nodes */
772625
class AstNode extends @dockerfile_ast_node {

ql/lib/iac.dbscheme

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -496,88 +496,6 @@ hcl_ast_node_info(
496496
int loc: @location_default ref
497497
);
498498

499-
/*- JSON dbscheme -*/
500-
#keyset[json_array, index]
501-
json_array_child(
502-
int json_array: @json_array ref,
503-
int index: int ref,
504-
unique int child: @json_value ref
505-
);
506-
507-
json_array_def(
508-
unique int id: @json_array
509-
);
510-
511-
#keyset[json_document, index]
512-
json_document_child(
513-
int json_document: @json_document ref,
514-
int index: int ref,
515-
unique int child: @json_value ref
516-
);
517-
518-
json_document_def(
519-
unique int id: @json_document
520-
);
521-
522-
#keyset[json_object, index]
523-
json_object_child(
524-
int json_object: @json_object ref,
525-
int index: int ref,
526-
unique int child: @json_pair ref
527-
);
528-
529-
json_object_def(
530-
unique int id: @json_object
531-
);
532-
533-
@json_pair_key_type = @json_string__ | @json_token_number
534-
535-
json_pair_def(
536-
unique int id: @json_pair,
537-
int key__: @json_pair_key_type ref,
538-
int value: @json_value ref
539-
);
540-
541-
json_string_child(
542-
unique int json_string__: @json_string__ ref,
543-
unique int child: @json_token_string_content ref
544-
);
545-
546-
json_string_def(
547-
unique int id: @json_string__
548-
);
549-
550-
@json_value = @json_array | @json_object | @json_string__ | @json_token_false | @json_token_null | @json_token_number | @json_token_true
551-
552-
json_tokeninfo(
553-
unique int id: @json_token,
554-
int kind: int ref,
555-
string value: string ref
556-
);
557-
558-
case @json_token.kind of
559-
0 = @json_reserved_word
560-
| 1 = @json_token_comment
561-
| 2 = @json_token_false
562-
| 3 = @json_token_null
563-
| 4 = @json_token_number
564-
| 5 = @json_token_string_content
565-
| 6 = @json_token_true
566-
;
567-
568-
569-
@json_ast_node = @json_array | @json_document | @json_object | @json_pair | @json_string__ | @json_token
570-
571-
@json_ast_node_parent = @file | @json_ast_node
572-
573-
#keyset[parent, parent_index]
574-
json_ast_node_info(
575-
unique int node: @json_ast_node ref,
576-
int parent: @json_ast_node_parent ref,
577-
int parent_index: int ref,
578-
int loc: @location_default ref
579-
);
580-
581499
/*- DOCKERFILE dbscheme -*/
582500
@dockerfile_add_instruction_child_type = @dockerfile_path | @dockerfile_token_param
583501

ql/test/library-tests/yaml/ast/AST.expected

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
| Chart.yml:6:10:6:14 | 0.1.0 |
1212
| Chart.yml:7:1:7:10 | appVersion |
1313
| Chart.yml:7:13:7:20 | "1.16.0" |
14+
| sample.json:1:1:8:1 | { |
15+
| sample.json:2:5:2:10 | "this" |
16+
| sample.json:2:13:2:16 | "is" |
17+
| sample.json:3:5:3:7 | "a" |
18+
| sample.json:3:10:6:5 | { |
19+
| sample.json:4:9:4:16 | "sample" |
20+
| sample.json:4:19:4:24 | "json" |
21+
| sample.json:5:9:5:14 | "file" |
22+
| sample.json:5:17:5:17 | 4 |
23+
| sample.json:7:5:7:13 | "testing" |
24+
| sample.json:7:16:7:19 | true |
1425
| sample.yml:1:1:1:4 | this |
1526
| sample.yml:1:1:6:11 | this: is |
1627
| sample.yml:1:7:1:8 | is |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"this": "is",
3+
"a": {
4+
"sample": "json",
5+
"file": 4
6+
},
7+
"testing": true
8+
}

0 commit comments

Comments
 (0)