2020牛客多校第七场J-Pointer Analysis

指针是C语言的精髓

Statement

有四种操作
2020牛客多校第七场J-Pointer Analysis_第1张图片
求每个指针可能指向位置

Solution

  • 首先,这是道暴力模拟题
  • 小写字母一定是指针指成的有向图中出度为零的点(结尾)
  • 我们考虑从后往前考虑
  • 一层一层遍历…
  • 是不是很像 b f s ? bfs? bfs?
  • 再想,更像 S P F A SPFA SPFA的思想
  • 每次从队列中取出点,合并
  • 如果合并后答案变了,就放进队列里

Pseudo Code

Let worklist be a set//set or queue
For every allocation statement A = x: 
	insert x into pt(A)
	If pt(A) has been changed, add A into worklist
While worklist is not empty:
	While worklist is not empty:
		select one element X from worklist
		delete X from worklist
		For every assignment statement like Y = X:
			merge pt(X) into pt(Y)
			If pt(Y) has been changed, add Y into worklist
	For every store statement Y.f = X:
		For every object o in pt(Y):
			merge pt(X) into pt(o.f)
	For every load statement Y = X.f:
		For every object o in pt(X):
			merge pt(o.f) into pt(Y)
			 If pt(Y) has been changed, add Y into worklist

你可能感兴趣的:(2020牛客暑期多校训练营)