Skip to content

Commit

Permalink
Changing visibility to protected for all members of passes (#1242)
Browse files Browse the repository at this point in the history
Changing visibility to protected for all members of passes as this allows to subclass and therefore extend passes
  • Loading branch information
konradweiss authored Jul 18, 2023
1 parent 82a2964 commit 1bf8d14
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
* their parent record (more accurately their type). Seems to be only used by
* [getOverridingCandidates] and should probably be replaced through a scope manager call.
*/
private val containingType = mutableMapOf<FunctionDeclaration, Type>()
protected val containingType = mutableMapOf<FunctionDeclaration, Type>()

override fun cleanup() {
containingType.clear()
Expand Down Expand Up @@ -96,13 +96,13 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
}
}

private fun registerMethods(currentClass: RecordDeclaration?, currentNode: Node?) {
protected fun registerMethods(currentClass: RecordDeclaration?, currentNode: Node?) {
if (currentNode is MethodDeclaration && currentClass != null) {
containingType[currentNode] = currentNode.parseType(currentClass.name)
}
}

private fun fixInitializers(node: Node?) {
protected fun fixInitializers(node: Node?) {
if (node is VariableDeclaration) {
// check if we have the corresponding class for this type
val typeString = node.type.root.name
Expand Down Expand Up @@ -159,7 +159,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
}
}

private fun handleCallExpression(curClass: RecordDeclaration?, call: CallExpression) {
protected fun handleCallExpression(curClass: RecordDeclaration?, call: CallExpression) {
// Function pointers are handled by extra pass, so we are not resolving them here
if (call.callee?.type is FunctionPointerType) {
return
Expand Down Expand Up @@ -233,7 +233,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
*
* In case a resolution is not possible, `null` can be returned.
*/
private fun resolveCallee(
protected fun resolveCallee(
callee: Expression?,
curClass: RecordDeclaration?,
call: CallExpression
Expand All @@ -260,7 +260,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
}
}

private fun handleArguments(call: CallExpression) {
protected fun handleArguments(call: CallExpression) {
val worklist: Deque<Node> = ArrayDeque()
call.arguments.forEach { worklist.push(it) }
while (worklist.isNotEmpty()) {
Expand All @@ -283,7 +283,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
* Resolves a [CallExpression.callee] of type [DeclaredReferenceExpression] to a possible list
* of [FunctionDeclaration] nodes.
*/
private fun resolveReferenceCallee(
protected fun resolveReferenceCallee(
callee: DeclaredReferenceExpression,
curClass: RecordDeclaration?,
call: CallExpression
Expand Down Expand Up @@ -365,7 +365,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
return invocationCandidates
}

private fun retrieveInvocationCandidatesFromCall(
protected fun retrieveInvocationCandidatesFromCall(
call: CallExpression,
curClass: RecordDeclaration?,
possibleContainingTypes: Set<Type>
Expand All @@ -392,7 +392,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
* @param possibleContainingTypes
* @param call
*/
private fun createMethodDummies(
protected fun createMethodDummies(
possibleContainingTypes: Set<Type>,
call: CallExpression
): List<FunctionDeclaration> {
Expand All @@ -416,11 +416,11 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
* @param call
* @return true if we should stop searching parent, false otherwise
*/
private fun shouldSearchForInvokesInParent(call: CallExpression): Boolean {
protected fun shouldSearchForInvokesInParent(call: CallExpression): Boolean {
return scopeManager.resolveFunctionStopScopeTraversalOnDefinition(call).isEmpty()
}

private fun handleConstructExpression(constructExpression: ConstructExpression) {
protected fun handleConstructExpression(constructExpression: ConstructExpression) {
if (constructExpression.instantiates != null && constructExpression.constructor != null)
return
val typeName = constructExpression.type.name
Expand Down Expand Up @@ -464,7 +464,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
}
}

private fun handleExplicitConstructorInvocation(eci: ExplicitConstructorInvocation) {
protected fun handleExplicitConstructorInvocation(eci: ExplicitConstructorInvocation) {
eci.containingClass?.let { containingClass ->
val recordDeclaration = recordMap[eci.parseName(containingClass)]
val signature = eci.arguments.map { it.type }
Expand All @@ -478,7 +478,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
}
}

private fun getPossibleContainingTypes(node: Node?): Set<Type> {
protected fun getPossibleContainingTypes(node: Node?): Set<Type> {
val possibleTypes = mutableSetOf<Type>()
if (node is MemberCallExpression) {
node.base?.let { base ->
Expand Down Expand Up @@ -523,7 +523,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
}
}

private fun getInvocationCandidatesFromParents(
protected fun getInvocationCandidatesFromParents(
name: String?,
call: CallExpression,
possibleTypes: Set<RecordDeclaration>
Expand Down Expand Up @@ -553,12 +553,12 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
}
}

private val Language<out LanguageFrontend>?.isCPP: Boolean
protected val Language<out LanguageFrontend>?.isCPP: Boolean
get() {
return this != null && this::class.simpleName == "CPPLanguage"
}

private fun getOverridingCandidates(
protected fun getOverridingCandidates(
possibleSubTypes: Set<Type?>,
declaration: FunctionDeclaration
): Set<FunctionDeclaration> {
Expand All @@ -572,7 +572,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
* @param recordDeclaration matching the class the ConstructExpression wants to construct
* @return ConstructorDeclaration that matches the provided signature
*/
private fun getConstructorDeclarationDirectMatch(
protected fun getConstructorDeclarationDirectMatch(
signature: List<Type?>,
recordDeclaration: RecordDeclaration
): ConstructorDeclaration? {
Expand All @@ -591,7 +591,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
* there is no valid ConstructDeclaration we will create an implicit ConstructDeclaration that
* matches the ConstructExpression.
*/
private fun getConstructorDeclaration(
protected fun getConstructorDeclaration(
constructExpression: ConstructExpression,
recordDeclaration: RecordDeclaration
): ConstructorDeclaration {
Expand All @@ -616,7 +616,7 @@ open class CallResolver(ctx: TranslationContext) : SymbolResolverPass(ctx) {
.createInferredConstructor(constructExpression.signature)
}

private fun getConstructorDeclarationForExplicitInvocation(
protected fun getConstructorDeclarationForExplicitInvocation(
signature: List<Type?>,
recordDeclaration: RecordDeclaration
): ConstructorDeclaration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ open class ControlFlowSensitiveDFGPass(ctx: TranslationContext) : TranslationUni
* Removes all the incoming and outgoing DFG edges for each variable declaration in the block of
* code [node].
*/
private fun clearFlowsOfVariableDeclarations(node: Node) {
protected fun clearFlowsOfVariableDeclarations(node: Node) {
for (varDecl in node.variables) {
varDecl.clearPrevDFG()
varDecl.clearNextDFG()
Expand All @@ -90,7 +90,7 @@ open class ControlFlowSensitiveDFGPass(ctx: TranslationContext) : TranslationUni
* - Assignments with an operation e.g. of the form "variable += rhs"
* - Read operations on a variable
*/
private fun handleStatementHolder(node: Node) {
protected fun handleStatementHolder(node: Node) {
// The list of nodes that we have to consider and the last write operations to the different
// variables.
val worklist =
Expand Down Expand Up @@ -291,7 +291,7 @@ open class ControlFlowSensitiveDFGPass(ctx: TranslationContext) : TranslationUni
* Removes the DFG edges for a potential implicit return statement if it is not in
* [reachableReturnStatements].
*/
private fun removeUnreachableImplicitReturnStatement(
protected fun removeUnreachableImplicitReturnStatement(
node: Node,
reachableReturnStatements: MutableSet<ReturnStatement>
) {
Expand All @@ -311,7 +311,7 @@ open class ControlFlowSensitiveDFGPass(ctx: TranslationContext) : TranslationUni
* was the path through the EOG to reach this state but apparently, all the writes in the
* different branches are obsoleted by one common write access which happens afterwards.
*/
private fun worklistHasSimilarPair(
protected fun worklistHasSimilarPair(
worklist: MutableList<Pair<Node, MutableMap<Declaration, MutableList<Node>>>>,
newPair: Pair<Node, MutableMap<Declaration, MutableList<Node>>>
): Boolean {
Expand Down Expand Up @@ -372,20 +372,20 @@ open class ControlFlowSensitiveDFGPass(ctx: TranslationContext) : TranslationUni
* Checks if the node performs an operation and an assignment at the same time e.g. with the
* operators +=, -=, *=, ...
*/
private fun isCompoundAssignment(currentNode: Node) =
protected fun isCompoundAssignment(currentNode: Node) =
currentNode is BinaryOperator &&
currentNode.operatorCode in
(currentNode.language?.compoundAssignmentOperators ?: setOf()) &&
(currentNode.lhs as? DeclaredReferenceExpression)?.refersTo != null

/** Checks if the node is a simple assignment of the form `var = ...` */
private fun isSimpleAssignment(currentNode: Node) =
protected fun isSimpleAssignment(currentNode: Node) =
currentNode is BinaryOperator &&
currentNode.operatorCode == "=" &&
(currentNode.lhs as? DeclaredReferenceExpression)?.refersTo != null

/** Checks if the node is an increment or decrement operator (e.g. i++, i--, ++i, --i) */
private fun isIncOrDec(currentNode: Node) =
protected fun isIncOrDec(currentNode: Node) =
currentNode is UnaryOperator &&
(currentNode.operatorCode == "++" || currentNode.operatorCode == "--") &&
(currentNode.input as? DeclaredReferenceExpression)?.refersTo != null
Expand All @@ -397,7 +397,7 @@ open class ControlFlowSensitiveDFGPass(ctx: TranslationContext) : TranslationUni
*
* @return true if a loop was detected, false otherwise
*/
private fun loopDetection(
protected fun loopDetection(
currentNode: Node,
writtenDecl: Declaration?,
currentWritten: Node,
Expand Down Expand Up @@ -437,7 +437,7 @@ open class ControlFlowSensitiveDFGPass(ctx: TranslationContext) : TranslationUni
* Copies the map. We remove all the declarations which are no longer relevant because they are
* in a child scope of the next hop.
*/
private fun copyMap(
protected fun copyMap(
map: Map<Declaration, MutableList<Node>>,
nextNode: Node
): MutableMap<Declaration, MutableList<Node>> {
Expand All @@ -456,7 +456,7 @@ open class ControlFlowSensitiveDFGPass(ctx: TranslationContext) : TranslationUni
return result
}

private fun Node.hasOuterScopeOf(node: Node): Boolean {
protected fun Node.hasOuterScopeOf(node: Node): Boolean {
var parentScope = node.scope?.parent
while (parentScope != null) {
if (this.scope == parentScope) {
Expand Down
Loading

0 comments on commit 1bf8d14

Please sign in to comment.