Browse Source

Add "Convert buffer to Boo" command to BooBinding.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@553 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 21 years ago
parent
commit
4b0ac9160e
  1. 20
      src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.addin
  2. 14
      src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.csproj
  3. 73
      src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/ConvertBuffer.cs
  4. 13
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/NRefactoryToBooConverter.csproj
  5. 7
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/Expressions/Expression.cs

20
src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.addin

@ -75,4 +75,24 @@
projectfileextension = ".booproj" projectfileextension = ".booproj"
class = "Grunwald.BooBinding.BooLanguageBinding" /> class = "Grunwald.BooBinding.BooLanguageBinding" />
</Path> </Path>
<Path name = "/SharpDevelop/Workbench/MainMenu/Tools">
<ComplexCondition action = "Disable">
<And>
<Or>
<Condition name = "WindowActive" activewindow="ICSharpCode.FormDesigner.FormDesignerViewContent"/>
<Condition name = "WindowActive" activewindow="ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.ITextEditorControlProvider"/>
</Or>
<Or>
<Condition name="ActiveContentExtension" activeextension=".cs"/>
<Condition name="ActiveContentExtension" activeextension=".vb"/>
</Or>
</And>
<MenuItem id = "ConvertBufferToBoo"
insertbefore = "ConvertBuffer"
insertafter = "Separator2"
label = "${res:XML.MainMenu.ToolMenu.ConvertBufferToBoo}"
class = "Grunwald.BooBinding.ConvertBuffer"/>
</ComplexCondition>
</Path>
</AddIn> </AddIn>

14
src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.csproj

@ -66,6 +66,7 @@
<Compile Include="Src\BooLanguageProperties.cs" /> <Compile Include="Src\BooLanguageProperties.cs" />
<Compile Include="Src\CodeCompletion\VariableLookupVisitor.cs" /> <Compile Include="Src\CodeCompletion\VariableLookupVisitor.cs" />
<Compile Include="Src\CodeCompletion\InferredReturnType.cs" /> <Compile Include="Src\CodeCompletion\InferredReturnType.cs" />
<Compile Include="Src\ConvertBuffer.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="BooBinding.addin"> <Content Include="BooBinding.addin">
@ -84,14 +85,27 @@
<ProjectReference Include="..\..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj"> <ProjectReference Include="..\..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project> <Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name> <Name>ICSharpCode.SharpDevelop</Name>
<Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\..\..\..\Main\Core\Project\ICSharpCode.Core.csproj"> <ProjectReference Include="..\..\..\..\..\Main\Core\Project\ICSharpCode.Core.csproj">
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project> <Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project>
<Name>ICSharpCode.Core</Name> <Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\..\Libraries\NRefactory\Project\NRefactory.csproj">
<Project>{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}</Project>
<Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj"> <ProjectReference Include="..\..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj">
<Project>{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}</Project> <Project>{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}</Project>
<Name>ICSharpCode.TextEditor</Name> <Name>ICSharpCode.TextEditor</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\NRefactoryToBooConverter\Project\NRefactoryToBooConverter.csproj">
<Project>{DBCF20A1-BA13-4582-BFA9-74DE4D987B73}</Project>
<Name>NRefactoryToBooConverter</Name>
<Private>True</Private>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />

73
src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/ConvertBuffer.cs

@ -0,0 +1,73 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.IO;
using Boo.Lang.Compiler;
using Boo.Lang.Compiler.Ast;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.Core;
using System.Text;
using ICSharpCode.NRefactory.PrettyPrinter;
using ICSharpCode.NRefactory.Parser;
using NRefactoryToBooConverter;
namespace Grunwald.BooBinding
{
public class ConvertBuffer : AbstractMenuCommand
{
ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings)
{
ConverterSettings settings = new ConverterSettings(fileName, errors, warnings);
settings.SimplifyTypeNames = true;
return settings;
}
public override void Run()
{
IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;
if (window != null && window.ViewContent is IEditable) {
StringBuilder errorBuilder = new StringBuilder();
CompilerErrorCollection errors = new CompilerErrorCollection();
CompilerWarningCollection warnings = new CompilerWarningCollection();
Module module;
IList<ICSharpCode.NRefactory.Parser.ISpecial> specials;
CompileUnit compileUnit = new CompileUnit();
using (StringReader r = new StringReader(((IEditable)window.ViewContent).Text)) {
module = Parser.ParseModule(compileUnit, r, ApplySettings(window.ViewContent.FileName, errors, warnings), out specials);
}
if (errors.Count > 0) {
foreach (CompilerError error in errors) {
errorBuilder.AppendLine(error.ToString());
}
} else {
if (warnings.Count > 0) {
foreach (CompilerWarning warning in warnings) {
errorBuilder.AppendLine(warning.ToString());
}
}
using (StringWriter w = new StringWriter()) {
BooPrinterVisitorWithComments printer = new BooPrinterVisitorWithComments(specials, w);
printer.OnModule(module);
printer.Finish();
FileService.NewFile("Generated.boo", "Boo", w.ToString());
}
}
if (errorBuilder.Length > 0) {
MessageService.ShowMessage(errorBuilder.ToString());
}
}
}
}
}

13
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/NRefactoryToBooConverter.csproj

@ -24,14 +24,12 @@
<Reference Include="Boo.Lang.Compiler"> <Reference Include="Boo.Lang.Compiler">
<HintPath>..\..\RequiredLibraries\Boo.Lang.Compiler.dll</HintPath> <HintPath>..\..\RequiredLibraries\Boo.Lang.Compiler.dll</HintPath>
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="Boo.Lang"> <Reference Include="Boo.Lang">
<HintPath>..\..\RequiredLibraries\Boo.Lang.dll</HintPath> <HintPath>..\..\RequiredLibraries\Boo.Lang.dll</HintPath>
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
</Reference> <Private>True</Private>
<Reference Include="ICSharpCode.NRefactory">
<HintPath>..\..\..\..\..\..\bin\ICSharpCode.NRefactory.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -51,5 +49,12 @@
<Compile Include="ConverterSettings.cs" /> <Compile Include="ConverterSettings.cs" />
<Compile Include="BooPrinterVisitorWithComments.cs" /> <Compile Include="BooPrinterVisitorWithComments.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\Libraries\NRefactory\Project\NRefactory.csproj">
<Project>{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}</Project>
<Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project> </Project>

7
src/Libraries/NRefactory/Project/Src/Parser/AST/General/Expressions/Expression.cs

@ -42,8 +42,13 @@ namespace ICSharpCode.NRefactory.Parser.AST
return new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); return new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
} }
BinaryOperatorExpression boe = expr as BinaryOperatorExpression; BinaryOperatorExpression boe = expr as BinaryOperatorExpression;
if (boe != null) { if (boe != null && boe.Op == BinaryOperatorType.Add) {
boe.Right = AddInteger(boe.Right, value); boe.Right = AddInteger(boe.Right, value);
if (boe.Right is PrimitiveExpression && ((PrimitiveExpression)boe.Right).Value is int) {
if ((int)((PrimitiveExpression)boe.Right).Value == 0) {
return boe.Left;
}
}
return boe; return boe;
} }
return new BinaryOperatorExpression(expr, BinaryOperatorType.Add, new PrimitiveExpression(value, value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo))); return new BinaryOperatorExpression(expr, BinaryOperatorType.Add, new PrimitiveExpression(value, value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)));

Loading…
Cancel
Save