@@ -34,7 +34,7 @@ public SemanticModel GetModel(SyntaxNode node)
3434 return cachedModel ;
3535 }
3636
37- private SemanticModel cachedModel ;
37+ private SemanticModel ? cachedModel ;
3838
3939 /// <summary>
4040 /// Access to the trap file.
@@ -49,7 +49,31 @@ public SemanticModel GetModel(SyntaxNode node)
4949 /// <param name="factory">The entity factory.</param>
5050 /// <param name="init">The initializer for the entity.</param>
5151 /// <returns>The new/existing entity.</returns>
52- public Entity CreateEntity < Type , Entity > ( ICachedEntityFactory < Type , Entity > factory , Type init ) where Entity : ICachedEntity
52+ public Entity CreateEntity < Type , Entity > ( ICachedEntityFactory < Type , Entity > factory , Type init ) where Entity : ICachedEntity where Type : struct
53+ {
54+ return CreateNonNullEntity ( factory , init ) ;
55+ }
56+
57+ /// <summary>
58+ /// Creates a new entity using the factory.
59+ /// </summary>
60+ /// <param name="factory">The entity factory.</param>
61+ /// <param name="init">The initializer for the entity.</param>
62+ /// <returns>The new/existing entity.</returns>
63+ public Entity CreateNullableEntity < Type , Entity > ( ICachedEntityFactory < Type , Entity > factory , Type init ) where Entity : ICachedEntity
64+ {
65+ return init == null ? CreateEntity2 ( factory , init ) : CreateNonNullEntity ( factory , init ) ;
66+ }
67+
68+ /// <summary>
69+ /// Creates a new entity using the factory.
70+ /// </summary>
71+ /// <param name="factory">The entity factory.</param>
72+ /// <param name="init">The initializer for the entity.</param>
73+ /// <returns>The new/existing entity.</returns>
74+ public Entity CreateEntityFromSymbol < Type , Entity > ( ICachedEntityFactory < Type , Entity > factory , Type init )
75+ where Entity : ICachedEntity
76+ where Type : ISymbol
5377 {
5478 return init == null ? CreateEntity2 ( factory , init ) : CreateNonNullEntity ( factory , init ) ;
5579 }
@@ -135,8 +159,11 @@ private void CheckEntityHasUniqueLabel(string id, ICachedEntity entity)
135159
136160 public Label GetNewLabel ( ) => new Label ( GetNewId ( ) ) ;
137161
138- private Entity CreateNonNullEntity < Type , Entity > ( ICachedEntityFactory < Type , Entity > factory , Type init ) where Entity : ICachedEntity
162+ public Entity CreateNonNullEntity < Type , Entity > ( ICachedEntityFactory < Type , Entity > factory , Type init )
163+ where Entity : ICachedEntity
139164 {
165+ if ( init is null ) throw new ArgumentException ( "Unexpected null value" , nameof ( init ) ) ;
166+
140167 if ( objectEntityCache . TryGetValue ( init , out var cached ) )
141168 return ( Entity ) cached ;
142169
@@ -360,7 +387,7 @@ public void EmitTrap(TextWriter trapFile)
360387 /// <param name="optionalSymbol">Symbol for reporting errors.</param>
361388 /// <param name="entity">The entity to populate.</param>
362389 /// <exception cref="InternalError">Thrown on invalid trap stack behaviour.</exception>
363- public void Populate ( ISymbol optionalSymbol , ICachedEntity entity )
390+ public void Populate ( ISymbol ? optionalSymbol , ICachedEntity entity )
364391 {
365392 if ( WritingLabel )
366393 {
@@ -453,9 +480,9 @@ public void BindComments(IEntity entity, Microsoft.CodeAnalysis.Location l)
453480 /// <param name="message">The error message.</param>
454481 /// <param name="entityText">A textual representation of the failed entity.</param>
455482 /// <param name="location">The location of the error.</param>
456- /// <param name="stackTrace">An optional stack trace of the error, or an empty string .</param>
483+ /// <param name="stackTrace">An optional stack trace of the error, or null .</param>
457484 /// <param name="severity">The severity of the error.</param>
458- public void ExtractionError ( string message , string entityText , Entities . Location location , string stackTrace = "" , Severity severity = Severity . Error )
485+ public void ExtractionError ( string message , string entityText , Entities . Location location , string ? stackTrace = null , Severity severity = Severity . Error )
459486 {
460487 var msg = new Message ( message , entityText , location , stackTrace , severity ) ;
461488 ExtractionError ( msg ) ;
@@ -467,7 +494,7 @@ public void ExtractionError(string message, string entityText, Entities.Location
467494 /// <param name="message">The text of the message.</param>
468495 /// <param name="optionalSymbol">The symbol of the error, or null.</param>
469496 /// <param name="optionalEntity">The entity of the error, or null.</param>
470- public void ExtractionError ( string message , ISymbol optionalSymbol , IEntity optionalEntity )
497+ public void ExtractionError ( string message , ISymbol ? optionalSymbol , IEntity optionalEntity )
471498 {
472499 if ( ! ( optionalSymbol is null ) )
473500 {
@@ -539,7 +566,7 @@ static public void ModelError(this Context cx, string msg)
539566 /// <param name="node">Optional syntax node for error reporting.</param>
540567 /// <param name="symbol">Optional symbol for error reporting.</param>
541568 /// <param name="a">The action to perform.</param>
542- static public void Try ( this Context context , SyntaxNode node , ISymbol symbol , Action a )
569+ static public void Try ( this Context context , SyntaxNode ? node , ISymbol ? symbol , Action a )
543570 {
544571 try
545572 {
0 commit comments