Skip to content

Commit

Permalink
[opt-viewer] Don't use __getattr__ for missing YAML attributes
Browse files Browse the repository at this point in the history
__getattr__ does not work well with debugging.  If the attribute function has
a run-time error, a missing attribute is reported instead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296765 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
anemet committed Mar 2, 2017
1 parent 4056116 commit 76f5727
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions utils/opt-viewer/optrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class Remark(yaml.YAMLObject):
# Work-around for http://pyyaml.org/ticket/154.
yaml_loader = Loader

def __getattr__(self, name):
# If hotness is missing, assume 0
if name == 'Hotness':
return 0
raise AttributeError(name)
def initmissing(self):
if not hasattr(self, 'Hotness'):
self.Hotness = 0
if not hasattr(self, 'Args'):
self.Args = []

@property
def File(self):
Expand Down Expand Up @@ -146,6 +146,7 @@ def get_remarks(input_file):
with open(input_file) as f:
docs = yaml.load_all(f, Loader=Loader)
for remark in docs:
remark.initmissing()
# Avoid remarks withoug debug location or if they are duplicated
if not hasattr(remark, 'DebugLoc') or remark.key in all_remarks:
continue
Expand Down

0 comments on commit 76f5727

Please sign in to comment.