mirror of
https://github.com/github/codeql.git
synced 2026-02-08 11:11:06 +01:00
add types
This commit is contained in:
committed by
GitHub
parent
ec98e8a82d
commit
a692794178
@@ -117,7 +117,7 @@ class VarDecl extends TVarDecl, AstNode {
|
||||
/**
|
||||
* Gets the name for this variable declaration.
|
||||
*/
|
||||
string getName() { result = var.getChild(_).(Generated::VarName).getChild().getValue() }
|
||||
string getName() { result = var.getChild(1).(Generated::VarName).getChild().getValue() }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "VarDecl" }
|
||||
|
||||
@@ -126,7 +126,41 @@ class VarDecl extends TVarDecl, AstNode {
|
||||
or
|
||||
result.(Class).getAField() = this
|
||||
}
|
||||
// TODO: Getter for the Type.
|
||||
|
||||
Type getType() { toGenerated(result) = var.getChild(0) }
|
||||
}
|
||||
|
||||
/**
|
||||
* A type, such as `DataFlow::Node`.
|
||||
*/
|
||||
class Type extends TType, AstNode {
|
||||
Generated::TypeExpr type;
|
||||
|
||||
Type() { this = TType(type) }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Type" }
|
||||
|
||||
/**
|
||||
* Gets the class name for the type.
|
||||
* E.g. `Node` in `DataFlow::Node`.
|
||||
* Also gets the name for primitive types such as `string` or `int`.
|
||||
*/
|
||||
string getClassName() {
|
||||
result = type.getName().getValue()
|
||||
or
|
||||
result = type.getChild().(Generated::PrimitiveType).getValue()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if this type is a primitive such as `string` or `int`.
|
||||
*/
|
||||
predicate isPrimitive() { type.getChild() instanceof Generated::PrimitiveType }
|
||||
|
||||
/**
|
||||
* Gets the module name of the type, if it exists.
|
||||
* E.g. `DataFlow` in `DataFlow::Node`.
|
||||
*/
|
||||
string getModuleName() { result = type.getChild().(Generated::ModuleExpr).getName().getValue() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@ newtype TAstNode =
|
||||
TNewType(Generated::Datatype dt) or
|
||||
TNewTypeBranch(Generated::DatatypeBranch branch) or
|
||||
TImport(Generated::ImportDirective imp) or
|
||||
TType(Generated::TypeExpr type) or
|
||||
TDisjunction(Generated::Disjunction disj) or
|
||||
TConjunction(Generated::Conjunction conj) or
|
||||
TComparisonFormula(Generated::CompTerm comp) or
|
||||
@@ -67,6 +68,8 @@ Generated::AstNode toGenerated(AST::AstNode n) {
|
||||
n = TNewTypeBranch(result)
|
||||
or
|
||||
n = TImport(result)
|
||||
or
|
||||
n = TType(result)
|
||||
}
|
||||
|
||||
class TPredicate = TCharPred or TClasslessPredicate or TClassPredicate;
|
||||
|
||||
Reference in New Issue
Block a user