Skip to content

Commit bf21d75

Browse files
Merge pull request #166 from SpiceSharp/cir
Fix null reference exceptions
2 parents 1386dbf + 772dd9d commit bf21d75

File tree

10 files changed

+98
-27
lines changed

10 files changed

+98
-27
lines changed

.github/workflows/test-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup dotnet tooling
2020
uses: actions/setup-dotnet@master
2121
with:
22-
dotnet-version: '6.0.x'
22+
dotnet-version: '8.0.x'
2323

2424
- name: Restore dependencies
2525
run:

src/SpiceSharpParser.CodeAnalysis/SpiceSharpParser.CodeAnalysis.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</ItemGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
24+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
2525
<PackageReference Include="SpiceSharp" Version="3.2.3" />
2626
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
2727
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
* Band pass filter - AC simulation
2+
V1 IN 0 AC 1
3+
LI IN MIDDLE {mc(0.6, tol)}
4+
C1 MIDDLE OUT {mc(10e-6, tol)}
5+
R1 OUT 0 {mc(1000, tol)}
6+
.ac oct 100 1 500
7+
.param tol=0.2
8+
.plot ac v(OUT)
9+
.end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
* Band pass filter - AC simulation stepping with mc()
2+
V1 IN 0 AC 1
3+
LI IN MIDDLE {mc(0.6, tol)}
4+
C1 MIDDLE OUT {mc(10e-6, tol)}
5+
R1 OUT 0 {mc(1000, tol)}
6+
.ac oct 100 1 500
7+
.step param X 0 10 1
8+
.param tol=0.2
9+
.plot ac v(OUT) merge
10+
.end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.IO;
2+
using Xunit;
3+
4+
namespace SpiceSharpParser.IntegrationTests.Examples
5+
{
6+
public class ExampleBandPass : BaseTests
7+
{
8+
[Fact]
9+
public void When_SimulatedBandPass_Expect_NoExceptions()
10+
{
11+
string path = Path.Combine(Directory.GetCurrentDirectory(), "Examples/Circuits/band-pass_1.cir");
12+
var netlistContent = File.ReadAllText(path);
13+
14+
var parser = new SpiceNetlistParser();
15+
parser.Settings.Lexing.HasTitle = true;
16+
17+
var parseResult = parser.ParseNetlist(netlistContent);
18+
19+
var spiceSharpReader = new SpiceSharpReader();
20+
spiceSharpReader.Settings.ExpandSubcircuits = false;
21+
var spiceSharpModel = spiceSharpReader.Read(parseResult.FinalModel);
22+
23+
RunSimulations(spiceSharpModel);
24+
}
25+
26+
[Fact]
27+
public void When_SimulatedBandPass2_Expect_NoExceptions()
28+
{
29+
string path = Path.Combine(Directory.GetCurrentDirectory(), "Examples/Circuits/band-pass_2.cir");
30+
var netlistContent = File.ReadAllText(path);
31+
32+
var parser = new SpiceNetlistParser();
33+
parser.Settings.Lexing.HasTitle = true;
34+
35+
var parseResult = parser.ParseNetlist(netlistContent);
36+
37+
var spiceSharpReader = new SpiceSharpReader();
38+
spiceSharpReader.Settings.ExpandSubcircuits = false;
39+
var spiceSharpModel = spiceSharpReader.Read(parseResult.FinalModel);
40+
41+
RunSimulations(spiceSharpModel);
42+
}
43+
}
44+
}

src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ProjectGuid>{57920E91-873B-4E66-B0EC-4CAC45007AA9}</ProjectGuid>
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
@@ -16,12 +16,12 @@
1616

1717

1818
<ItemGroup>
19-
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
19+
<PackageReference Include="coverlet.msbuild" Version="6.0.3">
2020
<PrivateAssets>all</PrivateAssets>
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
</PackageReference>
23-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
24-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
23+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
24+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
2525
<PackageReference Include="SpiceSharp" Version="3.2.3" />
2626
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
2727
<PackageReference Include="xunit" Version="2.9.2" />
@@ -30,7 +30,7 @@
3030
<PrivateAssets>all</PrivateAssets>
3131
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3232
</PackageReference>
33-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
33+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
3434
<PrivateAssets>all</PrivateAssets>
3535
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3636
</PackageReference>
@@ -42,6 +42,12 @@
4242
</ItemGroup>
4343

4444
<ItemGroup>
45+
<None Update="Examples\Circuits\band-pass_2.cir">
46+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
47+
</None>
48+
<None Update="Examples\Circuits\band-pass_1.cir">
49+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
50+
</None>
4551
<None Update="Examples\Circuits\example02.cir">
4652
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4753
</None>

src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<ProjectGuid>{53D996E7-8D58-49D0-97F6-71CAD49670A2}</ProjectGuid>
6-
<TargetFramework>net6.0</TargetFramework>
6+
<TargetFramework>net8.0</TargetFramework>
77
</PropertyGroup>
88

