/* ---------- Pending --------
         * public TypeG Visit(IntegerLiteral node)
         * {
         *  //Console.WriteLine("Rock"+ node.ToStringTree());
         *  //Console.WriteLine("TIPOOOO");
         *  VisitChildren(node);
         *  //Console.WriteLine("FIN");
         *  return TypeG.VOID;
         * }
         *
         */


        public TypeG Visit(IdentifierList node)
        {
            //Console.WriteLine("Rock"+ node.ToStringTree());
            VisitChildren(node);
            //Console.WriteLine("FIN");
            return(TypeG.VOID);
        }
Example #2
0
 public void processAnnotations(Context context, bool processDerivedFrom)
 {
     if (processDerivedFrom)
     {
         IdentifierList derivedFrom = getDerivedFrom();
         if (derivedFrom != null)
         {
             foreach (String name in derivedFrom)
             {
                 CategoryDeclaration decl = context.getRegisteredDeclaration <CategoryDeclaration>(name);
                 if (decl != null)
                 {
                     decl.processAnnotations(context, true);
                 }
             }
         }
         if (Annotations != null)
         {
             foreach (Annotation a in Annotations)
             {
                 a.processCategory(context, this);
             }
         }
     }
 }
Example #3
0
 protected void protoToMDialect(CodeWriter writer, IdentifierList derivedFrom)
 {
     if (this.Storable)
     {
         writer.append("storable ");
     }
     categoryTypeToMDialect(writer);
     writer.append(" ");
     writer.append(name);
     writer.append("(");
     if (derivedFrom != null)
     {
         derivedFrom.ToDialect(writer, false);
         if (attributes != null)
         {
             writer.append(", ");
         }
     }
     if (attributes != null)
     {
         attributes.ToDialect(writer, false);
     }
     writer.append("):\n");
     writer.newLine();
 }
Example #4
0
 public LiteralElement()
   : base((NodeType)SpecSharpNodeType.None){
   this.AttributeNames = new IdentifierList();
   this.AttributeValues = new ExpressionList();
   this.Contents = new ExpressionList();
   this.ContentsType = new Int32List();
 }
Example #5
0
 public AttributeDeclaration(String name, IType type, IAttributeConstraint constraint, IdentifierList indexTypes)
     : base(name)
 {
     this.type       = type;
     this.constraint = constraint;
     this.indexTypes = indexTypes;
 }
Example #6
0
        public Node ParameterDeclaration()
        {
            var result = new ParameterDeclaration();

            var identifierList = new IdentifierList()
            {
                new Identifier()
                {
                    AnchorToken = Expect(TokenCategory.IDENTIFIER)
                }
            };

            result.Add(identifierList);

            while (CurrentToken == TokenCategory.COMA)
            {
                Expect(TokenCategory.COMA);
                identifierList.Add(new Identifier()
                {
                    AnchorToken = Expect(TokenCategory.IDENTIFIER)
                });
            }

            Expect(TokenCategory.COLON);
            result.Add(Type());
            Expect(TokenCategory.SEMICOLON);

            return(result);
        }
Example #7
0
 public NativeResourceDeclaration(String name,
                                  IdentifierList attributes,
                                  NativeCategoryBindingList categoryBindings,
                                  NativeAttributeBindingListMap attributeBindings,
                                  MethodDeclarationList methods)
     : base(name, attributes, categoryBindings, attributeBindings, methods)
 {
 }
Example #8
0
 public LiteralElement()
     : base((NodeType)SpecSharpNodeType.None)
 {
     this.AttributeNames  = new IdentifierList();
     this.AttributeValues = new ExpressionList();
     this.Contents        = new ExpressionList();
     this.ContentsType    = new Int32List();
 }
Example #9
0
 /// <summary>
 /// Walks the statement list of the given block gathering information from declarations for use by forward references. Does not recurse into nested blocks.
 /// </summary>
 /// <param name="block">The block whose declarations are to be processed</param>
 /// <param name="scope">Maps identifiers to Metadata nodes (e.g. Fields).</param>
 /// <param name="targetFor">Maps labels (Identifiers) to the corresponding labeled blocks (single statements are promoted to blocks for this purpose).</param>
 /// <param name="labelList">A list of all the labels encountered by Declarer.</param>
 public virtual void VisitBlock(Block block, Class scope, TrivialHashtable targetFor, IdentifierList labelList){
   if (block == null) return;
   this.scope = scope;
   this.targetFor = targetFor;
   this.labelList = labelList;
   StatementList statements = block.Statements;
   if (statements == null) return;
   for (int i = 0, n = statements.Count; i < n; i++)
     statements[i] = (Statement)this.Visit(statements[i]);
 }
