Browse Source

Merge branch 'release'

Vladislav Folts 11 years ago
parent
commit
4632afe1d3
4 changed files with 40 additions and 4 deletions
  1. 26 4
      src/context.js
  2. 6 0
      test/expected/string.js
  3. 6 0
      test/input/string.ob
  4. 2 0
      test/test_unit.js

+ 26 - 4
src/context.js

@@ -157,13 +157,19 @@ exports.Real = ChainedContext.extend({
 });
 
 function escapeString(s){
+    var escapeChars = {"\\": "\\\\",
+                       "\"": "\\\"",
+                       "\n": "\\n",
+                       "\r": "\\r",
+                       "\t": "\\t",
+                       "\b": "\\b",
+                       "\f": "\\f"
+                      };
     var result = "\"";
     for(var i = 0; i < s.length; ++i){
         var c = s[i];
-        if (c == '"')
-            result += "\\\"";
-        else
-            result += s[i];
+        var escape = escapeChars[c];
+        result += escape !== undefined ? escape : c;
     }
     return result + "\"";
 }
@@ -480,6 +486,12 @@ exports.FormalParametersProcDecl = exports.FormalParameters.extend({
         exports.FormalParameters.prototype.addArgument.call(this, name, arg);
         this.parent().addArgument(name, arg);
     },
+    /*
+    handleSymbol: function(s){
+        exports.FormalParameters.prototype.handleSymbol.call(this, s);
+        this.parent().checkResultType(s);
+    },
+    */
     endParse: function(){
         exports.FormalParameters.prototype.endParse.call(this);
         this.parent().endParameters();
@@ -534,6 +546,16 @@ exports.ProcDecl = ChainedContext.extend({
         code.write(")");
         code.openScope();
     },
+    /*
+    checkResultType: function(s){
+        if (this.__id.exported()){
+            if (!s.scope().exports()[s.symbol().id()])
+                throw new Errors.Error(
+                    "exported PROCEDURE '" + this.__id.id()
+                    + "' uses non-exported type '" + s.symbol().id() + "'");
+        }
+    },
+    */
     handleReturn: function(type){
         var result = this.__type.result();
         if (!result)

+ 6 - 0
test/expected/string.js

@@ -40,6 +40,12 @@ var m = function (){
 var s1 = "\"";
 var s2 = "ABC";
 var s3 = "with space";
+var s4 = "\n";
+var s5 = "\r";
+var s6 = "\b";
+var s7 = "\t";
+var s8 = "\f";
+var s9 = "\\";
 var ch1 = 0;
 var a2 = RTL$.makeArray(3, 0);
 

+ 6 - 0
test/input/string.ob

@@ -4,6 +4,12 @@ CONST
 	s1 = 22X;
 	s2 = "ABC";
 	s3 = "with space";
+	s4 = 0AX;
+	s5 = 0DX;
+	s6 = 08X;
+	s7 = 09X;
+	s8 = 0CX;
+	s9 = "\";
 VAR
     ch1: CHAR;
 	a2: ARRAY 3 OF CHAR;

+ 2 - 0
test/test_unit.js

@@ -1288,6 +1288,8 @@ var testSuite = {
           "cannot export anonymous RECORD field: 'r'"],
          ["PROCEDURE p*; VAR i*: INTEGER; END p;",
           "cannot export from within procedure: variable 'i'"]
+         //["TYPE PT = POINTER TO RECORD END; PROCEDURE p*(): PT; RETURN NIL END p;",
+         //"exported PROCEDURE 'p' uses non-exported type 'PT'"]
          )
     ),
 "import JS": testWithGrammar(