@@ -19,8 +19,12 @@ private import Cfg1
1919private import Cfg2
2020import Public
2121
22- /** Provides an implementation of the AST signature for C#. */
23- private module Ast implements AstSig< Location > {
22+ /**
23+ * INTERNAL: Do not use.
24+ *
25+ * Provides an implementation of the AST signature for C#.
26+ */
27+ module Ast implements AstSig< Location > {
2428 private import csharp as CS
2529
2630 class AstNode = ControlFlowElementOrCallable ;
@@ -73,18 +77,41 @@ private module Ast implements AstSig<Location> {
7377 private AstNode getParent ( AstNode n ) { n = getChild ( result , _) }
7478
7579 Callable getEnclosingCallable ( AstNode node ) {
76- result = node .( ControlFlowElement ) .getEnclosingCallable ( ) or
77- result .( ObjectInitMethod ) .initializes ( getParent * ( node ) ) or
80+ result = node .( ControlFlowElement ) .getEnclosingCallable ( )
81+ or
82+ result .( ObjectInitMethod ) .initializes ( getParent * ( node ) )
83+ or
7884 Initializers:: staticMemberInitializer ( result , getParent * ( node ) )
85+ or
86+ result = node .( Parameter ) .getCallable ( )
87+ or
88+ not skipControlFlow ( node ) and
89+ getParent * ( node ) = any ( Parameter p | result = p .getCallable ( ) ) .getDefaultValue ( )
7990 }
8091
81- class Callable = CS:: Callable ;
92+ class Callable extends CS:: Callable {
93+ Callable ( ) { this .isUnboundDeclaration ( ) }
94+ }
8295
8396 AstNode callableGetBody ( Callable c ) {
8497 not skipControlFlow ( result ) and
8598 result = c .getBody ( )
8699 }
87100
101+ final private class ParameterFinal = CS:: Parameter ;
102+
103+ class Parameter extends ParameterFinal {
104+ Expr getDefaultValue ( ) {
105+ result = super .getDefaultValue ( ) and
106+ getCompilation ( result ) = getCompilation ( this )
107+ }
108+ }
109+
110+ Parameter callableGetParameter ( Callable c , int i ) {
111+ not skipControlFlow ( result ) and
112+ result = c .getParameter ( i )
113+ }
114+
88115 class Stmt = CS:: Stmt ;
89116
90117 class Expr = CS:: Expr ;
@@ -232,9 +259,11 @@ private class CompilationExt extends TCompilationExt {
232259}
233260
234261/** Gets the compilation that source file `f` belongs to. */
235- private CompilationExt getCompilation ( File f ) {
262+ bindingset [ e]
263+ pragma [ inline_late]
264+ private CompilationExt getCompilation ( Element e ) {
236265 exists ( Compilation c |
237- f = c .getAFileCompiled ( ) and
266+ e . getALocation ( ) . getFile ( ) = c .getAFileCompiled ( ) and
238267 result = TCompilation ( c )
239268 )
240269 or
@@ -415,12 +444,12 @@ private module Input implements InputSig1, InputSig2 {
415444 l = TLblGoto ( n .( LabelStmt ) .getLabel ( ) )
416445 }
417446
418- class CallableBodyPartContext = CompilationExt ;
447+ class CallableContext = CompilationExt ;
419448
420449 pragma [ nomagic]
421- Ast:: AstNode callableGetBodyPart ( Callable c , CallableBodyPartContext ctx , int index ) {
450+ Ast:: AstNode callableGetBodyPart ( Ast :: Callable c , CallableContext ctx , int index ) {
422451 not Ast:: skipControlFlow ( result ) and
423- ctx = getCompilation ( result . getFile ( ) ) and
452+ ctx = getCompilation ( result ) and
424453 (
425454 result = Initializers:: initializedInstanceMemberOrder ( c , index )
426455 or
@@ -437,9 +466,19 @@ private module Input implements InputSig1, InputSig2 {
437466 or
438467 i = 2 and result = ctor .getBody ( )
439468 )
469+ or
470+ not c instanceof Constructor and
471+ result = c .getBody ( ) and
472+ index = 0
440473 )
441474 }
442475
476+ pragma [ nomagic]
477+ Ast:: Parameter callableGetParameter ( Ast:: Callable c , CallableContext ctx , int index ) {
478+ result = Ast:: callableGetParameter ( c , index ) and
479+ ctx = getCompilation ( result )
480+ }
481+
443482 private Expr getQualifier ( QualifiableExpr qe ) {
444483 result = qe .getQualifier ( ) or
445484 result = qe .( ExtensionMethodCall ) .getArgument ( 0 )
0 commit comments