ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team:...

48
CSWF C# Web Framework C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg

Transcript of ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team:...

Page 1: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSWF C# Web Framework

C# to JavaScript Compiler

ADD

Application Design Document

Project team:

Tzah Granot

David Pankovski

Asaf Elazar

Academic Mentor:

Mayer Goldberg

Page 2: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 2

Table of Contents

1. Use Cases ...................................................................................................................................................................... 3

1.1 Use case ID: 1 ....................................................................................................................................................... 4

1.2 Use case ID: 2 ....................................................................................................................................................... 5

1.3 Use case ID: 3 ....................................................................................................................................................... 6

1.4 Use case ID: 4 ....................................................................................................................................................... 7

1.5 Use case ID: 5 ....................................................................................................................................................... 8

2. System Architecture ................................................................................................................................................. 9

3. Data Model ................................................................................................................................................................ 10

3.1 Description of Data Objects .......................................................................................................................... 10

3.2 Data Objects Relationships ........................................................................................................................... 14

3.3 Databases ............................................................................................................................................................ 15

4. Behavioral Analysis ................................................................................................................................................. 16

4.1 Sequence Diagrams .......................................................................................................................................... 16

4.2 Events ................................................................................................................................................................... 21

4.3 States .................................................................................................................................................................... 21

5. Object-Oriented Analysis ...................................................................................................................................... 22

5.1 Class Diagrams ................................................................................................................................................... 22

5.2 Class Description ............................................................................................................................................... 23

5.3 Packages .............................................................................................................................................................. 28

5.4 Unit Testing ......................................................................................................................................................... 29

6. User Interface Draft ................................................................................................................................................ 34

7. Testing ......................................................................................................................................................................... 35

7.1 Functional Requirements ............................................................................................................................... 35

7.2 Non Functional Requirements ...................................................................................................................... 36

8. Task List ....................................................................................................................................................................... 37

Page 3: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 3

Chapter 1

1. Use Cases

User Profiles (Actors)

• Web Developer – The main actor in this system. The system is built for web developers whom wish to write code in C# and generate JavaScript code with almost complete transparency, so the web developer will be the trigger for any kind of event.

Use Cases:

• Use case diagram:

Page 4: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 4

1.1 Use case ID: 1

Name: Compile via console

Actors: Web developer

Description: This use case describes the action of compiling C# files through the console application by starting the console application and sending input files to compile.

Trigger: The web developer starts the console application.

