QL code and tests for C#/C++/JavaScript.

This commit is contained in:
Pavel Avgustinov
2018-08-02 17:53:23 +01:00
commit b55526aa58
10684 changed files with 581163 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
| fields.cpp:1:6:1:9 | Type | fields.cpp:1:13:1:13 | S | getDeclaringEnum() |
| fields.cpp:1:6:1:9 | Type | fields.cpp:1:13:1:13 | S | getType() |
| fields.cpp:1:6:1:9 | Type | fields.cpp:1:16:1:16 | I | getDeclaringEnum() |
| fields.cpp:1:6:1:9 | Type | fields.cpp:1:16:1:16 | I | getType() |

View File

@@ -0,0 +1,11 @@
/**
* @name EnumConst
* @kind table
*/
import cpp
from Enum e, Declaration c, string reason
where (c.(EnumConstant).getDeclaringEnum() = e and reason = "getDeclaringEnum()") or
(c.(EnumConstant).getType() = e and reason = "getType()") or
(c.(Field).getDeclaringType() = e and reason = "getDeclaringType()")
select e, c, reason

View File

@@ -0,0 +1,13 @@
| fields.cpp:3:8:3:12 | Entry | fields.cpp:4:9:4:12 | name | public | CharPointerType | char |
| fields.cpp:3:8:3:12 | Entry | fields.cpp:5:8:5:8 | t | public | Enum | |
| fields.cpp:3:8:3:12 | Entry | fields.cpp:6:9:6:9 | s | public | CharPointerType | char |
| fields.cpp:3:8:3:12 | Entry | fields.cpp:7:7:7:7 | i | public | IntType | |
| fields.cpp:3:8:3:12 | Entry | fields.cpp:7:7:7:7 | i | public | MicrosoftInt32Type | |
| fields.cpp:3:8:3:12 | Entry | fields.cpp:9:7:9:14 | internal | private | IntType | |
| fields.cpp:3:8:3:12 | Entry | fields.cpp:9:7:9:14 | internal | private | MicrosoftInt32Type | |
| fields.cpp:12:7:12:10 | Name | fields.cpp:13:15:13:15 | s | private | PointerType | const char |
| fields.cpp:16:7:16:11 | Table | fields.cpp:17:9:17:9 | p | private | PointerType | Name |
| fields.cpp:16:7:16:11 | Table | fields.cpp:18:7:18:8 | sz | private | IntType | |
| fields.cpp:16:7:16:11 | Table | fields.cpp:18:7:18:8 | sz | private | MicrosoftInt32Type | |
| fields.cpp:26:7:26:10 | Date | fields.cpp:28:16:28:26 | cache_valid | private | BoolType | |
| fields.cpp:26:7:26:10 | Date | fields.cpp:30:17:30:21 | cache | public | CharPointerType | char |

View File

@@ -0,0 +1,40 @@
/**
* @name Fields
* @kind table
*/
import cpp
predicate nameCheck(Declaration d) {
count(d.toString()) = 1 and
count(string s | d.hasName(s)) = 1 and
d.hasName(d.toString())
}
string accessType(Field f) {
(f.isPublic() and result = "public") or
(f.isProtected() and result = "protected") or
(f.isPrivate() and result = "private")
}
string fieldType(Field f) {
result = f.getType().getAQlClass() and
(
result.matches("%Type") or
result = "Enum"
)
}
string pointedType(Field f) {
if f.getType() instanceof PointerType then (
result = f.getType().(PointerType).getBaseType().toString()
) else (
result = ""
)
}
from Class c, Field f
where f.getDeclaringType() = c and
c.getAField() = f and
nameCheck(c) and
nameCheck(f)
select c, f, accessType(f), fieldType(f), pointedType(f)

View File

@@ -0,0 +1,13 @@
| fields.cpp:4:9:4:12 | name | | public |
| fields.cpp:5:8:5:8 | t | | public |
| fields.cpp:6:9:6:9 | s | | public |
| fields.cpp:7:7:7:7 | i | | public |
| fields.cpp:9:7:9:14 | internal | | private |
| fields.cpp:13:15:13:15 | s | | private |
| fields.cpp:17:9:17:9 | p | | private |
| fields.cpp:18:7:18:8 | sz | | private |
| fields.cpp:27:16:27:21 | memtbl | static | extern |
| fields.cpp:27:16:27:21 | memtbl | static | private |
| fields.cpp:27:16:27:21 | memtbl | static | static |
| fields.cpp:28:16:28:26 | cache_valid | | private |
| fields.cpp:30:17:30:21 | cache | | public |

View File

@@ -0,0 +1,9 @@
/**
* @name MemberVariable
* @kind table
*/
import cpp
from MemberVariable m, string static
where if m.isStatic() then static = "static" else static = ""
select m, static, m.getASpecifier().toString()

View File

@@ -0,0 +1,33 @@
enum Type { S, I };
struct Entry {
char* name;
Type t;
char* s;
int i;
private:
int internal;
};
class Name {
const char* s;
};
class Table {
Name* p;
int sz;
public:
Table(int s=15) { p = new Name[sz=s]; } // constructor
~Table() { delete[] p; }
Name* lookup (const char*);
bool insert(Name*);
};
class Date {
static Table memtbl;
mutable bool cache_valid;
public:
mutable char* cache;
void compute_cache_value() const;
};