Index: default.build =================================================================== --- default.build (revision 2748) +++ default.build (working copy) @@ -66,10 +66,16 @@ + + @@ -105,6 +111,7 @@ + @@ -141,6 +148,7 @@ + @@ -152,7 +160,7 @@ - + + @@ -194,14 +203,14 @@ - + for p as System.Collections.DictionaryEntry in Project.Properties: print("${p.Key}: ${p.Value}") - + + + + @@ -250,7 +262,7 @@ - + - + + + @@ -318,7 +332,7 @@ - + @@ -345,7 +359,7 @@ - + @@ -376,11 +390,12 @@ + - + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -679,7 +739,7 @@ - + @@ -1034,7 +1094,7 @@ - + import System.IO Index: scripts/update-vs2005-env.boo =================================================================== --- scripts/update-vs2005-env.boo (revision 2748) +++ scripts/update-vs2005-env.boo (working copy) @@ -123,6 +123,7 @@ "src/Boo.Lang/Boo.Lang-VS2005.csproj", "src/Boo.Lang.Parser/Boo.Lang.Parser-VS2005.csproj", "src/Boo.Lang.Compiler/Boo.Lang.Compiler-VS2005.csproj", +#"src/Boo.Lang.Ast/Boo.Lang.Ast-VS2005.csproj", "tests/BooCompiler.Tests/BooCompiler.Tests-VS2005.csproj", "src/Boo.Lang.Compiler/Boo.Lang.Compiler.mdp", Index: src/booc/App.cs =================================================================== --- src/booc/App.cs (revision 2748) +++ src/booc/App.cs (working copy) @@ -96,6 +96,9 @@ _options = new CompilerParameters(false); //false means no stdlib loading yet _options.GenerateInMemory = false; + ArrayList tempLibPaths = _options.LibPaths.Clone() as ArrayList; + _options.LibPaths.Clear(); + BooCompiler compiler = new BooCompiler(_options); ParseOptions(args); @@ -106,10 +109,8 @@ } //move standard libpaths below any new ones: - _options.LibPaths.Add(_options.LibPaths[0]); - _options.LibPaths.Add(_options.LibPaths[1]); - _options.LibPaths.RemoveAt(0); - _options.LibPaths.RemoveAt(0); + foreach(object o in tempLibPaths) + _options.LibPaths.Add(o); if (_options.StdLib) { Property changes on: src\Boo.Lang.Ast ___________________________________________________________________ Name: svn:ignore + bin obj Index: src/Boo.Lang.Ast/Boo.Lang.Ast.csproj =================================================================== --- src/Boo.Lang.Ast/Boo.Lang.Ast.csproj (revision 0) +++ src/Boo.Lang.Ast/Boo.Lang.Ast.csproj (revision 0) @@ -0,0 +1,35 @@ + + + {4AC4D0A6-4192-4185-A68D-3EE8B3F38D64} + Debug + AnyCPU + Library + Boo.Lang.Ast + Boo.Lang.Ast + + + bin\Debug\ + True + Full + False + True + DEBUG;TRACE + + + bin\Release\ + False + None + True + False + TRACE + + + + + + + + + + + \ No newline at end of file Index: src/Boo.Lang.Ast/AssemblyInfo.cs =================================================================== --- src/Boo.Lang.Ast/AssemblyInfo.cs (revision 0) +++ src/Boo.Lang.Ast/AssemblyInfo.cs (revision 0) @@ -0,0 +1,47 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +using System.Reflection; +using System.Security.Permissions; + +[assembly: ReflectionPermission(SecurityAction.RequestMinimum, + ReflectionEmit=true)] +[assembly: AssemblyTitle("boo - an extensible programming language for the CLI")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("boo - an extensible programming language for the CLI")] +[assembly: AssemblyCopyright("(C) 2003-2007 Rodrigo Barreto de Oliveira")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: AssemblyVersion("2.0.0.0")] +[assembly: AssemblyDelaySign(false)] +#if !IGNOREKEYFILE +[assembly: AssemblyKeyFile("../src/boo.snk")] +#endif +[assembly: AssemblyKeyName("")] Property changes on: src\Boo.Lang.Extensions ___________________________________________________________________ Name: svn:ignore + bin obj Index: src/Boo.Lang.Extensions/Macros/YieldAllMacro.boo =================================================================== --- src/Boo.Lang.Extensions/Macros/YieldAllMacro.boo (revision 0) +++ src/Boo.Lang.Extensions/Macros/YieldAllMacro.boo (revision 0) @@ -0,0 +1,46 @@ +#region license +// Copyright (c) 2004, 2005 Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +namespace Boo.Lang.Extensions + +import System +import Boo.Lang.Compiler +import Boo.Lang.Compiler.Ast + +public class YieldAllMacro(AbstractAstMacro): + + override def Expand(macro as MacroStatement): + if (1 != macro.Arguments.Count) or (0 != macro.Block.Statements.Count): + Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, 'yieldAll ')) + return null + + fs = ForStatement(macro.LexicalInfo) + fs.Declarations.Add(Declaration(macro.LexicalInfo, '___item')) + fs.Iterator = macro.Arguments[0] + fs.Block.Add(YieldStatement(macro.LexicalInfo, ReferenceExpression('___item'))) + return fs Index: src/Boo.Lang.Extensions/Macros/AbstractPrintMacro.boo =================================================================== --- src/Boo.Lang.Extensions/Macros/AbstractPrintMacro.boo (revision 0) +++ src/Boo.Lang.Extensions/Macros/AbstractPrintMacro.boo (revision 0) @@ -0,0 +1,55 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +namespace Boo.Lang.Extensions + +import System +import Boo.Lang.Compiler +import Boo.Lang.Compiler.Ast + + +public abstract class AbstractPrintMacro(AbstractAstMacro): + + abstract def Expand(macro as MacroStatement) as Statement: + pass + + protected def Expand(macro as MacroStatement, writePrototype as Expression, writeLinePrototype as Expression): + li = macro.LexicalInfo + + argc = macro.Arguments.Count + if argc < 2: + mie = MethodInvocationExpression(li, writeLinePrototype.CloneNode()) + mie.Arguments = macro.Arguments + return ExpressionStatement(mie) + + block = Block() + for i in range(0, (argc - 1)): + block.Add(AstUtil.CreateMethodInvocationExpression(li, writePrototype.CloneNode(), macro.Arguments[i])) + block.Add(AstUtil.CreateMethodInvocationExpression(li, writePrototype.CloneNode(), StringLiteralExpression(' '))) + block.Add(AstUtil.CreateMethodInvocationExpression(li, writeLinePrototype.CloneNode(), macro.Arguments[(-1)])) + return block \ No newline at end of file Index: src/Boo.Lang.Extensions/Macros/AssertMacro.boo =================================================================== --- src/Boo.Lang.Extensions/Macros/AssertMacro.boo (revision 0) +++ src/Boo.Lang.Extensions/Macros/AssertMacro.boo (revision 0) @@ -0,0 +1,62 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +namespace Boo.Lang.Extensions + +import System +import System.IO +import Boo.Lang.Compiler +import Boo.Lang.Compiler.Ast +import Boo.Lang.Compiler.Ast.Visitors + + +public class AssertMacro(AbstractAstMacro): + + private static final ExceptionTypeReference = AstUtil.CreateReferenceExpression('Boo.Lang.Runtime.AssertionFailedException') + + public override def Expand(macro as MacroStatement): + argc = macro.Arguments.Count + if (argc != 1) and (argc != 2): + // TODO: localize this message + raise System.ArgumentException(Boo.Lang.ResourceManager.Format('AssertArgCount', argc)) + + // figure out the msg for the exception + condition = macro.Arguments[0] + message = (StringLiteralExpression(condition.LexicalInfo, condition.ToString()) if (argc == 1) else macro.Arguments[1]) + + // unless : + // raise Boo.AssertionFailedException() + stmt = UnlessStatement(macro.LexicalInfo) + stmt.Condition = condition + stmt.Block = Block(macro.LexicalInfo) + + throw = RaiseStatement(macro.LexicalInfo) + throw.Exception = AstUtil.CreateMethodInvocationExpression(ExceptionTypeReference, message) + stmt.Block.Add(throw) + + return stmt \ No newline at end of file Index: src/Boo.Lang.Extensions/Macros/UsingMacro.boo =================================================================== --- src/Boo.Lang.Extensions/Macros/UsingMacro.boo (revision 0) +++ src/Boo.Lang.Extensions/Macros/UsingMacro.boo (revision 0) @@ -0,0 +1,91 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +namespace Boo.Lang.Extensions + +import System +import Boo.Lang.Compiler +import Boo.Lang.Compiler.Ast + + +public class UsingMacro(AbstractAstMacro): + + private static final DisposableLocalName = '__disposable__' + + + override def Expand(macro as MacroStatement): + // try: + // assignment + // + // ensure: + // ... + stmt = TryStatement(macro.LexicalInfo) + stmt.EnsureBlock = Block(macro.LexicalInfo) + + for expression as Expression in macro.Arguments: + reference as Expression + + if expression isa ReferenceExpression: + reference = expression + elif IsAssignmentToReference(expression): + reference = cast(BinaryExpression, expression).Left.CloneNode() + stmt.ProtectedBlock.Add(expression) + else: + tempName as string = string.Format('__using{0}__', _context.AllocIndex()) + reference = ReferenceExpression(expression.LexicalInfo, tempName) + stmt.ProtectedBlock.Add(BinaryExpression(expression.LexicalInfo, BinaryOperatorType.Assign, reference.CloneNode(), expression)) + + AugmentEnsureBlock(stmt.EnsureBlock, reference) + + stmt.ProtectedBlock.Add(macro.Block) + return stmt + + + private def AugmentEnsureBlock(block as Block, reference as Expression): + // if __disposable = as System.IDisposable: + stmt = IfStatement() + stmt.Condition = BinaryExpression(BinaryOperatorType.Assign, ReferenceExpression(DisposableLocalName), TryCastExpression(reference, SimpleTypeReference('System.IDisposable'))) + + stmt.TrueBlock = Block() + + // __disposable.Dispose() + stmt.TrueBlock.Add(MethodInvocationExpression(MemberReferenceExpression(ReferenceExpression(DisposableLocalName), 'Dispose'))) + + // __disposable = null + stmt.TrueBlock.Add(BinaryExpression(BinaryOperatorType.Assign, ReferenceExpression(DisposableLocalName), NullLiteralExpression())) + + block.Add(stmt) + + + private def IsAssignmentToReference(expression as Expression): + if NodeType.BinaryExpression != expression.NodeType: + return false + + binaryExpression = cast(BinaryExpression, expression) + return ((BinaryOperatorType.Assign == binaryExpression.Operator) and (binaryExpression.Left isa ReferenceExpression)) + Index: src/Boo.Lang.Extensions/Macros/CheckedMacro.boo =================================================================== --- src/Boo.Lang.Extensions/Macros/CheckedMacro.boo (revision 0) +++ src/Boo.Lang.Extensions/Macros/CheckedMacro.boo (revision 0) @@ -0,0 +1,52 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +namespace Boo.Lang.Extensions + +import Boo.Lang.Compiler.Steps +import System.Diagnostics +import Boo.Lang.Compiler +import Boo.Lang.Compiler.Ast + + +public class UncheckedMacro(AbstractAstMacro): + + override def Expand(macro as MacroStatement): + Debug.Assert((0 == macro.Arguments.Count)) + AstAnnotations.MarkUnchecked(macro.Block) + return macro.Block + + +public class CheckedMacro(AbstractAstMacro): + + override def Expand(macro as MacroStatement): + Debug.Assert((0 == macro.Arguments.Count)) + AstAnnotations.MarkChecked(macro.Block) + return macro.Block + Index: src/Boo.Lang.Extensions/Macros/DebugMacro.boo =================================================================== --- src/Boo.Lang.Extensions/Macros/DebugMacro.boo (revision 0) +++ src/Boo.Lang.Extensions/Macros/DebugMacro.boo (revision 0) @@ -0,0 +1,51 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +namespace Boo.Lang.Extensions + +import System +import Boo.Lang.Compiler +import Boo.Lang.Compiler.Ast + + +public class DebugMacro(AbstractPrintMacro): + + private static final Debug_WriteLine as Expression = AstUtil.CreateReferenceExpression('System.Diagnostics.Debug.WriteLine') + + private static final Debug_Write as Expression = AstUtil.CreateReferenceExpression('System.Diagnostics.Debug.Write') + + override def Expand(macro as MacroStatement): + if not Context.Parameters.Debug: + return null + + if 0 == macro.Arguments.Count: + return ExpressionStatement(AstUtil.CreateMethodInvocationExpression(Debug_WriteLine.CloneNode(), StringLiteralExpression(''))) + + return Expand(macro, Debug_Write, Debug_WriteLine) + + Index: src/Boo.Lang.Extensions/Macros/LockMacro.boo =================================================================== --- src/Boo.Lang.Extensions/Macros/LockMacro.boo (revision 0) +++ src/Boo.Lang.Extensions/Macros/LockMacro.boo (revision 0) @@ -0,0 +1,84 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +namespace Boo.Lang.Extensions + +import System +import Boo.Lang.Compiler +import Boo.Lang.Compiler.Ast + + +public class LockMacro(AbstractAstMacro): + + public static final MonitorLocalName = '__monitor{0}__' + + private static final Monitor_Enter as Expression = AstUtil.CreateReferenceExpression('System.Threading.Monitor.Enter') + + private static final Monitor_Exit as Expression = AstUtil.CreateReferenceExpression('System.Threading.Monitor.Exit') + + override def Expand(macro as MacroStatement): + if 0 == macro.Arguments.Count: + raise Boo.Lang.Compiler.CompilerErrorFactory.InvalidLockMacroArguments(macro) + + resulting as Block = macro.Block + args as ExpressionCollection = macro.Arguments + for i in range(args.Count, 0, -1): + arg as Expression = args[(i - 1)] + + resulting = CreateLockedBlock(arg, resulting) + + return resulting + + private def CreateMonitorReference(lexicalInfo as LexicalInfo) as ReferenceExpression: + localIndex as int = _context.AllocIndex() + return ReferenceExpression(lexicalInfo, string.Format(MonitorLocalName, localIndex)) + + internal def CreateLockedBlock(monitor as Expression, body as Block) as Block: + monitorReference as ReferenceExpression = CreateMonitorReference(monitor.LexicalInfo) + + block = Block(body.LexicalInfo) + + // __monitorN__ = + block.Add(BinaryExpression(BinaryOperatorType.Assign, monitorReference, monitor)) + + // System.Threading.Monitor.Enter(__monitorN__) + block.Add(AstUtil.CreateMethodInvocationExpression(Monitor_Enter, monitorReference)) + + // try: + // + // ensure: + // Monitor.Leave + stmt = TryStatement() + stmt.ProtectedBlock = body + stmt.EnsureBlock = Block() + stmt.EnsureBlock.Add(AstUtil.CreateMethodInvocationExpression(Monitor_Exit, monitorReference)) + + block.Add(stmt) + + return block + Index: src/Boo.Lang.Extensions/Macros/PrintMacro.boo =================================================================== --- src/Boo.Lang.Extensions/Macros/PrintMacro.boo (revision 0) +++ src/Boo.Lang.Extensions/Macros/PrintMacro.boo (revision 0) @@ -0,0 +1,45 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +namespace Boo.Lang.Extensions + +import System +import Boo.Lang.Compiler +import Boo.Lang.Compiler.Ast + + +public class PrintMacro(AbstractPrintMacro): + + private static final Console_Write = AstUtil.CreateReferenceExpression('System.Console.Write') + + private static final Console_WriteLine = AstUtil.CreateReferenceExpression('System.Console.WriteLine') + + override def Expand(macro as MacroStatement): + return Expand(macro, Console_Write, Console_WriteLine) + + Index: src/Boo.Lang.Extensions/Macros/RawArrayIndexingMacro.boo =================================================================== --- src/Boo.Lang.Extensions/Macros/RawArrayIndexingMacro.boo (revision 0) +++ src/Boo.Lang.Extensions/Macros/RawArrayIndexingMacro.boo (revision 0) @@ -0,0 +1,49 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +namespace Boo.Lang.Extensions + +import Boo.Lang.Compiler.Steps +import System.Diagnostics +import Boo.Lang.Compiler +import Boo.Lang.Compiler.Ast + +public class NormalArrayIndexingMacro(AbstractAstMacro): + + override def Expand(macro as MacroStatement): + Debug.Assert((0 == macro.Arguments.Count)) + macro.Block[AstAnnotations.RawArrayIndexing] = false + return macro.Block + +public class RawArrayIndexingMacro(AbstractAstMacro): + + override def Expand(macro as MacroStatement): + Debug.Assert((0 == macro.Arguments.Count)) + macro.Block[AstAnnotations.RawArrayIndexing] = true + return macro.Block + Index: src/Boo.Lang.Extensions/Boo.Lang.Extensions.booproj =================================================================== --- src/Boo.Lang.Extensions/Boo.Lang.Extensions.booproj (revision 0) +++ src/Boo.Lang.Extensions/Boo.Lang.Extensions.booproj (revision 0) @@ -0,0 +1,48 @@ + + + {48E18542-C08D-4BAF-99D0-BA2882259F40} + Debug + AnyCPU + Library + Boo.Lang.Extensions + Boo.Lang.Extensions + + + bin\Debug\ + True + Full + False + + + bin\Release\ + False + None + True + + + + + + + + + + + + + + + + + + + + + + + {83C914F8-1F12-4879-925D-D831A04366BD} + Boo.Lang.Compiler + + + + \ No newline at end of file Index: src/Boo.Lang.Extensions/Attributes/RequiredAttribute.boo =================================================================== --- src/Boo.Lang.Extensions/Attributes/RequiredAttribute.boo (revision 0) +++ src/Boo.Lang.Extensions/Attributes/RequiredAttribute.boo (revision 0) @@ -0,0 +1,93 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +namespace Boo.Lang.Extensions + +import System +import Boo.Lang.Compiler.Ast + +//[AstAttributeTarget(typeof(ParameterDeclaration))] +public class RequiredAttribute(Boo.Lang.Compiler.AbstractAstAttribute): + + protected _condition as Expression + + public def constructor(): + pass + + public def constructor(condition as Expression): + if condition is null: + raise ArgumentNullException('condition') + _condition = condition + + public override def Apply(node as Boo.Lang.Compiler.Ast.Node): + name as string + parent as Node + errorMessage as string = null + + pd = (node as ParameterDeclaration) + if pd is not null: + name = pd.Name + parent = pd.ParentNode + else: + prop = (node as Property) + if (prop is not null) and (prop.Setter is not null): + name = 'value' + parent = prop.Setter + else: + InvalidNodeForAttribute('ParameterDeclaration or Property') + return + + exceptionClass as string = null + modifier as StatementModifier = null + if _condition is null: + exceptionClass = 'ArgumentNullException' + modifier = StatementModifier(StatementModifierType.If, BinaryExpression(BinaryOperatorType.ReferenceEquality, ReferenceExpression(name), NullLiteralExpression())) + else: + exceptionClass = 'ArgumentException' + modifier = StatementModifier(StatementModifierType.Unless, _condition) + errorMessage = ('Expected: ' + _condition.ToString()) + + x = MethodInvocationExpression() + x.Target = MemberReferenceExpression(ReferenceExpression('System'), exceptionClass) + if errorMessage is not null: + x.Arguments.Add(StringLiteralExpression(errorMessage)) + x.Arguments.Add(StringLiteralExpression(name)) + + rs = RaiseStatement(x, modifier) + rs.LexicalInfo = LexicalInfo + + method = (parent as Method) + if method is not null: + method.Body.Statements.Insert(0, rs) + else: + property = cast(Property, parent) + if property.Getter is not null: + property.Getter.Body.Statements.Insert(0, rs) + if property.Setter is not null: + property.Setter.Body.Statements.Insert(0, rs.CloneNode()) Index: src/Boo.Lang.Extensions/Attributes/DefaultAttribute.boo =================================================================== --- src/Boo.Lang.Extensions/Attributes/DefaultAttribute.boo (revision 0) +++ src/Boo.Lang.Extensions/Attributes/DefaultAttribute.boo (revision 0) @@ -0,0 +1,87 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +namespace Boo.Lang.Extensions + +import System +import Boo.Lang.Compiler +import Boo.Lang.Compiler.Ast +import Boo.Lang.Compiler.TypeSystem + +//[AstAttributeTarget(typeof(ParameterDeclaration))] +public class DefaultAttribute(Boo.Lang.Compiler.AbstractAstAttribute): + + protected _value as Expression + + public def constructor(value as Expression): + if value is null: + raise ArgumentNullException('value') + _value = value + + + public override def Apply(node as Boo.Lang.Compiler.Ast.Node): + name as string + parent as Node + type as IType + + pd = (node as ParameterDeclaration) + if pd is not null: + name = pd.Name + parent = pd.ParentNode + type = (NameResolutionService.Resolve(pd.Type.ToString(), EntityType.Type) as IType) + else: + prop = (node as Property) + if (prop is not null) and (prop.Setter is not null): + name = 'value' + parent = prop.Setter + type = (NameResolutionService.Resolve(prop.Type.ToString(), EntityType.Type) as IType) + else: + InvalidNodeForAttribute('ParameterDeclaration or Property') + return + + // error if parameter is a valuetype + // TODO: check nullable (type.IsValueType true or not here?) + if (type is not null) and type.IsValueType: + Errors.Add(CompilerErrorFactory.ValueTypeParameterCannotUseDefaultAttribute(parent, name)) + return + + //TODO: check if default value is type-compatible with argument type? + //TODO: handle nullable through assignIfHasValue + assignIfNull = IfStatement(LexicalInfo) + assignIfNull.Condition = BinaryExpression(BinaryOperatorType.ReferenceEquality, ReferenceExpression(name), NullLiteralExpression()) + assignIfNull.TrueBlock = Block(LexicalInfo) + assignIfNull.TrueBlock.Add(BinaryExpression(BinaryOperatorType.Assign, ReferenceExpression(name), _value)) + + method = (parent as Method) + if method is not null: + method.Body.Statements.Insert(0, assignIfNull) + else: + property = cast(Property, parent) + if property.Setter is not null: + property.Setter.Body.Statements.Insert(0, assignIfNull) \ No newline at end of file Index: src/Boo.Lang.Extensions/Attributes/PropertyAttribute.boo =================================================================== --- src/Boo.Lang.Extensions/Attributes/PropertyAttribute.boo (revision 0) +++ src/Boo.Lang.Extensions/Attributes/PropertyAttribute.boo (revision 0) @@ -0,0 +1,164 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +namespace Boo.Lang.Extensions + +import System +import Boo.Lang.Compiler.Ast + +public class PropertyAttribute(Boo.Lang.Compiler.AbstractAstAttribute): + + protected _propertyName as ReferenceExpression + + protected _setPreCondition as Expression + + protected _protected as BoolLiteralExpression + + protected _observable as BoolLiteralExpression + + protected _attributes as ListLiteralExpression + + public def constructor(propertyName as ReferenceExpression): + self(propertyName, null) + + public def constructor(propertyName as ReferenceExpression, setPreCondition as Expression): + if propertyName is null: + raise ArgumentNullException('propertyName') + _propertyName = propertyName + _setPreCondition = setPreCondition + + Protected: + get: + return _protected + set: + _protected = value + + protected IsProtected: + get: + if _protected is null: + return false + return _protected.Value + + Observable: + get: + return _observable + set: + _observable = value + + protected IsObservable: + get: + if _observable is null: + return false + return _observable.Value + + protected ChangedEventName: + get: + return (_propertyName.Name + 'Changed') + + Attributes: + get: + return _attributes + set: + _attributes = value + + public override def Apply(node as Node): + f = (node as Field) + if f is null: + InvalidNodeForAttribute('Field') + return + + p = Property() + if f.IsStatic: + p.Modifiers |= TypeMemberModifiers.Static + if IsProtected: + p.Modifiers |= TypeMemberModifiers.Protected + p.Name = _propertyName.Name + p.Type = f.Type + p.Getter = CreateGetter(f) + p.Setter = CreateSetter(f) + p.LexicalInfo = LexicalInfo + + if (Attributes is not null) and (Attributes.Items.Count > 0): + for item as Expression in Attributes.Items: + p.Attributes.Add(ConvertExpressionToAttribute(item)) + + f.DeclaringType.Members.Add(p) + + if IsObservable: + f.DeclaringType.Members.Add(CreateChangedEvent(f)) + + public static def ConvertExpressionToAttribute(item as Expression) as Boo.Lang.Compiler.Ast.Attribute: + att as Boo.Lang.Compiler.Ast.Attribute = Boo.Lang.Compiler.Ast.Attribute(item.LexicalInfo) + if item isa MethodInvocationExpression: + m = cast(MethodInvocationExpression, item) + att.Name = m.Target.ToString() + att.Arguments = m.Arguments + att.NamedArguments = m.NamedArguments + else: + att.Name = item.ToString() + return att + + + protected virtual def CreateGetter(f as Field) as Method: + // get: + // return + getter = Method() + getter.Name = 'get' + getter.Body.Statements.Add(ReturnStatement(super.LexicalInfo, ReferenceExpression(f.Name), null)) + return getter + + + protected virtual def CreateSetter(f as Field) as Method: + setter = Method() + setter.Name = 'set' + + if _setPreCondition is not null: + setter.Body.Add(RaiseStatement(_setPreCondition.LexicalInfo, AstUtil.CreateMethodInvocationExpression(AstUtil.CreateReferenceExpression('System.ArgumentException'), StringLiteralExpression((('precondition \'' + _setPreCondition.ToString()) + '\' failed:'))), StatementModifier(StatementModifierType.Unless, _setPreCondition))) + setter.Body.Add(BinaryExpression(super.LexicalInfo, BinaryOperatorType.Assign, MemberReferenceExpression(CreateRefTarget(f), f.Name), ReferenceExpression('value'))) + + if IsObservable: + mie = MethodInvocationExpression(ReferenceExpression(ChangedEventName)) + mie.Arguments.Add(SelfLiteralExpression()) + mie.Arguments.Add(MemberReferenceExpression(MemberReferenceExpression(ReferenceExpression('System'), 'EventArgs'), 'Empty')) + setter.Body.Add(mie) + return setter + + + private def CreateRefTarget(f as Field) as Expression: + if f.IsStatic: + return ReferenceExpression(LexicalInfo, f.DeclaringType.Name) + return SelfLiteralExpression(LexicalInfo) + + + protected def CreateChangedEvent(f as Field) as Event: + e = Event(_observable.LexicalInfo) + e.Name = ChangedEventName + e.Type = CodeBuilder.CreateTypeReference(f.LexicalInfo, typeof(System.EventHandler)) + return e + Index: src/Boo.Lang.Extensions/Attributes/LockAttribute.boo =================================================================== --- src/Boo.Lang.Extensions/Attributes/LockAttribute.boo (revision 0) +++ src/Boo.Lang.Extensions/Attributes/LockAttribute.boo (revision 0) @@ -0,0 +1,65 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +namespace Boo.Lang.Extensions + +import System +import Boo.Lang.Compiler +import Boo.Lang.Compiler.Ast + +public class LockAttribute(AbstractAstAttribute): + + private _monitor as Expression + + def constructor(monitor as Expression): + if monitor is null: + raise ArgumentNullException('monitor') + _monitor = monitor + + def constructor(): + pass + + override def Apply(node as Node): + if NodeType.Method != node.NodeType: + InvalidNodeForAttribute('Method') + return + + if _monitor is null: + _monitor = SelfLiteralExpression(LexicalInfo) + + method = cast(Method, node) + method.Body = CreateLockedBlock(method.Body) + + + private def CreateLockedBlock(body as Block): + try: + macro = LockMacro() + macro.Initialize(_context) + return macro.CreateLockedBlock(_monitor, body) + ensure: + macro.Dispose() if macro is not null \ No newline at end of file Index: src/Boo.Lang.Extensions/Attributes/GetterAttribute.boo =================================================================== --- src/Boo.Lang.Extensions/Attributes/GetterAttribute.boo (revision 0) +++ src/Boo.Lang.Extensions/Attributes/GetterAttribute.boo (revision 0) @@ -0,0 +1,47 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +namespace Boo.Lang.Extensions + +import System; +import Boo.Lang.Compiler.Ast + +public class GetterAttribute(PropertyAttribute): +""" +Creates a field accessor. + +@example +class Customer: + [getter(FirstName)] _fname as string + [getter(LastName)] _lname as string +""" + def constructor(propertyName as ReferenceExpression): + super(propertyName) + + override protected def CreateSetter(f as Field): + return null Index: src/Boo.Lang.Extensions/AssemblyInfo.boo =================================================================== --- src/Boo.Lang.Extensions/AssemblyInfo.boo (revision 0) +++ src/Boo.Lang.Extensions/AssemblyInfo.boo (revision 0) @@ -0,0 +1,43 @@ +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +import System.Reflection; +import System.Security.Permissions; + +[assembly: ReflectionPermission(SecurityAction.RequestMinimum, + ReflectionEmit: true)] +[assembly: AssemblyTitle("Boo Compiler Extensions")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("boo - an extensible programming language for the CLI")] +[assembly: AssemblyCopyright("(C) 2003-2007 Rodrigo Barreto de Oliveira")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: AssemblyVersion("2.0.0.0")] +[assembly: AssemblyKeyFile("../src/boo.snk")] Index: src/Boo.Lang/Boo.Lang-VS2005.csproj =================================================================== --- src/Boo.Lang/Boo.Lang-VS2005.csproj (revision 2748) +++ src/Boo.Lang/Boo.Lang-VS2005.csproj (working copy) @@ -67,6 +67,7 @@ + Index: src/Boo.Lang/Boo.Lang.csproj =================================================================== --- src/Boo.Lang/Boo.Lang.csproj (revision 2748) +++ src/Boo.Lang/Boo.Lang.csproj (working copy) @@ -58,6 +58,7 @@ + Index: src/Boo.Lang/MetaAttribute.cs =================================================================== --- src/Boo.Lang/MetaAttribute.cs (revision 2748) +++ src/Boo.Lang/MetaAttribute.cs (working copy) @@ -27,7 +27,7 @@ #endregion -namespace Boo.Lang.Compiler.MetaProgramming +namespace Boo.Lang { public class MetaAttribute : System.Attribute { Index: src/Boo.Lang.Useful/BooTemplate/TemplateCompiler.boo =================================================================== --- src/Boo.Lang.Useful/BooTemplate/TemplateCompiler.boo (revision 2748) +++ src/Boo.Lang.Useful/BooTemplate/TemplateCompiler.boo (working copy) @@ -49,6 +49,7 @@ compiler = BooCompiler() compiler.Parameters.Input.Add(input) compiler.Parameters.OutputType = CompilerOutputType.Library + compiler.Parameters.References.Add(typeof(Ast.Node).Assembly) pipeline = Pipelines.CompileToMemory() pipeline[0] = Boo.Lang.Parser.WSABooParsingStep() Index: src/Boo.NAnt.Tasks/BooTask.boo =================================================================== --- src/Boo.NAnt.Tasks/BooTask.boo (revision 2748) +++ src/Boo.NAnt.Tasks/BooTask.boo (working copy) @@ -42,10 +42,19 @@ class AbstractScript: - [property(Project)] + Project: + get: + return _project + set: + _project = value + _project as Project - [property(Task)] + Task: + get: + return _task + set: + _task = value _task as BooTask def print(msg): Index: src/Boo.NAnt.Tasks/AbstractBooTask.boo =================================================================== --- src/Boo.NAnt.Tasks/AbstractBooTask.boo (revision 2748) +++ src/Boo.NAnt.Tasks/AbstractBooTask.boo (working copy) @@ -150,10 +150,16 @@ self.Log(Level.Error, "${message}") def read(fname as string): - using reader=File.OpenText(fname): + try: + reader=File.OpenText(fname) return reader.ReadToEnd() + ensure: + reader.Dispose() unless reader is null def write(fname as string, contents as string): - using writer=StreamWriter(fname, false, System.Text.Encoding.UTF8): + try: + writer=StreamWriter(fname, false, System.Text.Encoding.UTF8) writer.Write(contents) + ensure: + writer.Dispose() unless writer is null Index: src/Boo.NAnt.Tasks/InsertLicenseTask.boo =================================================================== --- src/Boo.NAnt.Tasks/InsertLicenseTask.boo (revision 2748) +++ src/Boo.NAnt.Tasks/InsertLicenseTask.boo (working copy) @@ -68,14 +68,20 @@ def InsertLicense(fname as string, license as string): print(fname) contents = read(fname) - using writer=StreamWriter(fname, false, System.Text.Encoding.UTF8): + try: + writer=StreamWriter(fname, false, System.Text.Encoding.UTF8) writer.WriteLine(license) writer.WriteLine() writer.Write(contents) + ensure: + writer.Dispose() unless writer is null def GetFirstLine(fname as string): - using f=File.OpenText(fname): + try: + f=File.OpenText(fname) return f.ReadLine() + ensure: + f.Dispose() unless f is null def print(message): self.Log(Level.Info, "${message}") Index: src/Boo.Lang.Compiler/Compilation.cs =================================================================== --- src/Boo.Lang.Compiler/Compilation.cs (revision 0) +++ src/Boo.Lang.Compiler/Compilation.cs (revision 0) @@ -0,0 +1,106 @@ +#region license +// Copyright (c) 2003, 2004, 2005 Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using Boo.Lang.Compiler.Ast; +using Module=Boo.Lang.Compiler.Ast.Module; + +namespace Boo.Lang.Compiler.MetaProgramming +{ + public class CompilationErrorsException : System.Exception + { + private CompilerErrorCollection _errors; + + public CompilationErrorsException(CompilerErrorCollection errors) : base(errors.ToString()) + { + _errors = errors; + } + + public CompilerErrorCollection Errors + { + get { return _errors; } + } + } + + [CompilerGlobalScope] + public sealed class Compilation + { + public static Type compile(ClassDefinition klass, params System.Reflection.Assembly[] references) + { + Assembly generatedAssembly = compile(CreateCompileUnit(klass), references); + return generatedAssembly.GetType(klass.Name); + } + + public static Assembly compile(Module module, params System.Reflection.Assembly[] references) + { + return compile(new CompileUnit(module), references); + } + + public static Assembly compile(CompileUnit unit, params Assembly[] references) + { + BooCompiler compiler = CompilerFor(unit, references); + CompilerContext result = compiler.Run(unit); + if (result.Errors.Count > 0) throw new CompilationErrorsException(result.Errors); + return result.GeneratedAssembly; + } + + private static BooCompiler CompilerFor(CompileUnit unit, Assembly[] references) + { + BooCompiler compiler = new BooCompiler(); + compiler.Parameters.OutputType = IsApplication(unit) ? CompilerOutputType.ConsoleApplication : CompilerOutputType.Library; + compiler.Parameters.Pipeline = new Boo.Lang.Compiler.Pipelines.CompileToMemory(); + compiler.Parameters.References.Extend(references); + return compiler; + } + + private static bool IsApplication(CompileUnit unit) + { + foreach (Module m in unit.Modules) + { + if (m.Globals.HasStatements) return true; + } + return false; + } + + private static CompileUnit CreateCompileUnit(ClassDefinition klass) + { + return new CompileUnit(CreateModule(klass)); + } + + private static Module CreateModule(ClassDefinition klass) + { + Module module = new Module(); + module.Name = klass.Name; + module.Members.Add(klass); + return module; + } + } +} Index: src/Boo.Lang.Compiler/Macros/PrintMacro.cs =================================================================== --- src/Boo.Lang.Compiler/Macros/PrintMacro.cs (revision 2748) +++ src/Boo.Lang.Compiler/Macros/PrintMacro.cs (working copy) @@ -1,52 +0,0 @@ -#region license -// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -namespace Boo.Lang -{ - using System; - using Boo.Lang.Compiler; - using Boo.Lang.Compiler.Ast; - - /// - /// print foo, bar - /// print - /// print "Hello" - /// - public class PrintMacro : AbstractPrintMacro - { - static Expression Console_Write = AstUtil.CreateReferenceExpression("System.Console.Write"); - - static Expression Console_WriteLine = AstUtil.CreateReferenceExpression("System.Console.WriteLine"); - - override public Statement Expand(MacroStatement macro) - { - return Expand(macro, Console_Write, Console_WriteLine); - } - } -} - Index: src/Boo.Lang.Compiler/Macros/RawArrayIndexingMacro.cs =================================================================== --- src/Boo.Lang.Compiler/Macros/RawArrayIndexingMacro.cs (revision 2748) +++ src/Boo.Lang.Compiler/Macros/RawArrayIndexingMacro.cs (working copy) @@ -1,56 +0,0 @@ -#region license -// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -using Boo.Lang.Compiler.Steps; - -namespace Boo.Lang -{ - using System.Diagnostics; - using Boo.Lang.Compiler; - using Boo.Lang.Compiler.Ast; - - public class NormalArrayIndexingMacro : AbstractAstMacro - { - public override Statement Expand(MacroStatement macro) - { - Debug.Assert(0 == macro.Arguments.Count); - macro.Block[AstAnnotations.RawArrayIndexing] = false; - return macro.Block; - } - } - - public class RawArrayIndexingMacro : AbstractAstMacro - { - public override Statement Expand(MacroStatement macro) - { - Debug.Assert(0 == macro.Arguments.Count); - macro.Block[AstAnnotations.RawArrayIndexing] = true; - return macro.Block; - } - } -} Index: src/Boo.Lang.Compiler/Macros/YieldAllMacro.cs =================================================================== --- src/Boo.Lang.Compiler/Macros/YieldAllMacro.cs (revision 2748) +++ src/Boo.Lang.Compiler/Macros/YieldAllMacro.cs (working copy) @@ -1,61 +0,0 @@ -#region license -// Copyright (c) 2004, 2005 Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -namespace Boo.Lang -{ - using System; - using Boo.Lang.Compiler; - using Boo.Lang.Compiler.Ast; - - /// - /// yieldAll range(1, 5) - /// expands to - /// for ___item in range(1, 5): - /// yield ___item - /// - public class YieldAllMacro : AbstractAstMacro - { - override public Statement Expand(MacroStatement macro) - { - if (1 != macro.Arguments.Count || 0 != macro.Block.Statements.Count) - { - Errors.Add( - CompilerErrorFactory.CustomError(macro.LexicalInfo, "yieldAll ")); - return null; - } - - ForStatement fs = new ForStatement(macro.LexicalInfo); - fs.Declarations.Add(new Declaration(macro.LexicalInfo, "___item")); - fs.Iterator = macro.Arguments[0]; - fs.Block.Add( - new YieldStatement(macro.LexicalInfo, new ReferenceExpression("___item"))); - return fs; - } - } -} - Index: src/Boo.Lang.Compiler/Macros/AbstractPrintMacro.cs =================================================================== --- src/Boo.Lang.Compiler/Macros/AbstractPrintMacro.cs (revision 2748) +++ src/Boo.Lang.Compiler/Macros/AbstractPrintMacro.cs (working copy) @@ -1,78 +0,0 @@ -#region license -// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -namespace Boo.Lang -{ - using System; - using Boo.Lang.Compiler; - using Boo.Lang.Compiler.Ast; - - public abstract class AbstractPrintMacro : AbstractAstMacro - { - public abstract override Statement Expand(MacroStatement macro); - - protected Statement Expand(MacroStatement macro, - Expression writePrototype, - Expression writeLinePrototype) - { - LexicalInfo li = macro.LexicalInfo; - - int argc = macro.Arguments.Count; - if (argc < 2) - { - MethodInvocationExpression mie = new MethodInvocationExpression( - li, - writeLinePrototype.CloneNode()); - mie.Arguments = macro.Arguments; - return new ExpressionStatement(mie); - } - - Block block = new Block(); - for (int i=0; i - /// assert condition[, message] - /// - public class AssertMacro : AbstractAstMacro - { - private static Expression ExceptionTypeReference = - AstUtil.CreateReferenceExpression("Boo.Lang.Runtime.AssertionFailedException"); - - public override Statement Expand(MacroStatement macro) - { - int argc = macro.Arguments.Count; - if (argc != 1 && argc != 2) - { - // TODO: localize this message - throw new System.ArgumentException( - Boo.Lang.ResourceManager.Format("AssertArgCount", argc)); - } - - // figure out the msg for the exception - Expression condition = macro.Arguments[0]; - Expression message = (argc == 1) ? - new StringLiteralExpression( - condition.LexicalInfo, condition.ToString()) : - macro.Arguments[1]; - - // unless : - // raise Boo.AssertionFailedException() - UnlessStatement stmt = new UnlessStatement(macro.LexicalInfo); - stmt.Condition = condition; - stmt.Block = new Block(macro.LexicalInfo); - - RaiseStatement raise = new RaiseStatement(macro.LexicalInfo); - raise.Exception = - AstUtil.CreateMethodInvocationExpression(ExceptionTypeReference, message); - stmt.Block.Add(raise); - - return stmt; - } - } -} Index: src/Boo.Lang.Compiler/Macros/UsingMacro.cs =================================================================== --- src/Boo.Lang.Compiler/Macros/UsingMacro.cs (revision 2748) +++ src/Boo.Lang.Compiler/Macros/UsingMacro.cs (working copy) @@ -1,134 +0,0 @@ -#region license -// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -namespace Boo.Lang -{ - using System; - using Boo.Lang.Compiler; - using Boo.Lang.Compiler.Ast; - - /// - /// using file=File.OpenText(fname): - /// print(file.ReadLine()) - /// - public class UsingMacro : AbstractAstMacro - { - private const string DisposableLocalName = "__disposable__"; - - public override Statement Expand(MacroStatement macro) - { - // try: - // assignment - // - // ensure: - // ... - TryStatement stmt = new TryStatement(macro.LexicalInfo); - stmt.EnsureBlock = new Block(macro.LexicalInfo); - - foreach (Expression expression in macro.Arguments) - { - Expression reference; - - if (expression is ReferenceExpression) - { - reference = expression; - } - else - { - if (IsAssignmentToReference(expression)) - { - reference = ((BinaryExpression)expression).Left.CloneNode(); - stmt.ProtectedBlock.Add(expression); - } - else - { - string tempName = string.Format("__using{0}__", _context.AllocIndex()); - reference = new ReferenceExpression(expression.LexicalInfo, tempName); - stmt.ProtectedBlock.Add(new BinaryExpression(expression.LexicalInfo, - BinaryOperatorType.Assign, - reference.CloneNode(), - expression)); - - } - - } - - AugmentEnsureBlock(stmt.EnsureBlock, reference); - } - - stmt.ProtectedBlock.Add(macro.Block); - return stmt; - } - - private void AugmentEnsureBlock(Block block, Expression reference) - { - // if __disposable = as System.IDisposable: - IfStatement stmt = new IfStatement(); - stmt.Condition = new BinaryExpression( - BinaryOperatorType.Assign, - new ReferenceExpression(DisposableLocalName), - new TryCastExpression(reference, new SimpleTypeReference("System.IDisposable")) - ); - - stmt.TrueBlock = new Block(); - - // __disposable.Dispose() - stmt.TrueBlock.Add( - new MethodInvocationExpression( - new MemberReferenceExpression( - new ReferenceExpression(DisposableLocalName), - "Dispose") - ) - ); - - // __disposable = null - stmt.TrueBlock.Add( - new BinaryExpression( - BinaryOperatorType.Assign, - new ReferenceExpression(DisposableLocalName), - new NullLiteralExpression() - ) - ); - - block.Add(stmt); - } - - private bool IsAssignmentToReference(Expression expression) - { - if (NodeType.BinaryExpression != expression.NodeType) - { - return false; - } - - BinaryExpression binaryExpression = (BinaryExpression)expression; - return - BinaryOperatorType.Assign == binaryExpression.Operator && - binaryExpression.Left is ReferenceExpression; - } - } -} Index: src/Boo.Lang.Compiler/Macros/CheckedMacro.cs =================================================================== --- src/Boo.Lang.Compiler/Macros/CheckedMacro.cs (revision 2748) +++ src/Boo.Lang.Compiler/Macros/CheckedMacro.cs (working copy) @@ -1,56 +0,0 @@ -#region license -// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -using Boo.Lang.Compiler.Steps; - -namespace Boo.Lang -{ - using System.Diagnostics; - using Boo.Lang.Compiler; - using Boo.Lang.Compiler.Ast; - - public class UncheckedMacro : AbstractAstMacro - { - public override Statement Expand(MacroStatement macro) - { - Debug.Assert(0 == macro.Arguments.Count); - AstAnnotations.MarkUnchecked(macro.Block); - return macro.Block; - } - } - - public class CheckedMacro : AbstractAstMacro - { - public override Statement Expand(MacroStatement macro) - { - Debug.Assert(0 == macro.Arguments.Count); - AstAnnotations.MarkChecked(macro.Block); - return macro.Block; - } - } -} Index: src/Boo.Lang.Compiler/Macros/DebugMacro.cs =================================================================== --- src/Boo.Lang.Compiler/Macros/DebugMacro.cs (revision 2748) +++ src/Boo.Lang.Compiler/Macros/DebugMacro.cs (working copy) @@ -1,83 +0,0 @@ -#region license -// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -namespace Boo.Lang -{ - using System; - using Boo.Lang.Compiler; - using Boo.Lang.Compiler.Ast; - - /// - /// debug foo, bar - /// debug - /// debug "Hello" - /// - /// You can view debug messages by: - /// A. Pass the "-d" option to booi, if you have the patched booi version. - /// *Note* debug is already on by default in booi and booc. This option just - /// prints debug messages to System.Console.Error as well. To turn debugging - /// completely OFF, pass "-d-" or "-debug-" to booi or booc. - /// B. In Windows: using DebugView - /// http://www.sysinternals.com/ntw2k/freeware/debugview.shtml - /// C. In Mono (not tested): export MONO_TRACE=debug=Console.Out - /// D. In your boo script: add a few lines like: - /// import System.Diagnostics - /// Debug.Listeners.Add(TextWriterTraceListener(System.Console.Error)) - /// #Trace.Listeners.Add(TextWriterTraceListener(System.Console.Error)) - /// #(if you want to print Trace messages as well) - /// - /// To turn debugging off in booc or booi, use the "-d-" or "-debug-" command-line option - /// ("-d" or "-debug+" turns debugging on, but it is already on by default) - /// - /// - public class DebugMacro : AbstractPrintMacro - { - static Expression Debug_WriteLine = AstUtil.CreateReferenceExpression("System.Diagnostics.Debug.WriteLine"); - - static Expression Debug_Write = AstUtil.CreateReferenceExpression("System.Diagnostics.Debug.Write"); - - override public Statement Expand(MacroStatement macro) - { - if (!Context.Parameters.Debug) - { - return null; - } - - if (0 == macro.Arguments.Count) - { - return new ExpressionStatement( - AstUtil.CreateMethodInvocationExpression( - Debug_WriteLine.CloneNode(), - new StringLiteralExpression(""))); - } - - return Expand(macro, Debug_Write, Debug_WriteLine); - } - } -} - Index: src/Boo.Lang.Compiler/Macros/LockMacro.cs =================================================================== --- src/Boo.Lang.Compiler/Macros/LockMacro.cs (revision 2748) +++ src/Boo.Lang.Compiler/Macros/LockMacro.cs (working copy) @@ -1,146 +0,0 @@ -#region license -// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -namespace Boo.Lang -{ - using System; - using Boo.Lang.Compiler; - using Boo.Lang.Compiler.Ast; - - public class LockAttribute : Boo.Lang.Compiler.AbstractAstAttribute - { - Expression _monitor; - - public LockAttribute(Expression monitor) - { - if (null == monitor) - { - throw new ArgumentNullException("monitor"); - } - _monitor = monitor; - } - - public LockAttribute() - { - } - - override public void Apply(Node node) - { - if (NodeType.Method != node.NodeType) - { - InvalidNodeForAttribute("Method"); - return; - } - - if (null == _monitor) - { - _monitor = new SelfLiteralExpression(LexicalInfo); - } - - Method method = (Method)node; - method.Body = CreateLockedBlock(method.Body); - } - - Block CreateLockedBlock(Block body) - { - using (LockMacro macro = new LockMacro()) - { - macro.Initialize(_context); - return macro.CreateLockedBlock(_monitor, body); - } - } - } - - /// - /// lock obj1, obj2: - /// obj1.Foo(obj2) - /// - public class LockMacro : AbstractAstMacro - { - public const string MonitorLocalName = "__monitor{0}__"; - - static Expression Monitor_Enter = AstUtil.CreateReferenceExpression("System.Threading.Monitor.Enter"); - - static Expression Monitor_Exit = AstUtil.CreateReferenceExpression("System.Threading.Monitor.Exit"); - - public override Statement Expand(MacroStatement macro) - { - if (0 == macro.Arguments.Count) - { - throw Boo.Lang.Compiler.CompilerErrorFactory.InvalidLockMacroArguments(macro); - } - - Block resulting = macro.Block; - ExpressionCollection args = macro.Arguments; - for (int i=args.Count; i > 0; --i) - { - Expression arg = args[i-1]; - - resulting = CreateLockedBlock(arg, resulting); - } - - return resulting; - } - - ReferenceExpression CreateMonitorReference(LexicalInfo lexicalInfo) - { - int localIndex = _context.AllocIndex(); - return new ReferenceExpression(lexicalInfo, - string.Format(MonitorLocalName, localIndex)); - } - - internal Block CreateLockedBlock(Expression monitor, Block body) - { - ReferenceExpression monitorReference = CreateMonitorReference(monitor.LexicalInfo); - - Block block = new Block(body.LexicalInfo); - - // __monitorN__ = - block.Add(new BinaryExpression(BinaryOperatorType.Assign, - monitorReference, - monitor)); - - // System.Threading.Monitor.Enter(__monitorN__) - block.Add(AstUtil.CreateMethodInvocationExpression(Monitor_Enter, monitorReference)); - - // try: - // - // ensure: - // Monitor.Leave - TryStatement stmt = new TryStatement(); - stmt.ProtectedBlock = body; - stmt.EnsureBlock = new Block(); - stmt.EnsureBlock.Add( - AstUtil.CreateMethodInvocationExpression(Monitor_Exit, monitorReference)); - - block.Add(stmt); - - return block; - } - } -} Index: src/Boo.Lang.Compiler/TypeSystem/ExternalMethod.cs =================================================================== --- src/Boo.Lang.Compiler/TypeSystem/ExternalMethod.cs (revision 2748) +++ src/Boo.Lang.Compiler/TypeSystem/ExternalMethod.cs (working copy) @@ -56,7 +56,7 @@ { if (-1 == _isMeta) { - _isMeta = IsStatic && MetadataUtil.IsAttributeDefined(_memberInfo, typeof(Boo.Lang.Compiler.MetaProgramming.MetaAttribute)) + _isMeta = IsStatic && MetadataUtil.IsAttributeDefined(_memberInfo, typeof(Boo.Lang.MetaAttribute)) ? 1 : 0; } Index: src/Boo.Lang.Compiler/Boo.Lang.Compiler.mdp =================================================================== --- src/Boo.Lang.Compiler/Boo.Lang.Compiler.mdp (revision 2748) +++ src/Boo.Lang.Compiler/Boo.Lang.Compiler.mdp (working copy) @@ -20,6 +20,7 @@ + @@ -273,24 +274,9 @@ - - - - - - - - - - - - - - - Index: src/Boo.Lang.Compiler/Steps/IntroduceGlobalNamespaces.cs =================================================================== --- src/Boo.Lang.Compiler/Steps/IntroduceGlobalNamespaces.cs (revision 2748) +++ src/Boo.Lang.Compiler/Steps/IntroduceGlobalNamespaces.cs (working copy) @@ -38,6 +38,7 @@ NameResolutionService.GlobalNamespace = new NamespaceDelegator( NameResolutionService.GlobalNamespace, SafeGetNamespace("Boo.Lang"), + SafeGetNamespace("Boo.Lang.Extensions"), TypeSystemServices.BuiltinsType); } Index: src/Boo.Lang.Compiler/Boo.Lang.Compiler-VS2005.csproj =================================================================== --- src/Boo.Lang.Compiler/Boo.Lang.Compiler-VS2005.csproj (revision 2748) +++ src/Boo.Lang.Compiler/Boo.Lang.Compiler-VS2005.csproj (working copy) @@ -63,6 +63,7 @@ + @@ -316,24 +317,9 @@ - - - - - - - - - - - - - - - Index: src/Boo.Lang.Compiler/Attributes/GetterAttribute.cs =================================================================== --- src/Boo.Lang.Compiler/Attributes/GetterAttribute.cs (revision 2748) +++ src/Boo.Lang.Compiler/Attributes/GetterAttribute.cs (working copy) @@ -1,55 +0,0 @@ -#region license -// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -using System; -using Boo.Lang.Compiler.Ast; - -namespace Boo.Lang -{ - /// - /// Creates a field accessor. - /// - /// - ///
-	/// class Customer:
-	///		[getter(FirstName)] _fname as string
-	///		[getter(LastName)] _lname as string
-	/// 
- ///
- public class GetterAttribute : PropertyAttribute - { - public GetterAttribute(ReferenceExpression propertyName) : base(propertyName) - { - } - - override protected Method CreateSetter(Field f) - { - return null; - } - } -} Index: src/Boo.Lang.Compiler/Attributes/RequiredAttribute.cs =================================================================== --- src/Boo.Lang.Compiler/Attributes/RequiredAttribute.cs (revision 2748) +++ src/Boo.Lang.Compiler/Attributes/RequiredAttribute.cs (working copy) @@ -1,141 +0,0 @@ -#region license -// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -using System; -using Boo.Lang.Compiler.Ast; - -namespace Boo.Lang -{ - /// - /// Parameter validation. - /// - /// - ///
-	/// def constructor([required] name as string):
-	///		_name = name
-	/// 
- ///
- //[AstAttributeTarget(typeof(ParameterDeclaration))] - public class RequiredAttribute : Boo.Lang.Compiler.AbstractAstAttribute - { - protected Expression _condition; - - public RequiredAttribute() - { - } - - public RequiredAttribute(Expression condition) - { - if (null == condition) - { - throw new ArgumentNullException("condition"); - } - _condition = condition; - } - - override public void Apply(Boo.Lang.Compiler.Ast.Node node) - { - string name; - Node parent; - string errorMessage = null; - - ParameterDeclaration pd = node as ParameterDeclaration; - if (pd !=null) - { - name = pd.Name; - parent = pd.ParentNode; - } - else - { - Property prop = node as Property; - if (prop != null && prop.Setter != null) - { - name = "value"; - parent = prop.Setter; - } - else - { - InvalidNodeForAttribute("ParameterDeclaration or Property"); - return; - } - } - - string exceptionClass = null; - StatementModifier modifier = null; - if (null == _condition) - { - exceptionClass = "ArgumentNullException"; - modifier = new StatementModifier( - StatementModifierType.If, - new BinaryExpression(BinaryOperatorType.ReferenceEquality, - new ReferenceExpression(name), - new NullLiteralExpression())); - } - else - { - exceptionClass = "ArgumentException"; - modifier = new StatementModifier( - StatementModifierType.Unless, - _condition); - errorMessage = "Expected: " + _condition.ToString(); - } - - MethodInvocationExpression x = new MethodInvocationExpression(); - x.Target = new MemberReferenceExpression( - new ReferenceExpression("System"), - exceptionClass); - if (null != errorMessage) - { - x.Arguments.Add(new StringLiteralExpression(errorMessage)); - } - x.Arguments.Add(new StringLiteralExpression(name)); - - RaiseStatement rs = new RaiseStatement(x, modifier); - rs.LexicalInfo = LexicalInfo; - - Method method = parent as Method; - if (null != method) - { - method.Body.Statements.Insert(0, rs); - } - else - { - Property property = (Property)parent; - if (null != property.Getter) - { - property.Getter.Body.Statements.Insert(0, rs); - } - if (null != property.Setter) - { - property.Setter.Body.Statements.Insert(0, rs.CloneNode()); - } - } - - } - } -} Index: src/Boo.Lang.Compiler/Attributes/DefaultAttribute.cs =================================================================== --- src/Boo.Lang.Compiler/Attributes/DefaultAttribute.cs (revision 2748) +++ src/Boo.Lang.Compiler/Attributes/DefaultAttribute.cs (working copy) @@ -1,123 +0,0 @@ -#region license -// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -using System; -using Boo.Lang.Compiler; -using Boo.Lang.Compiler.Ast; -using Boo.Lang.Compiler.TypeSystem; - -namespace Boo.Lang -{ - /// - /// Parameter default value (when parameter is not a valuetype). - /// - /// - ///
-	/// def constructor([default("Cedric")] name as string):
-	///		_name = name
-	/// 
- ///
- //[AstAttributeTarget(typeof(ParameterDeclaration))] - public class DefaultAttribute : Boo.Lang.Compiler.AbstractAstAttribute - { - protected Expression _value; - - public DefaultAttribute(Expression value) - { - if (null == value) - { - throw new ArgumentNullException("value"); - } - _value = value; - } - - override public void Apply(Boo.Lang.Compiler.Ast.Node node) - { - string name; - Node parent; - IType type; - - ParameterDeclaration pd = node as ParameterDeclaration; - if (pd != null) - { - name = pd.Name; - parent = pd.ParentNode; - type = NameResolutionService.Resolve(pd.Type.ToString(), EntityType.Type) as IType; - } - else - { - Property prop = node as Property; - if (prop != null && prop.Setter != null) - { - name = "value"; - parent = prop.Setter; - type = NameResolutionService.Resolve(prop.Type.ToString(), EntityType.Type) as IType; - } - else - { - InvalidNodeForAttribute("ParameterDeclaration or Property"); - return; - } - } - - // error if parameter is a valuetype - // TODO: check nullable (type.IsValueType true or not here?) - if (null != type && type.IsValueType) { - Errors.Add(CompilerErrorFactory.ValueTypeParameterCannotUseDefaultAttribute(parent, name)); - return; - } - - //TODO: check if default value is type-compatible with argument type? - //TODO: handle nullable through assignIfHasValue - IfStatement assignIfNull = new IfStatement(LexicalInfo); - assignIfNull.Condition = new BinaryExpression( - BinaryOperatorType.ReferenceEquality, - new ReferenceExpression(name), - new NullLiteralExpression()); - assignIfNull.TrueBlock = new Block(LexicalInfo); - assignIfNull.TrueBlock.Add( - new BinaryExpression(BinaryOperatorType.Assign, - new ReferenceExpression(name), - _value)); - - Method method = parent as Method; - if (null != method) - { - method.Body.Statements.Insert(0, assignIfNull); - } - else - { - Property property = (Property) parent; - if (null != property.Setter) - { - property.Setter.Body.Statements.Insert(0, assignIfNull); - } - } - } - } -} Index: src/Boo.Lang.Compiler/Attributes/PropertyAttribute.cs =================================================================== --- src/Boo.Lang.Compiler/Attributes/PropertyAttribute.cs (revision 2748) +++ src/Boo.Lang.Compiler/Attributes/PropertyAttribute.cs (working copy) @@ -1,268 +0,0 @@ -#region license -// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -using System; -using Boo.Lang.Compiler.Ast; - -namespace Boo.Lang -{ - /// - /// Creates a property over a field. - /// - public class PropertyAttribute : Boo.Lang.Compiler.AbstractAstAttribute - { - protected ReferenceExpression _propertyName; - - protected Expression _setPreCondition; - - protected BoolLiteralExpression _protected; - - protected BoolLiteralExpression _observable; - - protected ListLiteralExpression _attributes; - - public PropertyAttribute(ReferenceExpression propertyName) : this(propertyName, null) - { - } - - public PropertyAttribute(ReferenceExpression propertyName, Expression setPreCondition) - { - if (null == propertyName) - { - throw new ArgumentNullException("propertyName"); - } - _propertyName = propertyName; - _setPreCondition = setPreCondition; - } - - public BoolLiteralExpression Protected - { - get - { - return _protected; - } - - set - { - _protected = value; - } - } - - protected bool IsProtected - { - get - { - if (null == _protected) - { - return false; - } - return _protected.Value; - } - } - - public BoolLiteralExpression Observable - { - get - { - return _observable; - } - - set - { - _observable = value; - } - } - - protected bool IsObservable - { - get - { - if (null == _observable) - { - return false; - } - return _observable.Value; - } - } - - protected string ChangedEventName - { - get - { - return _propertyName.Name + "Changed"; - } - } - - public ListLiteralExpression Attributes - { - get - { - return _attributes; - } - - set - { - _attributes = value; - } - } - - override public void Apply(Node node) - { - Field f = node as Field; - if (null == f) - { - InvalidNodeForAttribute("Field"); - return; - } - - Property p = new Property(); - if (f.IsStatic) - { - p.Modifiers |= TypeMemberModifiers.Static; - } - if (IsProtected) - { - p.Modifiers |= TypeMemberModifiers.Protected; - } - p.Name = _propertyName.Name; - p.Type = f.Type; - p.Getter = CreateGetter(f); - p.Setter = CreateSetter(f); - p.LexicalInfo = LexicalInfo; - - if (Attributes != null && Attributes.Items.Count > 0) - { - foreach (Expression item in Attributes.Items) - { - p.Attributes.Add(ConvertExpressionToAttribute(item)); - } - } - - f.DeclaringType.Members.Add(p); - - if (IsObservable) - { - f.DeclaringType.Members.Add(CreateChangedEvent(f)); - } - } - - static public Boo.Lang.Compiler.Ast.Attribute ConvertExpressionToAttribute( - Expression item) - { - Boo.Lang.Compiler.Ast.Attribute att = - new Boo.Lang.Compiler.Ast.Attribute(item.LexicalInfo); - if (item is MethodInvocationExpression) - { - MethodInvocationExpression m = (MethodInvocationExpression)item; - att.Name = m.Target.ToString(); - att.Arguments = m.Arguments; - att.NamedArguments = m.NamedArguments; - } - else - { - att.Name = item.ToString(); - } - return att; - } - - virtual protected Method CreateGetter(Field f) - { - // get: - // return - Method getter = new Method(); - getter.Name = "get"; - getter.Body.Statements.Add( - new ReturnStatement( - base.LexicalInfo, - new ReferenceExpression(f.Name), - null) - ); - return getter; - } - - virtual protected Method CreateSetter(Field f) - { - Method setter = new Method(); - setter.Name = "set"; - - if (null != _setPreCondition) - { - setter.Body.Add( - new RaiseStatement( - _setPreCondition.LexicalInfo, - AstUtil.CreateMethodInvocationExpression( - AstUtil.CreateReferenceExpression("System.ArgumentException"), - new StringLiteralExpression("precondition '" + - _setPreCondition.ToString() + - "' failed:")), - new StatementModifier( - StatementModifierType.Unless, - _setPreCondition))); - } - setter.Body.Add( - new BinaryExpression( - base.LexicalInfo, - BinaryOperatorType.Assign, - new MemberReferenceExpression( - CreateRefTarget(f), - f.Name), - new ReferenceExpression("value") - ) - ); - - if (IsObservable) - { - MethodInvocationExpression mie = new MethodInvocationExpression( - new ReferenceExpression(ChangedEventName)); - mie.Arguments.Add(new SelfLiteralExpression()); - mie.Arguments.Add( - new MemberReferenceExpression( - new MemberReferenceExpression( - new ReferenceExpression("System"), - "EventArgs"), - "Empty")); - setter.Body.Add(mie); - } - return setter; - } - - private Expression CreateRefTarget(Field f) - { - if (f.IsStatic) return new ReferenceExpression(LexicalInfo, f.DeclaringType.Name); - return new SelfLiteralExpressio