public static void CreateCommentNode(this SyntaxNode node, ISymbol symbol) { string commentStr = node.GetDocumentationComment(); if (commentStr == string.Empty) return; if (symbol.IsLimCompatibile()) { Member limNode = symbol.ConvertToLimNode() as Member; Comment comment = MainDeclaration.Instance.LimFactory.createCommentNode(commentStr.TrimEnd('\r', '\n')); Commons.Common.Safe_Edge(limNode, "HasComment", comment.Id); } }
/// <summary> /// </summary> /// <param name="symbol"></param> /// <param name="calledSymbol"></param> /// <param name="nodeFilter"></param> public static void CreateMethodCallEdge(ISymbol symbol, ISymbol calledSymbol, NodeFilter nodeFilter = null) { var isNeedToFilter = nodeFilter != null; var methodSymbol = symbol as IMethodSymbol; Base node; if (methodSymbol != null && methodSymbol.IsGenericMethod) { node = methodSymbol.GetMGI(calledSymbol as IMethodSymbol); var id = MainDeclaration.Instance.LimFactory.createTypeFormerType(node.Id).Id; MainDeclaration.Instance.LimFactory.addTypeFormer(id); var type = MainDeclaration.Instance.LimFactory.endType( ); if (isNeedToFilter) { nodeFilter(id); nodeFilter(type.Id); } } else { if (isNeedToFilter) { node = SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(( IMethodSymbol )calledSymbol); (( Member )node).IsCompilerGenerated = true; Commons.Common.FillFromMethodStack(MainDeclaration.Instance.MethodStack.Pop( )); } else { node = calledSymbol.ConvertToLimNode( ); } } if (isNeedToFilter) { nodeFilter(node.Id); } var methodCall = MainDeclaration.Instance.LimFactory.createMethodCall(node.Id); if (isNeedToFilter) { nodeFilter(methodCall.Id); } MainDeclaration.Instance.MethodStack.Peek( ) .Calls.Add(new KeyValuePair <uint, bool>(methodCall.Id, isNeedToFilter)); }
/// <summary> /// Type building strategy /// </summary> /// <param name="node"></param> /// <param name="refs"></param> public static void AddLimTypeFormers(ISymbol node, ISymbol refs = null) { switch (node.Kind) { case SymbolKind.ArrayType: MainDeclaration.Instance.LimFactory.addTypeFormer(MainDeclaration.Instance.LimFactory.createTypeFormerArray().Id); var arrayTypeSymbol = node as IArrayTypeSymbol; if (arrayTypeSymbol.ElementType != null) { if (arrayTypeSymbol.ElementType.IsInMetadata()) { AddLimTypeFormers(arrayTypeSymbol.ElementType); } else { SyntaxNode syntaxNode = null; var @ref = arrayTypeSymbol.ElementType.GetDefinition(out syntaxNode); if (@ref != null && @ref.Kind == arrayTypeSymbol.ElementType.Kind) { if (@ref is INamedTypeSymbol && ((INamedTypeSymbol)@ref).IsGenericType) { AddLimTypeFormers(arrayTypeSymbol.ElementType, @ref); } else { AddLimTypeFormers(@ref); } } } } break; case SymbolKind.TypeParameter: GenericParameter gp = (GenericParameter)node.ConvertToLimNode(); if (gp == null) { return; } MainDeclaration.Instance.LimFactory.addTypeFormer(MainDeclaration.Instance.LimFactory.createTypeFormerType(gp.Id).Id); break; case SymbolKind.PointerType: IPointerTypeSymbol pointerType = node as IPointerTypeSymbol; if (pointerType.IsReferenceType) { MainDeclaration.Instance.LimFactory.addTypeFormer(MainDeclaration.Instance.LimFactory.createTypeFormerPointer(Types.PointerKind.ptkReference).Id); } else { MainDeclaration.Instance.LimFactory.addTypeFormer(MainDeclaration.Instance.LimFactory.createTypeFormerPointer(Types.PointerKind.ptkPointer).Id); } AddLimTypeFormers(pointerType.PointedAtType); break; case SymbolKind.NamedType: var namedTypeSymbol = node as INamedTypeSymbol; if (namedTypeSymbol.IsGenericType) { ClassGenericInstance cgi = node.GetCGI(refs as INamedTypeSymbol); MainDeclaration.Instance.LimFactory.addTypeFormer( MainDeclaration.Instance.LimFactory.createTypeFormerType(cgi.Id).Id ); } else { Types.SimpleTypeKind stk = Types.SimpleTypeKind.stkUnknown; switch (namedTypeSymbol.SpecialType) { case SpecialType.System_Object: stk = Types.SimpleTypeKind.stkObject; break; case SpecialType.System_Void: stk = Types.SimpleTypeKind.stkVoid; break; case SpecialType.System_Single: stk = Types.SimpleTypeKind.stkSingle; break; case SpecialType.System_Boolean: stk = Types.SimpleTypeKind.stkBoolean; break; case SpecialType.System_Char: stk = Types.SimpleTypeKind.stkCharacter; break; case SpecialType.System_SByte: stk = Types.SimpleTypeKind.stkByte; break; case SpecialType.System_Byte: stk = Types.SimpleTypeKind.stkByte; break; case SpecialType.System_Int16: stk = Types.SimpleTypeKind.stkShort; break; case SpecialType.System_UInt16: stk = Types.SimpleTypeKind.stkUnsignedShort; break; case SpecialType.System_Int32: stk = Types.SimpleTypeKind.stkInteger; break; case SpecialType.System_UInt32: stk = Types.SimpleTypeKind.stkUnsignedInteger; break; case SpecialType.System_Int64: stk = Types.SimpleTypeKind.stkLong; break; case SpecialType.System_UInt64: stk = Types.SimpleTypeKind.stkUnsignedLong; break; case SpecialType.System_Decimal: stk = Types.SimpleTypeKind.stkDecimal; break; case SpecialType.System_Double: stk = Types.SimpleTypeKind.stkDouble; break; case SpecialType.System_String: stk = Types.SimpleTypeKind.stkString; break; default: SyntaxNode __node; var _node = node.GetDefinition(out __node); if (!node.IsInMetadata() && _node == null) { break; } Base refLimNode = node.ConvertToLimNode(); if (node.IsInMetadata()) { MetaDataNameFiller(node, (Member)refLimNode); } MainDeclaration.Instance.LimFactory.addTypeFormer(MainDeclaration.Instance.LimFactory.createTypeFormerType(refLimNode.Id).Id); return; } MainDeclaration.Instance.LimFactory.addTypeFormer( MainDeclaration.Instance.LimFactory.createTypeFormerType( MainDeclaration.Instance.LimFactory.createSimpleType(stk).Id ).Id ); } break; case SymbolKind.DynamicType: case SymbolKind.ErrorType: MainDeclaration.Instance.LimFactory.addTypeFormer(MainDeclaration.Instance.LimFactory.createTypeFormerNonType().Id); break; } }
private void fillMemberData(Member limNode, ISymbol roslynNode, bool setHasMember, bool aggregateLLOC = true) { limNode.Language = Types.LanguageKind.lnkCsharp; if (roslynNode.IsInMetadata()) { MainDeclaration.Instance.LimFactory.setFiltered(limNode.Id); } if (MainDeclaration.Instance.SoftFilter != null) { if (MainDeclaration.Instance.CurrentFileIsSoftFiltered) { MainDeclaration.Instance.LimFactory.setFiltered(limNode.Id); } } #region Accessibility switch (roslynNode.DeclaredAccessibility) { case Accessibility.Private: limNode.Accessibility = Types.AccessibilityKind.ackPrivate; break; case Accessibility.ProtectedAndInternal: limNode.Accessibility = Types.AccessibilityKind.ackInternal; break; case Accessibility.Protected: limNode.Accessibility = Types.AccessibilityKind.ackProtected; break; case Accessibility.Internal: limNode.Accessibility = Types.AccessibilityKind.ackInternal; break; case Accessibility.ProtectedOrInternal: limNode.Accessibility = Types.AccessibilityKind.ackProtectedInternal; break; case Accessibility.Public: limNode.Accessibility = Types.AccessibilityKind.ackPublic; break; default: break; } #endregion limNode.IsStatic = roslynNode.IsStatic; limNode.IsCompilerGenerated = false; limNode.MangledName = roslynNode.ToString(); limNode.DemangledName = limNode.MangledName; if (aggregateLLOC && !roslynNode.IsInMetadata()) { INamespaceSymbol ns = null; if (roslynNode.Kind == SymbolKind.Namespace) { ns = (INamespaceSymbol)roslynNode; } if (ns == null || (ns != null && !ns.IsGlobalNamespace)) { foreach (var location in roslynNode.DeclaringSyntaxReferences) { Commons.Common.AddIsContainedInEdge(limNode, location.GetSyntax()); } } } Commons.Common.Safe_Edge(limNode, "BelongsTo", MainDeclaration.Instance.Component.Id); if (setHasMember) { ISymbol roslynParent = roslynNode; Base limParent = null; do { roslynParent = roslynParent != null?roslynParent.Parent() : null; if (roslynParent != null) { limParent = roslynParent.ConvertToLimNode(); if (roslynParent.Kind == SymbolKind.Namespace) { fillMemberData((Member)limParent, roslynParent, true, false); } if (roslynParent.IsInMetadata()) { ((Member)limParent).IsCompilerGenerated = true; ((Scope)limParent).MangledName = ((Scope)limParent).DemangledName = roslynParent.ToString(); MainDeclaration.Instance.LimFactory.setFiltered(limParent.Id); } } else { limParent = null; } } while (roslynParent != null && !Lim.Asg.Common.getIsScope(limParent)); if (limParent != null) { Scope scope = (Scope)limParent; Commons.Common.Safe_Edge(scope, "HasMember", limNode.Id); } } if (aggregateLLOC && !roslynNode.IsInMetadata() && roslynNode.DeclaringSyntaxReferences.Length > 0) { foreach (var syntaxNode in roslynNode.DeclaringSyntaxReferences) { LLOC.CollectLineInfos(syntaxNode.GetSyntax()); } } }
/// <summary> /// Create cross edge for Attribute through the AtrributeAccess edge /// </summary> /// <param name="node"></param> /// <param name="symbol"></param> public static void CreateAttributeAccessEdge(CSharpSyntaxNode node, ISymbol symbol) { SyntaxNode field; var calledSymbol = symbol.GetDefinition(out field); if (calledSymbol != null && symbol.Kind == calledSymbol.Kind) { AttributeAccess attributeAccess; if (node.SyntaxTree.IsEquivalentTo(field.SyntaxTree)) // is it in source? { attributeAccess = MainDeclaration.Instance.LimFactory.createAttributeAccessNode(symbol.ConvertToLimNode( ).Id); } else // is it out source? { attributeAccess = MainDeclaration.Instance.LimFactory.createAttributeAccessNode( calledSymbol.ConvertToLimNode( ).Id); } MainDeclaration.Instance.MethodStack.Peek( ) .AccessAttribute.Add(new KeyValuePair <uint, bool>(attributeAccess.Id, false)); } }