TriggerEvent.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Xml.Linq;
  5. namespace csharp_sccd_compiler
  6. {
  7. public class TriggerEvent
  8. {
  9. public bool is_after { get; private set; }
  10. public bool is_uc { get; private set; }
  11. public int after_index { get; set; }
  12. public List<FormalEventParameter> parameters { get; private set; }
  13. public string event_name { get; set; }
  14. public string port { get; private set; }
  15. public Expression after_expression { get; private set; }
  16. public TriggerEvent(XElement xml)
  17. {
  18. after_index = -1; //Initial value
  19. //Parse "port" attribute
  20. XAttribute port_attribute = xml.Attribute("port");
  21. if (port_attribute == null || port_attribute.Value.Trim() == "")
  22. this.port = null;
  23. else
  24. this.port = port_attribute.Value.Trim();
  25. //Parse "after" attribute
  26. XAttribute after_attribute = xml.Attribute("after");
  27. if (after_attribute == null || after_attribute.Value.Trim() == "")
  28. {
  29. this.after_expression = null;
  30. this.is_after = false;
  31. }
  32. else
  33. {
  34. this.after_expression = new Expression(after_attribute.Value.Trim());
  35. if (this.port != null)
  36. throw new CompilerException("An after event can not have a port defined.");
  37. this.is_after = true;
  38. }
  39. //parse "event" attribute
  40. XAttribute event_name_attribute = xml.Attribute("event");
  41. if (event_name_attribute == null || event_name_attribute.Value.Trim() == "")
  42. {
  43. this.event_name = null;
  44. if (this.port != null)
  45. throw new CompilerException("A transition without event can not have a port.");
  46. if (!this.is_after)
  47. this.is_uc = true;
  48. }
  49. else
  50. {
  51. this.event_name = event_name_attribute.Value.Trim();
  52. if (this.is_after)
  53. throw new CompilerException("Cannot have both the event and after attribute set for a transition.");
  54. }
  55. this.parameters = new List<FormalEventParameter>();
  56. foreach (XElement parameter_xml in xml.Elements("parameter"))
  57. {
  58. this.parameters.Add(new FormalEventParameter(parameter_xml));
  59. }
  60. if(this.parameters.Count > 0 && (this.is_after || this.is_uc ))
  61. throw new CompilerException("AFTER and unconditional events can not have parameters defined.");
  62. }
  63. }
  64. }