예제 #1
0
 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
 internal void SetString(string/*!*/ value, StringLiteralEncoding encoding) {
     Assert.NotNull(value);
     String = value;
     _integer1 = (int)encoding;
     _type = TokenValueType.String;
 }
예제 #5
0
 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
 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);
                }
            }
        }