public IntType(PredefinedTypeSyntax syntax, Package containingPackage, int bitLength, bool isSigned) : base(syntax, containingPackage, bitLength, isSigned) { var prefix = isSigned ? "int" : "uint"; Requires.That(syntax.Name.Text.StartsWith(prefix), nameof(syntax), $"Syntax must be for {prefix} type"); }
public FixedType(PredefinedTypeSyntax syntax, Package containingPackage, int bitLength, bool isSigned, int fractionalBits) : base(syntax, containingPackage, bitLength, isSigned) { Requires.That(fractionalBits <= bitLength, nameof(fractionalBits), "Must be less than bit length"); FractionalBits = fractionalBits; }
public override AnalyzeResult analyze() { var root = syntaxTree.GetRoot(); var methods = root.DescendantNodes().OfType <MethodDeclarationSyntax>().ToList(); List <Warning> warnings = new List <Warning>(); foreach (MethodDeclarationSyntax method in methods) { var parameters = method.ParameterList.Parameters.ToList(); foreach (var param in parameters) { PredefinedTypeSyntax type = (PredefinedTypeSyntax)param.Type; if (type.Keyword.Value == "bool") { warnings.Add(new Warning(String.Format(warning_format, method.Identifier, GetLineNumber(syntaxTree, method)))); break; } } } return(new AnalyzeResult( IssueDetail.BooleanParameter, warnings )); }
public string GetTypeScriptType(TypeSyntax propertyType) { PredefinedTypeSyntax predefinedType = propertyType as PredefinedTypeSyntax; if (predefinedType != null) { switch (predefinedType.Keyword.ValueText) { case "sbyte": case "byte": case "int": case "uint": case "short": case "ushort": case "long": case "ulong": case "float": case "double": case "decimal": return("number"); case "bool": return("boolean"); case "string": case "char": return("string"); } } return("any"); }
public override void VisitPredefinedType(PredefinedTypeSyntax node) { if (visitorContext.topCaptureScope != null) { visitorContext.topCaptureScope.ResolveAccessToken(node.Keyword.ValueText); } }
private async Task <Document> ChangePropertyTypeToStringAsync(Document document, TextSpan diagnosticSpan, CancellationToken cancellationToken) { SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var propertyNode = GetPropertyNodeWithDiagnostic(root, diagnosticSpan); if (propertyNode == null) { return(document); } PredefinedTypeSyntax stringType = SyntaxFactory.PredefinedType( SyntaxFactory.Token(SyntaxKind.StringKeyword)); if (stringType == null) { return(document); } var modifiedPropertyNode = propertyNode.WithType(stringType); if (modifiedPropertyNode == null || cancellationToken.IsCancellationRequested) { return(document); } var modifiedRoot = root.ReplaceNode(propertyNode, modifiedPropertyNode); return(document.WithSyntaxRoot(modifiedRoot)); }
public override void VisitPredefinedType(PredefinedTypeSyntax node) { string name = node.Keyword.Text; name = convert_type(name); emit(name); }
private void Analyze(INamedTypeSymbol namedSymbol, SyntaxNodeAnalysisContext context) { MethodDeclarationSyntax methodDeclaration = (MethodDeclarationSyntax)context.Node; if (!methodDeclaration.Modifiers.Any(SyntaxKind.AsyncKeyword)) { return; } PredefinedTypeSyntax predefinedTypeSyntax = methodDeclaration.ReturnType as PredefinedTypeSyntax; if (predefinedTypeSyntax == null || predefinedTypeSyntax.Keyword.Kind() != SyntaxKind.VoidKeyword) { return; } ISymbol symbol = context.SemanticModel.GetDeclaredSymbol(methodDeclaration); if (symbol is null || !(symbol is IMethodSymbol methodSymbol)) { return; } // check for the Event handlers as they use async void if (methodSymbol.Parameters.Any(x => x.Type is INamedTypeSymbol namedTypeSymbol && namedTypeSymbol.IsDerivedFrom(namedSymbol))) { return; } context.ReportDiagnostic(Diagnostic.Create(Rule, methodDeclaration.ReturnType.GetLocation(), methodSymbol.ReturnType.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat))); }
public static string ToTypescript(this PredefinedTypeSyntax syntaxItem) { switch (syntaxItem.Keyword.Kind()) { case SyntaxKind.StringKeyword: case SyntaxKind.CharKeyword: return("string"); case SyntaxKind.BoolKeyword: return("boolean"); case SyntaxKind.ByteKeyword: case SyntaxKind.SByteKeyword: case SyntaxKind.ShortKeyword: case SyntaxKind.UShortKeyword: case SyntaxKind.IntKeyword: case SyntaxKind.UIntKeyword: case SyntaxKind.LongKeyword: case SyntaxKind.ULongKeyword: case SyntaxKind.DoubleKeyword: case SyntaxKind.FloatKeyword: case SyntaxKind.DecimalKeyword: return("number"); case SyntaxKind.ObjectKeyword: return("any"); default: Log.Warn($"Unknown type: {syntaxItem}"); return("any"); } }
protected BoolMarshallerBase(PredefinedTypeSyntax nativeType, int trueValue, int falseValue, bool compareToTrue) { _nativeType = nativeType; _trueValue = trueValue; _falseValue = falseValue; _compareToTrue = compareToTrue; }
private PredefinedTypeNode ParsePredefinedType(PredefinedTypeSyntax type) { var keyword = KSyntaxFactory.Token(KSyntaxKind.LocalKeyword); var kPredefinedType = KSyntaxFactory.PredefinedType(keyword); return(kPredefinedType); }
public override void VisitPredefinedType(PredefinedTypeSyntax node) { IncrementNodeCount(1); // Predefined types are simple identifiers. AddOperand(node.Keyword.ValueText); base.VisitPredefinedType(node); }
public TypeSymbol ResolveIntrinsicType(PredefinedTypeSyntax type, ISymbolTable symbolTable, Symbol contextSymbol) { switch (type.Kind) { case SyntaxKind.PredefinedScalarType: return(ResolveIntrinsicScalarType((ScalarTypeSyntax)type)); case SyntaxKind.PredefinedVectorType: return(ResolveIntrinsicVectorType((VectorTypeSyntax)type)); case SyntaxKind.PredefinedGenericVectorType: return(ResolveIntrinsicGenericVectorType((GenericVectorTypeSyntax)type)); case SyntaxKind.PredefinedMatrixType: return(ResolveIntrinsicMatrixType((MatrixTypeSyntax)type)); case SyntaxKind.PredefinedGenericMatrixType: return(ResolveIntrinsicGenericMatrixType((GenericMatrixTypeSyntax)type)); case SyntaxKind.PredefinedObjectType: return(ResolveIntrinsicObjectType((PredefinedObjectTypeSyntax)type, symbolTable, contextSymbol)); default: throw new ArgumentOutOfRangeException(nameof(type), "Unmapped intrinsic type"); } }
public override IStmt VisitPredefinedType(PredefinedTypeSyntax node) { return(new IdentifierExpr { Identifier = node.Keyword.Text }); }
protected override object VisitPredefinedType(PredefinedTypeSyntax node) { var name = _Name(node.Keyword); var type = _ResolveLangType(node); return(type); }
/// <summary> /// 從程式碼讀出 class 的結構 /// </summary> public static CsSchema.Class AnalysisClass(string programText) { CsSchema.Class csClass = new CsSchema.Class(); List <CsSchema.Property> csProperties = new List <CsSchema.Property>(); SyntaxTree tree = CSharpSyntaxTree.ParseText(programText); CompilationUnitSyntax root = tree.GetRoot() as CompilationUnitSyntax; ClassDeclarationSyntax classSyntax = root.DescendantNodes().OfType <ClassDeclarationSyntax>().Single(); IEnumerable <PropertyDeclarationSyntax> propertiesSyntax = classSyntax.DescendantNodes().OfType <PropertyDeclarationSyntax>(); foreach (var propertySyntax in propertiesSyntax) { PredefinedTypeSyntax typeSyntax = propertySyntax.DescendantNodes().OfType <PredefinedTypeSyntax>().Single(); SyntaxToken type = typeSyntax.Keyword; SyntaxToken property = propertySyntax.Identifier; csProperties.Add(new CsSchema.Property() { Name = property.Text, TypeName = type.Text }); } csClass.Name = classSyntax.Identifier.Text; csClass.Properties = csProperties.ToArray(); return(csClass); }
public override SyntaxNode VisitPredefinedType(PredefinedTypeSyntax node) { if (MainDataType == DataType.Complexf) { if (node.ToString() == "float") { var newNode = node.WithKeyword(SyntaxFactory.ParseToken("double")); return(newNode.WithTriviaFrom(node)); } else { return(base.VisitPredefinedType(node)); } } if (node.ToString() != mainDataTypeName) { return(base.VisitPredefinedType(node)); } if (TargetDataType == DataType.Double) { var newNode = node.WithKeyword(SyntaxFactory.ParseToken("double")); return(newNode.WithTriviaFrom(node)); } else { var newNode = SyntaxFactory.IdentifierName(targetDataTypeName); return(newNode.WithTriviaFrom(node)); } }
private static string GetTypeNameForTypeSyntax(TypeSyntax type) { return(type switch { IdentifierNameSyntax identifierName => identifierName.Identifier.ValueText, PredefinedTypeSyntax predefinedType => predefinedType.Keyword.ValueText, _ => throw new NotSupportedException($"Type {type?.GetType()} is not supported") });
protected override IValue VisitPredefinedType(PredefinedTypeSyntax node) { var rt = ModelExtensions.GetTypeInfo(state.Context.RoslynModel, node); // var t = TypesUtil.PRIMITIVE_TYPES[node.Keyword.ValueText.Trim()]; var t = state.Context.Roslyn_ResolveType(rt.Type); return(new TypeValue(t)); }
// "int", "string" public override void VisitPredefinedType(PredefinedTypeSyntax node) { string nodeText = node.ToString(); foreach (string item in _typeToCheck) { return; } }
public override void VisitPredefinedType(PredefinedTypeSyntax predefinedType) { TypeInfo typeInfo = currentFileModel.semanticModel.GetTypeInfo(predefinedType); if (typeInfo.Type == null) { throw new InvalidOperationException(); } AddTypeAndNamespace(typeInfo.Type); }
public override void VisitPredefinedType(PredefinedTypeSyntax node) { if (!PreVisit(node)) { return; } base.VisitPredefinedType(node); PostVisit(node); }
private async Task<Document> ReplaceDateTimeAsync(Document document, PredefinedTypeSyntax node, CancellationToken cancellationToken) { var semanticModel = await document.GetSemanticModelAsync(cancellationToken); var root = await document.GetSyntaxRootAsync(); var node2 = node.WithKeyword(SyntaxFactory.ParseToken("DateTimeOffset")).WithTrailingTrivia(node.GetTrailingTrivia()); var newRoot = root.ReplaceNode(node, node2); var newDocument = document.WithSyntaxRoot(newRoot); return newDocument; }
/// <summary> /// Generates a sequence of initialize <see cref="StatementSyntax"/> for the specified sequence of <see cref="CommandElement"/>. /// </summary> /// <param name="commands">The sequence of <see cref="CommandElement"/> for which to generate the code.</param> /// <returns>The sequence of generated <see cref="StatementSyntax"/>.</returns> private static IEnumerable <StatementSyntax> GenerateInitializeStatements(IEnumerable <CommandElement> commands) { if (SyntaxFactory.ParseTypeName(DelegateCommand) is QualifiedNameSyntax typeName) { IdentifierNameSyntax parameterName = SyntaxFactory.IdentifierName(Parameter1Name); NameSyntax actionLeft = SyntaxFactory.ParseName(typeof(Action <object>).Namespace); GenericNameSyntax actionRight = SyntaxFactory.GenericName(nameof(Action <object>)); NameSyntax funcLeft = SyntaxFactory.ParseName(typeof(Func <object, bool>).Namespace); GenericNameSyntax funcRight = SyntaxFactory.GenericName(nameof(Func <object, bool>)); PredefinedTypeSyntax boolType = SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.BoolKeyword)); InvocationExpressionSyntax name = SyntaxFactory.InvocationExpression(SyntaxFactory.IdentifierName(SyntaxFactory.ParseToken(SyntaxFactory.Token(SyntaxKind.NameOfKeyword).ValueText))); foreach (CommandElement command in commands) { List <ArgumentSyntax> arguments = new List <ArgumentSyntax>(); arguments.Add( SyntaxFactory.Argument( SyntaxFactory.ObjectCreationExpression(SyntaxFactory.QualifiedName(actionLeft, actionRight.AddTypeArgumentListArguments(command.ParameterType))).AddArgumentListArguments( SyntaxFactory.Argument(SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, parameterName, SyntaxFactory.IdentifierName(command.Execute))) ) ) ); if (command.CanExecute.HasValue) { arguments.Add( SyntaxFactory.Argument( SyntaxFactory.ObjectCreationExpression(SyntaxFactory.QualifiedName(funcLeft, funcRight.AddTypeArgumentListArguments(command.ParameterType, boolType))).AddArgumentListArguments( SyntaxFactory.Argument(SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, parameterName, SyntaxFactory.IdentifierName(command.CanExecute.Value))) ) ) ); } arguments.Add(SyntaxFactory.Argument(name.AddArgumentListArguments(SyntaxFactory.Argument(SyntaxFactory.IdentifierName(command.Identifier))))); TypeSyntax type = typeName.WithRight(SyntaxFactory.GenericName(typeName.Right.Identifier).AddTypeArgumentListArguments(command.ParameterType)); yield return(SyntaxFactory.ExpressionStatement( SyntaxFactory.AssignmentExpression( SyntaxKind.SimpleAssignmentExpression, SyntaxFactory.IdentifierName(command.Identifier), SyntaxFactory.InvocationExpression(SyntaxFactory.ObjectCreationExpression(type)).AddArgumentListArguments(arguments.ToArray()) ) )); } } }
public static Type GetNodeDataType(SyntaxNode node) { PredefinedTypeSyntax castedNode = (PredefinedTypeSyntax)node; string value = castedNode.Keyword.Text; if (!PredefinedTypes.ContainsKey(value)) { throw new NotSupportedException($"PredefinedType {value} not catered for"); } return(PredefinedTypes[value]); }
private static async Task <Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) { var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); if (semanticModel == null) { return(document); } var node = root.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true, getInnermostNodeForTie: true); var memberAccess = node.Parent as MemberAccessExpressionSyntax; if (memberAccess != null) { if (node == memberAccess.Name) { node = memberAccess; } } var type = semanticModel.GetSymbolInfo(node, cancellationToken).Symbol as INamedTypeSymbol; SyntaxKind specialKind; if (!PredefinedSpecialTypes.TryGetValue(type.SpecialType, out specialKind)) { return(document); } SyntaxNode newNode; PredefinedTypeSyntax typeSyntax = SyntaxFactory.PredefinedType(SyntaxFactory.Token(specialKind)); if (node is CrefSyntax) { newNode = SyntaxFactory.TypeCref(typeSyntax); } else { newNode = typeSyntax; } newNode = newNode .WithTriviaFrom(node) .WithoutFormatting(); var newRoot = root.ReplaceNode(node, newNode); return(document.WithSyntaxRoot(newRoot)); }
private async Task<Document> ReplaceDateAsync(Document document, PredefinedTypeSyntax node, CancellationToken cancellationToken) { var root = await document.GetSyntaxRootAsync(); var generator = SyntaxGenerator.GetGenerator(document); var newIdentifierSyntax = generator.IdentifierName("DateTimeOffset").WithTrailingTrivia(node.GetTrailingTrivia()); var newRoot = root.ReplaceNode(node, newIdentifierSyntax); var newDocument = document.WithSyntaxRoot(newRoot); return newDocument; }
public static bool GetPredefinedType(INamedTypeSymbol type, out PredefinedTypeSyntax predefined) { var kind = type.SpecialType.ToSyntaxKind(); if (kind == SyntaxKind.None) { predefined = null; return(false); } predefined = PredefinedType(Token(kind)); return(true); }
public override SyntaxNode VisitPredefinedType(PredefinedTypeSyntax node) { node = (PredefinedTypeSyntax)base.VisitPredefinedType(node); var token = node.Keyword; if ((transformKind == TransformKind.IntTypeToLongType) && (token.Kind() == SyntaxKind.IntKeyword)) { var longToken = SyntaxFactory.Token(token.LeadingTrivia, SyntaxKind.LongKeyword, token.TrailingTrivia); return(SyntaxFactory.PredefinedType(longToken)); } return(node); }
private async Task<Document> ConvertPredefinedToSpecificTypeAsync(Document document, PredefinedTypeSyntax errorToken, CancellationToken c) { String predefinedType = errorToken.ToString(); var newType = SyntaxFactory.ParseTypeName(AvoidPreDefinedTypesAnalyzer.TypeMap[predefinedType]); newType = newType.WithAdditionalAnnotations(Formatter.Annotation); var root = await document.GetSyntaxRootAsync(c); var newRoot = root.ReplaceNode(errorToken, newType); var newDocument = document.WithSyntaxRoot(newRoot); return newDocument; }
public TypeStructure ConvertTypeStructure(TypeSyntax syntax) { return(syntax switch { PredefinedTypeSyntax ptSyntax => ToPredefinedIdentifierStructure(ptSyntax.Keyword.Text), IdentifierNameSyntax inSyntax => ToIdentifierStructure(inSyntax, _typeLocator), QualifiedNameSyntax qnSyntax => ToIdentifierStructure(qnSyntax), GenericNameSyntax gnSyntax => ToGenericTypeStructure(gnSyntax), ArrayTypeSyntax atSyntax => ToArrayTypeStructure(atSyntax), PointerTypeSyntax ptSyntax => ToPointerTypeStructure(ptSyntax), NullableTypeSyntax ntSyntax => ToNullableTypeStructure(ntSyntax), TupleTypeSyntax ttSyntax => ToTupleTypeStructure(ttSyntax), _ => throw new ArgumentException(syntax.GetType().ToString()) });
public static EnumDeclarationSyntax ToBaseType(this EnumDeclarationSyntax syntax, EnumBaseType baseType) { if (baseType == EnumBaseType.None) { return(syntax.WithBaseList(null)); } SyntaxKind keyword = enumBaseTypeMap[baseType]; PredefinedTypeSyntax typeSyntax = SyntaxFactory.PredefinedType(SyntaxFactory.Token(keyword)); SeparatedSyntaxList <BaseTypeSyntax> baseTypes = SyntaxFactory.SingletonSeparatedList <BaseTypeSyntax>(SyntaxFactory.SimpleBaseType(typeSyntax)); return(syntax.WithBaseList(SyntaxFactory.BaseList(baseTypes))); }
public override void VisitPredefinedType(PredefinedTypeSyntax node) { TypeInfo typeInfo = m_Model.GetTypeInfo(node); var type = typeInfo.Type; if (null != type) { string fullName = ClassInfo.GetFullName(type); CodeBuilder.Append(fullName); } else { CodeBuilder.Append(node.Keyword.Text); } }
public override SyntaxNode VisitPredefinedType(PredefinedTypeSyntax node) { bool oldAlwaysSimplify = this.alwaysSimplify; if (!this.alwaysSimplify) { this.alwaysSimplify = node.HasAnnotation(Simplifier.Annotation); } var result = SimplifyExpression( node, newNode: base.VisitPredefinedType(node), simplifier: SimplifyName); this.alwaysSimplify = oldAlwaysSimplify; return result; }
private SyntaxNode VisitPredefinedTypeSyntax(PredefinedTypeSyntax node) { if (node.Keyword.ValueText == "void") { return node; } String replacement; if (!replacements.TryGetValue(node.Keyword.ValueText, out replacement)) { throw new InvalidOperationException($"ERROR: Type '{node.Keyword.Value}' not defined."); } _typeKeywordsReplaced = true; return SyntaxFactory .IdentifierName(replacement) .WithTriviaFrom(node); }
public override void VisitPredefinedType(PredefinedTypeSyntax node) { var s = ""; var up = node.HasParent<VariableDeclarationSyntax, FieldDeclarationSyntax>(); if (up == null) { } else { s = "var "; } _2JS.Append(s); base.VisitPredefinedType(node); }
public static PredefinedTypeSyntax PredefinedType() { var result = new PredefinedTypeSyntax(); return result; }
public void VisitPredefinedType(PredefinedTypeSyntax node) { if (node == null) throw new ArgumentNullException("node"); node.Validate(); ExpressionStart(node); switch (node.Type) { case PredefinedType.Bool: _writer.WriteKeyword(PrinterKeyword.Bool); break; case PredefinedType.Byte: _writer.WriteKeyword(PrinterKeyword.Byte); break; case PredefinedType.Char: _writer.WriteKeyword(PrinterKeyword.Char); break; case PredefinedType.Decimal: _writer.WriteKeyword(PrinterKeyword.Decimal); break; case PredefinedType.Double: _writer.WriteKeyword(PrinterKeyword.Double); break; case PredefinedType.Float: _writer.WriteKeyword(PrinterKeyword.Float); break; case PredefinedType.Int: _writer.WriteKeyword(PrinterKeyword.Int); break; case PredefinedType.Long: _writer.WriteKeyword(PrinterKeyword.Long); break; case PredefinedType.Object: _writer.WriteKeyword(PrinterKeyword.Object); break; case PredefinedType.SByte: _writer.WriteKeyword(PrinterKeyword.SByte); break; case PredefinedType.Short: _writer.WriteKeyword(PrinterKeyword.Short); break; case PredefinedType.String: _writer.WriteKeyword(PrinterKeyword.String); break; case PredefinedType.UInt: _writer.WriteKeyword(PrinterKeyword.UInt); break; case PredefinedType.ULong: _writer.WriteKeyword(PrinterKeyword.ULong); break; case PredefinedType.UShort: _writer.WriteKeyword(PrinterKeyword.UShort); break; case PredefinedType.Void: _writer.WriteKeyword(PrinterKeyword.Void); break; default: throw ThrowHelper.InvalidEnumValue(node.Type); } ExpressionEnd(node); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitPredefinedType(PredefinedTypeSyntax node) { this.OnNodeVisited(node); if (!this.traverseRootOnly) base.VisitPredefinedType(node); }
public static bool TryGetPredefinedType(SpecialType specialType, out PredefinedTypeSyntax predefinedTypeSyntax) { return PredefinedSpecialTypes.TryGetValue(specialType, out predefinedTypeSyntax); }
public PredefinedTypeTranslation(PredefinedTypeSyntax syntax, SyntaxTranslation parent) : base(syntax, parent) { }
public override SyntaxNode VisitPredefinedType(PredefinedTypeSyntax node) { node = (PredefinedTypeSyntax)base.VisitPredefinedType(node); var token = node.Keyword; if ((transformKind == TransformKind.IntTypeToLongType) && (token.Kind() == SyntaxKind.IntKeyword)) { var longToken = SyntaxFactory.Token(token.LeadingTrivia, SyntaxKind.LongKeyword, token.TrailingTrivia); return SyntaxFactory.PredefinedType(longToken); } return node; }
public static string PredefinedType(PredefinedTypeSyntax type) { return Type(type.Keyword.Text); }
public virtual void VisitPredefinedType(PredefinedTypeSyntax node) { DefaultVisit(node); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitPredefinedType(PredefinedTypeSyntax node) { this.OnNodeVisited(node, this.type.IsInstanceOfType(node)); base.VisitPredefinedType(node); }