Ejemplo n.º 1
0
func DumpAST(body string) {
	scanner := new(parsing.Scanner)
	scanner.Init([]rune(body), 0)
	defs := parsing.Parse(scanner)

	pp.Println(defs)
}
Ejemplo n.º 2
0
func DumpGraph(body string) {
	scanner := new(parsing.Scanner)
	scanner.Init([]rune(body), 0)
	defs := parsing.Parse(scanner)

	if err := typecheck.TypeCheck(defs); err != nil {
		log.Fatal("TypeCheck error:", err)
	}

	conversion.DumpGraph(defs)
}
Ejemplo n.º 3
0
func CompileFile(body string) (string, error) {
	scanner := new(parsing.Scanner)
	scanner.Init([]rune(body), 0)
	defs := parsing.Parse(scanner)

	if err := typecheck.TypeCheck(defs); err != nil {
		return "", err
	}

	return conversion.ConvertASTToNuSMV(defs)
}
Ejemplo n.º 4
0
func TestConvertASTToIntModuleForSend(t *testing.T) {
	return // FIXME:
	sendWithTagSource := `
		fault send(ch channel { bool }) @omission {
			// do nothing
		}

		proc SendProc(ch channel { bool }) {
			send(ch, true) @omission
		}

		init {
			ch: channel { bool },
			sp: SendProc(ch),
		}
	`
	expected := []intModule{
		intHandshakeChannel{
			Name:      "HandshakeChannel0",
			ValueType: []string{"boolean"},
			ZeroValue: []string{"FALSE"},
		},
		intProcModule{
			Name: "__pid0_SendProc",
			Args: []string{"__orig_ch"},
			Vars: []intVar{
				{"ch", "HandshakeChannel0Proxy(__orig_ch)"},
			},
			InitState: intState("state0"),
			Trans: []intTransition{
				{
					FromState: "state0",
					NextState: "state2",
					Condition: "",
					Actions:   []intAssign(nil),
				},
				{
					FromState: "state2",
					NextState: "state3",
					Condition: "!(ch.ready)",
					Actions: []intAssign{
						{"ch.send_filled", "TRUE"},
						{"ch.send_value_0", "TRUE"},
					},
				},
				{
					FromState: "state3",
					NextState: "state4",
					Condition: "(ch.ready) & (ch.received)",
					Actions: []intAssign{
						{"ch.send_leaving", "TRUE"},
					},
				},
				{
					FromState: "state4",
					NextState: "state1",
					Condition: "",
					Actions:   []intAssign(nil),
				},
				{
					FromState: "state0",
					NextState: "state5",
					Condition: "",
					Actions:   []intAssign(nil),
				},
				{
					FromState: "state5",
					NextState: "state6",
					Condition: "!(ch.ready)",
					Actions: []intAssign{
						{"ch.send_filled", "TRUE"},
						{"ch.send_value_0", "TRUE"},
					},
				},
				{
					FromState: "state6",
					NextState: "state7",
					Condition: "(ch.ready) & (ch.received)",
					Actions: []intAssign{
						{"ch.send_leaving", "TRUE"},
					},
				},
				{
					FromState: "state7",
					NextState: "state1",
					Condition: "",
					Actions:   []intAssign(nil),
				},
			},
			Defaults: map[string]string{
				"ch.send_leaving":  "FALSE",
				"ch.send_filled":   "FALSE",
				"ch.recv_received": "FALSE",
				"ch.send_value_0":  "ch.value_0",
			},
			Defs: []intAssign(nil),
		},
		intMainModule{
			Vars: []intVar{
				{"ch", "HandshakeChannel0"},
				{"sp", "process __pid0_SendProc(ch)"},
			},
		},
	}

	scanner := new(parsing.Scanner)
	scanner.Init([]rune(sendWithTagSource), 0)
	defs := parsing.Parse(scanner)

	err, intMods := astToIr1(defs)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}
	actualPP := pp.PP(intMods)
	expectPP := pp.PP(expected)
	if actualPP != expectPP {
		t.Errorf("Unmatched\n%s\n", diff.Diff(expectPP, actualPP))
	}
}