Repository: Konstantin8105/c4go
Pull request #273 (2019-02-15 12:27:06)

CSTD: sys/time.h: add gettimeofday


Patch:
diff --git a/ast/ast.go b/ast/ast.go
index b64d67f..e00403a 100644
--- a/ast/ast.go
+++ b/ast/ast.go
@@ -273,8 +273,6 @@ func Parse(fullline string) (returnNode Node, err error) {
 		return parseUnaryOperator(line), nil
 	case "UnusedAttr":
 		return parseUnusedAttr(line), nil
-	case "UsedAttr":
-		return parseUsedAttr(line), nil
 	case "VAArgExpr":
 		return parseVAArgExpr(line), nil
 	case "VarDecl":
diff --git a/ast/position.go b/ast/position.go
index 13de67b..a34ae63 100644
--- a/ast/position.go
+++ b/ast/position.go
@@ -408,8 +408,6 @@ func setPosition(node Node, position Position) {
 		n.Pos = position
 	case *UnusedAttr:
 		n.Pos = position
-	case *UsedAttr:
-		n.Pos = position
 	case *VAArgExpr:
 		n.Pos = position
 	case *VarDecl:
diff --git a/ast/used_attr.go b/ast/used_attr.go
deleted file mode 100644
index fb622c1..0000000
--- a/ast/used_attr.go
+++ /dev/null
@@ -1,44 +0,0 @@
-package ast
-
-// UsedAttr is attribute
-type UsedAttr struct {
-	Addr       Address
-	Pos        Position
-	ChildNodes []Node
-}
-
-func parseUsedAttr(line string) *UsedAttr {
-	groups := groupsFromRegex(
-		"<(?P<position>.*)>",
-		line,
-	)
-
-	return &UsedAttr{
-		Addr:       ParseAddress(groups["address"]),
-		Pos:        NewPositionFromString(groups["position"]),
-		ChildNodes: []Node{},
-	}
-}
-
-// AddChild adds a new child node. Child nodes can then be accessed with the
-// Children attribute.
-func (n *UsedAttr) AddChild(node Node) {
-	n.ChildNodes = append(n.ChildNodes, node)
-}
-
-// Address returns the numeric address of the node. See the documentation for
-// the Address type for more information.
-func (n *UsedAttr) Address() Address {
-	return n.Addr
-}
-
-// Children returns the child nodes. If this node does not have any children or
-// this node does not support children it will always return an empty slice.
-func (n *UsedAttr) Children() []Node {
-	return n.ChildNodes
-}
-
-// Position returns the position in the original source code.
-func (n *UsedAttr) Position() Position {
-	return n.Pos
-}
diff --git a/noarch/sys_time.go b/noarch/sys_time.go
index b2ff2a5..278d7ff 100644
--- a/noarch/sys_time.go
+++ b/noarch/sys_time.go
@@ -11,3 +11,8 @@ type Timezone struct {
 	TzMinuteswest int // minutes west of Greenwich
 	TzDsttime     int // type of DST correction
 }
+
+// Gettimeofday - gettimeofday from <sys/time.h>
+func Gettimeofday(tv []Timeval, tz []Timezone) int {
+	return -1
+}
diff --git a/program/definition_function.go b/program/definition_function.go
index 236c259..6c2b977 100644
--- a/program/definition_function.go
+++ b/program/definition_function.go
@@ -319,6 +319,9 @@ var builtInFunctionDefinitions = map[string][]string{
 	"sys/ioctl.h": {
 		"int ioctl(int , int , ... ) -> noarch.Ioctl",
 	},
+	"sys/time.h": {
+		"int gettimeofday(struct timeval *, struct timezone *) -> noarch.Gettimeofday",
+	},
 	"fcntl.h": {
 		"int open(const char *, int , mode_t ) -> noarch.OpenM",
 		"int open(const char *, int ) -> noarch.Open",


Test patch:
diff --git a/ast/used_attr_test.go b/ast/used_attr_test.go
deleted file mode 100644
index c3c4d4c..0000000
--- a/ast/used_attr_test.go
+++ /dev/null
@@ -1,17 +0,0 @@
-package ast
-
-import (
-	"testing"
-)
-
-func TestUsedAttr(t *testing.T) {
-	nodes := map[string]Node{
-		`0x3be4e70 <col:44>`: &UsedAttr{
-			Addr:       0x3be4e70,
-			Pos:        NewPositionFromString("col:44"),
-			ChildNodes: []Node{},
-		},
-	}
-
-	runNodeTests(t, nodes)
-}
diff --git a/main_test.go b/main_test.go
index 6bf07de..9a2081b 100644
--- a/main_test.go
+++ b/main_test.go
@@ -199,6 +199,9 @@ func runC(file, subFolder, stdin string, args []string) (string, error) {
 	cmd.Stdout = &cProgram.stdout
 	cmd.Stderr = &cProgram.stderr
 	err = cmd.Run()
+	if err != nil {
+		fmt.Fprintf(os.Stdout, "Error: %v\n", err)
+	}
 	cProgram.isZero = err == nil
 
 	// Check for special exit codes that signal that tests have failed.
diff --git a/tests/cast.c b/tests/cast.c
index 71502e1..54929f3 100644
--- a/tests/cast.c
+++ b/tests/cast.c
@@ -91,6 +91,16 @@ void test_bool_to_int()
     is_eq(x, 11);
 }
 
+// void test_unsafe_pnt()
+// {
+	// (otri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l);
+	// int pnt;
+	// long l = 42;
+	// pnt = (int) (&l);
+	// long *l_pnt = (long *)(l);
+	// is_eq(*l_pnt,42);
+// }
+
 int main()
 {
     plan(33);
@@ -100,6 +110,7 @@ int main()
     START_TEST(castbool);
     START_TEST(vertex);
     START_TEST(strCh);
+	// START_TEST(unsafe_pnt);
 
     {
         typedef unsigned int u32;
diff --git a/tests/time.c b/tests/time.c
index c6a3965..2a10480 100644
--- a/tests/time.c
+++ b/tests/time.c
@@ -99,6 +99,17 @@ void test_timezone()
     is_eq(tv.tz_dsttime, 75000);
 }
 
+void test_gettime()
+{
+	struct timeval  tv;
+	struct timezone tz;
+	int r = gettimeofday(&tv,&tz);
+	printf("timezone: %d %d\n",tz.tz_minuteswest, tz.tz_dsttime);
+	(void) tv;
+	(void) r;
+}
+
+
 int main()
 {
     plan(23);
@@ -114,6 +125,7 @@ int main()
     // sys/time.h
     START_TEST(timeval);
     START_TEST(timezone);
+	START_TEST(gettime);
 
     done_testing();
 }