Example #10
0
 public virtual SwitchCase VisitSwitchCase(SwitchCase switchCase, Class scope,
                                           TrivialHashtable targetFor, IdentifierList labelList)
 {
     if (switchCase == null)
     {
         return(null);
     }
     this.VisitBlock(switchCase.Body, scope, targetFor, labelList);
     return(switchCase);
 }
Example #11
0
 public NativeCategoryDeclaration(String name,
                                  IdentifierList attributes,
                                  NativeCategoryBindingList categoryBindings,
                                  NativeAttributeBindingListMap attributeBindings,
                                  MethodDeclarationList methods)
     : base(name, attributes, null, methods)
 {
     this.categoryBindings = categoryBindings;
     // this.attributeBindings = attributeBindings;
 }
Example #12
0
        public CategoryType getSuperType(Context context)
        {
            IDeclaration decl = getDeclaration(context);

            if (decl is CategoryDeclaration)
            {
                IdentifierList derived = ((CategoryDeclaration)decl).getDerivedFrom();
                if (derived != null && derived.Count > 0)
                {
                    return(new CategoryType(derived[0]));
                }
            }
            throw new SyntaxError("No super type for:" + GetTypeName());
        }
Example #13
0
        /// <summary>
        /// Walks the statement list of the given block gathering information from declarations for use by forward references. Does not recurse into nested blocks.
        /// </summary>
        /// <param name="block">The block whose declarations are to be processed</param>
        /// <param name="scope">Maps identifiers to Metadata nodes (e.g. Fields).</param>
        /// <param name="targetFor">Maps labels (Identifiers) to the corresponding labeled blocks (single statements are promoted to blocks for this purpose).</param>
        /// <param name="labelList">A list of all the labels encountered by Declarer.</param>
        public virtual void VisitBlock(Block block, Class scope, TrivialHashtable targetFor, IdentifierList labelList)
        {
            if (block == null)
            {
                return;
            }
            this.scope     = scope;
            this.targetFor = targetFor;
            this.labelList = labelList;
            StatementList statements = block.Statements;

            if (statements == null)
            {
                return;
            }
            for (int i = 0, n = statements.Count; i < n; i++)
            {
                statements[i] = (Statement)this.Visit(statements[i]);
            }
        }
Example #14
0
 public Looker(Scope scope, ErrorHandler errorHandler, TrivialHashtable scopeFor, TypeSystem typeSystem, TrivialHashtable ambiguousTypes, TrivialHashtable referencedLabels)
   : base(errorHandler){
   //TODO: verify that crucial system types have either been imported or defined by the Parser
   this.scope = scope;
   this.AddToAllScopes(this.scope);
   this.scopeFor = scopeFor;
   this.ambiguousTypes = ambiguousTypes;
   this.referencedLabels = referencedLabels;
   this.alreadyReported = new TrivialHashtable();
   this.hasExplicitBaseClass = new TrivialHashtable();
   this.typesToKeepUninstantiated = new TrivialHashtable();
   this.UsedNamespaces = new UsedNamespaceList();
   this.targetFor = new TrivialHashtable();
   this.labelList = new IdentifierList();
   this.AbstractSealedUsedAsType = Error.NotAType;
   Debug.Assert(typeSystem != null);
   this.typeSystem = typeSystem;
   this.useGenerics = TargetPlatform.UseGenerics;
   this.inMethodParameter = false;
   this.inEventContext = false;
 }
Example #15
0
        public List <Annotation> GetAllAnnotations(Context context)
        {
            List <Annotation> result      = new List <Annotation>();
            IdentifierList    derivedFrom = getDerivedFrom();

            if (derivedFrom != null)
            {
                foreach (String name in derivedFrom)
                {
                    CategoryDeclaration decl = context.getRegisteredDeclaration <CategoryDeclaration>(name);
                    if (decl != null)
                    {
                        result.AddRange(decl.GetAllAnnotations(context));
                    }
                }
            }
            if (Annotations != null)
            {
                result.AddRange(Annotations);
            }
            return(result);
        }
