mirror of
https://github.com/github/codeql.git
synced 2025-12-17 09:13:20 +01:00
C++/C#: Make IRVariable and its derived classes non-abstract
This commit is contained in:
@@ -17,10 +17,16 @@ IRUserVariable getIRUserVariable(Language::Function func, Language::Variable var
|
|||||||
* be a user-declared variable (`IRUserVariable`) or a temporary variable
|
* be a user-declared variable (`IRUserVariable`) or a temporary variable
|
||||||
* generated by the AST-to-IR translation (`IRTempVariable`).
|
* generated by the AST-to-IR translation (`IRTempVariable`).
|
||||||
*/
|
*/
|
||||||
abstract class IRVariable extends TIRVariable {
|
class IRVariable extends TIRVariable {
|
||||||
Language::Function func;
|
Language::Function func;
|
||||||
|
|
||||||
abstract string toString();
|
IRVariable() {
|
||||||
|
this = TIRUserVariable(_, _, func) or
|
||||||
|
this = TIRTempVariable(func, _, _, _) or
|
||||||
|
this = TIRStringLiteral(func, _, _, _)
|
||||||
|
}
|
||||||
|
|
||||||
|
string toString() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds if this variable's value cannot be changed within a function. Currently used for string
|
* Holds if this variable's value cannot be changed within a function. Currently used for string
|
||||||
@@ -41,19 +47,19 @@ abstract class IRVariable extends TIRVariable {
|
|||||||
/**
|
/**
|
||||||
* Gets the type of the variable.
|
* Gets the type of the variable.
|
||||||
*/
|
*/
|
||||||
abstract Language::LanguageType getLanguageType();
|
Language::LanguageType getLanguageType() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the AST node that declared this variable, or that introduced this
|
* Gets the AST node that declared this variable, or that introduced this
|
||||||
* variable as part of the AST-to-IR translation.
|
* variable as part of the AST-to-IR translation.
|
||||||
*/
|
*/
|
||||||
abstract Language::AST getAST();
|
Language::AST getAST() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an identifier string for the variable. This identifier is unique
|
* Gets an identifier string for the variable. This identifier is unique
|
||||||
* within the function.
|
* within the function.
|
||||||
*/
|
*/
|
||||||
abstract string getUniqueId();
|
string getUniqueId() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the source location of this variable.
|
* Gets the source location of this variable.
|
||||||
@@ -101,16 +107,31 @@ class IRUserVariable extends IRVariable, TIRUserVariable {
|
|||||||
* stack. This includes all parameters, non-static local variables, and
|
* stack. This includes all parameters, non-static local variables, and
|
||||||
* temporary variables.
|
* temporary variables.
|
||||||
*/
|
*/
|
||||||
abstract class IRAutomaticVariable extends IRVariable { }
|
class IRAutomaticVariable extends IRVariable {
|
||||||
|
IRAutomaticVariable() {
|
||||||
|
exists(Language::Variable var |
|
||||||
|
this = TIRUserVariable(var, _, func) and
|
||||||
|
Language::isVariableAutomatic(var)
|
||||||
|
) or
|
||||||
|
this = TIRTempVariable(func, _, _, _)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a user-declared variable that is allocated on the stack. This
|
||||||
|
* includes all parameters and non-static local variables.
|
||||||
|
*/
|
||||||
class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable {
|
class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable {
|
||||||
override Language::AutomaticVariable var;
|
override Language::AutomaticVariable var;
|
||||||
|
|
||||||
IRAutomaticUserVariable() { Language::isVariableAutomatic(var) }
|
|
||||||
|
|
||||||
final override Language::AutomaticVariable getVariable() { result = var }
|
final override Language::AutomaticVariable getVariable() { result = var }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a user-declared variable that is not allocated on the stack. This
|
||||||
|
* includes all global variables, namespace-scope variables, static fields, and
|
||||||
|
* static local variables.
|
||||||
|
*/
|
||||||
class IRStaticUserVariable extends IRUserVariable {
|
class IRStaticUserVariable extends IRUserVariable {
|
||||||
override Language::StaticVariable var;
|
override Language::StaticVariable var;
|
||||||
|
|
||||||
@@ -119,10 +140,19 @@ class IRStaticUserVariable extends IRUserVariable {
|
|||||||
final override Language::StaticVariable getVariable() { result = var }
|
final override Language::StaticVariable getVariable() { result = var }
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class IRGeneratedVariable extends IRVariable {
|
/**
|
||||||
|
* Represents a variable that is not user-declared. This includes temporary
|
||||||
|
* variables generated as part of IR construction, as well as string literals.
|
||||||
|
*/
|
||||||
|
class IRGeneratedVariable extends IRVariable {
|
||||||
Language::AST ast;
|
Language::AST ast;
|
||||||
Language::LanguageType type;
|
Language::LanguageType type;
|
||||||
|
|
||||||
|
IRGeneratedVariable() {
|
||||||
|
this = TIRTempVariable(func, ast, _, type) or
|
||||||
|
this = TIRStringLiteral(func, ast, type, _)
|
||||||
|
}
|
||||||
|
|
||||||
final override Language::LanguageType getLanguageType() { result = type }
|
final override Language::LanguageType getLanguageType() { result = type }
|
||||||
|
|
||||||
final override Language::AST getAST() { result = ast }
|
final override Language::AST getAST() { result = ast }
|
||||||
@@ -144,6 +174,11 @@ IRTempVariable getIRTempVariable(Language::AST ast, TempVariableTag tag) {
|
|||||||
result.getTag() = tag
|
result.getTag() = tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a temporary variable introduced by IR construction. The most common examples are the
|
||||||
|
* variable generated to hold the return value of afunction, or the variable generated to hold the
|
||||||
|
* result of a condition operator (`a ? b : c`).
|
||||||
|
*/
|
||||||
class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVariable {
|
class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVariable {
|
||||||
TempVariableTag tag;
|
TempVariableTag tag;
|
||||||
|
|
||||||
@@ -158,18 +193,28 @@ class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVa
|
|||||||
override string getBaseString() { result = "#temp" }
|
override string getBaseString() { result = "#temp" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The temporary variable generated to hold the return value of a function.
|
||||||
|
*/
|
||||||
class IRReturnVariable extends IRTempVariable {
|
class IRReturnVariable extends IRTempVariable {
|
||||||
IRReturnVariable() { tag = ReturnValueTempVar() }
|
IRReturnVariable() { tag = ReturnValueTempVar() }
|
||||||
|
|
||||||
final override string toString() { result = "#return" }
|
final override string toString() { result = "#return" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The temporary variable generated to hold the exception thrown by a `ThrowValue` instruction.
|
||||||
|
*/
|
||||||
class IRThrowVariable extends IRTempVariable {
|
class IRThrowVariable extends IRTempVariable {
|
||||||
IRThrowVariable() { tag = ThrowTempVar() }
|
IRThrowVariable() { tag = ThrowTempVar() }
|
||||||
|
|
||||||
override string getBaseString() { result = "#throw" }
|
override string getBaseString() { result = "#throw" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The variable generated to represent the contents of a string literal. This variable acts much
|
||||||
|
* like a read-only global variable.
|
||||||
|
*/
|
||||||
class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
|
class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
|
||||||
Language::StringLiteral literal;
|
Language::StringLiteral literal;
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,16 @@ IRUserVariable getIRUserVariable(Language::Function func, Language::Variable var
|
|||||||
* be a user-declared variable (`IRUserVariable`) or a temporary variable
|
* be a user-declared variable (`IRUserVariable`) or a temporary variable
|
||||||
* generated by the AST-to-IR translation (`IRTempVariable`).
|
* generated by the AST-to-IR translation (`IRTempVariable`).
|
||||||
*/
|
*/
|
||||||
abstract class IRVariable extends TIRVariable {
|
class IRVariable extends TIRVariable {
|
||||||
Language::Function func;
|
Language::Function func;
|
||||||
|
|
||||||
abstract string toString();
|
IRVariable() {
|
||||||
|
this = TIRUserVariable(_, _, func) or
|
||||||
|
this = TIRTempVariable(func, _, _, _) or
|
||||||
|
this = TIRStringLiteral(func, _, _, _)
|
||||||
|
}
|
||||||
|
|
||||||
|
string toString() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds if this variable's value cannot be changed within a function. Currently used for string
|
* Holds if this variable's value cannot be changed within a function. Currently used for string
|
||||||
@@ -41,19 +47,19 @@ abstract class IRVariable extends TIRVariable {
|
|||||||
/**
|
/**
|
||||||
* Gets the type of the variable.
|
* Gets the type of the variable.
|
||||||
*/
|
*/
|
||||||
abstract Language::LanguageType getLanguageType();
|
Language::LanguageType getLanguageType() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the AST node that declared this variable, or that introduced this
|
* Gets the AST node that declared this variable, or that introduced this
|
||||||
* variable as part of the AST-to-IR translation.
|
* variable as part of the AST-to-IR translation.
|
||||||
*/
|
*/
|
||||||
abstract Language::AST getAST();
|
Language::AST getAST() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an identifier string for the variable. This identifier is unique
|
* Gets an identifier string for the variable. This identifier is unique
|
||||||
* within the function.
|
* within the function.
|
||||||
*/
|
*/
|
||||||
abstract string getUniqueId();
|
string getUniqueId() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the source location of this variable.
|
* Gets the source location of this variable.
|
||||||
@@ -101,16 +107,31 @@ class IRUserVariable extends IRVariable, TIRUserVariable {
|
|||||||
* stack. This includes all parameters, non-static local variables, and
|
* stack. This includes all parameters, non-static local variables, and
|
||||||
* temporary variables.
|
* temporary variables.
|
||||||
*/
|
*/
|
||||||
abstract class IRAutomaticVariable extends IRVariable { }
|
class IRAutomaticVariable extends IRVariable {
|
||||||
|
IRAutomaticVariable() {
|
||||||
|
exists(Language::Variable var |
|
||||||
|
this = TIRUserVariable(var, _, func) and
|
||||||
|
Language::isVariableAutomatic(var)
|
||||||
|
) or
|
||||||
|
this = TIRTempVariable(func, _, _, _)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a user-declared variable that is allocated on the stack. This
|
||||||
|
* includes all parameters and non-static local variables.
|
||||||
|
*/
|
||||||
class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable {
|
class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable {
|
||||||
override Language::AutomaticVariable var;
|
override Language::AutomaticVariable var;
|
||||||
|
|
||||||
IRAutomaticUserVariable() { Language::isVariableAutomatic(var) }
|
|
||||||
|
|
||||||
final override Language::AutomaticVariable getVariable() { result = var }
|
final override Language::AutomaticVariable getVariable() { result = var }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a user-declared variable that is not allocated on the stack. This
|
||||||
|
* includes all global variables, namespace-scope variables, static fields, and
|
||||||
|
* static local variables.
|
||||||
|
*/
|
||||||
class IRStaticUserVariable extends IRUserVariable {
|
class IRStaticUserVariable extends IRUserVariable {
|
||||||
override Language::StaticVariable var;
|
override Language::StaticVariable var;
|
||||||
|
|
||||||
@@ -119,10 +140,19 @@ class IRStaticUserVariable extends IRUserVariable {
|
|||||||
final override Language::StaticVariable getVariable() { result = var }
|
final override Language::StaticVariable getVariable() { result = var }
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class IRGeneratedVariable extends IRVariable {
|
/**
|
||||||
|
* Represents a variable that is not user-declared. This includes temporary
|
||||||
|
* variables generated as part of IR construction, as well as string literals.
|
||||||
|
*/
|
||||||
|
class IRGeneratedVariable extends IRVariable {
|
||||||
Language::AST ast;
|
Language::AST ast;
|
||||||
Language::LanguageType type;
|
Language::LanguageType type;
|
||||||
|
|
||||||
|
IRGeneratedVariable() {
|
||||||
|
this = TIRTempVariable(func, ast, _, type) or
|
||||||
|
this = TIRStringLiteral(func, ast, type, _)
|
||||||
|
}
|
||||||
|
|
||||||
final override Language::LanguageType getLanguageType() { result = type }
|
final override Language::LanguageType getLanguageType() { result = type }
|
||||||
|
|
||||||
final override Language::AST getAST() { result = ast }
|
final override Language::AST getAST() { result = ast }
|
||||||
@@ -144,6 +174,11 @@ IRTempVariable getIRTempVariable(Language::AST ast, TempVariableTag tag) {
|
|||||||
result.getTag() = tag
|
result.getTag() = tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a temporary variable introduced by IR construction. The most common examples are the
|
||||||
|
* variable generated to hold the return value of afunction, or the variable generated to hold the
|
||||||
|
* result of a condition operator (`a ? b : c`).
|
||||||
|
*/
|
||||||
class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVariable {
|
class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVariable {
|
||||||
TempVariableTag tag;
|
TempVariableTag tag;
|
||||||
|
|
||||||
@@ -158,18 +193,28 @@ class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVa
|
|||||||
override string getBaseString() { result = "#temp" }
|
override string getBaseString() { result = "#temp" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The temporary variable generated to hold the return value of a function.
|
||||||
|
*/
|
||||||
class IRReturnVariable extends IRTempVariable {
|
class IRReturnVariable extends IRTempVariable {
|
||||||
IRReturnVariable() { tag = ReturnValueTempVar() }
|
IRReturnVariable() { tag = ReturnValueTempVar() }
|
||||||
|
|
||||||
final override string toString() { result = "#return" }
|
final override string toString() { result = "#return" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The temporary variable generated to hold the exception thrown by a `ThrowValue` instruction.
|
||||||
|
*/
|
||||||
class IRThrowVariable extends IRTempVariable {
|
class IRThrowVariable extends IRTempVariable {
|
||||||
IRThrowVariable() { tag = ThrowTempVar() }
|
IRThrowVariable() { tag = ThrowTempVar() }
|
||||||
|
|
||||||
override string getBaseString() { result = "#throw" }
|
override string getBaseString() { result = "#throw" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The variable generated to represent the contents of a string literal. This variable acts much
|
||||||
|
* like a read-only global variable.
|
||||||
|
*/
|
||||||
class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
|
class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
|
||||||
Language::StringLiteral literal;
|
Language::StringLiteral literal;
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,16 @@ IRUserVariable getIRUserVariable(Language::Function func, Language::Variable var
|
|||||||
* be a user-declared variable (`IRUserVariable`) or a temporary variable
|
* be a user-declared variable (`IRUserVariable`) or a temporary variable
|
||||||
* generated by the AST-to-IR translation (`IRTempVariable`).
|
* generated by the AST-to-IR translation (`IRTempVariable`).
|
||||||
*/
|
*/
|
||||||
abstract class IRVariable extends TIRVariable {
|
class IRVariable extends TIRVariable {
|
||||||
Language::Function func;
|
Language::Function func;
|
||||||
|
|
||||||
abstract string toString();
|
IRVariable() {
|
||||||
|
this = TIRUserVariable(_, _, func) or
|
||||||
|
this = TIRTempVariable(func, _, _, _) or
|
||||||
|
this = TIRStringLiteral(func, _, _, _)
|
||||||
|
}
|
||||||
|
|
||||||
|
string toString() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds if this variable's value cannot be changed within a function. Currently used for string
|
* Holds if this variable's value cannot be changed within a function. Currently used for string
|
||||||
@@ -41,19 +47,19 @@ abstract class IRVariable extends TIRVariable {
|
|||||||
/**
|
/**
|
||||||
* Gets the type of the variable.
|
* Gets the type of the variable.
|
||||||
*/
|
*/
|
||||||
abstract Language::LanguageType getLanguageType();
|
Language::LanguageType getLanguageType() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the AST node that declared this variable, or that introduced this
|
* Gets the AST node that declared this variable, or that introduced this
|
||||||
* variable as part of the AST-to-IR translation.
|
* variable as part of the AST-to-IR translation.
|
||||||
*/
|
*/
|
||||||
abstract Language::AST getAST();
|
Language::AST getAST() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an identifier string for the variable. This identifier is unique
|
* Gets an identifier string for the variable. This identifier is unique
|
||||||
* within the function.
|
* within the function.
|
||||||
*/
|
*/
|
||||||
abstract string getUniqueId();
|
string getUniqueId() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the source location of this variable.
|
* Gets the source location of this variable.
|
||||||
@@ -101,16 +107,31 @@ class IRUserVariable extends IRVariable, TIRUserVariable {
|
|||||||
* stack. This includes all parameters, non-static local variables, and
|
* stack. This includes all parameters, non-static local variables, and
|
||||||
* temporary variables.
|
* temporary variables.
|
||||||
*/
|
*/
|
||||||
abstract class IRAutomaticVariable extends IRVariable { }
|
class IRAutomaticVariable extends IRVariable {
|
||||||
|
IRAutomaticVariable() {
|
||||||
|
exists(Language::Variable var |
|
||||||
|
this = TIRUserVariable(var, _, func) and
|
||||||
|
Language::isVariableAutomatic(var)
|
||||||
|
) or
|
||||||
|
this = TIRTempVariable(func, _, _, _)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a user-declared variable that is allocated on the stack. This
|
||||||
|
* includes all parameters and non-static local variables.
|
||||||
|
*/
|
||||||
class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable {
|
class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable {
|
||||||
override Language::AutomaticVariable var;
|
override Language::AutomaticVariable var;
|
||||||
|
|
||||||
IRAutomaticUserVariable() { Language::isVariableAutomatic(var) }
|
|
||||||
|
|
||||||
final override Language::AutomaticVariable getVariable() { result = var }
|
final override Language::AutomaticVariable getVariable() { result = var }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a user-declared variable that is not allocated on the stack. This
|
||||||
|
* includes all global variables, namespace-scope variables, static fields, and
|
||||||
|
* static local variables.
|
||||||
|
*/
|
||||||
class IRStaticUserVariable extends IRUserVariable {
|
class IRStaticUserVariable extends IRUserVariable {
|
||||||
override Language::StaticVariable var;
|
override Language::StaticVariable var;
|
||||||
|
|
||||||
@@ -119,10 +140,19 @@ class IRStaticUserVariable extends IRUserVariable {
|
|||||||
final override Language::StaticVariable getVariable() { result = var }
|
final override Language::StaticVariable getVariable() { result = var }
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class IRGeneratedVariable extends IRVariable {
|
/**
|
||||||
|
* Represents a variable that is not user-declared. This includes temporary
|
||||||
|
* variables generated as part of IR construction, as well as string literals.
|
||||||
|
*/
|
||||||
|
class IRGeneratedVariable extends IRVariable {
|
||||||
Language::AST ast;
|
Language::AST ast;
|
||||||
Language::LanguageType type;
|
Language::LanguageType type;
|
||||||
|
|
||||||
|
IRGeneratedVariable() {
|
||||||
|
this = TIRTempVariable(func, ast, _, type) or
|
||||||
|
this = TIRStringLiteral(func, ast, type, _)
|
||||||
|
}
|
||||||
|
|
||||||
final override Language::LanguageType getLanguageType() { result = type }
|
final override Language::LanguageType getLanguageType() { result = type }
|
||||||
|
|
||||||
final override Language::AST getAST() { result = ast }
|
final override Language::AST getAST() { result = ast }
|
||||||
@@ -144,6 +174,11 @@ IRTempVariable getIRTempVariable(Language::AST ast, TempVariableTag tag) {
|
|||||||
result.getTag() = tag
|
result.getTag() = tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a temporary variable introduced by IR construction. The most common examples are the
|
||||||
|
* variable generated to hold the return value of afunction, or the variable generated to hold the
|
||||||
|
* result of a condition operator (`a ? b : c`).
|
||||||
|
*/
|
||||||
class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVariable {
|
class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVariable {
|
||||||
TempVariableTag tag;
|
TempVariableTag tag;
|
||||||
|
|
||||||
@@ -158,18 +193,28 @@ class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVa
|
|||||||
override string getBaseString() { result = "#temp" }
|
override string getBaseString() { result = "#temp" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The temporary variable generated to hold the return value of a function.
|
||||||
|
*/
|
||||||
class IRReturnVariable extends IRTempVariable {
|
class IRReturnVariable extends IRTempVariable {
|
||||||
IRReturnVariable() { tag = ReturnValueTempVar() }
|
IRReturnVariable() { tag = ReturnValueTempVar() }
|
||||||
|
|
||||||
final override string toString() { result = "#return" }
|
final override string toString() { result = "#return" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The temporary variable generated to hold the exception thrown by a `ThrowValue` instruction.
|
||||||
|
*/
|
||||||
class IRThrowVariable extends IRTempVariable {
|
class IRThrowVariable extends IRTempVariable {
|
||||||
IRThrowVariable() { tag = ThrowTempVar() }
|
IRThrowVariable() { tag = ThrowTempVar() }
|
||||||
|
|
||||||
override string getBaseString() { result = "#throw" }
|
override string getBaseString() { result = "#throw" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The variable generated to represent the contents of a string literal. This variable acts much
|
||||||
|
* like a read-only global variable.
|
||||||
|
*/
|
||||||
class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
|
class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
|
||||||
Language::StringLiteral literal;
|
Language::StringLiteral literal;
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,16 @@ IRUserVariable getIRUserVariable(Language::Function func, Language::Variable var
|
|||||||
* be a user-declared variable (`IRUserVariable`) or a temporary variable
|
* be a user-declared variable (`IRUserVariable`) or a temporary variable
|
||||||
* generated by the AST-to-IR translation (`IRTempVariable`).
|
* generated by the AST-to-IR translation (`IRTempVariable`).
|
||||||
*/
|
*/
|
||||||
abstract class IRVariable extends TIRVariable {
|
class IRVariable extends TIRVariable {
|
||||||
Language::Function func;
|
Language::Function func;
|
||||||
|
|
||||||
abstract string toString();
|
IRVariable() {
|
||||||
|
this = TIRUserVariable(_, _, func) or
|
||||||
|
this = TIRTempVariable(func, _, _, _) or
|
||||||
|
this = TIRStringLiteral(func, _, _, _)
|
||||||
|
}
|
||||||
|
|
||||||
|
string toString() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds if this variable's value cannot be changed within a function. Currently used for string
|
* Holds if this variable's value cannot be changed within a function. Currently used for string
|
||||||
@@ -41,19 +47,19 @@ abstract class IRVariable extends TIRVariable {
|
|||||||
/**
|
/**
|
||||||
* Gets the type of the variable.
|
* Gets the type of the variable.
|
||||||
*/
|
*/
|
||||||
abstract Language::LanguageType getLanguageType();
|
Language::LanguageType getLanguageType() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the AST node that declared this variable, or that introduced this
|
* Gets the AST node that declared this variable, or that introduced this
|
||||||
* variable as part of the AST-to-IR translation.
|
* variable as part of the AST-to-IR translation.
|
||||||
*/
|
*/
|
||||||
abstract Language::AST getAST();
|
Language::AST getAST() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an identifier string for the variable. This identifier is unique
|
* Gets an identifier string for the variable. This identifier is unique
|
||||||
* within the function.
|
* within the function.
|
||||||
*/
|
*/
|
||||||
abstract string getUniqueId();
|
string getUniqueId() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the source location of this variable.
|
* Gets the source location of this variable.
|
||||||
@@ -101,16 +107,31 @@ class IRUserVariable extends IRVariable, TIRUserVariable {
|
|||||||
* stack. This includes all parameters, non-static local variables, and
|
* stack. This includes all parameters, non-static local variables, and
|
||||||
* temporary variables.
|
* temporary variables.
|
||||||
*/
|
*/
|
||||||
abstract class IRAutomaticVariable extends IRVariable { }
|
class IRAutomaticVariable extends IRVariable {
|
||||||
|
IRAutomaticVariable() {
|
||||||
|
exists(Language::Variable var |
|
||||||
|
this = TIRUserVariable(var, _, func) and
|
||||||
|
Language::isVariableAutomatic(var)
|
||||||
|
) or
|
||||||
|
this = TIRTempVariable(func, _, _, _)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a user-declared variable that is allocated on the stack. This
|
||||||
|
* includes all parameters and non-static local variables.
|
||||||
|
*/
|
||||||
class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable {
|
class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable {
|
||||||
override Language::AutomaticVariable var;
|
override Language::AutomaticVariable var;
|
||||||
|
|
||||||
IRAutomaticUserVariable() { Language::isVariableAutomatic(var) }
|
|
||||||
|
|
||||||
final override Language::AutomaticVariable getVariable() { result = var }
|
final override Language::AutomaticVariable getVariable() { result = var }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a user-declared variable that is not allocated on the stack. This
|
||||||
|
* includes all global variables, namespace-scope variables, static fields, and
|
||||||
|
* static local variables.
|
||||||
|
*/
|
||||||
class IRStaticUserVariable extends IRUserVariable {
|
class IRStaticUserVariable extends IRUserVariable {
|
||||||
override Language::StaticVariable var;
|
override Language::StaticVariable var;
|
||||||
|
|
||||||
@@ -119,10 +140,19 @@ class IRStaticUserVariable extends IRUserVariable {
|
|||||||
final override Language::StaticVariable getVariable() { result = var }
|
final override Language::StaticVariable getVariable() { result = var }
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class IRGeneratedVariable extends IRVariable {
|
/**
|
||||||
|
* Represents a variable that is not user-declared. This includes temporary
|
||||||
|
* variables generated as part of IR construction, as well as string literals.
|
||||||
|
*/
|
||||||
|
class IRGeneratedVariable extends IRVariable {
|
||||||
Language::AST ast;
|
Language::AST ast;
|
||||||
Language::LanguageType type;
|
Language::LanguageType type;
|
||||||
|
|
||||||
|
IRGeneratedVariable() {
|
||||||
|
this = TIRTempVariable(func, ast, _, type) or
|
||||||
|
this = TIRStringLiteral(func, ast, type, _)
|
||||||
|
}
|
||||||
|
|
||||||
final override Language::LanguageType getLanguageType() { result = type }
|
final override Language::LanguageType getLanguageType() { result = type }
|
||||||
|
|
||||||
final override Language::AST getAST() { result = ast }
|
final override Language::AST getAST() { result = ast }
|
||||||
@@ -144,6 +174,11 @@ IRTempVariable getIRTempVariable(Language::AST ast, TempVariableTag tag) {
|
|||||||
result.getTag() = tag
|
result.getTag() = tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a temporary variable introduced by IR construction. The most common examples are the
|
||||||
|
* variable generated to hold the return value of afunction, or the variable generated to hold the
|
||||||
|
* result of a condition operator (`a ? b : c`).
|
||||||
|
*/
|
||||||
class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVariable {
|
class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVariable {
|
||||||
TempVariableTag tag;
|
TempVariableTag tag;
|
||||||
|
|
||||||
@@ -158,18 +193,28 @@ class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVa
|
|||||||
override string getBaseString() { result = "#temp" }
|
override string getBaseString() { result = "#temp" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The temporary variable generated to hold the return value of a function.
|
||||||
|
*/
|
||||||
class IRReturnVariable extends IRTempVariable {
|
class IRReturnVariable extends IRTempVariable {
|
||||||
IRReturnVariable() { tag = ReturnValueTempVar() }
|
IRReturnVariable() { tag = ReturnValueTempVar() }
|
||||||
|
|
||||||
final override string toString() { result = "#return" }
|
final override string toString() { result = "#return" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The temporary variable generated to hold the exception thrown by a `ThrowValue` instruction.
|
||||||
|
*/
|
||||||
class IRThrowVariable extends IRTempVariable {
|
class IRThrowVariable extends IRTempVariable {
|
||||||
IRThrowVariable() { tag = ThrowTempVar() }
|
IRThrowVariable() { tag = ThrowTempVar() }
|
||||||
|
|
||||||
override string getBaseString() { result = "#throw" }
|
override string getBaseString() { result = "#throw" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The variable generated to represent the contents of a string literal. This variable acts much
|
||||||
|
* like a read-only global variable.
|
||||||
|
*/
|
||||||
class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
|
class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
|
||||||
Language::StringLiteral literal;
|
Language::StringLiteral literal;
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,16 @@ IRUserVariable getIRUserVariable(Language::Function func, Language::Variable var
|
|||||||
* be a user-declared variable (`IRUserVariable`) or a temporary variable
|
* be a user-declared variable (`IRUserVariable`) or a temporary variable
|
||||||
* generated by the AST-to-IR translation (`IRTempVariable`).
|
* generated by the AST-to-IR translation (`IRTempVariable`).
|
||||||
*/
|
*/
|
||||||
abstract class IRVariable extends TIRVariable {
|
class IRVariable extends TIRVariable {
|
||||||
Language::Function func;
|
Language::Function func;
|
||||||
|
|
||||||
abstract string toString();
|
IRVariable() {
|
||||||
|
this = TIRUserVariable(_, _, func) or
|
||||||
|
this = TIRTempVariable(func, _, _, _) or
|
||||||
|
this = TIRStringLiteral(func, _, _, _)
|
||||||
|
}
|
||||||
|
|
||||||
|
string toString() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds if this variable's value cannot be changed within a function. Currently used for string
|
* Holds if this variable's value cannot be changed within a function. Currently used for string
|
||||||
@@ -41,19 +47,19 @@ abstract class IRVariable extends TIRVariable {
|
|||||||
/**
|
/**
|
||||||
* Gets the type of the variable.
|
* Gets the type of the variable.
|
||||||
*/
|
*/
|
||||||
abstract Language::LanguageType getLanguageType();
|
Language::LanguageType getLanguageType() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the AST node that declared this variable, or that introduced this
|
* Gets the AST node that declared this variable, or that introduced this
|
||||||
* variable as part of the AST-to-IR translation.
|
* variable as part of the AST-to-IR translation.
|
||||||
*/
|
*/
|
||||||
abstract Language::AST getAST();
|
Language::AST getAST() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an identifier string for the variable. This identifier is unique
|
* Gets an identifier string for the variable. This identifier is unique
|
||||||
* within the function.
|
* within the function.
|
||||||
*/
|
*/
|
||||||
abstract string getUniqueId();
|
string getUniqueId() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the source location of this variable.
|
* Gets the source location of this variable.
|
||||||
@@ -101,16 +107,31 @@ class IRUserVariable extends IRVariable, TIRUserVariable {
|
|||||||
* stack. This includes all parameters, non-static local variables, and
|
* stack. This includes all parameters, non-static local variables, and
|
||||||
* temporary variables.
|
* temporary variables.
|
||||||
*/
|
*/
|
||||||
abstract class IRAutomaticVariable extends IRVariable { }
|
class IRAutomaticVariable extends IRVariable {
|
||||||
|
IRAutomaticVariable() {
|
||||||
|
exists(Language::Variable var |
|
||||||
|
this = TIRUserVariable(var, _, func) and
|
||||||
|
Language::isVariableAutomatic(var)
|
||||||
|
) or
|
||||||
|
this = TIRTempVariable(func, _, _, _)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a user-declared variable that is allocated on the stack. This
|
||||||
|
* includes all parameters and non-static local variables.
|
||||||
|
*/
|
||||||
class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable {
|
class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable {
|
||||||
override Language::AutomaticVariable var;
|
override Language::AutomaticVariable var;
|
||||||
|
|
||||||
IRAutomaticUserVariable() { Language::isVariableAutomatic(var) }
|
|
||||||
|
|
||||||
final override Language::AutomaticVariable getVariable() { result = var }
|
final override Language::AutomaticVariable getVariable() { result = var }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a user-declared variable that is not allocated on the stack. This
|
||||||
|
* includes all global variables, namespace-scope variables, static fields, and
|
||||||
|
* static local variables.
|
||||||
|
*/
|
||||||
class IRStaticUserVariable extends IRUserVariable {
|
class IRStaticUserVariable extends IRUserVariable {
|
||||||
override Language::StaticVariable var;
|
override Language::StaticVariable var;
|
||||||
|
|
||||||
@@ -119,10 +140,19 @@ class IRStaticUserVariable extends IRUserVariable {
|
|||||||
final override Language::StaticVariable getVariable() { result = var }
|
final override Language::StaticVariable getVariable() { result = var }
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class IRGeneratedVariable extends IRVariable {
|
/**
|
||||||
|
* Represents a variable that is not user-declared. This includes temporary
|
||||||
|
* variables generated as part of IR construction, as well as string literals.
|
||||||
|
*/
|
||||||
|
class IRGeneratedVariable extends IRVariable {
|
||||||
Language::AST ast;
|
Language::AST ast;
|
||||||
Language::LanguageType type;
|
Language::LanguageType type;
|
||||||
|
|
||||||
|
IRGeneratedVariable() {
|
||||||
|
this = TIRTempVariable(func, ast, _, type) or
|
||||||
|
this = TIRStringLiteral(func, ast, type, _)
|
||||||
|
}
|
||||||
|
|
||||||
final override Language::LanguageType getLanguageType() { result = type }
|
final override Language::LanguageType getLanguageType() { result = type }
|
||||||
|
|
||||||
final override Language::AST getAST() { result = ast }
|
final override Language::AST getAST() { result = ast }
|
||||||
@@ -144,6 +174,11 @@ IRTempVariable getIRTempVariable(Language::AST ast, TempVariableTag tag) {
|
|||||||
result.getTag() = tag
|
result.getTag() = tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a temporary variable introduced by IR construction. The most common examples are the
|
||||||
|
* variable generated to hold the return value of afunction, or the variable generated to hold the
|
||||||
|
* result of a condition operator (`a ? b : c`).
|
||||||
|
*/
|
||||||
class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVariable {
|
class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVariable {
|
||||||
TempVariableTag tag;
|
TempVariableTag tag;
|
||||||
|
|
||||||
@@ -158,18 +193,28 @@ class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVa
|
|||||||
override string getBaseString() { result = "#temp" }
|
override string getBaseString() { result = "#temp" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The temporary variable generated to hold the return value of a function.
|
||||||
|
*/
|
||||||
class IRReturnVariable extends IRTempVariable {
|
class IRReturnVariable extends IRTempVariable {
|
||||||
IRReturnVariable() { tag = ReturnValueTempVar() }
|
IRReturnVariable() { tag = ReturnValueTempVar() }
|
||||||
|
|
||||||
final override string toString() { result = "#return" }
|
final override string toString() { result = "#return" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The temporary variable generated to hold the exception thrown by a `ThrowValue` instruction.
|
||||||
|
*/
|
||||||
class IRThrowVariable extends IRTempVariable {
|
class IRThrowVariable extends IRTempVariable {
|
||||||
IRThrowVariable() { tag = ThrowTempVar() }
|
IRThrowVariable() { tag = ThrowTempVar() }
|
||||||
|
|
||||||
override string getBaseString() { result = "#throw" }
|
override string getBaseString() { result = "#throw" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The variable generated to represent the contents of a string literal. This variable acts much
|
||||||
|
* like a read-only global variable.
|
||||||
|
*/
|
||||||
class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
|
class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
|
||||||
Language::StringLiteral literal;
|
Language::StringLiteral literal;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user