mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
C#: Add .editorconfig file (#4129)
This commit is contained in:
@@ -26,28 +26,28 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
// Arguments
|
||||
int index = 0;
|
||||
foreach(var arg in args)
|
||||
foreach (var arg in args)
|
||||
{
|
||||
trapFile.compilation_args(this, index++, arg);
|
||||
}
|
||||
|
||||
// Files
|
||||
index = 0;
|
||||
foreach(var file in cx.Compilation.SyntaxTrees.Select(tree => Extraction.Entities.File.Create(cx, tree.FilePath)))
|
||||
foreach (var file in cx.Compilation.SyntaxTrees.Select(tree => Extraction.Entities.File.Create(cx, tree.FilePath)))
|
||||
{
|
||||
trapFile.compilation_compiling_files(this, index++, file);
|
||||
}
|
||||
|
||||
// References
|
||||
index = 0;
|
||||
foreach(var file in cx.Compilation.References.OfType<PortableExecutableReference>().Select(r => Extraction.Entities.File.Create(cx, r.FilePath)))
|
||||
foreach (var file in cx.Compilation.References.OfType<PortableExecutableReference>().Select(r => Extraction.Entities.File.Create(cx, r.FilePath)))
|
||||
{
|
||||
trapFile.compilation_referencing_files(this, index++, file);
|
||||
}
|
||||
|
||||
// Diagnostics
|
||||
index = 0;
|
||||
foreach(var diag in cx.Compilation.GetDiagnostics().Select(d => new Diagnostic(cx, d)))
|
||||
foreach (var diag in cx.Compilation.GetDiagnostics().Select(d => new Diagnostic(cx, d)))
|
||||
{
|
||||
trapFile.diagnostic_for(diag, this, 0, index++);
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
var trapFile = cx.TrapWriter.Writer;
|
||||
int index = 0;
|
||||
foreach(float metric in p.Metrics)
|
||||
foreach (float metric in p.Metrics)
|
||||
{
|
||||
trapFile.compilation_time(this, -1, index++, metric);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
trapFile.type_nullability(this, n);
|
||||
}
|
||||
|
||||
if(Info.FlowState != NullableFlowState.None)
|
||||
if (Info.FlowState != NullableFlowState.None)
|
||||
{
|
||||
trapFile.expr_flowstate(this, (int)Info.FlowState);
|
||||
}
|
||||
@@ -292,7 +292,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
protected Expression(ExpressionNodeInfo info)
|
||||
: base(info)
|
||||
{
|
||||
Syntax = (SyntaxNode)info.Node;
|
||||
Syntax = (SyntaxNode)info.Node;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -307,7 +307,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
protected new Expression TryPopulate()
|
||||
{
|
||||
cx.Try(Syntax, null, ()=>PopulateExpression(cx.TrapWriter.Writer));
|
||||
cx.Try(Syntax, null, () => PopulateExpression(cx.TrapWriter.Writer));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
}
|
||||
|
||||
public ImplicitCast(ExpressionNodeInfo info, IMethodSymbol method)
|
||||
: base(new ExpressionInfo(info.Context, Entities.Type.Create(info.Context, info.ConvertedType), info.Location, ExprKind.OPERATOR_INVOCATION, info.Parent, info.Child, true, info.ExprValue) )
|
||||
: base(new ExpressionInfo(info.Context, Entities.Type.Create(info.Context, info.ConvertedType), info.Location, ExprKind.OPERATOR_INVOCATION, info.Parent, info.Child, true, info.ExprValue))
|
||||
{
|
||||
Expr = Factory.Create(info.SetParent(this, 0));
|
||||
|
||||
|
||||
@@ -50,7 +50,8 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
public static Lambda Create(ExpressionNodeInfo info, SimpleLambdaExpressionSyntax node) => new Lambda(info, node);
|
||||
|
||||
Lambda(ExpressionNodeInfo info, AnonymousMethodExpressionSyntax node) :
|
||||
this(info.SetKind(ExprKind.ANONYMOUS_METHOD), node.Body, node.ParameterList == null ? Enumerable.Empty<ParameterSyntax>() : node.ParameterList.Parameters) { }
|
||||
this(info.SetKind(ExprKind.ANONYMOUS_METHOD), node.Body, node.ParameterList == null ? Enumerable.Empty<ParameterSyntax>() : node.ParameterList.Parameters)
|
||||
{ }
|
||||
|
||||
public static Lambda Create(ExpressionNodeInfo info, AnonymousMethodExpressionSyntax node) => new Lambda(info, node);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
class Literal : Expression<LiteralExpressionSyntax>
|
||||
{
|
||||
Literal(ExpressionNodeInfo info) : base(info.SetKind(GetKind(info)) ) { }
|
||||
Literal(ExpressionNodeInfo info) : base(info.SetKind(GetKind(info))) { }
|
||||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new Literal(info).TryPopulate();
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
static ExprKind GetKind(ExpressionNodeInfo info)
|
||||
{
|
||||
switch(info.Node.Kind())
|
||||
switch (info.Node.Kind())
|
||||
{
|
||||
case SyntaxKind.DefaultLiteralExpression:
|
||||
return ExprKind.DEFAULT;
|
||||
|
||||
@@ -27,10 +27,12 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
}
|
||||
}
|
||||
|
||||
public static Expression Create(ExpressionNodeInfo info, ConditionalAccessExpressionSyntax node) =>
|
||||
public static Expression Create(ExpressionNodeInfo info, ConditionalAccessExpressionSyntax node)
|
||||
{
|
||||
// The qualifier is located by walking the syntax tree.
|
||||
// `node.WhenNotNull` will contain a MemberBindingExpressionSyntax, calling the method below.
|
||||
CreateFromNode(new ExpressionNodeInfo(info.Context, node.WhenNotNull, info.Parent, info.Child, info.TypeInfo));
|
||||
return CreateFromNode(new ExpressionNodeInfo(info.Context, node.WhenNotNull, info.Parent, info.Child, info.TypeInfo));
|
||||
}
|
||||
|
||||
public static Expression Create(ExpressionNodeInfo info, MemberBindingExpressionSyntax node)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
protected override void Populate(TextWriter trapFile)
|
||||
{
|
||||
var @namespace = (INamespaceSymbol) cx.GetModel(Node).GetSymbolInfo(Node.Name).Symbol;
|
||||
var @namespace = (INamespaceSymbol)cx.GetModel(Node).GetSymbolInfo(Node.Name).Symbol;
|
||||
var ns = Namespace.Create(cx, @namespace);
|
||||
trapFile.namespace_declarations(this, ns);
|
||||
trapFile.namespace_declaration_location(this, cx.Create(Node.Name.GetLocation()));
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
Emit(trapFile, Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
Create(cx, nts.ElementType, this, nt.symbol.IsReferenceType ? nt : nt.TypeArguments[0]);
|
||||
}
|
||||
else if(Type is ArrayType array)
|
||||
else if (Type is ArrayType array)
|
||||
{
|
||||
Create(cx, nts.ElementType, Parent, array);
|
||||
}
|
||||
|
||||
@@ -35,14 +35,14 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
if (symbol.HasConstructorConstraint)
|
||||
trapFile.general_type_parameter_constraints(constraints, 3);
|
||||
|
||||
if(symbol.HasUnmanagedTypeConstraint)
|
||||
if (symbol.HasUnmanagedTypeConstraint)
|
||||
trapFile.general_type_parameter_constraints(constraints, 4);
|
||||
|
||||
ITypeSymbol baseType = symbol.HasValueTypeConstraint ?
|
||||
Context.Compilation.GetTypeByMetadataName(valueTypeName) :
|
||||
Context.Compilation.ObjectType;
|
||||
|
||||
if(symbol.ReferenceTypeConstraintNullableAnnotation == NullableAnnotation.Annotated)
|
||||
if (symbol.ReferenceTypeConstraintNullableAnnotation == NullableAnnotation.Annotated)
|
||||
trapFile.general_type_parameter_constraints(constraints, 5);
|
||||
|
||||
foreach (var abase in symbol.GetAnnotatedTypeConstraints())
|
||||
|
||||
@@ -140,6 +140,12 @@ namespace Semmle.Extraction.CSharp
|
||||
return ExitCode.Failed;
|
||||
}
|
||||
|
||||
// csc.exe (CSharpCompiler.cs) also provides CompilationOptions
|
||||
// .WithMetadataReferenceResolver(),
|
||||
// .WithXmlReferenceResolver() and
|
||||
// .WithSourceReferenceResolver().
|
||||
// These would be needed if we hadn't explicitly provided the source/references
|
||||
// already.
|
||||
var compilation = CSharpCompilation.Create(
|
||||
compilerArguments.CompilationName,
|
||||
syntaxTrees,
|
||||
@@ -147,11 +153,6 @@ namespace Semmle.Extraction.CSharp
|
||||
compilerArguments.CompilationOptions.
|
||||
WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default).
|
||||
WithStrongNameProvider(new DesktopStrongNameProvider(compilerArguments.KeyFileSearchPaths))
|
||||
// csc.exe (CSharpCompiler.cs) also provides WithMetadataReferenceResolver,
|
||||
// WithXmlReferenceResolver and
|
||||
// WithSourceReferenceResolver.
|
||||
// These would be needed if we hadn't explicitly provided the source/references
|
||||
// already.
|
||||
);
|
||||
|
||||
analyser.EndInitialize(compilerArguments, commandLineArguments, compilation);
|
||||
|
||||
Reference in New Issue
Block a user