clair
clair copied to clipboard
Documentation for the M3 Model
It would be helpful to have the M3 model documented:
- which relations are there?
- what can they be used for?
- example
Reason: To benefit from the level of abstraction provided by the M3, it needs to be understandable. Discovering what the M3 captures might lead to misunderstandings, missed data that is contained in the M3, and too much focus on understanding inner workings rather than to work on the abstraction itself.
To give this a start let's collect the information here and then move it to the docs of the clair project:
generic M3
- see https://www.rascal-mpl.org/docs/Library/analysis/m3/Core/, but these are most relevant:
-
rel[loc name, loc src] declarations = {}, // maps declarations to where they are declared. contains any kind of data or type or code declaration (classes, fields, methods, variables, etc. etc.) -
set[loc] implicitDeclarations = {}, // some languages provide builtin implicit declarations, e.g. |java+class:///java/lang/Object| may not have a source location but still exist. -
rel[loc from, loc to] containment = {}, // what inner declaration (to) is logically contained in what outer declaration (from) (not necessarily physically, but usually also)
-
C/C++ specific M3
- [x]
rel[loc base, loc derived] extends = {},-- which class extends which other class - [x]
rel[loc caller, loc callee] methodInvocations = {},-- from caller id to callee id (usually a function, or virtual method). Calls to constructors also end up here as calls tonew:///.... See alsomethodOverrides - [ ]
rel[loc field, loc accesser] fieldAccess = {}, - [ ]
rel[loc caller, loc typeName] typeDependency = {}, - [x]
rel[loc base, loc override] methodOverrides = {},-- for everynewcall the code (constructor, function, template) that thenewinvokes, and for every (virtual) method that is implemented or overridden, by whom. This is a one-to-many relation. - [x]
rel[loc file, loc macro] macroExpansions = {},-- explains where in the input file which macro was expanded - [ ]
rel[loc macro, loc src] macroDefinitions = {},-- a subset ofdeclarationsfocuses only on macros. perhaps should be folded intodeclarationsfor simplicity's sake. - [ ]
rel[loc directive, loc occurrence] includeDirectives = {},-- TODO? - [ ]
rel[loc directive, loc occurrence] inactiveIncludes = {},-- TODO? - [ ]
rel[loc directive, loc resolved] includeResolution = {},-- maps#includeinstances to the file they were resolved to. after merging M3 models, this can be become a one-to-many relation if the include path was different when extracting from different compilation units. - [ ]
rel[loc decl, TypeSymbol typ] declaredType = {},-- TODO? - [ ]
rel[loc decl, loc visiblity] memberAccessModifiers = {},-- TODO? how is this different frommodifiersin Core? - [ ]
rel[loc decl, loc src] functionDefinitions = {},-- TODO? why is this different fromdeclarationsin Core? - [ ]
rel[loc decl, loc src] cFunctionsToNoArgs = {},-- TODO? - [ ]
rel[loc decl, loc impl] declarationToDefinition = {},-- TODO? - [x]
rel[loc directive, loc file] unresolvedIncludes = {},-- reports which #include's where not resolved for easy diagnostics and assessing the impact on the accuracy of the rest of the model. - [ ]
list[loc] comments = [],-- lists where all the comments are - [ ]
rel[loc includer, loc includee] requires = {},-- TODO ? - [ ]
rel[loc provider, loc providee] provides = {},-- TODO ? - [ ]
rel[loc decl, loc file] partOf = {},-- TODO? - [x]
rel[loc caller, loc callee] callGraph = {}-- an initial call graph links caller (functions, methods, constructors, static blocks) to callee (functions, methods, constructors, virtual methods, methods). Make sure to complete withmethodOverrides. This is calledmethodInvocationin the Java M3 model, but Java only has methods and C/C++ also has other things that can be called.
@rodinaarssen if you have some time, could you help with these TODO's?