add types

This commit is contained in:
Erik Krogh Kristensen
2021-05-26 21:10:37 +00:00
committed by GitHub
parent ec98e8a82d
commit a692794178
2 changed files with 39 additions and 2 deletions

View File

@@ -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() }
}
/**

View File

@@ -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;