コード例 #1
0
ファイル: TokenValue.cs プロジェクト: gaybro8777/ironruby
 internal void SetString(string /*!*/ value, StringLiteralEncoding encoding)
 {
     Assert.NotNull(value);
     String    = value;
     _integer1 = (int)encoding;
     _type     = TokenValueType.String;
 }
コード例 #2
0
        private static StringLiteralEncoding CombineEncoding(StringLiteralEncoding encoding, StringLiteral literal)
        {
            if (encoding == StringLiteralEncoding.UTF8 || literal.IsUTF8)
            {
                return(StringLiteralEncoding.UTF8);
            }

            if (encoding == StringLiteralEncoding.Ascii && literal.IsAscii)
            {
                return(StringLiteralEncoding.Ascii);
            }

            return(StringLiteralEncoding.Default);
        }
コード例 #3
0
 private static char OpSuffix(AstGenerator /*!*/ gen, StringLiteralEncoding encoding)
 {
     if (encoding == StringLiteralEncoding.Ascii)
     {
         return(RubyOps.SuffixBinary);
     }
     else if (encoding == StringLiteralEncoding.UTF8 || gen.Encoding == Encoding.UTF8)
     {
         return(RubyOps.SuffixUTF8);
     }
     else if (gen.Encoding == BinaryEncoding.Instance)
     {
         return(RubyOps.SuffixBinary);
     }
     else
     {
         return(RubyOps.SuffixEncoded);
     }
 }
コード例 #4
0
ファイル: TokenValue.cs プロジェクト: mscottford/ironruby
 internal void SetString(string/*!*/ value, StringLiteralEncoding encoding) {
     Assert.NotNull(value);
     String = value;
     _integer1 = (int)encoding;
     _type = TokenValueType.String;
 }
コード例 #5
0
ファイル: TokenValue.cs プロジェクト: joshholmes/ironruby
 internal void SetString(string/*!*/ value, StringLiteralEncoding encoding) {
     Assert.NotNull(value);
     String = value;
     Integer1 = (int)encoding;
 }
コード例 #6
0
        //
        // Traverses expressions in "parts" and concats all contiguous literal strings.
        // Notes:
        //  - Instead of usign StringBuilder we place the string values that can be concatenated so far in to "literals" list and keep track
        //    of their total length in "concatLength" and encoding in "concatEncoding".
        //    If we reach a non-literal expression and we have some literals ready in "literals" array we do the concat and clear the list
        //    and "concatLength" and "concatEncoding".
        //  - "result" list contains argument expressions to the CreateMutableString* overloads.
        //  - "opName" contains the name of the operation. This method appends suffix based on the argument types (see RubyOps.Suffix*).
        //
        private static void ConcatLiteralsAndTransformRecursive(AstGenerator /*!*/ gen, List <Expression> /*!*/ parts,
                                                                List <string> /*!*/ literals, ref int concatLength, ref StringLiteralEncoding concatEncoding, List <MSA.Expression> /*!*/ result,
                                                                StringBuilder /*!*/ opName)
        {
            for (int i = 0; i < parts.Count; i++)
            {
                Expression        part = parts[i];
                StringLiteral     literal;
                StringConstructor ctor;

                if ((literal = part as StringLiteral) != null)
                {
                    literals.Add(literal.Value);
                    concatEncoding = CombineEncoding(concatEncoding, literal);
                    concatLength  += literal.Value.Length;
                }
                else if ((ctor = part as StringConstructor) != null)
                {
                    ConcatLiteralsAndTransformRecursive(gen, ctor.Parts, literals, ref concatLength, ref concatEncoding, result, opName);
                }
                else
                {
                    if (literals.Count > 0)
                    {
                        result.Add(Ast.Constant(Concat(literals, concatLength)));
                        opName.Append(OpSuffix(gen, concatEncoding));
                        concatLength   = 0;
                        concatEncoding = StringLiteralEncoding.Ascii;
                        literals.Clear();
                    }

                    result.Add(
                        Ast.Dynamic(
                            ConvertToSAction.Instance,
                            typeof(MutableString),
                            gen.CurrentScopeVariable, part.TransformRead(gen)
                            )
                        );
                    opName.Append(RubyOps.SuffixMutable);
                }
            }
        }
