Repository: Konstantin8105/c4go
Pull request #263 (2019-02-09 13:09:14)

pointerArithmetic: add todo and unicode convertor


Patch:
diff --git a/transpiler/enum.go b/transpiler/enum.go
index 9e1c0b1..534a104 100644
--- a/transpiler/enum.go
+++ b/transpiler/enum.go
@@ -92,7 +92,7 @@ func transpileEnumDeclWithType(p *program.Program, n *ast.EnumDecl, enumType str
 	decls []goast.Decl, err error) {
 	defer func() {
 		if err != nil {
-			err = fmt.Errorf("Cannot transpileEnumDeclWithoutName. %v", err)
+			err = fmt.Errorf("Cannot transpileEnumDeclWithName. %v", err)
 		}
 	}()
 	preStmts := []goast.Stmt{}
@@ -163,15 +163,9 @@ func transpileEnumDeclWithType(p *program.Program, n *ast.EnumDecl, enumType str
 		case *goast.BasicLit:
 			var value int
 			value, err = strconv.Atoi(v.Value)
-			if err != nil {
-				err = fmt.Errorf("Cannot parse '%s' in BasicLit", v.Value)
-				return
-			}
 			if err != nil {
 				e = val
 				counter++
-				p.AddMessage(p.GenerateWarningMessage(
-					fmt.Errorf("Cannot parse '%s' in BasicLit", v.Value), n))
 				break
 			}
 			if sign == -1 {
diff --git a/transpiler/operators.go b/transpiler/operators.go
index 8ddb2c4..0888144 100644
--- a/transpiler/operators.go
+++ b/transpiler/operators.go
@@ -303,6 +303,8 @@ func main(){
 	fset := token.NewFileSet() // positions are relative to fset
 	body := strings.Replace(source.String(), "&#43;", "+", -1)
 	body = strings.Replace(body, "&amp;", "&", -1)
+	body = strings.Replace(body, "&#34;", "\"", -1)
+	// TODO: add unicode convertor
 	f, err := parser.ParseFile(fset, "", body, 0)
 	if err != nil {
 		err = fmt.Errorf("Cannot parse file. err = %v", err)
diff --git a/transpiler/unary.go b/transpiler/unary.go
index 3e8b8f3..133c924 100644
--- a/transpiler/unary.go
+++ b/transpiler/unary.go
@@ -600,6 +600,8 @@ func transpileUnaryExprOrTypeTraitExpr(n *ast.UnaryExprOrTypeTraitExpr, p *progr
 			realFirstChild = c.Children()[0]
 		case *ast.DeclRefExpr:
 			t = c.Type
+		case *ast.UnaryOperator:
+			t = c.Type
 		case *ast.MemberExpr:
 			t = c.Type
 		case *ast.ArraySubscriptExpr:


Test patch:
diff --git a/tests/enum.c b/tests/enum.c
index d9a60fb..1027056 100644
--- a/tests/enum.c
+++ b/tests/enum.c
@@ -137,10 +137,21 @@ typedef enum {
 enum { e1 = 1,
     e2 };
 
+enum {
+	MBchar = 'U', 
+	Troffchar = 'C', 
+	Number = 'N', 
+	Install = 'i', 
+	Lookup = 'l' 
+};
+
+
 // main function
 int main()
 {
-    plan(43);
+    plan(44);
+
+	is_eq(MBchar, 'U');
 
     test_unary();
     test_parent();
diff --git a/tests/unary.c b/tests/unary.c
index c265081..74e6862 100644
--- a/tests/unary.c
+++ b/tests/unary.c
@@ -39,12 +39,35 @@ void test_notptr()
     }
 }
 
+int conv(int i)
+{
+	return i;
+}
+
+void test_sizeoftest()
+{
+	// example :
+	// while ((n = fread(buf, sizeof *buf, sizeof buf, fin)) > 0)
+// UnaryExprOrTypeTraitExpr 'unsigned long' sizeof
+// `-UnaryOperator 0x2e1a880 'char' lvalue prefix '*'
+//   `-ImplicitCastExpr 0x2e1a868 'char *' <ArrayToPointerDecay>
+//     `-DeclRefExpr 0x2e1a840 'char [1024]' lvalue Var 0x2e19d78 'buf' 'char [1024]'
+	char *buf = NULL;
+	if (conv(sizeof *buf) > 0) {
+		pass("ok");
+	} else {
+		fail("fail");
+	}
+	(void)(buf);
+}
+
 int main()
 {
-    plan(4);
+    plan(5);
 
     START_TEST(notint)
     START_TEST(notptr)
+	START_TEST(sizeoftest)
 
     done_testing();
 }