protected internal override bool ValidateInitializer(IDefinitionInstallerContext installer) { if (installer == null) { throw new ArgumentNullException(); } // 2. Get the global. GlobalVariableOrConstantBinding globalBinding = installer.GetGlobalVariableOrConstantBinding(this.GlobalName.Value); ClassBinding classBinding = installer.GetClassBinding(this.GlobalName.Value); // 3. Check that such a binding exists ... but not both if (!((globalBinding == null) ^ (classBinding == null))) { return(installer.ReportError(this.GlobalName, InstallerErrors.GlobalInvalidName)); } if ((classBinding != null) && (classBinding.Value == null)) { throw new InvalidOperationException("Should have been set in ClassDefinition.CreataGlobalObject()."); } if (classBinding != null) { return(this.Factory.ValidateClassInitializer(this, classBinding.Value, installer, new IntermediateCodeValidationErrorSink(this.MethodSourceCodeService, installer))); } if (globalBinding.IsConstantBinding && globalBinding.HasBeenSet) { return(installer.ReportError(this.GlobalName, InstallerErrors.GlobalIsConstant)); } return(this.Factory.ValidateGlobalInitializer(this, installer, new IntermediateCodeValidationErrorSink(this.MethodSourceCodeService, installer))); }
public static CompiledInitializer AddGlobalInitializer(SmalltalkRuntime runtime, SmalltalkNameScope scope, Type delegateType, string delegateName, string globalName) { GlobalVariableOrConstantBinding binding = scope.GetGlobalVariableOrConstantBinding(globalName); if (binding == null) { throw new ArgumentException(String.Format("Global variable or constant named {0} does not exist.", globalName)); } return(NativeLoadHelper.AddInitializer(scope, InitializerType.GlobalInitializer, binding, delegateType, delegateName)); }
public bool TryGetGlobal(Symbol name, out object value) { GlobalVariableOrConstantBinding binding = this.Runtime.GlobalScope.GetGlobalVariableOrConstantBinding(name); if ((binding == null) || !binding.HasBeenSet) { value = null; return(false); } value = binding.Value; return(true); }
/// <summary> /// Get global variable or global constant with the given name. /// </summary> /// <param name="name">Global variable or global constant name.</param> /// <param name="exists">True if the global variable or global constant exists, otherwise false.</param> /// <returns>Value of the global variable or global constant. If not found, null is returned.</returns> public object GetGlobal(string name, out bool exists) { GlobalVariableOrConstantBinding binding = this.GlobalScope.GetGlobalVariableOrConstantBinding(name); if (binding == null) { exists = false; return(null); } else { exists = true; return(binding.Value); } }
public CompiledInitializer CreateInitializer(InitializerDefinition definition, IDefinitionInstallerContext installer) { GlobalVariableOrConstantBinding globalBinding = installer.GetGlobalVariableOrConstantBinding(this.GlobalName); ClassBinding classBinding = installer.GetClassBinding(this.GlobalName); // 3. Check that such a binding exists ... but not both if (!((globalBinding == null) ^ (classBinding == null))) { return(null); } if (classBinding != null) { return(new RuntimeGlobalInitializer(this.ParseTree, new DebugInfoService(this.SourceCodeService), classBinding)); } if (globalBinding != null) { return(new RuntimeGlobalInitializer(this.ParseTree, new DebugInfoService(this.SourceCodeService), globalBinding)); } return(null); }
public RuntimeGlobalInitializer(InitializerNode parseTree, IDebugInfoService debugInfoService, GlobalVariableOrConstantBinding binding) : base(InitializerType.GlobalInitializer, binding, parseTree, debugInfoService) { }