public object GetDefaultValue(MemberInfo member, object settingsNode) { var d = new XmlDictionary <string, CompilerConfigurationNode>(); var clientCode = new CompilerConfigurationNode { OpenSimCompilerSettings = LSLOpenSimCompilerSettings.CreateOpenSimClientSide() }; clientCode.OpenSimCompilerSettings.ScriptHeader = ClientSideScriptCompilerHeader; d.Add("OpenSim Client Code", clientCode); var clientCodeCoOp = new CompilerConfigurationNode { OpenSimCompilerSettings = LSLOpenSimCompilerSettings.CreateOpenSimClientSide() }; clientCodeCoOp.OpenSimCompilerSettings.ScriptHeader = ClientSideScriptCompilerHeader; clientCodeCoOp.OpenSimCompilerSettings.InsertCoOpTerminationCalls = true; d.Add("OpenSim Client Code (co-op Stop)", clientCodeCoOp); var serverCode = new CompilerConfigurationNode { OpenSimCompilerSettings = LSLOpenSimCompilerSettings.CreateOpenSimServerSide() }; serverCode.OpenSimCompilerSettings.ScriptHeader = ServerSideScriptCompilerHeader; d.Add("OpenSim Server Code", serverCode); var serverCodeCoOp = new CompilerConfigurationNode { OpenSimCompilerSettings = LSLOpenSimCompilerSettings.CreateOpenSimServerSide() }; serverCodeCoOp.OpenSimCompilerSettings.ScriptHeader = ServerSideScriptCompilerHeader; serverCodeCoOp.OpenSimCompilerSettings.InsertCoOpTerminationCalls = true; d.Add("OpenSim Server Code (co-op Stop)", serverCodeCoOp); return(d); }
public int Compile(string outputFile) { LSLCodeValidatorStrategies codeValidatorStrategies = new LSLCodeValidatorStrategies { ExpressionValidator = ExpressionValidator, StringLiteralPreProcessor = StringLiteralPreProcessor }; codeValidatorStrategies.SyntaxErrorListener = new SyntaxErrorListener(this); codeValidatorStrategies.SyntaxWarningListener = new SyntaxWarningListener(this); var defaultProvider = new LSLEmbeddedLibraryDataProvider(); foreach (var library in LibrarySubsets) { if (defaultProvider.SubsetDescriptions.ContainsKey(library)) { defaultProvider.ActiveSubsets.Add(library); } else { WriteLine(CmdWarningHeader + "Library subset '{0}' does not exist and was ignored.", library); } } codeValidatorStrategies.LibraryDataProvider = defaultProvider; var validator = new LSLCodeValidator(codeValidatorStrategies); ILSLCompilationUnitNode validated; WriteLine(CmdNoticeHeader + "Compiling '{0}'...", _fileName); try { using (var infile = new StreamReader(_fileName)) { validated = validator.Validate(infile); if (validator.HasSyntaxErrors) { WriteLine(); WriteLine("==============================="); WriteLine(); WriteLine("Syntax Errors:"); WriteLine(); foreach (var msg in _syntaxErrorMessages) { WriteLine(msg); } _syntaxErrorMessages.Clear(); WriteLine("==============================="); WriteLine(); } if (validator.HasSyntaxWarnings) { if (!validator.HasSyntaxErrors) { WriteLine(); WriteLine("==============================="); WriteLine(); } WriteLine("Syntax Warnings:"); WriteLine(); foreach (var msg in _syntaxWarningMessages) { WriteLine(msg); } _syntaxWarningMessages.Clear(); WriteLine("==============================="); WriteLine(); } if (validator.HasSyntaxErrors) { WriteLine("Compilation phase did not start due to syntax errors."); return(ReturnCode.SyntaxErrors); } } } catch (IOException error) { WriteLine(CmdErrorHeader + "Input File '{0}' could not be read from.", _fileName); WriteLine(); WriteLine(CmdExceptionHeader + error.Message); return(ReturnCode.InputFileUnreadable); } catch (UnauthorizedAccessException error) { WriteLine(CmdErrorHeader + "Input File '{0}' could not be read from.", _fileName); WriteLine(); WriteLine(CmdExceptionHeader + error.Message); return(ReturnCode.InputFileUnreadable); } catch (LSLCodeValidatorInternalException error) { WriteLine(); WriteLine("Code Validator, internal error."); WriteLine(); WriteLine(CmdExceptionHeader + error.Message); WriteLine(); WriteLine(InternalErrorMessage); return(ReturnCode.CodeValidatorInternalError); } catch (Exception error) { WriteLine(); WriteLine("Code Validator, unknown error."); WriteLine(); WriteLine(CmdExceptionHeader + error.Message); WriteLine(); WriteLine(InternalErrorMessage); return(ReturnCode.CodeValidatorUnknownError); } //========== // Compile Tree Into Code //========== LSLOpenSimCompilerSettings compilerSettings; if (!ClientCode) { compilerSettings = LSLOpenSimCompilerSettings.CreateOpenSimServerSide(); compilerSettings.ScriptHeader = ServerSideScriptCompilerHeader; compilerSettings.InsertCoOpTerminationCalls = CoOpStop; } else { compilerSettings = LSLOpenSimCompilerSettings.CreateOpenSimClientSide(); compilerSettings.ScriptHeader = ClientSideScriptCompilerHeader; compilerSettings.InsertCoOpTerminationCalls = CoOpStop; } try { var dir = Path.GetDirectoryName(outputFile); if (!string.IsNullOrWhiteSpace(dir)) { Directory.CreateDirectory(dir); } using (var outfile = File.Create(outputFile)) { var compiler = new LSLOpenSimCompiler(defaultProvider, compilerSettings); compiler.Compile(validated, new StreamWriter(outfile, Encoding.UTF8)); } WriteLine("Finished, output to \"" + outputFile + "\""); } catch (IOException error) { WriteLine(CmdErrorHeader + "Output File '{0}' could not be written to.", outputFile); WriteLine(); WriteLine(CmdExceptionHeader + error.Message); return(ReturnCode.OutputFileUnwritable); } catch (UnauthorizedAccessException error) { WriteLine(CmdErrorHeader + "Output File '{0}' could not be written to.", outputFile); WriteLine(); WriteLine(CmdExceptionHeader + error.Message); return(ReturnCode.OutputFileUnwritable); } catch (LSLCompilerInternalException error) { WriteLine(); WriteLine("Compiler internal error:"); WriteLine(); WriteLine(CmdExceptionHeader + error.Message); WriteLine(); WriteLine(InternalErrorMessage); return(ReturnCode.CompilerInternalError); } catch (Exception error) { WriteLine(); WriteLine("Compiler unknown error:"); WriteLine(); WriteLine(CmdExceptionHeader + error.Message); WriteLine(); WriteLine(InternalErrorMessage); return(ReturnCode.CompilerUnknownError); } return(ReturnCode.Success); }