private static ITranslationUnit BuildLiteralExpressionTranslationUnit(LiteralExpressionSyntax expression, SemanticModel semanticModel) { SyntaxToken token = expression.Token; switch (token.Kind()) { case SyntaxKind.NumericLiteralToken: return(LiteralTranslationUnit <int> .Create((int)token.Value)); case SyntaxKind.StringLiteralToken: return(LiteralTranslationUnit <string> .Create((string)token.Value)); case SyntaxKind.CharacterLiteralExpression: return(null); case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: return(LiteralTranslationUnit <bool> .Create((bool)token.Value)); case SyntaxKind.NullKeyword: return(LiteralTranslationUnit.Null); } throw new InvalidOperationException(string.Format("Cannot build a literal expression for token type {0}!", token.Kind())); }
public string MixedExpressionSimpleArithmetic() { // Expression: 2 * 3 + 10 var translationUnit = BinaryExpressionTranslationUnit.Create( BinaryExpressionTranslationUnit.Create( LiteralTranslationUnit <int> .Create(2), LiteralTranslationUnit <int> .Create(3), OperatorToken.Multiplication), LiteralTranslationUnit <int> .Create(10), OperatorToken.Addition); return(translationUnit.Translate()); }
public void IntegerLiteral() { int number = Expressions.RandomInteger; ITranslationUnit translationUnit = LiteralTranslationUnit <int> .Create(number); string typescript = translationUnit.Translate(); new Utils.FileWriter(TestSuite.Context).WriteToFile(typescript, string.Format("{0}.Code", nameof(this.IntegerLiteral)), Utils.FileType.TypeScript); Assert.AreEqual(string.Format("{0}", number.ToString()), typescript, "Literal does not match expected!"); }
public void StringLiteral() { string str = "this is a string"; ITranslationUnit translationUnit = LiteralTranslationUnit <string> .Create(str); string typescript = translationUnit.Translate(); new Utils.FileWriter(TestSuite.Context).WriteToFile(typescript, string.Format("{0}.Code", nameof(this.StringLiteral)), Utils.FileType.TypeScript); Assert.AreEqual(string.Format("{1}{0}{1}", str, Lexems.SingleQuote), typescript, "Literal does not match expected!"); }
private static ITranslationUnit BuildLiteralExpressionTranslationUnit(LiteralExpressionSyntax expression, SemanticModel semanticModel) { SyntaxToken token = expression.Token; switch (token.Kind()) { case SyntaxKind.NumericLiteralToken: Type arg_type = token.Value.GetType(); Type genericLiteralTranslationUnit = typeof(LiteralTranslationUnit <>).MakeGenericType(arg_type); MethodInfo mi = genericLiteralTranslationUnit.GetMethod("Create", BindingFlags.Static | BindingFlags.Public); return((ITranslationUnit)mi.Invoke(null, new object[] { token.Value })); //return LiteralTranslationUnit<token.Value.GetType()>.Create((int)token.Value); //} //else //{ // return LiteralTranslationUnit<decimal>.Create((decimal)token.Value); //} case SyntaxKind.StringLiteralToken: return(LiteralTranslationUnit <string> .Create((string)token.Value)); case SyntaxKind.CharacterLiteralToken: return(LiteralTranslationUnit <char> .Create((char)token.Value)); case SyntaxKind.CharacterLiteralExpression: return(null); case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: return(LiteralTranslationUnit <bool> .Create((bool)token.Value)); case SyntaxKind.NullKeyword: return(LiteralTranslationUnit.Null); } throw new InvalidOperationException(string.Format("Cannot build a literal expression for token type {0}!", token.Kind())); }
public string MixedExpressionSimpleParentheticArithmetic() { // Expression: 2 * 3 + 100++ * (200 - 300) var translationUnit = BinaryExpressionTranslationUnit.Create( BinaryExpressionTranslationUnit.Create( LiteralTranslationUnit <int> .Create(2), LiteralTranslationUnit <int> .Create(3), OperatorToken.Multiplication), BinaryExpressionTranslationUnit.Create( UnaryExpressionTranslationUnit.Create( LiteralTranslationUnit <int> .Create(100), OperatorToken.Increment, UnaryExpressionTranslationUnit.UnaryPosition.Postfix), ParenthesizedExpressionTranslationUnit.Create( BinaryExpressionTranslationUnit.Create( LiteralTranslationUnit <int> .Create(200), LiteralTranslationUnit <int> .Create(300), OperatorToken.Subtraction)), OperatorToken.Multiplication), OperatorToken.Addition); return(translationUnit.Translate()); }
/// <summary> /// /// </summary> /// <param name="operatorToken"></param> /// <param name="number"></param> /// <param name="postfix"></param> /// <returns></returns> public static ITranslationUnit BuildExpressionTranslationUnit(OperatorToken operatorToken, int number, bool postfix = true) { return(UnaryExpressionTranslationUnit.Create( LiteralTranslationUnit <int> .Create(number), operatorToken, postfix ? UnaryExpressionTranslationUnit.UnaryPosition.Postfix : UnaryExpressionTranslationUnit.UnaryPosition.Prefix)); }
/// <summary> /// /// </summary> /// <param name="operatorToken"></param> /// <param name="number1"></param> /// <param name="number2"></param> /// <returns></returns> public static ITranslationUnit BuildExpressionTranslationUnit(OperatorToken operatorToken, int number1, int number2) { return(BinaryExpressionTranslationUnit.Create( LiteralTranslationUnit <int> .Create(number1), LiteralTranslationUnit <int> .Create(number2), operatorToken)); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public static ITranslationUnit BuildLiteralTranslationUnit(bool value) { return(LiteralTranslationUnit <bool> .Create(value)); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public static ITranslationUnit BuildLiteralTranslationUnit(string value) { return(LiteralTranslationUnit <string> .Create(value)); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public static ITranslationUnit BuildLiteralTranslationUnit(int value) { return(LiteralTranslationUnit <int> .Create(value)); }