Example #16
0
        public void testAnonymousAnyTypeWithAttribute()
        {
            // any x with attribute name
            IdentifierList list     = new IdentifierList("name");
            IParameter     argument = new ExtendedParameter(AnyType.Instance, "x", list);

            argument.register(context);
            IType st = argument.GetIType(context);

            Assert.IsTrue(st is CategoryType);
            Assert.IsFalse(st.isAssignableFrom(context, BooleanType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, IntegerType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, DecimalType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, TextType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, DateType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, DateTimeType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, MissingType.Instance));
            Assert.IsFalse(st.isAssignableFrom(context, AnyType.Instance));                     // any type never compatible
            Assert.IsTrue(st.isAssignableFrom(context, new CategoryType("Simple")));            // since Simple has a name
            Assert.IsFalse(st.isAssignableFrom(context, new CategoryType("Root")));             // since Root has no name
            Assert.IsFalse(st.isAssignableFrom(context, new CategoryType("DerivedWithOther"))); // since DerivedWithOther has no name
            Assert.IsTrue(st.isAssignableFrom(context, new CategoryType("DerivedWithName")));   // since DerivedWithName has a name
        }
Example #17
0
        public Node ParamDeclaration()
        {
            var result = new ParamDeclaration();
            var idList = new IdentifierList();

            idList.Add(new Identifier()
            {
                AnchorToken = Expect(TokenCategory.IDENTIFIER)
            });
            while (CurrentToken != TokenCategory.TWOPOINTS)
            {
                Expect(TokenCategory.COMA);
                idList.Add(new Identifier()
                {
                    AnchorToken = Expect(TokenCategory.IDENTIFIER)
                });
            }
            result.Add(idList);
            Expect(TokenCategory.TWOPOINTS);
            result.Add(ChimeraType());
            Expect(TokenCategory.SEMICOL);
            return(result);
        }
Example #18
0
        Lexem Identifier(ref int row, string substring)
        {
            Idnt tempIdnt = IdentifierList.Find(x => x.Name == substring);

            if (tempIdnt != null)
            {
                LexemList.Add(new Lexem(row, tempIdnt.Name, 34, indexIdnt: tempIdnt.Index)); return(null);
            }
            else
            {
                if (LexemList.Count == 0)
                {
                    throw new Exception("Identifier can`t be first");
                }

                Lexem temp = LexemList.Last <Lexem>();
                if (temp.Code == 30)
                {
                    IdentifierList.Add(new Idnt(substring, IdentifierList.Count, "int"));
                }
                else if (temp.Code == 31)
                {
                    IdentifierList.Add(new Idnt(substring, IdentifierList.Count, "float"));
                }
                else if (temp.Code == 0)
                {
                    IdentifierList.Add(new Idnt(substring, IdentifierList.Count, "program"));
                }
                else
                {
                    throw new Exception($"Opps,I see a problem.Maybe you forgot about type 'int', 'float'or 'program' type in row {row} near '{substring}'");
                }
            }
            LexemList.Add(new Lexem(row, substring, 34, indexIdnt: IdentifierList.Count - 1));
            return(null);
        }
Example #19
0
 public override void ForEachId(Action <Identifier> Func)
 {
     IdentifierList.ForEach(Func);
     base.ForEachId(Func);
 }
