public static UnifiedExpression CreateEnumSpecifier(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "enum_specifier"); /* * enum_specifier * : 'enum' '{' enumerator_list '}' | 'enum' IDENTIFIER '{' enumerator_list '}' | 'enum' IDENTIFIER */ // enum { RED, BLUE, YELLOW } -> 宣言 // enum COLOR { RED, BLUE, YELLOW } -> 宣言 // enum COLOR -> 型 if (node.Elements("enumerator_list").Count() == 0) { // TODO 型名はどうなるのか? return (UnifiedType.Create( "enum " + node.FirstElement("IDENTIFIER").Value)); } var identifier = node.Element("IDENTIFIER"); UnifiedIdentifier name = identifier != null ? UnifiedIdentifier.CreateVariable( identifier.Value) : null; var body = CreateEnumeratorList(node.Element("enumerator_list")); return(UnifiedEnumDefinition.Create( null, null, name, null, null, body)); }
public UnifiedElement VisitTypeDeclaration( TypeDeclaration dec, object data) { var attrs = dec.Attributes.AcceptVisitorAsAttrs(this, data); var mods = LookupModifiers(dec.Modifiers); var name = UnifiedVariableIdentifier.Create(dec.Name); var typeParams = dec.TypeParameters.AcceptVisitorAsTypeParams( this, data); if (typeParams.Count == 0) { typeParams = null; } var extends = dec.BaseTypes.AcceptVisitorAsConstrains(this, data); var body = UnifiedBlock.Create(); foreach (var node in dec.Members) { var uExpr = node.TryAcceptForExpression(this); if (uExpr != null) { body.Add(uExpr); } } // set constraint var dic = CreateDictionary(dec.Constraints); if (typeParams != null) { foreach ( var generic in typeParams.Descendants <UnifiedGenericParameter>( )) { var tName = GetTypeName(generic.Type); if (dic.ContainsKey(tName)) { foreach (var c in dic[tName]) { if (generic.Constrains == null) { generic.Constrains = UnifiedSet <UnifiedTypeConstrain> .Create(); } generic.Constrains.Add(c.DeepCopy()); } } } } foreach ( var generic in extends.Descendants <UnifiedGenericParameter>()) { var tName = GetTypeName(generic.Type); if (dic.ContainsKey(tName)) { foreach (var c in dic[tName]) { if (generic.Constrains == null) { generic.Constrains = UnifiedSet <UnifiedTypeConstrain> .Create(); } generic.Constrains.Add(c.DeepCopy()); } } } switch (dec.ClassType) { case ClassType.Class: return(UnifiedClassDefinition.Create( attrs, mods, name, typeParams, extends, body)); case ClassType.Struct: return(UnifiedStructDefinition.Create( attrs, mods, name, typeParams, extends, body)); case ClassType.Interface: return(UnifiedInterfaceDefinition.Create( attrs, mods, name, typeParams, extends, body)); case ClassType.Enum: return(UnifiedEnumDefinition.Create( attrs, mods, name, typeParams, extends, body)); } var msg = "LookupClassKind : " + dec.ClassType + "には対応していません。"; throw new InvalidOperationException(msg); }