Inference/src/Semantic/SSAAlgorithm/SSAHelper.cs
/// <summary>
/// Updates the type of every symbol, following the following algorithm used in the SSA proccess of the switch statement:
/// The new type of each symbols is a union of its types in the typeExpressionsAfterCases container.
/// Additionaly, if the symbol does not exist in the intersection set, the type in typeExpressionsBeforeSwitch is also added to the union.
/// </summary>
/// <param name="typeExpressionsBeforeSwitch">Types of all the references before the switch</param>
/// <param name="typeExpressionsAfterCases">Types of the references after each switch</param>
/// <param name="typeExpressionIntersectionSet">References that are used in all the cases (including default)</param>
/// <param name="methodAnalyzed">The method being analyzed</param>
/// <param name="actualImplicitObject">The actual implicit object</param>
Updates the type of every symbol, following the following algorithm used in the SSA proccess of the switch statement:
The new type of each symbols is a union of its types in the typeExpressionsAfterCases container.
Additionaly, if the symbol does not exist in the intersection set, the type in typeExpressionsBeforeSwitch is also added to the union.
Updates the type of every symbol following the following algorithm used in the SSA proccess of the switch statement : The new type of each symbols is a union of its types in the typeExpressionsAfterCases container . Additionaly if the symbol does not exist in the intersection set the type in typeExpressionsBeforeSwitch is also added to the union .
public static void SetUnionTypesOfReferences(IDictionary<Block, IDictionary<SingleIdentifierExpression, TypeExpression>> typeExpressionsBeforeSwitch,
                                                     IDictionary<Block, IDictionary<SingleIdentifierExpression, TypeExpression>> typeExpressionsAfterCases,
                                                     IDictionary<SingleIdentifierExpression, TypeExpression> typeExpressionIntersectionSet,
                                                     MethodType methodAnalyzed, TypeExpression actualImplicitObject) {
            foreach (KeyValuePair<Block, IDictionary<SingleIdentifierExpression, TypeExpression>> pair1 in typeExpressionsBeforeSwitch)
                foreach (KeyValuePair<SingleIdentifierExpression, TypeExpression> pair2 in pair1.Value)
                    pair2.Key.IdSymbol.SymbolType = null;
            foreach (KeyValuePair<Block, IDictionary<SingleIdentifierExpression, TypeExpression>> pair1 in typeExpressionsAfterCases)
                foreach (KeyValuePair<SingleIdentifierExpression, TypeExpression> pair2 in pair1.Value)
                    pair2.Key.IdSymbol.SymbolType = UnionType.collect(pair2.Key.IdSymbol.SymbolType, pair2.Value);
            foreach (KeyValuePair<Block, IDictionary<SingleIdentifierExpression, TypeExpression>> pair1 in typeExpressionsBeforeSwitch)
                foreach (KeyValuePair<SingleIdentifierExpression, TypeExpression> pair2 in pair1.Value)
                    if (typeExpressionIntersectionSet == null || !typeExpressionIntersectionSet.ContainsKey(pair2.Key))
                        pair2.Key.IdSymbol.SymbolType = UnionType.collect(pair2.Key.IdSymbol.SymbolType, pair2.Value);
        }
public static void SetUnionTypesOfReferences ( IDictionary < Block , IDictionary < SingleIdentifierExpression , TypeExpression > > typeExpressionsBeforeSwitch , IDictionary < Block , IDictionary < SingleIdentifierExpression , TypeExpression > > typeExpressionsAfterCases , IDictionary < SingleIdentifierExpression , TypeExpression > typeExpressionIntersectionSet , MethodType methodAnalyzed , TypeExpression actualImplicitObject ) { foreach ( KeyValuePair < Block , IDictionary < SingleIdentifierExpression , TypeExpression > > pair1 in typeExpressionsBeforeSwitch ) foreach ( KeyValuePair < SingleIdentifierExpression , TypeExpression > pair2 in pair1 . Value ) pair2 . Key . IdSymbol . SymbolType = null ; foreach ( KeyValuePair < Block , IDictionary < SingleIdentifierExpression , TypeExpression > > pair1 in typeExpressionsAfterCases ) foreach ( KeyValuePair < SingleIdentifierExpression , TypeExpression > pair2 in pair1 . Value ) pair2 . Key . IdSymbol . SymbolType = UnionType . collect ( pair2 . Key . IdSymbol . SymbolType , pair2 . Value ) ; foreach ( KeyValuePair < Block , IDictionary < SingleIdentifierExpression , TypeExpression > > pair1 in typeExpressionsBeforeSwitch ) foreach ( KeyValuePair < SingleIdentifierExpression , TypeExpression > pair2 in pair1 . Value ) if ( typeExpressionIntersectionSet == null || ! typeExpressionIntersectionSet . ContainsKey ( pair2 . Key ) ) pair2 . Key . IdSymbol . SymbolType = UnionType . collect ( pair2 . Key . IdSymbol . SymbolType , pair2 . Value ) ; }
Updates the type of every symbol, following the following algorithm used in the SSA proccess of the switch statement:
The new type of each symbols is a union of its types in the typeExpressionsAfterCases container.
Updates the type of every symbol following the following algorithm used in the SSA proccess of the switch statement : The new type of each symbols is a union of its types in the typeExpressionsAfterCases container .
// * We set all types to null // * We set the union types of all the references in a case body // * We add the initial type to all those symbols that were not used in all the cases
typeExpressionsBeforeSwitch
IDictionary<Block, IDictionary<SingleIdentifierExpression, TypeExpression>>
Types of all the references before the switch
Types of all the references before the switch
typeExpressionsAfterCases
IDictionary<Block, IDictionary<SingleIdentifierExpression, TypeExpression>>
Types of the references after each switch
Types of the references after each switch
typeExpressionIntersectionSet
IDictionary<SingleIdentifierExpression, TypeExpression>
References that are used in all the cases (including default)
References that are used in all the cases ( including default )
methodAnalyzed
MethodType
The method being analyzed
The method being analyzed
actualImplicitObject
TypeExpression
The actual implicit object
The actual implicit object