Example #20
0
        private void ParserLine(List <LexicalUnit> lexUnitInRowList)
        {
            int   tempInt;
            float tempFloat;

            foreach (var unit in lexUnitInRowList)
            {
                //if we have this lexem in reserved lexem
                tempInt = Check.IsReservedLexem(unit.Substring);
                if (tempInt >= 0)
                {
                    LexemList.Add(new Lexem(unit.Row, unit.Substring, tempInt));
                    continue;
                }

                //if this lexem is a constant
                if (float.TryParse(unit.Substring.Replace('.', ','), out tempFloat))
                {
                    if (int.TryParse(unit.Substring, out tempInt))
                    {
                        var const_ = ConstantList.Find(x => x._Const == tempInt);

                        if (const_ != null)
                        {
                            LexemList.Add(new Lexem(unit.Row, unit.Substring, 38, indexConst: const_.Index));
                        }
                        else
                        {
                            ConstantList.Add(new Const(tempInt, ConstantList.Count, "int"));
                            LexemList.Add(new Lexem(unit.Row, unit.Substring, 38, indexConst: ConstantList.Count - 1));
                        }
                    }
                    else
                    {
                        var const_ = ConstantList.Find(x => x._Const == tempInt);

                        if (const_ != null)
                        {
                            LexemList.Add(new Lexem(unit.Row, unit.Substring, 38, indexConst: const_.Index));
                        }
                        else
                        {
                            ConstantList.Add(new Const(tempInt, ConstantList.Count, "float"));
                            LexemList.Add(new Lexem(unit.Row, unit.Substring, 38, indexConst: ConstantList.Count - 1));
                        }
                    }
                    continue;
                }

                //if this lexem is a idnt;
                Idnt tempIdnt = IdentifierList.Find(x => x.Name == unit.Substring);
                if (tempIdnt != null)
                {
                    LexemList.Add(new Lexem(unit.Row, tempIdnt.Name, 35, indexIdnt: tempIdnt.Index));
                }
                else
                {
                    if (lexUnitInRowList.Exists(x => (x.Substring.Contains("float"))) &&
                        (lexUnitInRowList.Exists(x => x.Substring.Contains("="))))
                    {
                        IdentifierList.Add(new Idnt(unit.Substring, IdentifierList.Count, "float"));
                        LexemList.Add(new Lexem(unit.Row, unit.Substring, 35, indexIdnt: IdentifierList.Count - 1));
                    }


                    else if (lexUnitInRowList.Exists(x => (x.Substring.Contains("int"))) &&
                             (lexUnitInRowList.Exists(x => x.Substring.Contains("="))))
                    {
                        IdentifierList.Add(new Idnt(unit.Substring, IdentifierList.Count, "int"));
                        LexemList.Add(new Lexem(unit.Row, unit.Substring, 35, indexIdnt: IdentifierList.Count - 1));
                    }


                    else if ((lexUnitInRowList.Exists(x => x.Substring.Contains("program"))))
                    {
                        IdentifierList.Add(new Idnt(unit.Substring, IdentifierList.Count, "program"));
                        LexemList.Add(new Lexem(unit.Row, unit.Substring, 35, indexIdnt: IdentifierList.Count - 1));
                    }

                    else
                    {
                        throw new Exception($"not defined variable {unit.Substring} ");
                    }
                }
            }
        }
Example #21
0
 public CategoryDeclaration(String name, IdentifierList attributes)
     : base(name)
 {
     this.attributes = attributes;
 }
Example #22
0
 public SingletonCategoryDeclaration(String name, IdentifierList attributes, MethodDeclarationList methods)
     : base(name, attributes, null, methods)
 {
 }
Example #23
0
 public virtual SwitchCase VisitSwitchCase(SwitchCase switchCase, Class scope, 
   TrivialHashtable targetFor, IdentifierList labelList){
   if (switchCase == null) return null;
   this.VisitBlock(switchCase.Body, scope, targetFor, labelList);
   return switchCase;
 }
Example #24
0
 public AssignTupleStatement(IdentifierList names, IExpression expression)
 {
     this.names      = names;
     this.expression = expression;
 }
Example #25
0
 public ExtendedParameter(IType type, String name, IdentifierList attributes)
     : base(type, name)
 {
     this.attributes = attributes;
 }
