source: CIVL/examples/languageFeatures/scopeOperators.cvl@ 978afe7

main test-branch
Last change on this file since 978afe7 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[e6b02c8]1#include <civlc.cvh>
2#include <comm.cvh>
3#include <scope.cvh>
[0b9a80a]4#include <stdio.h>
[9f6b224]5
6void main(){
7 $scope s = $here, t = $here;
8 $scope p = $scope_parent(s);
9 $gcomm g = $gcomm_create(p, 5);
10 $gcomm f;
11
12 void foo(){
13 $scope fs = $here;
14 $scope sum = fs + s;// compute the lowest common ancestors of fs and s.
15
[d980649]16 $assert(s > fs);
17 $assert(sum == s);
[0b9a80a]18 printf("foo done.\n");
19 }
20
21 void goo(){
22 $scope s1 = $here;
23 int x;
24 double a[10];
25
26 {
27 $scope s2 = $here;
28 int *p = &x;
29 double *q = &a[4];
30
[d980649]31 $assert($scopeof(x)==s1);
32 $assert($scopeof(p)==s2);
33 $assert($scopeof(*p)==s1);
34 $assert($scopeof(a)==s1);
35 $assert($scopeof(a[5])==s1);
36 $assert($scopeof(q)==s2);
37 $assert($scopeof(*q)==s1);
[0b9a80a]38 printf("goo done.\n");
39 }
[9f6b224]40 }
41
42 f = g;
43 g = f;
44 foo();
[0b9a80a]45 goo();
[d980649]46 $assert($scopeof(g) == $scopeof(f));
47 $assert(s == t);
48 $assert(s != p);
49 $assert(s <= p);// s is equal to p or s is strictly a descendant of p.
[9f6b224]50 $assert(s < p);// s is strictly a descendant of p
[d980649]51 $assert(p >= s);// p is equal to s or p is strictly an ancestor of s.
[9f6b224]52 $assert(p > s);// p is strictly a ancestor of s.
[07f7630]53 $gcomm_destroy(g, NULL);
[9f6b224]54}
Note: See TracBrowser for help on using the repository browser.