Skip to content

Commit

Permalink
added resolution of overloaded binary and unary operators including t…
Browse files Browse the repository at this point in the history
…he call syntax itself
  • Loading branch information
jurgenvinju committed Feb 29, 2024
1 parent e897488 commit 521eeb4
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 374 deletions.
2 changes: 1 addition & 1 deletion src/lang/cpp/AST.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ data Declaration(list[Attribute] attributes = [], loc src=|unknown:///|, bool is
;


data Expression(loc src = |unknown:///|, TypeSymbol typ = \unresolved(), bool isMacroExpansion = false) //no attributes
data Expression(loc src = |unknown:///|, loc decl=|not-overloaded:///|, TypeSymbol typ = \unresolved(), bool isMacroExpansion = false) //no attributes
= \multiply(Expression lhs, Expression rhs)
| \divide(Expression lhs, Expression rhs)
| \modulo(Expression lhs, Expression rhs)
Expand Down
2 changes: 1 addition & 1 deletion src/lang/cpp/ASTgen.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ str type2FactoryCall(Symbol t){
bool hasDecl("Declaration", str cname)
= cname in {"enumerator", "usingDirective", "sttClass", "sttTypename", "tttParameter", "tttParameterWithDefault", "baseSpecifier", "namespaceDefinition", "namespaceDefinitionInline", "usingDeclaration", "namespaceAlias", "alias", "pointerToMember"};
bool hasDecl("Expression", str cname)
= cname in {"new", "newWithArgs", "globalNew", "globalNewWithArgs", "idExpression", "fieldReference", "fieldReferencePointerDeref", "templateId", "constructorChainInitializer", "capture", "captureByRef"};
= cname in {"new", "newWithArgs", "globalNew", "globalNewWithArgs", "idExpression", "fieldReference", "fieldReferencePointerDeref", "templateId", "constructorChainInitializer", "capture", "captureByRef"} || hasTyp("Expression", cname);
bool hasDecl("Statement", str cname) = cname in {"label", "goto"};
bool hasDecl("Name", "qualifiedName") = true;
bool hasDecl("Name", "templateId") = true;
Expand Down
10 changes: 5 additions & 5 deletions src/lang/cpp/M3.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ M3 cppASTToM3(Declaration tu, M3 model = m3(tu.src.top)) {
= { // direct function calls
*{<declarator.decl, functionName.decl> | /functionCall(Expression functionName, _) := body, functionName.decl?},
// calls via brackets
// calls via brackets (TODO: missing case for `operator ()` overloads)
*{<declarator.decl, functionName.expression.decl> | /functionCall(Expression functionName, _) := body, functionName is bracketed, functionName.expression.decl?},

// constructor calls
*{<declarator.decl, e.decl> | /Expression e := body, e is new || e is newWithArgs || e is globalNew || e is globalNewWithArgs, e.decl?}
// constructor calls and operator invocations
*{<declarator.decl, e.decl> | /Expression e := body, e is new || e is newWithArgs || e is globalNew || e is globalNewWithArgs || str _(_,_) := e || str _(_) := e, e.decl?}
| /functionDefinition(_, Declarator declarator, _, Statement body) := tu
}
;
Expand All @@ -105,7 +105,7 @@ rel[loc caller, loc callee] extractCallGraph(Declaration ast) = extractCallGraph
@synopsis{extracts dependencies between every declaration and every name that is used in it, that is not-not a "call"}
rel[loc caller, loc callee] extractCallGraph(set[Declaration] asts)
= { <caller.declarator.decl, c.decl> | ast <- asts, /Declaration caller := ast, caller has declarator, /Expression c := caller, c has decl,
c.decl.scheme notin {"cpp+class", "cpp+enumerator", "cpp+field", "cpp+parameter", "cpp+typedef", "cpp+variable", "c+variable", "unknown", "cpp+unknown"} }; //Over-approximation
c.decl.scheme notin {"not-overloaded", "cpp+class", "cpp+enumerator", "cpp+field", "cpp+parameter", "cpp+typedef", "cpp+variable", "c+variable", "unknown", "cpp+unknown"} }; //Over-approximation

private loc pretty(loc subject) = |<subject.scheme>:///| + pretty(subject.path);
private str pretty(str path) = replaceAll(path, "\\", "/");
Expand Down
Loading

0 comments on commit 521eeb4

Please sign in to comment.