override public void OnStructDefinition(StructDefinition node) { ClassDefinition cd = new ClassDefinition(node.LexicalInfo); cd.Name = node.Name; cd.Attributes = node.Attributes; cd.Modifiers = node.Modifiers; cd.Members = node.Members; cd.GenericParameters = node.GenericParameters; cd.BaseTypes = node.BaseTypes; cd.BaseTypes.Insert(0, CodeBuilder.CreateTypeReference(TypeSystemServices.ValueTypeType)); foreach (TypeMember member in cd.Members) { if (member.IsVisibilitySet) continue; switch (member.NodeType) { case NodeType.Field: member.Visibility = Context.Parameters.DefaultFieldVisibility; break; case NodeType.Property: member.Visibility = Context.Parameters.DefaultPropertyVisibility; break; case NodeType.Method: member.Visibility = Context.Parameters.DefaultMethodVisibility; break; } if (member.IsProtected) member.Visibility = TypeMemberModifiers.Public; } OnClassDefinition(cd); ReplaceCurrentNode(cd); }
override public object Clone() { StructDefinition clone = (StructDefinition)FormatterServices.GetUninitializedObject(typeof(StructDefinition)); clone._lexicalInfo = _lexicalInfo; clone._endSourceLocation = _endSourceLocation; clone._documentation = _documentation; clone._isSynthetic = _isSynthetic; clone._entity = _entity; if (_annotations != null) { clone._annotations = (Hashtable)_annotations.Clone(); } clone._modifiers = _modifiers; clone._name = _name; if (null != _attributes) { clone._attributes = _attributes.Clone() as AttributeCollection; clone._attributes.InitializeParent(clone); } if (null != _members) { clone._members = _members.Clone() as TypeMemberCollection; clone._members.InitializeParent(clone); } if (null != _baseTypes) { clone._baseTypes = _baseTypes.Clone() as TypeReferenceCollection; clone._baseTypes.InitializeParent(clone); } if (null != _genericParameters) { clone._genericParameters = _genericParameters.Clone() as GenericParameterDeclarationCollection; clone._genericParameters.InitializeParent(clone); } return(clone); }
//throws RecognitionException, TokenStreamException protected void class_definition( TypeMemberCollection container ) { IToken id = null; TypeDefinition td = null; TypeReferenceCollection baseTypes = null; TypeMemberCollection members = null; GenericParameterDeclarationCollection genericParameters = null; try { // for error handling { switch ( LA(1) ) { case CLASS: { match(CLASS); if (0==inputState.guessing) { td = new ClassDefinition(); } break; } case STRUCT: { match(STRUCT); if (0==inputState.guessing) { td = new StructDefinition(); } break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } id = LT(1); match(ID); if (0==inputState.guessing) { td.LexicalInfo = SourceLocationFactory.ToLexicalInfo(id); td.Name = id.getText(); td.Modifiers = _modifiers; AddAttributes(td.Attributes); container.Add(td); baseTypes = td.BaseTypes; members = td.Members; genericParameters = td.GenericParameters; } { switch ( LA(1) ) { case LBRACK: { match(LBRACK); { switch ( LA(1) ) { case OF: { match(OF); break; } case ID: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } generic_parameter_declaration_list(genericParameters); match(RBRACK); break; } case LPAREN: case COLON: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { switch ( LA(1) ) { case LPAREN: { base_types(baseTypes); break; } case COLON: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } begin_with_doc(td); { // ( ... )* for (;;) { switch ( LA(1) ) { case SPLICE_BEGIN: { splice_type_definition_body(members); break; } case ABSTRACT: case CALLABLE: case CLASS: case DEF: case ENUM: case EVENT: case FINAL: case INTERFACE: case INTERNAL: case NEW: case OVERRIDE: case PUBLIC: case PROTECTED: case PRIVATE: case SELF: case STATIC: case STRUCT: case TRANSIENT: case VIRTUAL: case PARTIAL: case ID: case LBRACK: { type_definition_member(members); break; } default: { goto _loop67_breakloop; } } } _loop67_breakloop: ; } // ( ... )* end(td); } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex); recover(ex,tokenSet_32_); } else { throw ex; } } }
public override void LeaveStructDefinition(StructDefinition node) { LeaveTypeDefinition(node); }
public object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { if (typeDeclaration.Templates.Count > 0) { AddError(typeDeclaration, "Generic type definitions are not supported."); } B.TypeDefinition oldType = currentType; B.TypeDefinition typeDef; switch (typeDeclaration.Type) { case ClassType.Class: typeDef = new B.ClassDefinition(GetLexicalInfo(typeDeclaration)); break; case ClassType.Interface: typeDef = new B.InterfaceDefinition(GetLexicalInfo(typeDeclaration)); break; case ClassType.Enum: typeDef = new B.EnumDefinition(GetLexicalInfo(typeDeclaration)); break; case ClassType.Struct: typeDef = new B.StructDefinition(GetLexicalInfo(typeDeclaration)); break; case ClassType.Module: typeDef = new B.ClassDefinition(GetLexicalInfo(typeDeclaration)); typeDeclaration.Modifier |= Modifiers.Static; break; default: AddError(typeDeclaration, "Unknown class type."); return null; } if (currentType != null) typeDef.Modifiers = ConvertModifier(typeDeclaration, B.TypeMemberModifiers.Private); else typeDef.Modifiers = ConvertModifier(typeDeclaration, B.TypeMemberModifiers.Internal); typeDef.Name = typeDeclaration.Name; typeDef.EndSourceLocation = GetLocation(typeDeclaration.EndLocation); ConvertAttributes(typeDeclaration.Attributes, typeDef.Attributes); ConvertTypeReferences(typeDeclaration.BaseTypes, typeDef.BaseTypes); if (currentType != null) currentType.Members.Add(typeDef); else module.Members.Add(typeDef); currentType = typeDef; typeDeclaration.AcceptChildren(this, data); currentType = oldType; return typeDef; }
public override void OnStructDefinition(StructDefinition node) { EnterNamespace((INamespace)GetEntity(node)); VisitTypeDefinitionBody(node); LeaveNamespace(); }
public override void OnStructDefinition(StructDefinition node) { EnterTypeDefinition(node); base.OnStructDefinition(node); fieldStack.Pop(); }
public override void OnStructDefinition(StructDefinition node) { WriteTypeDefinition("struct", node); }
public override void LeaveStructDefinition(StructDefinition node) { CantBeMarkedAbstract(node); CantBeMarkedFinal(node); CantBeMarkedStatic(node); CantBeMarkedPartial(node); }
public override void OnStructDefinition(StructDefinition node) { AddMember(node); }
//throws RecognitionException, TokenStreamException protected void class_definition( TypeMemberCollection container ) { IToken id = null; TypeDefinition td = null; TypeReferenceCollection baseTypes = null; TypeMemberCollection members = null; GenericParameterDeclarationCollection genericParameters = null; try { // for error handling { switch ( LA(1) ) { case CLASS: { match(CLASS); if (0==inputState.guessing) { td = new ClassDefinition(); } break; } case STRUCT: { match(STRUCT); if (0==inputState.guessing) { td = new StructDefinition(); } break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } id = LT(1); match(ID); if (0==inputState.guessing) { td.LexicalInfo = SourceLocationFactory.ToLexicalInfo(id); td.Name = id.getText(); td.Modifiers = _modifiers; AddAttributes(td.Attributes); container.Add(td); baseTypes = td.BaseTypes; members = td.Members; genericParameters = td.GenericParameters; } { switch ( LA(1) ) { case LBRACK: { match(LBRACK); { switch ( LA(1) ) { case OF: { match(OF); break; } case ID: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } generic_parameter_declaration_list(genericParameters); match(RBRACK); break; } case LPAREN: case COLON: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { switch ( LA(1) ) { case LPAREN: { base_types(baseTypes); break; } case COLON: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } begin_with_doc(td); { // ( ... )* for (;;) { if ((tokenSet_28_.member(LA(1)))) { type_definition_member(members); } else { goto _loop61_breakloop; } } _loop61_breakloop: ; } // ( ... )* end(td); } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex); recover(ex,tokenSet_27_); } else { throw ex; } } }
public override bool EnterStructDefinition(StructDefinition node) { return false; }
override public object Clone() { StructDefinition clone = new StructDefinition(); clone._lexicalInfo = _lexicalInfo; clone._endSourceLocation = _endSourceLocation; clone._documentation = _documentation; clone._isSynthetic = _isSynthetic; clone._entity = _entity; if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone(); clone._modifiers = _modifiers; clone._name = _name; if (null != _attributes) { clone._attributes = _attributes.Clone() as AttributeCollection; clone._attributes.InitializeParent(clone); } if (null != _members) { clone._members = _members.Clone() as TypeMemberCollection; clone._members.InitializeParent(clone); } if (null != _baseTypes) { clone._baseTypes = _baseTypes.Clone() as TypeReferenceCollection; clone._baseTypes.InitializeParent(clone); } if (null != _genericParameters) { clone._genericParameters = _genericParameters.Clone() as GenericParameterDeclarationCollection; clone._genericParameters.InitializeParent(clone); } return clone; }
public override void OnStructDefinition(StructDefinition node) { ClassDefinition cd = new ClassDefinition(node.LexicalInfo); cd.Name = node.Name; cd.Attributes = node.Attributes; cd.Modifiers = node.Modifiers; cd.Members = node.Members; cd.GenericParameters = node.GenericParameters; cd.BaseTypes = node.BaseTypes; cd.BaseTypes.Insert(0, CodeBuilder.CreateTypeReference(TypeSystemServices.ValueTypeType)); foreach (TypeMember member in cd.Members) { if (!member.IsVisibilitySet) { member.Modifiers |= TypeMemberModifiers.Public; } } OnClassDefinition(cd); ReplaceCurrentNode(cd); }
public override void OnStructDefinition(StructDefinition node) { ConvertTypeDefinition(node).IsStruct = true; }
public override void OnStructDefinition(StructDefinition node) { OnTypeDefinition(node); }
protected void class_definition( TypeMemberCollection container ) //throws RecognitionException, TokenStreamException { IToken id = null; IToken begin = null; TypeDefinition td = null; TypeReferenceCollection baseTypes = null; TypeMemberCollection members = null; GenericParameterDeclarationCollection genericParameters = null; Expression nameSplice = null; try { // for error handling { switch ( LA(1) ) { case CLASS: { match(CLASS); if (0==inputState.guessing) { td = new ClassDefinition(); } break; } case STRUCT: { match(STRUCT); if (0==inputState.guessing) { td = new StructDefinition(); } break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { switch ( LA(1) ) { case ID: { id = LT(1); match(ID); break; } case SPLICE_BEGIN: { begin = LT(1); match(SPLICE_BEGIN); nameSplice=atom(); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } if (0==inputState.guessing) { IToken token = id ?? begin; td.LexicalInfo = ToLexicalInfo(token); td.Name = token.getText(); td.Modifiers = _modifiers; AddAttributes(td.Attributes); baseTypes = td.BaseTypes; members = td.Members; genericParameters = td.GenericParameters; if (id != null) { container.Add(td); } else { container.Add(new SpliceTypeMember(td, nameSplice)); } } { switch ( LA(1) ) { case LBRACK: { match(LBRACK); { switch ( LA(1) ) { case OF: { match(OF); break; } case ID: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } generic_parameter_declaration_list(genericParameters); match(RBRACK); break; } case LPAREN: case COLON: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { switch ( LA(1) ) { case LPAREN: { base_types(baseTypes); break; } case COLON: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } begin_with_doc(td); { switch ( LA(1) ) { case PASS: { { match(PASS); eos(); } break; } case EOL: case ABSTRACT: case CALLABLE: case CLASS: case CONSTRUCTOR: case DEF: case DESTRUCTOR: case ENUM: case EVENT: case FINAL: case INTERFACE: case INTERNAL: case NEW: case OVERRIDE: case PARTIAL: case PUBLIC: case PROTECTED: case PRIVATE: case SELF: case STATIC: case STRUCT: case THEN: case TRANSIENT: case VIRTUAL: case EOS: case ID: case LBRACK: case SPLICE_BEGIN: { { { switch ( LA(1) ) { case EOL: case EOS: { eos(); break; } case ABSTRACT: case CALLABLE: case CLASS: case CONSTRUCTOR: case DEF: case DESTRUCTOR: case ENUM: case EVENT: case FINAL: case INTERFACE: case INTERNAL: case NEW: case OVERRIDE: case PARTIAL: case PUBLIC: case PROTECTED: case PRIVATE: case SELF: case STATIC: case STRUCT: case THEN: case TRANSIENT: case VIRTUAL: case ID: case LBRACK: case SPLICE_BEGIN: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { // ( ... )+ int _cnt76=0; for (;;) { bool synPredMatched75 = false; if (((LA(1)==SPLICE_BEGIN) && (tokenSet_37_.member(LA(2))))) { int _m75 = mark(); synPredMatched75 = true; inputState.guessing++; try { { splice_expression(); eos(); } } catch (RecognitionException) { synPredMatched75 = false; } rewind(_m75); inputState.guessing--; } if ( synPredMatched75 ) { splice_type_definition_body(members); } else if ((tokenSet_38_.member(LA(1))) && (tokenSet_39_.member(LA(2)))) { type_definition_member(members); } else { if (_cnt76 >= 1) { goto _loop76_breakloop; } else { throw new NoViableAltException(LT(1), getFilename());; } } _cnt76++; } _loop76_breakloop: ; } // ( ... )+ } break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } end(td); } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex, "class_definition"); recover(ex,tokenSet_22_); } else { throw ex; } } }
public object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { if (typeDeclaration.Templates.Count > 0) { AddError(typeDeclaration, "Generic type definitions are not supported."); } B.TypeDefinition oldType = currentType; B.TypeDefinition typeDef; switch (typeDeclaration.Type) { case ClassType.Class: typeDef = new B.ClassDefinition(GetLexicalInfo(typeDeclaration)); break; case ClassType.Interface: typeDef = new B.InterfaceDefinition(GetLexicalInfo(typeDeclaration)); break; case ClassType.Enum: typeDef = new B.EnumDefinition(GetLexicalInfo(typeDeclaration)); break; case ClassType.Struct: typeDef = new B.StructDefinition(GetLexicalInfo(typeDeclaration)); break; case ClassType.Module: typeDef = new B.ClassDefinition(GetLexicalInfo(typeDeclaration)); typeDeclaration.Modifier |= Modifiers.Static; break; default: AddError(typeDeclaration, "Unknown class type."); return(null); } if (currentType != null) { typeDef.Modifiers = ConvertModifier(typeDeclaration, B.TypeMemberModifiers.Private); } else { typeDef.Modifiers = ConvertModifier(typeDeclaration, B.TypeMemberModifiers.Internal); } typeDef.Name = typeDeclaration.Name; typeDef.EndSourceLocation = GetLocation(typeDeclaration.EndLocation); ConvertAttributes(typeDeclaration.Attributes, typeDef.Attributes); ConvertTypeReferences(typeDeclaration.BaseTypes, typeDef.BaseTypes); if (currentType != null) { currentType.Members.Add(typeDef); } else { module.Members.Add(typeDef); } currentType = typeDef; typeDeclaration.AcceptChildren(this, data); currentType = oldType; return(typeDef); }
public override void LeaveStructDefinition(StructDefinition node) { CheckName(node,node.Name); }
override public void OnStructDefinition(StructDefinition node) { VisitTypeDefinition(node); }