Example #1
0
 private void AddNode(TreeIter parent, UserDefinedNode userDefinedNode)
 {
     store.AppendValues(parent, "user defined", userDefinedNode);
 }
Example #2
0
        public void Define(RuntimeState state)
        {
            AbstractPattern basePattern;
            
            Type baseType;

            if (this.baseType != null)
            {
                baseType = (Type) this.baseType.Get(state);
                basePattern = (AbstractPattern) Pattern.PatternForType(baseType);
            }
            else
            {
                baseType = typeof(RuntimeObject);
                basePattern = null;
            }

            ClassBuilder classBuilder = new ClassBuilder(
                state.Runtime.CompilerModule,
                state.Scope.GetModule(),
                name.name,
                baseType);

            // Go through members
            
            if (members != null)
            {
                foreach (object member in members)
                    ((Member) member).Build(state, classBuilder);
            }
            
            UserDefinedNode userDefined = null;;
            
            if (classBuilder.Pattern == null)
            {
                bool parseMethod = false;;
                
                foreach (Method method in classBuilder.Methods)
                    if (method.Name == "Parse")
                    {
                        parseMethod = true;
                        break;
                    }
                
                if (parseMethod)
                {
                    userDefined = new UserDefinedNode(Source,
                        null);
                    
                    classBuilder.Pattern = new ConcretePattern(Source,
                        name.name, userDefined);
                }
                else
                    classBuilder.Pattern = new AbstractPattern(Source,
                        classBuilder.TypeBuilder.Name);
            }

            // Create the class, which closes the pattern, and define the pattern

            Type type = classBuilder.CreateType();
            state.Runtime.Grammar.PatternDefined(classBuilder.Pattern);

            state.Scope.SetName(name.name, type);
            
            if (userDefined != null)
                userDefined.Type = type;

            // Add a concrete class as an alt to its abstract

            if (basePattern != null)
            {
                basePattern.AddAltPattern(classBuilder.Pattern);
                basePattern.Updated();
            }
        }