Changeset 15697ff for src/Parser


Ignore:
Timestamp:
Sep 11, 2017, 5:11:40 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
7b1d5ec
Parents:
f4b77f2
Message:

change processing of concatenated (juxtaposed) string and string encodings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rf4b77f2 r15697ff  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep 10 10:07:10 2017
    13 // Update Count     : 2752
     12// Last Modified On : Mon Sep 11 08:22:25 2017
     13// Update Count     : 2783
    1414//
    1515
     
    4343#define YYDEBUG_LEXER_TEXT (yylval)                                             // lexer loads this up each time
    4444#define YYDEBUG 1                                                                               // get the pretty debugging code to compile
     45#define YYERROR_VERBOSE
    4546
    4647#undef __GNUC_MINOR__
     
    6263stack< LinkageSpec::Spec > linkageStack;
    6364
    64 void appendStr( string *to, string *from ) {
    65         // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string.
    66         to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) );
     65bool appendStr( string & to, string & from ) {
     66        // 1. Multiple strings are concatenated into a single string but not combined internally. The reason is that
     67        //    "\x12" "3" is treated as 2 characters versus 3 because "escape sequences are converted into single members of
     68        //    the execution character set just prior to adjacent string literal concatenation" (C11, Section 6.4.5-8). It is
     69        //    easier to let the C compiler handle this case.
     70        //
     71        // 2. String encodings are transformed into canonical form (one encoding at start) so the encoding can be found
     72        //    without searching the string, e.g.: "abc" L"def" L"ghi" => L"abc" "def" "ghi". Multiple encodings must match,
     73        //    i.e., u"a" U"b" L"c" is disallowed.
     74
     75        if ( from[0] != '"' ) {                                                         // encoding ?
     76                if ( to[0] != '"' ) {                                                   // encoding ?
     77                        if ( to[0] != from[0] ) {                                       // different encodings ?
     78                                yyerror( "non-matching string encodings for string-literal concatenation" );
     79                                return false;                                                   // parse error, must call YYERROR in action
     80                        } // if
     81                } else {
     82                        to = from[0] + to;                                                      // move encoding to start
     83                } // if
     84                from.erase( 0, 1 );                                                             // remove 2nd encoding
     85        } // if
     86        to += " " + from;                                                                       // concatenated into single string
     87        return true;
    6788} // appendStr
    6889
     
    88109bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
    89110%}
     111
     112%define parse.error verbose
    90113
    91114// Types declaration
     
    391414        | string_literal_list STRINGliteral
    392415                {
    393                         appendStr( $1, $2 );                                            // append 2nd juxtaposed string to 1st
     416                        if ( ! appendStr( *$1, *$2 ) ) YYERROR;         // append 2nd juxtaposed string to 1st
    394417                        delete $2;                                                                      // allocated by lexer
    395418                        $$ = $1;                                                                        // conversion from tok to str
Note: See TracChangeset for help on using the changeset viewer.