Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ See full changelog at https://github.com/sillsdev/liblcm/blob/develop/CHANGELOG.
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
<ChangelogFile>$(MSBuildThisFileDirectory)/CHANGELOG.md</ChangelogFile>
<BuildInParallel>false</BuildInParallel>
<LangVersion>9.0</LangVersion>
<Nullable>warnings</Nullable>
</PropertyGroup>
</Project>
4 changes: 4 additions & 0 deletions src/CSTools/Tools/Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
<PackageReference Include="GitVersion.MsBuild" Version="5.6.10" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="SIL.ReleaseTasks" Version="2.5.0" PrivateAssets="All" />
<PackageReference Include="Nullable" Version="1.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/CSTools/Tools/dfa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public override int Match(string str, int pos, int max)
if (m_sub!=null)
a = m_sub.Match(str, pos, max);
if (m_alt!=null)
b = m_sub.Match(str, pos, max);
b = m_alt.Match(str, pos, max);
return (a>b)?a:b;
}
public override void Build(Nfa nfa)
Expand Down
10 changes: 4 additions & 6 deletions src/CSTools/Tools/genbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.IO;
using System.Text;
using System.Diagnostics.CodeAnalysis;
using YYClass;

namespace SIL.LCModel.Tools
Expand Down Expand Up @@ -169,12 +170,8 @@ public void EmitClassDefin(string b,ref int p,int max,CsReader inf,string defbas
}
m_outFile.WriteLine("}");
}
/// <summary>
///
/// </summary>
/// <param name="n"></param>
/// <param name="p"></param>
/// <param name="str"></param>

[DoesNotReturn]
public void Error(int n,int p,string str)
{
Console.WriteLine(str);
Expand All @@ -185,6 +182,7 @@ public void Error(int n,int p,string str)
}
erh.Error(new CSToolsFatalException(n,line(p),position(p),"",str));
}

public virtual int line(int pos) { return 0; }
public virtual int position(int pos) { return pos; }
public virtual string Saypos(int pos) { return "at "+pos+": "; }
Expand Down
32 changes: 18 additions & 14 deletions src/CSTools/Tools/lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
//using System.Runtime.Serialization.Formatters.Binary;


namespace SIL.LCModel.Tools
{

Expand Down Expand Up @@ -384,7 +386,7 @@ public static object create(string cls_name,Lexer yyl)
yyl.tokens.erh.Error(new CSToolsException(6,yyl,cls_name,String.Format("no factory for {0}",cls_name)));
try
{
return cr(yyl);
return cr!(yyl);
}
catch (CSToolsException x)
{
Expand Down Expand Up @@ -605,7 +607,7 @@ public static implicit operator int (SYMBOL s) // 4.0c
s = (SYMBOL)d;
try
{
rv =(int)d;
rv =(int)d!;
}
catch(Exception e)
{
Expand Down Expand Up @@ -638,8 +640,8 @@ public virtual bool Pass(Symbols syms,int snum,out ParserEntry entry)
string s = string.Format("No parsinginfo for symbol {0}",yyname());
syms.erh.Error(new CSToolsFatalException(9,yylx,yyname(),s));
}
bool r = pi.m_parsetable.Contains(snum);
entry = r?((ParserEntry)pi.m_parsetable[snum]):null;
bool r = pi != null && pi.m_parsetable.Contains(snum);
entry = pi != null && r ? ((ParserEntry)pi.m_parsetable[snum]) : null;
return r;
}
public virtual string yyname() { return "SYMBOL"; }
Expand Down Expand Up @@ -675,8 +677,8 @@ public override bool Pass(Symbols syms,int snum, out ParserEntry entry)
ParsingInfo pi = (ParsingInfo)syms.literalInfo[m_str];
if (pi==null)
syms.erh.Error(new CSToolsException(10,yylx,m_str,String.Format("Parser does not recognise literal <{0}>",m_str)));
bool r = pi.m_parsetable.Contains(snum);
entry = r?((ParserEntry)pi.m_parsetable[snum]):null;
bool r = pi != null && pi.m_parsetable.Contains(snum);
entry = pi != null && r ? ((ParserEntry)pi.m_parsetable[snum]) : null;
return r;
}
public override bool IsTerminal() { return true; }
Expand Down Expand Up @@ -971,20 +973,22 @@ public virtual void Error(Exception e)
{
counter++;
if (throwExceptions || (e is CSToolsFatalException))
throw(e);
if (e is CSToolsException)
throw e;
if (e is CSToolsException x)
{
CSToolsException x = (CSToolsException)e;
if (x.handled)
return;
x.handled = true;
// if (x.nLine !=0 || x.nChar!=0)
// {
// Console.WriteLine("line "+x.nLine+", char "+x.nChar+": "+x.Message);
// return;
// }

}
Console.WriteLine(e.Message);
}

[DoesNotReturn]
public virtual void Error(CSToolsFatalException e)
{
counter++;
throw e;
}
}
}
7 changes: 5 additions & 2 deletions src/CSTools/Tools/parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ protected bool Error(ref ParseStackEntry top, string str)
newtop = pe.m_action.Action(this); // before we change the stack
m_ungot = top.m_value;
Pop(ref top,((ParserReduce)pe).m_depth,er);
newtop.pos = top.m_value.pos;
newtop!.pos = top.m_value.pos;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wont this throw if pe.m_action is null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will. The way I interpret this section is, "if pe is non-null, so is pe.m_action"

top.m_value = newtop;
}
else
Expand Down Expand Up @@ -1554,6 +1554,8 @@ SYMBOL Parse()
ParseStackEntry top = new ParseStackEntry(this,0,NextSym());
for (;;)
{
if (top.m_value == null)
throw new NullReferenceException("Stack entry m_value cannot be null");
string cnm = top.m_value.yyname();
if (m_debug)
{
Expand Down Expand Up @@ -1693,7 +1695,8 @@ public static object create(string cls_name,Parser yyp)
yyp.m_symbols.erh.Error(new CSToolsException(16,yyp.m_lexer,"no factory for {"+cls_name+")"));
try
{
return cr(yyp);
if (cr != null)
return cr(yyp);
}
catch (CSToolsException e)
{
Expand Down
3 changes: 2 additions & 1 deletion src/CSTools/pg/pg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections;
using System.IO;
using System.Text;
using System.Diagnostics.CodeAnalysis;
using SIL.LCModel.Tools;

public class PrecReference : TOKEN
Expand Down Expand Up @@ -782,7 +783,7 @@ internal void ParseProduction()
Error(39,m_tok.pos,string.Format("Illegal left hand side <{0}> for production",m_tok.yytext));
if (m_symbols.m_startSymbol==null)
m_symbols.m_startSymbol = lhs;
if (lhs.m_symtype==CSymbol.SymType.unknown)
if (lhs!.m_symtype==CSymbol.SymType.unknown)
lhs.m_symtype = CSymbol.SymType.nonterminal;
if ((!lhs.m_defined) && lhs.m_prods.Count==0)
{ // lhs not defined in %symbol statement and not previously a lhs
Expand Down
8 changes: 4 additions & 4 deletions src/SIL.LCModel.Core/Phonology/PhonEnvRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public bool Result
public static bool CanInsertItem(string sEnv, int ichEnd, int ichAnchor)
{
Debug.Assert(sEnv != null);
Debug.Assert(ichEnd <= sEnv.Length && ichAnchor <= sEnv.Length);
Debug.Assert(ichEnd <= sEnv!.Length && ichAnchor <= sEnv.Length);
if (ichEnd < 0 || ichAnchor < 0)
return false;
int ichSlash = sEnv.IndexOf('/');
Expand Down Expand Up @@ -199,7 +199,7 @@ public static bool CanInsertItem(string sEnv, int ichEnd, int ichAnchor)
public static bool CanInsertHashMark(string sEnv, int ichEnd, int ichAnchor)
{
Debug.Assert(sEnv != null);
Debug.Assert(ichEnd <= sEnv.Length && ichAnchor <= sEnv.Length);
Debug.Assert(ichEnd <= sEnv!.Length && ichAnchor <= sEnv.Length);
if (ichEnd < 0 || ichAnchor < 0)
return false;
int ichSlash = sEnv.IndexOf('/');
Expand Down Expand Up @@ -297,10 +297,10 @@ public static void CreateErrorMessageFromXml(string strRep1, string sXmlMessage,
// there were XML reserved characters in the environment.
// until we get that fixed, at least don't crash, just draw squiggly under the entire word
xdoc.LoadXml(sXmlMessage);
XmlAttribute posAttr = xdoc.DocumentElement.Attributes["pos"];
XmlAttribute posAttr = xdoc.DocumentElement!.Attributes["pos"];
pos = (posAttr != null) ? Convert.ToInt32(posAttr.Value) : 0;
XmlAttribute statusAttr = xdoc.DocumentElement.Attributes["status"];
sStatus = statusAttr.InnerText;
sStatus = statusAttr!.InnerText;
}
catch
{
Expand Down
4 changes: 4 additions & 0 deletions src/SIL.LCModel.Core/SIL.LCModel.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ SIL.LCModel.Core provides a base library with core functionality.</Description>
<ProjectReference Include="..\CSTools\Tools\Tools.csproj" />
<ProjectReference Include="..\SIL.LCModel.Build.Tasks\SIL.LCModel.Build.Tasks.csproj" />
<ProjectReference Include="..\SIL.LCModel.Utils\SIL.LCModel.Utils.csproj" />
<PackageReference Include="Nullable" Version="1.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions src/SIL.LCModel.Core/Scripture/MultilingScrBooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,11 @@ public virtual string GetBookAbbrev(int nBook)

// No abbreviation found in primary writing system; get SIL code instead
wsNames = GetWsNames(kWsSilCodes); // SIL codes
Debug.Assert (wsNames != null);
if (wsNames == null)
throw new InvalidOperationException("Could not get SIL codes");
sAbbrev = wsNames.Name[nBook - 1]; // full SIL code is the .Name
Debug.Assert(sAbbrev != null);
if (sAbbrev == null)
throw new InvalidOperationException("Could not get abbreviation for book " + nBook);
return sAbbrev;
}

Expand Down
5 changes: 3 additions & 2 deletions src/SIL.LCModel.Core/Text/CustomIcu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ public static void InitIcuDataDir()
// application (e.g. Flex & Paratext)
if (Platform.IsWindows)
{
var executingAssemblyFolder = Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path);
var executingAssemblyFolder = Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().Location).Path);
var assemblyDir = Path.GetDirectoryName(executingAssemblyFolder);
// ReSharper disable once AssignNullToNotNullAttribute -- The directory of the executing assembly will not be null
if (assemblyDir == null)
throw new InvalidOperationException("Could not get assembly directory from " + executingAssemblyFolder);
var icu32Path = Path.Combine(assemblyDir, "lib", "win-x86");
var icu64Path = Path.Combine(assemblyDir, "lib", "win-x64");
var flexIcu32Path = Path.Combine(assemblyDir, "lib", "x86");
Expand Down
9 changes: 4 additions & 5 deletions src/SIL.LCModel.Core/Text/PUACharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,12 +1018,11 @@ protected int CompareRegions(string property2)
public override int CompareTo(object obj)
{
// if they give us a UCDCharacter, compare Properties
if (obj is UCDCharacter)
if (obj is UCDCharacter c)
{
UCDCharacter ucdChar = obj as UCDCharacter;
if (SameRegion(ucdChar))
return MiscUtils.CompareHex(CodePoint, ucdChar.CodePoint);
return CompareRegions(ucdChar.Property);
if (SameRegion(c))
return MiscUtils.CompareHex(CodePoint, c.CodePoint);
return CompareRegions(c.Property);
}
// if they give us a string, assume its a codepoint
else if (obj is string)
Expand Down
8 changes: 4 additions & 4 deletions src/SIL.LCModel.Core/Text/TsString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private ITsString get_NormalizedFormAndFixOffsets(FwNormalizationMode nm, ArrayP
// Note that our local mapping is from the start of this segment, but we want to keep track of indexes from the start
// of the *string*. (Both the original string and the output, normalized string). So we adjust the indexes here.
if (mapping.isFirstCharOfDecomposition)
stringOffsetMapping[segmentMin + mapping.origIdx] = outputLenSoFar + mapping.normIdx;
stringOffsetMapping![segmentMin + mapping.origIdx] = outputLenSoFar + mapping.normIdx;
}
}
}
Expand Down Expand Up @@ -489,7 +489,7 @@ private ITsString get_NormalizedFormAndFixOffsets(FwNormalizationMode nm, ArrayP
resultBuilder.SetProperties(outputIdx, outputIdx + size, origProperties);
// And if we also need to fix up offsets at the end, we keep track of the ones we'll need
if (willFixOffsets && mapping.isFirstCharOfDecomposition)
stringOffsetMapping[segmentMin + mapping.origIdx] = outputLenSoFar + mapping.normIdx;
stringOffsetMapping![segmentMin + mapping.origIdx] = outputLenSoFar + mapping.normIdx;
}
}

Expand Down Expand Up @@ -526,11 +526,11 @@ private ITsString get_NormalizedFormAndFixOffsets(FwNormalizationMode nm, ArrayP
}
if (willFixOffsets)
{
stringOffsetMapping[segmentMin] = resultBuilder.Length;
stringOffsetMapping![segmentMin] = resultBuilder.Length;
int ptrSize = Marshal.SizeOf(typeof(IntPtr));
for (int i = 0; i < numOffsetsToFix; i++)
{
IntPtr offsetPtr = Marshal.ReadIntPtr(oldOffsetsToFix.IntPtr, i * ptrSize);
IntPtr offsetPtr = Marshal.ReadIntPtr(oldOffsetsToFix!.IntPtr, i * ptrSize);
int oldOffset = Marshal.ReadInt32(offsetPtr);
int newOffset;
if (stringOffsetMapping.TryGetValue(oldOffset, out newOffset))
Expand Down
31 changes: 16 additions & 15 deletions src/SIL.LCModel.Core/Text/TsStringUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,12 +1387,13 @@ public static ITsString MergeString(ITsString source, ITsString dest)
/// ------------------------------------------------------------------------------------
public static ITsString MergeString(ITsString source, ITsString dest, bool fConcatenateIfBoth)
{
string destText = (dest != null) ? dest.Text : null;
string sourceText = (source != null) ? source.Text : null;

if (string.IsNullOrEmpty(destText) && !string.IsNullOrEmpty(sourceText))
if (dest == null && source == null)
return null;
if (dest == null || string.IsNullOrEmpty(dest.Text))
return source;
else if (fConcatenateIfBoth && !string.IsNullOrEmpty(destText) && !string.IsNullOrEmpty(sourceText) && !dest.Equals(source))
if (source == null || string.IsNullOrEmpty(source.Text))
return dest;
if (fConcatenateIfBoth && !dest.Equals(source))
{
// concatenate
ITsStrBldr tsb = dest.GetBldr();
Expand Down Expand Up @@ -1633,23 +1634,23 @@ public static ITsTextProps PropsForWs(int ws)
Justification = "If a tss is null, crunBoth will be 0, so we'll never try to access it.")]
public static TsStringDiffInfo GetDiffsInTsStrings(ITsString tssOld, ITsString tssNew)
{
if (tssOld == null && tssNew == null)
return null;
if (tssOld == null)
return new TsStringDiffInfo(0, tssNew.Length, 0, true);
if (tssNew == null)
return new TsStringDiffInfo(0, 0, tssOld.Length, true);
// no diff found
var ichMin = -1;

int cchOld = 0;
int crunOld = 0;
int crunNew = 0;
int cchNew = 0;
if (tssNew != null)
{
cchNew = tssNew.Length;
crunNew = tssNew.RunCount;
}
if (tssOld != null)
{
cchOld = tssOld.Length;
crunOld = tssOld.RunCount;
}
cchNew = tssNew.Length;
crunNew = tssNew.RunCount;
cchOld = tssOld.Length;
crunOld = tssOld.RunCount;
var crunBoth = Math.Min(crunOld, crunNew);

// Set ichMin to the index of the first character that is different or has different properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ private void MainCharacterSetChanged(object sender, NotifyCollectionChangedEvent
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
if (e.NewItems == null) throw new NullReferenceException("e.NewItems");
AddWordFormingOverrides(e.NewItems.Cast<string>());
break;
case NotifyCollectionChangedAction.Remove:
if (e.OldItems == null) throw new NullReferenceException("e.OldItems");
RemoveWordFormingOverrides(e.OldItems.Cast<string>());
break;
case NotifyCollectionChangedAction.Replace:
if (e.NewItems == null) throw new NullReferenceException("e.NewItems");
if (e.OldItems == null) throw new NullReferenceException("e.OldItems");
RemoveWordFormingOverrides(e.OldItems.Cast<string>());
AddWordFormingOverrides(e.NewItems.Cast<string>());
break;
Expand Down
3 changes: 2 additions & 1 deletion src/SIL.LCModel.Core/WritingSystems/ValidCharacters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,8 @@ public static IEnumerable<string> ParseLegacyWordFormingCharOverrides(string pat
{
foreach (XmlNode charNode in charsList)
{
string codepointStr = charNode.Attributes["val"].InnerText;
string codepointStr = charNode.Attributes?["val"]?.InnerText;
if (codepointStr == null) throw new InvalidOperationException("Could not get codepoint from " + charNode.OuterXml);
int codepoint = Convert.ToInt32(codepointStr, 16);
var c = (char) codepoint;
result.Add(c.ToString(CultureInfo.InvariantCulture));
Expand Down
2 changes: 2 additions & 0 deletions src/SIL.LCModel.Utils/FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ public static string ActualFilePath(string sPathname)
return sPathname.Normalize(NormalizationForm.FormD);

string sDir = Path.GetDirectoryName(sPathname);
if (sDir == null)
throw new InvalidOperationException("Could not get directory name from path " + sPathname);
string sFile = Path.GetFileName(sPathname).Normalize();
if (!Platform.IsUnix) // Using IsUnix to decide if a file system is case sensitive
{ // isn't the best way since some Unix file systems are case
Expand Down
Loading
Loading