99
<ItemGroup>
1010
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
11+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
1213
<PackageReference Include="SpiceSharp" Version="3.2.3" />
1314
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
1415
<PackageReference Include="xunit.runner.console" Version="2.9.2">
1516
<PrivateAssets>all</PrivateAssets>
1617
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1718
</PackageReference>
18-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
19+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
1920
<PrivateAssets>all</PrivateAssets>
2021
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2122
</PackageReference>

src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ProjectGuid>{94394567-BC35-43EE-92CB-31AC780305FE}</ProjectGuid>
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
@@ -14,12 +14,13 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
17+
<PackageReference Include="coverlet.msbuild" Version="6.0.3">
1818
<PrivateAssets>all</PrivateAssets>
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
</PackageReference>
21-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
22-
<PackageReference Include="NSubstitute" Version="5.1.0" />
21+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
23+
<PackageReference Include="NSubstitute" Version="5.3.0" />
2324
<PackageReference Include="SpiceSharp" Version="3.2.3" />
2425
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
2526
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
@@ -32,7 +33,7 @@
3233
<PrivateAssets>all</PrivateAssets>
3334
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3435
</PackageReference>
35-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
36+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
3637
<PrivateAssets>all</PrivateAssets>
3738
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3839
</PackageReference>

src/SpiceSharpParser/ModelWriters/CSharp/Events/ACWithEvents.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,25 @@ public IEnumerable<int> InvokeEvents(IEnumerable<int> codes)
4242
switch (code)
4343
{
4444
case Simulation.BeforeValidation:
45-
EventBeforeValidation.Invoke(this, EventArgs.Empty);
45+
EventBeforeValidation?.Invoke(this, EventArgs.Empty);
4646
break;
4747

4848
case Simulation.AfterValidation:
49-
EventAfterValidation.Invoke(this, EventArgs.Empty);
49+
EventAfterValidation?.Invoke(this, EventArgs.Empty);
5050
break;
5151

5252
case Simulation.BeforeSetup:
53-
EventBeforeSetup.Invoke(this, EventArgs.Empty);
53+
EventBeforeSetup?.Invoke(this, EventArgs.Empty);
5454
break;
5555
case Simulation.AfterSetup:
56-
EventAfterSetup.Invoke(this, EventArgs.Empty);
56+
EventAfterSetup?.Invoke(this, EventArgs.Empty);
5757
break;
5858
case Simulation.BeforeUnsetup:
59-
EventBeforeUnSetup.Invoke(this, EventArgs.Empty);
59+
EventBeforeUnSetup?.Invoke(this, EventArgs.Empty);
6060
break;
6161

6262
case Simulation.BeforeExecute:
63-
EventBeforeExecute.Invoke(this, EventArgs.Empty);
63+
EventBeforeExecute?.Invoke(this, EventArgs.Empty);
6464

6565
if (this is IBiasingSimulation)
6666
{
@@ -70,7 +70,7 @@ public IEnumerable<int> InvokeEvents(IEnumerable<int> codes)
7070
break;
7171

7272
case Simulation.AfterExecute:
73-
EventAfterExecute.Invoke(this, EventArgs.Empty);
73+
EventAfterExecute?.Invoke(this, EventArgs.Empty);
7474
break;
7575

7676
case AC.ExportSmallSignal:

src/SpiceSharpParser/SpiceSharpParser.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
<PropertyGroup>
44
<ProjectGuid>{DF3DD787-71CC-4C89-9E33-DC4536A52278}</ProjectGuid>
5-
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
5+
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
66
<Authors>SpiceSharp</Authors>
77
<PackageProjectUrl>https://github.com/SpiceSharp/SpiceSharpParser</PackageProjectUrl>
8-
<Copyright>Copyright 2024</Copyright>
8+
<Copyright>Copyright 2025</Copyright>
99
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1010
<RepositoryUrl>https://github.com/SpiceSharp/SpiceSharpParser</RepositoryUrl>
1111
<RepositoryType></RepositoryType>
@@ -22,7 +22,7 @@
2222
<StartupObject />
2323
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2424
<LangVersion>latest</LangVersion>
25-
<Version>3.2.3</Version>
25+
<Version>3.2.4</Version>
2626
</PropertyGroup>
2727

2828
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard1.5|AnyCPU'">
@@ -35,10 +35,10 @@
3535
</ItemGroup>
3636

3737
<ItemGroup>
38-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
38+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
3939
<PackageReference Include="SpiceSharp" Version="3.2.3" />
4040
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
41-
<PackageReference Include="SpiceSharpGenerator" Version="1.0.7">
41+
<PackageReference Include="SpiceSharpGenerator" Version="1.0.9">
4242
<PrivateAssets>all</PrivateAssets>
4343
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4444
</PackageReference>

0 commit comments

Comments
 (0)