internal abstract void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase);
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) { }
internal override void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { foreach (Expression item in this.Items) { item.PerformLocalIdAllocation(parser, varIds, phase); } }
internal override void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { }
internal override void ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { this.Root.ResolveVariableOrigins(parser, varIds, phase); } }
internal override void PerformLocalIdAllocation(Parser parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { if (this.Expression != null) { this.Expression.PerformLocalIdAllocation(parser, varIds, phase); } }
internal abstract void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase);
internal override void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { if (phase != VariableIdAllocPhase.REGISTER_AND_ALLOC) { foreach (Executable ex in this.Code) { ex.PerformLocalIdAllocation(parser, varIds, phase); } this.Condition.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.Condition.PerformLocalIdAllocation(parser, varIds, VariableIdAllocPhase.ALLOC); } }
internal override void PerformLocalIdAllocation(ParserContext parser, 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(parser, varIds, phase); this.Values[i].PerformLocalIdAllocation(parser, varIds, phase); } } }
internal override void ResolveVariableOrigins(ParserContext parser, VariableScope 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].ResolveVariableOrigins(parser, varIds, phase); this.Values[i].ResolveVariableOrigins(parser, varIds, phase); } } }
internal override void ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { foreach (Expression arg in this.Args) { arg.ResolveVariableOrigins(parser, varIds, phase); } } }
internal override void ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase) { this.Condition.ResolveVariableOrigins(parser, varIds, phase); this.TrueValue.ResolveVariableOrigins(parser, varIds, phase); this.FalseValue.ResolveVariableOrigins(parser, varIds, phase); }
internal override void PerformLocalIdAllocation(ParserContext 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 ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase) { this.IterationExpression.ResolveVariableOrigins(parser, varIds, phase); if ((phase & VariableIdAllocPhase.REGISTER) != 0) { varIds.RegisterVariable(this.IterationType, this.IterationVariable.Value); this.IndexLocalId = varIds.RegisterSyntheticVariable(AType.Integer(this.FirstToken)); this.ListLocalId = varIds.RegisterSyntheticVariable(AType.Any(this.FirstToken)); } if (phase != VariableIdAllocPhase.REGISTER_AND_ALLOC) { foreach (Executable ex in this.Code) { ex.ResolveVariableOrigins(parser, varIds, phase); } } else { foreach (Executable ex in this.Code) { ex.ResolveVariableOrigins(parser, varIds, VariableIdAllocPhase.REGISTER); } foreach (Executable ex in this.Code) { ex.ResolveVariableOrigins(parser, varIds, VariableIdAllocPhase.ALLOC); } } this.IterationVariableId = varIds.GetVarId(this.IterationVariable); }
internal override void PerformLocalIdAllocation(ParserContext 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 PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { // Throws if it finds any variable. this.DefaultValue.PerformLocalIdAllocation(parser, varIds, phase); }
internal override void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { this.Value.PerformLocalIdAllocation(parser, 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(parser, varIds, phase); }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { this.Root.PerformLocalIdAllocation(varIds, phase); }
internal override void PerformLocalIdAllocation(ParserContext 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 PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { this.Root.PerformLocalIdAllocation(parser, varIds, phase); } }
internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { // Not called this way. throw new InvalidOperationException(); }
internal override void ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase) { if (this.Expression != null) { this.Expression.ResolveVariableOrigins(parser, varIds, phase); } }
internal override void ResolveVariableOrigins(ParserContext parser, VariableScope 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.ResolveVariableOrigins(parser, varIds, phase); } this.Condition.ResolveVariableOrigins(parser, varIds, phase); if (both) { foreach (Executable ex in this.Code.Concat(this.Step)) { ex.ResolveVariableOrigins(parser, varIds, VariableIdAllocPhase.REGISTER); } foreach (Executable ex in this.Code.Concat(this.Step)) { ex.ResolveVariableOrigins(parser, varIds, VariableIdAllocPhase.ALLOC); } } else { foreach (Executable ex in this.Code.Concat(this.Step)) { ex.ResolveVariableOrigins(parser, varIds, phase); } } }
internal override void ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase) { }
internal override void PerformLocalIdAllocation(Parser parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { // Not called in this way. throw new System.NotImplementedException(); }
internal override void PerformLocalIdAllocation(ParserContext parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { foreach (Expression arg in this.Args) { arg.PerformLocalIdAllocation(parser, varIds, phase); } } }
internal override void ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { if (this.Root is Variable) { ((Variable)this.Root).DirectOwner = this; } this.Root.ResolveVariableOrigins(parser, varIds, phase); foreach (Expression arg in this.Args) { arg.ResolveVariableOrigins(parser, varIds, phase); } } }
internal override void ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase) { this.Condition.ResolveVariableOrigins(parser, varIds, phase); if (phase != VariableIdAllocPhase.REGISTER_AND_ALLOC) { foreach (Executable ex in this.Code) { ex.ResolveVariableOrigins(parser, varIds, phase); } } else { foreach (Executable ex in this.Code) { ex.ResolveVariableOrigins(parser, varIds, VariableIdAllocPhase.REGISTER); } foreach (Executable ex in this.Code) { ex.ResolveVariableOrigins(parser, varIds, 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.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); } } } }