Pre conditions: The input files must be with the extension .cs (C# file).

Post conditions: In case of success (the input was valid) the system will produce output file/files, with .js extension, of the compiled code.

Main success scenario:

1. The user starts the application. 2. The system asks for an input file/directory. 3. The user inserts a file/directory. 4. The system asks the user for additional files/directories. 5. If the user selects more files – repeat steps 4, 5. 6. The system asks the user for an output directory. 7. The system compiles the files successfully and produces output files in the requested directory.

Alternate scenario:

7. The system discovers compilation errors and alerts the user about these errors, and then terminates.

Page 5: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 5

1.2 Use case ID: 2

Name: Compile via Visual Studio

Actors: Web developer

Description: This use case describes the action of compiling C# files through the Visual Studio template after having a project open on the working set.

Trigger: The web developer presses the "build" option on VS.

Pre conditions: The project is open in VS and is of the type CSWF (see appendix 1), all of the compiled files are *.cs type.

Post conditions: In case of success (the input was valid) the system will produce output file/files, with .js extension, of the compiled code.

Main success scenario:

1. The user writes code in Visual Studio and then pressed the "build" button. 2. The system compiles the files successfully and produces output files in the requested directory.

Alternate scenario:

2. The system discovers compilation errors and alerts the user about these errors, and doesn't proceed with the compilation progress.

Page 6: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 6

1.3 Use case ID: 3

Name: Execute code in Visual Studio

Actors: Web developer

Description: This use case describes the action of executing the compiled code after compilation.

Trigger: The web developer pressed the "execute" button in Visual Studio.

Pre conditions: The project exists and all files are valid (.cs files).

Post conditions: In case of success (the input was valid) the system will produce output file/files, with .js extension, of the compiled code. Afterwards the system will open the web browser and execute the compiled *.js files.

Main success scenario:

1. The user writes code in Visual Studio and then presses the "execute" button. 2. In case the code is not compiled, the system first compiles it. 3. After the compilation succeeds, the system executes the resulting files on the default web browser.

Alternate scenario:

3. In case the compilation process fails, the execution terminates.

Page 7: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 7

1.4 Use case ID: 4

Name: Create new project

Actors: Web developer

Description: This use case describes the action of creating a new CSWF project using the Visual Studio template.

Trigger: The web developer selects "create new project" in Visual Studio.

Pre conditions: None.

Post conditions: A new CSWF project will be created.

Main success scenario:

1. The user opens Visual Studio and selects "create new project". 2. Visual Studio shows the user a list of available project types. 3. The user selects CSWF project. 4. The system creates a new project and opens it in Visual Studio.

Alternate scenario:

3. The user selects another type of project; in this case the system will do nothing.

Page 8: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 8

1.5 Use case ID: 5

Name: Import existing project

Actors: Web developer

Description: This use case describes the action of importing an existing CSWF project using the Visual Studio template.

Trigger: The web developer selects "import existing project" in Visual Studio.

Pre conditions: None.

Post conditions: In case the project exists, Visual Studio will open the project in the workspace.

Main success scenario:

1. The user opens Visual Studio and selects "import existing project". 2. Visual Studio requests the project's path. 3. The user enters the path of a CSWF project. 4. The system restores the project's settings and opens it in Visual Studio.

Alternate scenario:

3. The user enters a path of another type of project. 4. Visual Studio opens the project regularly.

Page 9: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 9

Chapter 2

2. System Architecture

Our development framework is composed of 4 main components:

• Standalone C# to JavaScript compiler

The compiler is composed of 3 main components written in C#:

• Parser We will use the “Microsoft Roslyn Project” Version 1.1 Parser.

• Semantic Analyser Will manipulate the AST with the help of “Microsoft Roslyn” semantic model.

• JavaScript Code Generator Will act as the “Visitor” in a “Visitor Pattern” and will visit each concrete node type in order to generate the JavaScript code.

• JavaScript Runtime Compiler The runtime compiler is written in JavaScript. Its purpose is to take types metadata generated by the static compiler and make them available to the JavaScript interpreter.

• Standard Library with DOM Types The standard library will contain most of .NET general purpose types and W3C Level 2 package.

• Visual Studio Template with MSBUILD Project File Will allow the developer to select C# Web Framework project type, compile and run the project directly from Visual Studio.

Page 10: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 10

Chapter 3

3. Data Model

3.1 Description of Data Objects

Here we will present our abstract syntax tree node types.

We will divide them into 3 main categories:

• Declaration Types

• Statement Types

• Expression Types

The rest of the compiler is composed of classes responsible of manipulating these types and generating the compiled code

Page 11: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 11

3.1.1 Declarations Types

Represents declaration of members (classes, methods etc.) within the type system

Page 12: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 12

3.1.2 Statement Types

Represents statements and program flow commands

Page 13: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 13

3.1.3 Expression Types

Represents value returning expressions

Page 14: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 14

3.2 Data Objects Relationships

Due to complexity of our data model relationships, we will present in this section only part of the relationships, the rest will be presented in the object oriented analysis section.

Page 15: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 15

3.3 Databases

Not Applicable.

Page 16: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 16

Chapter 4

4. Behavioral Analysis

4.1 Sequence Diagrams

Use Case 1

Page 17: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 17

Use Case 2

Page 18: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 18

Use Case 3

Page 19: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 19

Use Case 4

Page 20: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 20

Use Case 5

Page 21: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 21

4.2 Events

Not Applicable.

4.3 States

Not Applicable.

Page 22: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 22

Chapter 5

5. Object-Oriented Analysis

5.1 Class Diagrams

The following two pages contain the following class diagrams:

5.1.1 Syntax Node Classes

5.1.2 Compiler Classes

Page 23: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web
Page 24: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web
Page 25: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 23

5.2 Class Description

• JsCompiler This is the main class of the compiler. It encapsulates most of the compiler logic. The class use SyntaxTree, SemanticAnalyzer and JsGenerator in order to perform its job. Methods:

o public string Compile(string csharp) This is the main method of the class. It receives CSharp string and return the compiled JavaScript code Pre: There are no pre conditions about the input, any compile-time error will be available through the exception. Post: The returned JavaScript code is syntactically correct and semantically equals to the given code.

• SemanticAnalyzer This is the main class responsible for the semantic analysis of the AST. Methods:

o public SemanticModel Analyze(SyntaxTree tree) This is the main method of the class. It receives an AST generated by the parser preforms various manipulations upon it and returns SemanticModel ready for code generation. Pre: There are no pre conditions about the input. Post: The returned semantic model is correct and semantically equals to the given tree.

• JsGenerator This is the main class responsible for the code generation of the semantic model. The class inherits from SyntaxVisitor<string> and participates in a “Visitor” design pattern in which every Visit_ method of it responsible of generating code for a specific syntax type. Methods:

o public string GenerateJs(SemanticModel model) This is the main method of the class. It receives a SemanticModel ready for code generation and returns the JavaScript translation of it. Pre: The given semantic model should be correct and semantically equals to the

Page 26: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 24

given AST. Post: The returned JavaScript code is syntactically correct and semantically equals to the given code.

• PropertyDeclarationRewriter Most of JavaScript versions does not support property getter and setters. This class is responsible of adding a getter and setter methods to each property defined in a class. Methods:

o public SyntaxTree Rewrite(SemanticModel model) This is the main rewriter method. It receives a correct semantic model and returns a manipulated syntax tree such that every occurrence of a property adds the relevant getter and setter methods to its parent class. Pre: The given semantic model should be correct and semantically equals to the given AST. Post: For every property in the syntax tree exists a getter, setter methods and a backing field if applicable.

• IndexerDeclarationRewriter JavaScript does not support indexers. This class is responsible of adding a getter and setter methods to each indexer defined in a class. Methods:

o public SyntaxTree Rewrite(SemanticModel model) This is the main rewriter method. It receives a correct semantic model and returns a manipulated syntax tree such that every occurrence of an indexer adds the relevant getter and setter methods to its parent class. Pre: The given semantic model should be correct and semantically equals to the given AST. Post: For every indexer in the syntax tree exists a getter and setter methods if applicable.

• EventDeclarationRewriter JavaScript does not support the notion of events. This class is responsible of adding a adder and remover methods to each event defined in a class. Methods:

Page 27: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 25

o public SyntaxTree Rewrite(SemanticModel model) This is the main rewriter method. It receives a correct semantic model and returns a manipulated syntax tree such that every occurrence of an event adds the relevant adder and remover methods to its parent class. Pre: The given semantic model should be correct and semantically equals to the given AST. Post: For every event in the syntax tree exists an adder and remover methods.

• IndexerOrPropertyGetAccessRewriter This class is responsible of converting each read access to a property or indexer to an invocation of the appropriate getter method. Methods:

o public SyntaxTree Rewrite(SemanticModel model) This is the main rewriter method. It receives a correct semantic model and returns a manipulated syntax tree such that every occurrence of read access to a property or indexer is replaced by an invocation of the relevant getter method. Pre: The given semantic model should be correct and semantically equals to the given AST. Post: Every property or indexer read access in the given syntax tree was replaced by the correct getter method invocation.

• IndexerOrPropertySetAccessRewriter This class is responsible of converting each write access to a property or indexer to an invocation of the appropriate setter method. Methods:

o public SyntaxTree Rewrite(SemanticModel model) This is the main rewriter method. It receives a correct semantic model and returns a manipulated syntax tree such that every occurrence of write access to a property or indexer is replaced by an invocation of the relevant setter method. Pre: The given semantic model should be correct and semantically equals to the given AST. Post: Every property or indexer write access in the given syntax tree was replaced by the correct setter method invocation.

• DefaultConstructorRewriter This class is responsible of adding default instance or static constructors to a class in case

Page 28: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 26

they are not explicitly defined in it. Methods:

o public SyntaxTree Rewrite(SemanticModel model) This is the main rewriter method. It receives a correct semantic model and returns a manipulated syntax tree such that every occurrence of a class declaration that doesn’t explicitly declare default instance or static constructors is replaced by the same declaration with the default constructors. Pre: The given semantic model should be correct and semantically equals to the given AST. Post: Every class declaration that doesn’t explicitly declare default instance or static constructors in the given syntax tree was replaced by the same declaration with the default constructors.

• ConstructorInitializerRewriter This class is responsible manipulating all instance and static constructor so that they first initialize all static and instance fields with default values. Methods:

o public SyntaxTree Rewrite(SemanticModel model) This is the main rewriter method. It receives a correct semantic model and returns a manipulated syntax tree such that every instance and static constructor first initialize all static and instance fields with default values. Pre: The given semantic model should be correct and semantically equals to the given AST. Post: Every instance and static constructor declaration in the given syntax tree was replaced by the same declaration with field initialization statements at the beginning of its body.

• ForEachRewriter JavaScript does not support for-each loops. This class is responsible of converting every “foreach” statement to a “while” statement wrapped in a “try-finally” statement to check an IDisposable implementation. Methods:

o public SyntaxTree Rewrite(SemanticModel model) This is the main rewriter method. It receives a correct semantic model and returns a manipulated syntax tree such that every occurrence of “foreach”

Page 29: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 27

statement is replaced by a “try-finally” statement. Pre: The given semantic model should be correct and semantically equals to the given AST. Post: Every “foreach” statement in the given syntax tree was replaced by a “try-finally” statment.

• UsingRewriter This class is responsible of converting each “using” statement to a “try-finally” statement which invokes the Dispose method of the target object in the finally clause. Methods:

o public SyntaxTree Rewrite(SemanticModel model) This is the main rewriter method. It receives a correct semantic model and returns a manipulated syntax tree such that every occurrence of “using” statement is replaced by a “try-finally” statement. Pre: The given semantic model should be correct and semantically equals to the given AST. Post: Every “using” statement in the given syntax tree was replaced by a “try-finally” statement.

• TryCatchFinallyRewriter This class is responsible of manipulating each “try-catch-finally” statement in such a way that it will be JavaScript compatible. JavaScript does not support multiple catch clauses so we will convert multiple catch clauses into an “if-then-else” statement. Methods:

o public SyntaxTree Rewrite(SemanticModel model) This is the main rewriter method. It receives a correct semantic model and returns a manipulated syntax tree such that every occurrence of “try-catch-finally” statement is replaced by a single catch clause “try-catch-finally” statement. Pre: The given semantic model should be correct and semantically equals to the given AST. Post: Every “try-catch-finally” statement in the given syntax tree was replaced by a single catch clause “try-catch-finally” statement.

Page 30: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 28

5.3 Packages

Our system is composed of the following packages:

• Tad.CsWF.CsJs (Tad.CsWF.CsJs.dll) The compiler itself as a set.

• Tad.CsWF.CsJs.Cmd (csjs.exe) Command line interface for the compiler.

• Jscorlib (jscorlib.dll) Standard Library for the Web Framework.

Page 31: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 29

5.4 Unit Testing

PropertyDeclarationRewriter

ID Goal Test Expected output 1 Standard Property Property in the form of:

public string prop { get { [getter_code] } set { [setter_code] } }

public string get_prop () { [getter_code] }; public string set_prop (string value) { [setter_code] };

2 Auto Property Property in the form of: public string prop { get; set; }

private string prop; public string get_prop () { return this.prop; }; public string set_prop (string value) { this.prop = value; };

IndexerDeclarationRewriter

ID Goal Test Expected output 1 Indexer check Indexer in the form of:

public string this[int num] { get { [getter_code] } set { [setter_code] } }

public string get_this (int num) { [getter_code] } public string set_this (string value, int num) { [setter_code] }

Page 32: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 30

EventDeclarationRewriter

ID Goal Test Expected output 1 Event

Field Event in the form of: public event Action evnt;

private Action evnt; public void add_evnt (Action value) { this.evnt = (Action)Delegate.Combine(this.evnt, value); } public void remove_evnt (Action value) { this.evnt = (Action)Delegate.Remove(this.evnt, value); }

2 Standard Event

Event in the form of: public event Action evnt { add { [add_code] } remove { [remove_code] } }

public void add_evnt (Action value) { [add_code] } public void remove_evnt (Action value) { [remove_code] }

IndexerOrPropertyGetAccessRewriter

ID Goal Test Expected output 1 Property Getter

Access Property Access in the form of: variable = instance.prop;

variable = instance.get_prop();

2 Indexer Getter Access

variable = instance[3]; variable = instance.get_item(3);

Page 33: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 31

IndexerOrPropertySetAccessRewriter

ID Goal Test Expected output 1 Property Setter

Access Property Access in the form of: instance.prop = “abcd”;

instance.set_prop(“abcd”);

2 Indexer Setter Access

Instance[5] = “abcd”; instance.set_this(“abcd”, 5);

DefaultConstructorRewriter

ID Goal Test Expected output 1 Default constructor

with no constructors

Class declaration in the form of: Public class A { }

Public class A { public A(){ } static A() { } }

2 Default constructor with both constructors

Class declaration in the form of: Public class A { public A(){ [instance_code] } static A() { [static_code] } }

(no change) Public class A { public A(){ [instance_code] } static A() { [static_code] } }

ConstructorInitializerRewriter

ID Goal Test Expected output 1 Static constructor

Constructor declaration in the form of: public class A { private static int field; static A() { [static_code] } }

public class A { static A() { A.field = 0; [static_code] } }

2 Instance Constructor

Constructor declaration in the form of: public class A { private int field; public A() { [instance_code] } }

public class A { private int field; public A() { this.field = 0; [instance_code] } }

Page 34: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 32

ForEachRewriter

ID Goal Test Expected output 1 For each statement Foreach statement in the

form of: int[] arr = new int[] { 1, 2, 3 }; foreach (var i in arr) { var temp = i; }

int[] arr = new int[] { 1, 2, 3 }; var $temp = arr.GetEnumerator(); try { while ($temp.MoveNext()) { var i = $temp.get_Current(); var temp = i; } } finally { if ($temp != null) if ($temp is IDisposable) ((IDisposable)$temp).Dispose(); }

UsingRewriter

ID Goal Test Expected output 1 Using statement Using statement in the form of:

var lst = new List<string>(); using (var enm = lst.GetEnumerator()) { [using_code] }

var enm = lst.GetEnumerator(); try { [using_code] } finally { if (enm != null) enm.Dispose(); }

Page 35: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 33

TryCatchFinallyRewriter

ID Description Expected Output 1 Try-Catch-finally statement in the

form of: try { [try_code] } catch (InvalidOperationException e1) { [catch1_code] } catch (Exception e2) { [catch2_code] } finally { [finally_code] }

try { [try_code] } catch (Exception $temp) { if ($temp is InvalidOperationException) { var e1 = (InvalidOperationException)$temp; [catch1_code] } else if ($temp is Exception) { var e2 = (Exception)$temp; [catch2_code] } } finally { [finally_code] }

Page 36: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 34

Chapter 6

6. User Interface Draft

Not Applicable.

Page 37: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 35

Chapter 7

7. Testing

7.1 Functional Requirements

We would test each of the next sections, by compiling it and checking that the output is semantically equal in JS.

Each of the tests would be indecencies.

Section Sort 1 Type Numeric type, Boolean types, Enum types, Nullable types, Class type,

interface type, array type, delegate type. 2 Expression Literal expression, parenthesized expression, conditional expression,

invocation expression, Member Access Expression, this expression, base expression, simple lambda expression, parenthesized lambda expression, element access expression, array creation expression, implicit array creation expression, anonymous method creation expression, object creation expression, anonymous object creation express, binary expression, prefix unary expression, postfix unary expression, cast expression, default expression, type of expression.

3 Statement Block statement, expression statement, if statement, else statement, switch statement, labelled statement, for each statement, for statement, while statement, do while statement, continue statement, break statement, return statement, try statement, throw statement, local declaration statement, using statement

4 Namespace 5 Classes Abstracted classes, sealed classes, static classes, type parameters, base

classes, interface implementation 6 Class

members Constants, Field, methods, properties, indexer, static or instance members, constants, fields, indexer, static constructors

7 Inheritance Some inheritance form (inheritance members, transitive inheritance and poly-morphism support.

8 Methods Static methods, virtual methods, override methods, abstract methods, extension methods, methods overloading, events

9 Property Accessors, Automatically implemented properties, virtual, sealed, override, and abstract accessor, instance constructor

10 Array Array creation, Array element access, Array members. 11 Interface Interface declaration, interface members 12 Enum Enum declaration, Enum modifiers, Enum members, Enum value and

operations 12 Delegate Delegate compatibility, delegate invocation, delegate declaration 13 Exceptions System.expection class 14 Attribute Attribute classes, Attribute specification, Attribute specification,

Attribute instances 15 Reflection

Page 38: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 36

7.2 Non Functional Requirements

Constraint Description Test Speed • The system's startup will

take no more than 10 seconds (not including Visual Studio's startup).

• Start the complier, and check that the system's startup take less than 10 seconds.

Capacity • The system will support

any size of input. • In console application,

the system will use at most 200 MB of RAM.

• In Visual Studio, the system will use at most 200 MB of RAM in addition to the RAM used by

Visual Studio.

• Creating several class: Some with complicated statement, some with many line code, and some with both, and checking that a result is backed.

• Checking the CPU consumption in any stage of the compilation, and verify it use at most 200 MB.

Usability • The system should have clear documentation and tutorials so that web developers can use it intuitively (no more than 3 hours to learn the system's usage).

• Apperfect.com suggests clear rules for right documentation, and we will check that we are matching these rules.

• Some volunteers will check the documentation, and say If it possible to learn the system in less than 3 hours.

Reliability • Input faults should be handled and the system will not proceed while having those.

• The output should have 0% syntax errors.

• Insert type which not supported in our compiler (for example, operator overloading)

• Insert code which is incorrectly syntactically.

Page 39: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 37

Chapter 8

8. Task List

The following chapter will show an estimation of the tasks to be completed in order to finish the project. The tasks will be ordered according to their implementation order and some of them can be developed simultaneously, as will be shown.

Page 40: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 38

Task ID: 1 Title: Research Description: Checking the need and practicality of the project, and learning how

to use the parser from the outside library. Est. Starting Date: 20.10.12 Actual Starting Date: 21.10.12 Duration: 2 days Actual Duration: 2 days Sub-Tasks:

Task ID: 2 Title: Learning JavaScript Description: Reading guides about javascript and fully understanding the

language. Est. Starting Date: 22.10.12 Actual Starting Date: 23.10.12 Duration: 1 week Actual Duration: 9 days Sub-Tasks:

Task ID: 3 Title: Rewriters Description: Implementation of the syntax rewriters for the semantic analyzer,

the work will be divided so that the rewriters are independent from each other.

Est. Starting Date: 10.4.13 Actual Starting Date: 18.4.13 Duration: 3 weeks Actual Duration: Sub-Tasks: 3.1 – 3.16

Task ID: 3.1 Title: ClassOverloadsRewriter Description: Implementation of ClassOverloadsRewriter Est. Starting Date: 10.4.13 Actual Starting Date: 18.4.13 Duration: 2 days Actual Duration: 2 days Sub-Tasks:

Task ID: 3.2 Title: EventDeclerationRewriter Description: Implementation of EventDeclerationRewriter Est. Starting Date: 10.4.13 Actual Starting Date: 18.4.13 Duration: 2 days Actual Duration: 2 days Sub-Tasks:

Page 41: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 39

Task ID: 3.3 Title: IndexerDeclerationRewriter Description: Implementation of IndexerDeclerationRewriter Est. Starting Date: 12.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Task ID: 3.4 Title: TryCatchFinallyRewriter Description: Implementation of TryCatchFinallyRewriter Est. Starting Date: 12.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Task ID: 3.5 Title: ExplicitIdentifiersRewriter Description: Implementation of ExplicitIdentifiersRewriter Est. Starting Date: 14.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Task ID: 3.6 Title: IndexerOrPropertyGetAccessRewriter Description: Implementation of IndexerOrPropertyGetAccessRewriter Est. Starting Date: 14.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Task ID: 3.7 Title: UsingRewriter Description: Implementation of UsingRewriter Est. Starting Date: 16.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Page 42: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 40

Task ID: 3.8 Title: ConstructorInitializeRewriter Description: Implementation of ConstructorInitializeRewriter Est. Starting Date: 16.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Task ID: 3.9 Title: ExtensionMethodsRewriter Description: Implementation of ExtensionMethodsRewriter Est. Starting Date: 18.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Task ID: 3.10 Title: IndexerOrPropertySetAccessRewriter Description: Implementation of IndexerOrPropertySetAccessRewriter Est. Starting Date: 18.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Task ID: 3.11 Title: DefaultConstructorRewriter Description: Implementation of DefaultConstructorRewriter Est. Starting Date: 20.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Task ID: 3.12 Title: ForEachRewriter Description: Implementation of ForEachRewriter Est. Starting Date: 20.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Task ID: 3.13 Title: InterfaceOverloadsRewriter Description: Implementation of InterfaceOverloadsRewriter Est. Starting Date: 22.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Page 43: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 41

Task ID: 3.14 Title: PropertyDeclerationRewriter Description: Implementation of PropertyDeclerationRewriter Est. Starting Date: 22.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Task ID: 3.15 Title: DelegateAccessRewriter Description: Implementation of DelegateAccessRewriter Est. Starting Date: 24.4.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Task ID: 3.16 Title: GenericsRewriter Description: Implementation of GenericsRewriter Est. Starting Date: 24.4.13 Actual Starting Date: Duration: 3 days Actual Duration: Sub-Tasks:

Task ID: 4 Title: Javascript Generator Description: Implementation of the JsGenerator component, which does the

javascript code generation. We will divide the generation functionality into groups like on the semantic analyzing and we will implement each group simultaneously.

Est. Starting Date: 27.4.13 Actual Starting Date: Duration: 1 week Actual Duration: Sub-Tasks: 4.1, 4.2, 4.3 (simultaneously)

Task ID: 4.1 Title: JsGenerator – 1st part Description: Implementation of 1/3 of the functions. Est. Starting Date: 27.4.13 Actual Starting Date: Duration: 1 week Actual Duration: Sub-Tasks:

Page 44: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 42

Task ID: 4.2 Title: JsGenerator – 2nd part Description: Implementation of 1/3 of the functions. Est. Starting Date: 27.4.13 Actual Starting Date: Duration: 1 week Actual Duration: Sub-Tasks:

Task ID: 4.3 Title: JsGenerator – 3rd part Description: Implementation of 1/3 of the functions. Est. Starting Date: 27.4.13 Actual Starting Date: Duration: 1 week Actual Duration: Sub-Tasks:

Task ID: 5 Title: Javascript Runtime Compiler Description: Implementation of the Js runtime compiler, will be divided to

foreign groups for simultaneous work. Est. Starting Date: 5.5.13 Actual Starting Date: Duration: 1 week Actual Duration: Sub-Tasks:

Task ID: 6 Title: Standard Library Description: Creating the standard library pre-defined modules, which will be

divided into the .NET framework, the JavaScript and HTML framework, and the RPC framework.

Est. Starting Date: 12.5.13 Actual Starting Date: Duration: 6 weeks Actual Duration: Sub-Tasks: 6.1, 6.2, 6.3

Task ID: 6.1 Title: .NET framework Description: Implementation of the .NET framework which includes most of

C#'s main classes and interfaces. Est. Starting Date: 12.5.13 Actual Starting Date: Duration: 4 weeks Actual Duration: Sub-Tasks: 6.1.1 – 6.1.4

Page 45: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 43

Task ID: 6.1.1 Title: Namespace System Description: Implementation of the System namespace of .NET Est. Starting Date: 12.5.13 Actual Starting Date: Duration: 1 week Actual Duration: Sub-Tasks: 6.1.1.1, 6.1.1.2

Task ID: 6.1.1.1 Title: System interfaces and basic classes Description: Implementation of the System interfaces and basic classes such as

Char, Double, Bool, etc. Est. Starting Date: 12.5.13 Actual Starting Date: Duration: 1 day Actual Duration: Sub-Tasks:

Task ID: 6.1.1.2 Title: System complex classes Description: Implementation of the System complex classes such as DateTime,

Math, Random, String, etc. Est. Starting Date: 13.5.13 Actual Starting Date: Duration: 6 days Actual Duration: Sub-Tasks:

Task ID: 6.1.2 Title: Namespace System.Collections Description: Implementation of the System Collections Est. Starting Date: 19.5.13 Actual Starting Date: Duration: 1 week Actual Duration: Sub-Tasks: 6.1.2.1, 6.1.2.2

Task ID: 6.1.2.1 Title: 1st Part of collections implementation Description: Implementation of Collection interfaces, ArrayList and Queue

classes. Est. Starting Date: 19.5.13 Actual Starting Date: Duration: 4 days Actual Duration: Sub-Tasks:

Page 46: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 44

Task ID: 6.1.2.2 Title: 2nd Part of collections implementation Description: Implementation of Stack and SortedList classes. Est. Starting Date: 23.5.13 Actual Starting Date: Duration: 3 days Actual Duration: Sub-Tasks:

Task ID: 6.1.3 Title: Namespace System.Collections.Generic Description: Implementation of the generic collections Est. Starting Date: 26.5.13 Actual Starting Date: Duration: 2 weeks Actual Duration: Sub-Tasks: 6.1.3.1 – 6.1.3.4

Task ID: 6.1.3.1 Title: Generic collections interfaces Description: Implementation of the generic collections interfaces, such as

ICollection<T>, IComparer<T>, etc. Est. Starting Date: 26.5.13 Actual Starting Date: Duration: 1 day Actual Duration: Sub-Tasks:

Task ID: 6.1.3.2 Title: Dictionary class Description: Implementation of the Dictionary collection Est. Starting Date: 27.5.13 Actual Starting Date: Duration: 3 days Actual Duration: Sub-Tasks:

Task ID: 6.1.3.3 Title: Comparer, List, LinkedList Description: Implementation of the Comparer, List and LinkedList classes. Est. Starting Date: 30.5.13 Actual Starting Date: Duration: 3 days Actual Duration: Sub-Tasks:

Task ID: 6.1.3.4 Title: Queue, Stack, HashSet Description: Implementation of the Queue, Stack and HashSet classes. Est. Starting Date: 2.6.13 Actual Starting Date: Duration: 4 days Actual Duration: Sub-Tasks:

Page 47: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 45

Task ID: 6.1.4 Title: Namespace System.Linq Description: Implementation of the System.Linq namespace, including the

interfaces IGrouping, ILookup and IOrderedEnumerable and the classes Enumerable and Lookup.

Est. Starting Date: 6.6.13 Actual Starting Date: Duration: 3 days Actual Duration: Sub-Tasks:

Task ID: 6.2 Title: Javascript and HTML framework Description: Implementation of the javascript and HTML namespaces, mostly

will be adaptations to regular javascript libraries. Est. Starting Date: 9.6.13 Actual Starting Date: Duration: 4 days Actual Duration: Sub-Tasks: 6.2.1 – 6.2.3

Task ID: 6.2.1 Title: Namespace Tad.CSWF.Client.dom Description: Implementation of the Tad.CSWF.Client.dom namespace. Est. Starting Date: 9.6.13 Actual Starting Date: Duration: 2 days Actual Duration: Sub-Tasks:

Task ID: 6.2.2 Title: Namespace Tad.CSWF.Client.dom.event Description: Implementation of the Tad.CSWF.Client.dom.event namespace. Est. Starting Date: 11.6.13 Actual Starting Date: Duration: 1 day Actual Duration: Sub-Tasks:

Task ID: 6.2.3 Title: Namespace Tad.CSWF.Client.xhr Description: Implementation of the Tad.CSWF.Client.xhr namespace. Est. Starting Date: 12.6.13 Actual Starting Date: Duration: 1 day Actual Duration: Sub-Tasks:

Page 48: ADD · 2013. 4. 22. · C# to JavaScript Compiler ADD Application Design Document Project team: Tzah Granot David Pankovski Asaf Elazar Academic Mentor: Mayer Goldberg . CSharp Web

CSharp Web Framework – Application Design Document

Page | 46

Task ID: 6.3 Title: RPC Description: Implementation of the RPC framework, for the client and the

server sides. Est. Starting Date: 13.6.13 Actual Starting Date: Duration: 1 week Actual Duration: Sub-Tasks: 6.3.1, 6.3.2

Task ID: 6.3.1 Title: Namespace Tad.CSWF.Client.Rpc Description: Implementation of Tad.CSWF.Client.Rpc namespace. Est. Starting Date: 13.6.13 Actual Starting Date: Duration: 4 days Actual Duration: Sub-Tasks:

Task ID: 6.3.2 Title: Namespace Tad.CSWF.Server.Rpc Description: Implementation of Tad.CSWF.Server.Rpc namespace. Est. Starting Date: 17.6.13 Actual Starting Date: Duration: 3 days Actual Duration: Sub-Tasks:

Task ID: 7 Title: MSBuild Description: Creating the MSBuild for Visual Studio. Est. Starting Date: 20.6.13 Actual Starting Date: Duration: 3 days Actual Duration: Sub-Tasks:

Task ID: 8 Title: Visual Studio 2010 Template Description: Creating the template for Visual Studio in order to create CSWF

projects through the editor. Est. Starting Date: 23.6.13 Actual Starting Date: Duration: 3 days Actual Duration: Sub-Tasks: