Skip to content

Commit

Permalink
Remove more public DMCompiler fields
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit committed Nov 15, 2024
1 parent 6281fbc commit 3b59466
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
8 changes: 4 additions & 4 deletions DMCompiler/Compiler/DMPreprocessor/DMPreprocessorLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ namespace DMCompiler.Compiler.DMPreprocessor;
/// taking in raw text and outputting vague tokens descriptive enough for the preprocessor to run on them.
/// </summary>
internal sealed class DMPreprocessorLexer {
public readonly DMCompiler Compiler;
private static readonly StringBuilder TokenTextBuilder = new();

public readonly string IncludeDirectory;
public readonly string File;

private readonly DMCompiler _compiler;
private readonly StreamReader _source;
private readonly bool _isDMStandard;
private char _current;
private int _currentLine = 1, _currentColumn;
private readonly Queue<Token> _pendingTokenQueue = new(); // TODO: Possible to remove this?

public DMPreprocessorLexer(DMCompiler compiler, string includeDirectory, string file, string source) {
Compiler = compiler;
_compiler = compiler;
IncludeDirectory = includeDirectory;
File = file;

Expand All @@ -32,7 +32,7 @@ public DMPreprocessorLexer(DMCompiler compiler, string includeDirectory, string
}

public DMPreprocessorLexer(DMCompiler compiler, string includeDirectory, string file, bool isDMStandard) {
Compiler = compiler;
_compiler = compiler;
IncludeDirectory = includeDirectory;
File = file;

Expand Down Expand Up @@ -393,7 +393,7 @@ public Token NextToken(bool ignoreWhitespace = false) {

string macroAttempt = text.ToLower();
if (TryMacroKeyword(macroAttempt, out var attemptKeyword)) { // if they mis-capitalized the keyword
Compiler.Emit(WarningCode.MiscapitalizedDirective, attemptKeyword.Value.Location,
_compiler.Emit(WarningCode.MiscapitalizedDirective, attemptKeyword.Value.Location,
$"#{text} is not a valid macro keyword. Did you mean '#{macroAttempt}'?");
}

Expand Down
23 changes: 8 additions & 15 deletions DMCompiler/DM/DMObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace DMCompiler.DM;
/// including its procs, vars, path, parent, etc.
/// </remarks>
internal sealed class DMObject(DMCompiler compiler, int id, DreamPath path, DMObject? parent) {
public readonly DMCompiler Compiler = compiler;
public readonly int Id = id;
public DreamPath Path = path;
public DMObject? Parent = parent;
Expand Down Expand Up @@ -96,20 +95,20 @@ public bool OwnsProc(string name) {
}

public DMComplexValueType? GetProcReturnTypes(string name) {
if (this == Compiler.DMObjectTree.Root && Compiler.DMObjectTree.TryGetGlobalProc(name, out var globalProc))
if (this == compiler.DMObjectTree.Root && compiler.DMObjectTree.TryGetGlobalProc(name, out var globalProc))
return globalProc.RawReturnTypes;
if (GetProcs(name) is not { } procs)
return Parent?.GetProcReturnTypes(name);

var proc = Compiler.DMObjectTree.AllProcs[procs[0]];
var proc = compiler.DMObjectTree.AllProcs[procs[0]];
if ((proc.Attributes & ProcAttributes.IsOverride) != 0)
return Parent?.GetProcReturnTypes(name) ?? DMValueType.Anything;

return proc.RawReturnTypes;
}

public void AddVerb(DMProc verb) {
if (!Compiler.Settings.NoStandard && !IsSubtypeOf(DreamPath.Atom) && !IsSubtypeOf(DreamPath.Client))
if (!compiler.Settings.NoStandard && !IsSubtypeOf(DreamPath.Atom) && !IsSubtypeOf(DreamPath.Client))
return;

_verbs ??= [];
Expand Down Expand Up @@ -146,29 +145,23 @@ public void AddGlobalVariable(DMVariable global, int id) {
return Parent?.GetGlobalVariableId(name);
}

public DMVariable? GetGlobalVariable(string name) {
int? id = GetGlobalVariableId(name);

return (id == null) ? null : Compiler.DMObjectTree.Globals[id.Value];
}

public DMComplexValueType GetReturnType(string name) {
var procId = GetProcs(name)?[^1];

return procId is null ? DMValueType.Anything : Compiler.DMObjectTree.AllProcs[procId.Value].ReturnTypes;
return procId is null ? DMValueType.Anything : compiler.DMObjectTree.AllProcs[procId.Value].ReturnTypes;
}

public void CreateInitializationProc() {
if (InitializationProcExpressions.Count <= 0 || InitializationProc != null)
return;

var init = Compiler.DMObjectTree.CreateDMProc(this, null);
var init = compiler.DMObjectTree.CreateDMProc(this, null);
InitializationProc = init.Id;
init.Call(DMReference.SuperProc, DMCallArgumentsType.None, 0);

foreach (DMExpression expression in InitializationProcExpressions) {
init.DebugSource(expression.Location);
expression.EmitPushValue(new(Compiler, this, init));
expression.EmitPushValue(new(compiler, this, init));
}
}

Expand All @@ -182,14 +175,14 @@ public DreamTypeJson CreateJsonRepresentation() {
typeJson.Variables = new Dictionary<string, object>();

foreach (KeyValuePair<string, DMVariable> variable in Variables) {
if (!variable.Value.TryAsJsonRepresentation(Compiler, out var valueJson))
if (!variable.Value.TryAsJsonRepresentation(compiler, out var valueJson))
throw new Exception($"Failed to serialize {Path}.{variable.Key}");

typeJson.Variables.Add(variable.Key, valueJson);
}

foreach (KeyValuePair<string, DMVariable> variable in VariableOverrides) {
if (!variable.Value.TryAsJsonRepresentation(Compiler, out var valueJson))
if (!variable.Value.TryAsJsonRepresentation(compiler, out var valueJson))
throw new Exception($"Failed to serialize {Path}.{variable.Key}");

typeJson.Variables[variable.Key] = valueJson;
Expand Down

0 comments on commit 3b59466

Please sign in to comment.