internal override void GenerateGlobalNameIdManifest(VariableIdAllocator varIds) { foreach (Executable ex in this.Code) { ex.GenerateGlobalNameIdManifest(varIds); } }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { foreach (Executable ex in this.Code) { ex.PerformLocalIdAllocation(varIds, VariableIdAllocPhase.REGISTER_AND_ALLOC); } }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { foreach (Expression item in this.Items) { item.PerformLocalIdAllocation(varIds, phase); } }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { this.Expression.PerformLocalIdAllocation(varIds, phase); } }
internal override void CalculateLocalIdPass(VariableIdAllocator varIds) { for (int i = 0; i < this.Code.Length; ++i) { this.Code[i].CalculateLocalIdPass(varIds); } }
internal override void CalculateLocalIdPass(VariableIdAllocator varIds) { foreach (Executable ex in this.Init.Concat(this.Step).Concat(this.Code)) { ex.CalculateLocalIdPass(varIds); } }
internal override void PerformLocalIdAllocation(Parser parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { this.IterationExpression.PerformLocalIdAllocation(parser, varIds, phase); if ((phase & VariableIdAllocPhase.REGISTER) != 0) { varIds.RegisterVariable(this.IterationVariable.Value); } if (phase != VariableIdAllocPhase.REGISTER_AND_ALLOC) { foreach (Executable ex in this.Code) { ex.PerformLocalIdAllocation(parser, varIds, phase); } } else { foreach (Executable ex in this.Code) { ex.PerformLocalIdAllocation(parser, varIds, VariableIdAllocPhase.REGISTER); } foreach (Executable ex in this.Code) { ex.PerformLocalIdAllocation(parser, varIds, VariableIdAllocPhase.ALLOC); } } this.IterationVariableId = varIds.GetVarId(this.IterationVariable); }
internal override void PerformLocalIdAllocation(Parser parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { bool register = (phase & VariableIdAllocPhase.REGISTER) != 0; bool alloc = (phase & VariableIdAllocPhase.ALLOC) != 0; bool both = register && alloc; foreach (Executable ex in this.Init) { ex.PerformLocalIdAllocation(parser, varIds, phase); } this.Condition.PerformLocalIdAllocation(parser, varIds, phase); if (both) { foreach (Executable ex in this.Code.Concat(this.Step)) { ex.PerformLocalIdAllocation(parser, varIds, VariableIdAllocPhase.REGISTER); } foreach (Executable ex in this.Code.Concat(this.Step)) { ex.PerformLocalIdAllocation(parser, varIds, VariableIdAllocPhase.ALLOC); } } else { foreach (Executable ex in this.Code.Concat(this.Step)) { ex.PerformLocalIdAllocation(parser, varIds, phase); } } }
internal override void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { if (this.Expression != null) { this.Expression.PerformLocalIdAllocation(parser, varIds, phase); } }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { foreach (Expression item in this.Items) { item.SetLocalIdPass(varIds); } }
internal override void PerformLocalIdAllocation(Parser parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { this.Root.PerformLocalIdAllocation(parser, varIds, phase); } }
internal override void GenerateGlobalNameIdManifest(VariableIdAllocator varIds) { foreach (Executable ex in this.TrueCode.Concat<Executable>(this.FalseCode)) { ex.GenerateGlobalNameIdManifest(varIds); } }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { for (int i = 0; i < this.Args.Length; ++i) { this.Args[i].SetLocalIdPass(varIds); } }
internal override void CalculateLocalIdPass(VariableIdAllocator varIds) { foreach (Executable ex in this.TrueCode.Concat(this.FalseCode)) { ex.CalculateLocalIdPass(varIds); } }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { if (this.Expression != null) { this.Expression.SetLocalIdPass(varIds); } }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { foreach (Expression expr in this.Expressions) { expr.SetLocalIdPass(varIds); } }
internal override void GenerateGlobalNameIdManifest(VariableIdAllocator varIds) { if (this.Target is Variable) { varIds.RegisterVariable(((Variable)this.Target).Name); } }
internal void AllocateLocalScopeIds() { VariableIdAllocator variableIds = new VariableIdAllocator(); for (int i = 0; i < this.ArgNames.Length; ++i) { variableIds.RegisterVariable(this.ArgNames[i].Value); } foreach (Executable ex in this.Code) { ex.CalculateLocalIdPass(variableIds); } this.LocalScopeSize = variableIds.Size; if (this.BaseArgs != null) { foreach (Expression ex in this.BaseArgs) { ex.SetLocalIdPass(variableIds); } } foreach (Executable ex in this.Code) { ex.SetLocalIdPass(variableIds); } }
internal override void PerformLocalIdAllocation(Parser parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { // Despite potentially assigning to a varaible, it does not declare it, so it gets no special treatment. this.Root.PerformLocalIdAllocation(parser, varIds, phase); } }
internal override void CalculateLocalIdPass(VariableIdAllocator varIds) { varIds.RegisterVariable(this.IterationVariable.Value); for (int i = 0; i < this.Code.Length; ++i) { this.Code[i].CalculateLocalIdPass(varIds); } }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { this.Condition.SetLocalIdPass(varIds); for (int i = 0; i < this.Code.Length; ++i) { this.Code[i].SetLocalIdPass(varIds); } }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { for (int i = 0, length = this.Keys.Length; i < length; ++i) { this.Keys[i].SetLocalIdPass(varIds); this.Values[i].SetLocalIdPass(varIds); } }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { this.Condition.SetLocalIdPass(varIds); foreach (Executable ex in this.TrueCode.Concat(this.FalseCode)) { ex.SetLocalIdPass(varIds); } }
internal override void PerformLocalIdAllocation(Parser parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { this.PrimaryExpression.PerformLocalIdAllocation(parser, varIds, phase); this.SecondaryExpression.PerformLocalIdAllocation(parser, varIds, phase); } }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { this.IterationExpression.SetLocalIdPass(varIds); this.IterationVariableId = varIds.GetVarId(this.IterationVariable, false); for (int i = 0; i < this.Code.Length; ++i) { this.Code[i].SetLocalIdPass(varIds); } }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { foreach (Executable ex in this.Code) { ex.SetLocalIdPass(varIds); } this.Condition.SetLocalIdPass(varIds); }
internal override void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { foreach (Expression ex in this.Expressions) { ex.PerformLocalIdAllocation(parser, varIds, phase); } } }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { foreach (Expression arg in this.Args) { arg.PerformLocalIdAllocation(varIds, phase); } } }
internal override void GenerateGlobalNameIdManifest(VariableIdAllocator varIds) { string iterator = this.IterationVariable.Value; varIds.RegisterVariable(iterator); foreach (Executable ex in this.Code) { ex.GenerateGlobalNameIdManifest(varIds); } }
internal override void GenerateGlobalNameIdManifest(VariableIdAllocator varIds) { foreach (Token argToken in this.ArgNames) { varIds.RegisterVariable(argToken.Value); } foreach (Executable line in this.Code) { line.GenerateGlobalNameIdManifest(varIds); } }
internal override void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { this.Root.PerformLocalIdAllocation(parser, varIds, phase); foreach (Expression arg in this.Args) { arg.PerformLocalIdAllocation(parser, varIds, phase); } } }
internal void AllocateLocalScopeIds() { VariableIdAllocator variableIds = new VariableIdAllocator(); for (int i = 0; i < this.ArgNames.Length; ++i) { variableIds.RegisterVariable(this.ArgNames[i].Value); } this.PerformLocalIdAllocation(variableIds, VariableIdAllocPhase.REGISTER_AND_ALLOC); this.LocalScopeSize = variableIds.Size; }
internal override void PerformLocalIdAllocation(Parser parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { this.Root.PerformLocalIdAllocation(parser, varIds, phase); foreach (Expression item in this.Items) { if (item != null) { item.PerformLocalIdAllocation(parser, varIds, phase); } } }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { // Iterate through KVP in parallel so that errors will get reported in the preferred order. for (int i = 0; i < this.Keys.Length; ++i) { this.Keys[i].PerformLocalIdAllocation(varIds, phase); this.Values[i].PerformLocalIdAllocation(varIds, phase); } } }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { this.Root.SetLocalIdPass(varIds); for (int i = 0; i < this.Items.Length; ++i) { Expression item = this.Items[i]; if (item != null) { this.Items[i].SetLocalIdPass(varIds); } } }
internal override void PerformLocalIdAllocation(Parser parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { foreach (Expression arg in this.BaseArgs) { arg.PerformLocalIdAllocation(parser, varIds, VariableIdAllocPhase.ALLOC); } foreach (Executable ex in this.Code) { ex.PerformLocalIdAllocation(parser, varIds, VariableIdAllocPhase.REGISTER_AND_ALLOC); } }
internal override void CalculateLocalIdPass(VariableIdAllocator varIds) { Variable variable = this.TargetAsVariable; // Note that things like += do not declare a new variable name and so they don't count as assignment // in this context. foo += value should NEVER take a global scope value and assign it to a local scope value. // Globals cannot be assigned to from outside the global scope. if (variable != null && this.AssignmentOpToken.Value == "=") { varIds.RegisterVariable(variable.Name); } }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { this.LocalScopeId = varIds.GetVarId(this.FirstToken); if (this.LocalScopeId == -1) { string name = this.FirstToken.Value; if (SystemLibraryManager.IsValidLibrary(name)) { throw new ParserException(this.FirstToken, "'" + name + "' is referenced but not imported in this file."); } throw new ParserException(this.FirstToken, "'" + name + "' is used but is never assigned to."); } } }
internal override void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { this.LocalScopeId = varIds.GetVarId(this.FirstToken); if (this.LocalScopeId == -1) { string name = this.FirstToken.Value; if (parser.LibraryManager.IsValidLibraryNameFromLocale(this.Owner.FileScope.CompilationScope.Locale, name)) { throw new ParserException(this.FirstToken, "'" + name + "' is referenced but not imported in this file."); } TopLevelConstruct owner = this.Owner; while (owner != null && !(owner is ClassDefinition)) { owner = owner.Owner; } if (owner != null) { ClassDefinition cd = (ClassDefinition)owner; foreach (FieldDeclaration fd in cd.Fields) { if (fd.NameToken.Value == name) { string message = "'" + name + "' is used like a local variable but it is " + (fd.IsStaticField ? "a static" : "an instance") + " field."; message += " Did you mean '" + (fd.IsStaticField ? cd.NameToken.Value : "this") + "." + name + "' instead of '" + name + "'?"; throw new ParserException(this.FirstToken, message); } } } // TODO: But if it's being called like a function then... // - give a better error message "function 'foo' is not defined" // - give an even better error message when there's a class or instance function with the same name // e.g. "'foo' is a static function and must be invoked with the class name: FooClass.foo(...) // - if there's a method, suggest using "this." // - if the variable name matches a library that is available, suggest it as a missing import. throw new ParserException(this.FirstToken, "The variable '" + name + "' is used but is never assigned to."); } } }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { this.Value.PerformLocalIdAllocation(varIds, phase); if ((phase & VariableIdAllocPhase.REGISTER) != 0) { bool isVariableDeclared = // A variable is considered declared if the target is a variable and = is used instead of something like += this.Target is Variable && this.AssignmentOpToken.Value == "="; if (isVariableDeclared) { varIds.RegisterVariable(this.TargetAsVariable.Name); } } this.Target.PerformLocalIdAllocation(varIds, phase); }
internal override void GenerateGlobalNameIdManifest(VariableIdAllocator varIds) { varIds.RegisterVariable(this.NameToken.Value); foreach (FieldDeclaration fd in this.Fields) { fd.GenerateGlobalNameIdManifest(varIds); } if (this.StaticConstructor != null) { this.StaticConstructor.GenerateGlobalNameIdManifest(varIds); } if (this.Constructor != null) { this.Constructor.GenerateGlobalNameIdManifest(varIds); } foreach (FunctionDefinition fd in this.Methods) { fd.GenerateGlobalNameIdManifest(varIds); } }
internal override void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { this.Condition.PerformLocalIdAllocation(parser, varIds, phase); if (phase != VariableIdAllocPhase.REGISTER_AND_ALLOC || this.chunks.Length <= 1) { foreach (Chunk chunk in this.chunks) { foreach (Executable ex in chunk.Code) { ex.PerformLocalIdAllocation(parser, varIds, phase); } } } else { VariableIdAllocator[] varIdBranches = new VariableIdAllocator[this.chunks.Length]; for (int i = 0; i < this.chunks.Length; ++i) { Chunk chunk = this.chunks[i]; varIdBranches[i] = varIds.Clone(); foreach (Executable ex in chunk.Code) { ex.PerformLocalIdAllocation(parser, varIdBranches[i], phase); } } varIds.MergeClonesBack(varIdBranches); for (int i = 0; i < this.chunks.Length; ++i) { Chunk chunk = this.chunks[i]; varIdBranches[i] = varIds.Clone(); foreach (Executable ex in chunk.Code) { ex.PerformLocalIdAllocation(parser, varIdBranches[i], VariableIdAllocPhase.ALLOC); } } } }
internal override void PerformLocalIdAllocation(Parser parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { this.Condition.PerformLocalIdAllocation(parser, varIds, phase); if (phase != VariableIdAllocPhase.REGISTER_AND_ALLOC || this.TrueCode.Length == 0 || this.FalseCode.Length == 0) { foreach (Executable ex in this.TrueCode.Concat(this.FalseCode)) { ex.PerformLocalIdAllocation(parser, varIds, phase); } } else { // branch the variable ID allocator. VariableIdAllocator trueVars = varIds.Clone(); VariableIdAllocator falseVars = varIds.Clone(); // Go through and register and allocate all variables. // The allocated ID's are going to be garbage, but this enforces that they must be // declared before being used. foreach (Executable ex in this.TrueCode) { ex.PerformLocalIdAllocation(parser, trueVars, VariableIdAllocPhase.REGISTER_AND_ALLOC); } foreach (Executable ex in this.FalseCode) { ex.PerformLocalIdAllocation(parser, falseVars, VariableIdAllocPhase.REGISTER_AND_ALLOC); } // Now that the code is as correct as we can verify, merge the branches back together // creating a new set of variable ID's. varIds.MergeClonesBack(trueVars, falseVars); // Go back through and do another allocation pass and assign the correct variable ID's. foreach (Executable ex in this.TrueCode.Concat(this.FalseCode)) { ex.PerformLocalIdAllocation(parser, varIds, VariableIdAllocPhase.ALLOC); } } }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { if (phase != VariableIdAllocPhase.REGISTER_AND_ALLOC) { foreach (Executable ex in this.Code) { ex.PerformLocalIdAllocation(varIds, phase); } this.Condition.PerformLocalIdAllocation(varIds, phase); } else { foreach (Executable ex in this.Code) { ex.PerformLocalIdAllocation(varIds, VariableIdAllocPhase.REGISTER); } foreach (Executable ex in this.Code) { ex.PerformLocalIdAllocation(varIds, VariableIdAllocPhase.ALLOC); } this.Condition.PerformLocalIdAllocation(varIds, VariableIdAllocPhase.ALLOC); } }
internal override void PerformLocalIdAllocation(Parser parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { foreach (Executable ex in this.TryBlock) { ex.PerformLocalIdAllocation(parser, varIds, phase); } foreach (CatchBlock cb in this.CatchBlocks) { if (cb.ExceptionVariableToken != null) { if ((phase & VariableIdAllocPhase.REGISTER) != 0) { varIds.RegisterVariable(cb.ExceptionVariableToken.Value); } if ((phase & VariableIdAllocPhase.ALLOC) != 0) { cb.VariableLocalScopeId = varIds.GetVarId(cb.ExceptionVariableToken); } } foreach (Executable ex in cb.Code) { ex.PerformLocalIdAllocation(parser, varIds, phase); } } if (this.FinallyBlock != null) { foreach (Executable ex in this.FinallyBlock) { ex.PerformLocalIdAllocation(parser, varIds, phase); } } }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { this.Condition.PerformLocalIdAllocation(varIds, phase); this.TrueValue.PerformLocalIdAllocation(varIds, phase); this.FalseValue.PerformLocalIdAllocation(varIds, phase); }
internal override void GenerateGlobalNameIdManifest(VariableIdAllocator varIds) { // no assignments }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { // Translate mode only. throw new NotImplementedException(); }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { // Not called in this way. throw new NotImplementedException(); }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { throw new InvalidOperationException(); // never call this function directly. }
internal override void GenerateGlobalNameIdManifest(VariableIdAllocator varIds) { varIds.RegisterVariable(this.NameToken.Value); }
internal abstract void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase);
internal override void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { throw new NotImplementedException(); }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { throw new System.InvalidOperationException(); // never call this directly on a class. }
internal override void CalculateLocalIdPass(VariableIdAllocator varIds) { }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { this.Root.SetLocalIdPass(varIds); this.Index.SetLocalIdPass(varIds); }
internal override void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { }
internal override void SetLocalIdPass(VariableIdAllocator varIds) { this.PrimaryExpression.SetLocalIdPass(varIds); this.SecondaryExpression.SetLocalIdPass(varIds); }