public BooClassBuilder CreateClass(string name, TypeMemberModifiers modifiers) { BooClassBuilder builder = CreateClass(name); builder.Modifiers = modifiers; return(builder); }
public GeneratorMethodProcessor(CompilerContext context, InternalMethod method) { _labels = new List(); _mapping = new Hashtable(); _generator = method; _generatorItemType = (IType)_generator.Method["GeneratorItemType"]; _enumerable = (BooClassBuilder)_generator.Method["GeneratorClassBuilder"]; Debug.Assert(null != _generatorItemType); Debug.Assert(null != _enumerable); Initialize(context); }
public ClassDefinition GetCompilerGeneratedExtensionsClass() { if (null == _compilerGeneratedExtensionsClass) { BooClassBuilder builder = CodeBuilder.CreateClass("CompilerGeneratedExtensions"); builder.Modifiers = TypeMemberModifiers.Final | TypeMemberModifiers.Transient | TypeMemberModifiers.Public; builder.AddBaseType(ObjectType); BooMethodBuilder ctor = builder.AddConstructor(); ctor.Modifiers = TypeMemberModifiers.Private; ctor.Body.Add( CodeBuilder.CreateSuperConstructorInvocation(ObjectType)); ClassDefinition cd = builder.ClassDefinition; Module module = GetCompilerGeneratedExtensionsModule(); module.Members.Add(cd); ((ModuleEntity)module.Entity).InitializeModuleClass(cd); _compilerGeneratedExtensionsClass = cd; } return(_compilerGeneratedExtensionsClass); }
Field DeclareFieldInitializedFromConstructorParameter(BooClassBuilder type, BooMethodBuilder constructor, string parameterName, IType parameterType) { Field field = type.AddInternalField("$" + parameterName + _context.AllocIndex(), parameterType); InitializeFieldFromConstructorParameter(constructor, field, parameterName, parameterType); return field; }
void CreateEnumerator() { IType abstractEnumeratorType = TypeSystemServices.Map(typeof(Boo.Lang.GenericGeneratorEnumerator<>)). GenericInfo.ConstructType(new IType[] {_generatorItemType}); _state = NameResolutionService.ResolveField(abstractEnumeratorType, "_state"); _yield = NameResolutionService.ResolveMethod(abstractEnumeratorType, "Yield"); _enumerator = CodeBuilder.CreateClass("$"); _enumerator.AddAttribute(CodeBuilder.CreateAttribute(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute))); _enumerator.Modifiers |= TypeMemberModifiers.Final; _enumerator.LexicalInfo = this.LexicalInfo; _enumerator.AddBaseType(abstractEnumeratorType); _enumerator.AddBaseType(TypeSystemServices.IEnumeratorType); CreateEnumeratorConstructor(); CreateMoveNext(); _enumerable.ClassDefinition.Members.Add(_enumerator.ClassDefinition); //new Boo.Lang.Compiler.Ast.Visitors.BooPrinterVisitor(System.Console.Out).Visit(_enumerator.ClassDefinition); }
BooMethodBuilder CreateConstructor(BooClassBuilder builder) { BooMethodBuilder constructor = builder.AddConstructor(); constructor.Body.Add(CodeBuilder.CreateSuperConstructorInvocation(builder.Entity.BaseType)); return constructor; }
void CreateAnonymousGeneratorType() { _enumerable = (BooClassBuilder)_generator["GeneratorClassBuilder"]; // Set up some important types _sourceItemType = TypeSystemServices.ObjectType; _sourceEnumeratorType = TypeSystemServices.IEnumeratorType; _sourceEnumerableType = TypeSystemServices.IEnumerableType; _resultItemType = (IType)_generator["GeneratorItemType"]; _resultEnumeratorType = TypeSystemServices.IEnumeratorGenericType.GenericInfo.ConstructType(_resultItemType); _enumerator = _collector.CreateSkeletonClass("Enumerator",_generator.LexicalInfo); // use a generic enumerator for the source type if possible _sourceItemType = TypeSystemServices.GetGenericEnumerableItemType(_generator.Iterator.ExpressionType); if (_sourceItemType != null && _sourceItemType != TypeSystemServices.ObjectType) { _sourceEnumerableType = TypeSystemServices.IEnumerableGenericType.GenericInfo.ConstructType(_sourceItemType); _sourceEnumeratorType = TypeSystemServices.IEnumeratorGenericType.GenericInfo.ConstructType(_sourceItemType); } else { _sourceItemType = TypeSystemServices.ObjectType; } // Add base types _enumerator.AddBaseType(_resultEnumeratorType); _enumerator.AddBaseType(TypeSystemServices.Map(typeof(ICloneable))); _enumerator.AddBaseType(TypeSystemServices.Map(typeof(IDisposable))); // Add fields _enumeratorField = _enumerator.AddField("$$enumerator", _sourceEnumeratorType); _current = _enumerator.AddField("$$current", _resultItemType); // Add methods CreateReset(); CreateCurrent(); CreateMoveNext(); CreateClone(); CreateDispose(); EnumeratorConstructorMustCallReset(); _collector.AdjustReferences(); _collector.DeclareFieldsAndConstructor(_enumerable); CreateGetEnumerator(); _enumerable.ClassDefinition.Members.Add(_enumerator.ClassDefinition); }
public void DeclareFieldsAndConstructor(BooClassBuilder builder) { // referenced entities turn into fields foreach (ITypedEntity entity in Builtins.array(_referencedEntities.Keys)) { Field field = builder.AddInternalField("__" + entity.Name + _context.AllocIndex(), entity.Type); _referencedEntities[entity] = field.Entity; } // single constructor taking all referenced entities BooMethodBuilder constructor = builder.AddConstructor(); constructor.Modifiers = TypeMemberModifiers.Public; constructor.Body.Add(CodeBuilder.CreateSuperConstructorInvocation(builder.Entity.BaseType)); foreach (ITypedEntity entity in _referencedEntities.Keys) { InternalField field = (InternalField)_referencedEntities[entity]; ParameterDeclaration parameter = constructor.AddParameter(field.Name, entity.Type); constructor.Body.Add( CodeBuilder.CreateAssignment(CodeBuilder.CreateReference(field), CodeBuilder.CreateReference(parameter))); } }