コード例 #7
0
ファイル: StringLiteral.cs プロジェクト: gaybro8777/ironruby
 internal StringLiteral(string /*!*/ value, StringLiteralEncoding encoding, SourceSpan location)
     : base(location)
 {
     _value    = value;
     _encoding = encoding;
 }
コード例 #8
0
 internal StringLiteral(string/*!*/ value, StringLiteralEncoding encoding, SourceSpan location)
     : base(location) {
     _value = value;
     _encoding = encoding;
 }
コード例 #9
0
 private static char OpSuffix(AstGenerator/*!*/ gen, StringLiteralEncoding encoding) {
     if (encoding == StringLiteralEncoding.Ascii) {
         return RubyOps.SuffixBinary;
     } else if (encoding == StringLiteralEncoding.UTF8 || gen.Encoding == Encoding.UTF8) {
         return RubyOps.SuffixUTF8;
     } else if (gen.Encoding == BinaryEncoding.Instance) {
         return RubyOps.SuffixBinary;
     } else {
         return RubyOps.SuffixEncoded;
     }
 }
コード例 #10
0
        private static StringLiteralEncoding CombineEncoding(StringLiteralEncoding encoding, StringLiteral literal) {
            if (encoding == StringLiteralEncoding.UTF8 || literal.IsUTF8) {
                return StringLiteralEncoding.UTF8;
            }

            if (encoding == StringLiteralEncoding.Ascii && literal.IsAscii) {
                return StringLiteralEncoding.Ascii;
            }

            return StringLiteralEncoding.Default;
        }
コード例 #11
0
        //
        // Traverses expressions in "parts" and concats all contiguous literal strings.
        // Notes: 
        //  - Instead of usign StringBuilder we place the string values that can be concatenated so far in to "literals" list and keep track
        //    of their total length in "concatLength" and encoding in "concatEncoding". 
        //    If we reach a non-literal expression and we have some literals ready in "literals" array we do the concat and clear the list 
        //    and "concatLength" and "concatEncoding".
        //  - "result" list contains argument expressions to the CreateMutableString* overloads.
        //  - "opName" contains the name of the operation. This method appends suffix based on the argument types (see RubyOps.Suffix*).
        //
        private static void ConcatLiteralsAndTransformRecursive(AstGenerator/*!*/ gen, List<Expression>/*!*/ parts, 
            List<string>/*!*/ literals, ref int concatLength, ref StringLiteralEncoding concatEncoding, List<MSA.Expression>/*!*/ result,
            StringBuilder/*!*/ opName) {

            for (int i = 0; i < parts.Count; i++) {
                Expression part = parts[i];
                StringLiteral literal;
                StringConstructor ctor;

                if ((literal = part as StringLiteral) != null) {
                    literals.Add(literal.Value);
                    concatEncoding = CombineEncoding(concatEncoding, literal);
                    concatLength += literal.Value.Length;
                } else if ((ctor = part as StringConstructor) != null) {
                    ConcatLiteralsAndTransformRecursive(gen, ctor.Parts, literals, ref concatLength, ref concatEncoding, result, opName);
                } else {
                    if (literals.Count > 0) {
                        result.Add(Ast.Constant(Concat(literals, concatLength)));
                        opName.Append(OpSuffix(gen, concatEncoding));
                        concatLength = 0;
                        concatEncoding = StringLiteralEncoding.Ascii;
                        literals.Clear();
                    }

                    result.Add(
                        Ast.Dynamic(
                            ConvertToSAction.Instance,
                            typeof(MutableString),
                            Methods.GetContextFromScope.OpCall(gen.CurrentScopeVariable), part.TransformRead(gen)
                        )
                    );
                    opName.Append(RubyOps.SuffixMutable);
                }
            }
        }