Example #26
0
 public virtual void ConstructMethodForNestedFunction(Node func, Method method, TypeNode returnType, ParameterList parList, Block body){
   if (!(this.scope is BlockScope || this.scope is MethodScope)){Debug.Assert(false); return;}
   Scope savedScope = this.scope;
   TrivialHashtable savedOuterTargetFor = this.outerTargetFor;
   this.outerTargetFor = this.targetFor;
   this.targetFor = new TrivialHashtable();
   IdentifierList savedLabelList = this.labelList;
   this.labelList = new IdentifierList();
   Class closureClass = savedScope is BlockScope ? ((BlockScope)savedScope).ClosureClass : ((MethodScope)savedScope).ClosureClass;
   method.SourceContext = func.SourceContext;
   if (body != null && body.SourceContext.Document != null) {
     method.SourceContext.EndPos = body.SourceContext.EndPos;
     Debug.Assert(method.SourceContext.EndPos >= method.SourceContext.StartPos);
   }
   method.Flags = MethodFlags.CompilerControlled;
   // It turns out that nested functions might be nested within a class and not within a method
   // This happens when, e.g., a comprehension appears in a field initializer.
   // The resulting anonymous nested function must be static to generate verifiable code.
   if (this.currentMethod != null){
     method.CallingConvention = CallingConventionFlags.HasThis;
   }else{
     method.Flags |= MethodFlags.Static;
   }
   method.InitLocals = true;
   method.DeclaringType = closureClass;
   if (closureClass == null) method.DeclaringType = this.currentType;
   TypeNodeList methodTemplParams = this.currentMethod == null ? null : this.currentMethod.TemplateParameters;
   TypeNodeList closureTemplParams = closureClass == null ? null : closureClass.TemplateParameters;
   int numTemplateParams = methodTemplParams == null ? 0 : methodTemplParams.Count;
   if (closureTemplParams == null)
     numTemplateParams = 0;
   else if (closureTemplParams.Count < numTemplateParams)
     numTemplateParams = closureTemplParams.Count;
   Class scope = this.scope = method.Scope = new MethodScope(this.scope, this.UsedNamespaces, method);
   this.AddToAllScopes(this.scope);
   this.inMethodParameter = true;
   ParameterList methPars = new ParameterList();
   for (int i = 0, n = parList == null ? 0 : parList.Count; i < n; i++){
     Parameter p = parList[i];
     if (p == null) continue;
     methPars.Add(p);
     TypeNode pType = p.Type = this.VisitTypeReference(p.Type, true);
     if (pType == null) continue;
     if (pType is MethodTypeParameter || pType is MethodClassParameter) {
       for (int j = 0; j < numTemplateParams; j++) {
         if (methodTemplParams[j] == pType) {
           //pType = closureTemplParams[j];
           //Parameter mp = (Parameter)p.Clone();
           //mp.Type = pType;
           //methPars[methPars.Count-1] = mp;
           break;
         }
       }
     }
     ParameterField f = new ParameterField();
     f.Parameter = p;
     f.Flags = FieldFlags.CompilerControlled;
     f.Name = p.Name;
     f.Type = pType;
     f.DeclaringType = scope;
     scope.Members.Add(f);
   }
   this.inMethodParameter = false;
   method.Parameters = methPars;
   method.ReturnType = this.VisitTypeReference(returnType, true);
   Method savedMethod = this.currentMethod;
   this.currentMethod = method;
   method.Body = this.VisitBlock(body);
   if (returnType == null) method.ReturnType = null;
   this.currentMethod = savedMethod;
   this.scope = savedScope;
   this.targetFor = this.outerTargetFor;
   this.outerTargetFor = savedOuterTargetFor;
   this.labelList = savedLabelList;
 }
Example #27
0
 public void setDerivedFrom(IdentifierList derivedFrom)
 {
     this.derivedFrom = derivedFrom;
 }
Example #28
0
 public ArrowExpression(IdentifierList args, String argsSuite, String arrowSuite)
 {
     this.Arguments  = args;
     this.ArgsSuite  = argsSuite;
     this.ArrowSuite = arrowSuite;
 }
Example #29
0
 public EnumeratedCategoryDeclaration(String name, IdentifierList attrs, IdentifierList derived, CategorySymbolList symbols)
     : base(name, attrs, derived, null)
 {
     type = new EnumeratedCategoryType(name);
     setSymbols(symbols);
 }
Example #30
0
 public void setAttributes(IdentifierList attributes)
 {
     this.attributes = attributes;
 }
Example #31
0
 public ConcreteCategoryDeclaration(String name, IdentifierList attrs, IdentifierList derivedFrom, MethodDeclarationList methods)
     : base(name, attrs)
 {
     this.derivedFrom = derivedFrom;
     this.methods     = methods != null ? methods : new MethodDeclarationList();
 }