Beispiel #1
0
        public override void Visit(EnumAST enumAST)
        {
            var typeInfo = new CustomTypeInfo
            {
                type           = enumAST,
                kind           = TypeKind.ENUM,
                scopeId        = _currentScope.id,
                position       = _currentNodePosition,
                memberNameType = new Dictionary <string, TypeAST>()
            };

            foreach (var member in enumAST.Values)
            {
                var variableDec = member as VariableDecAST;

                typeInfo.memberNameType.Add(variableDec.Name, variableDec.Type);
            }

            AddType(typeInfo);

            if (_currentScope.id != 0)
            {
                return;
            }

            GlobalTypes.Add(enumAST.Name);
        }
Beispiel #2
0
        private void AddType(CustomTypeInfo typeInfo)
        {
            /* ATM all types are declared in the global scope so they must have different names */
            if (_symTable.TypeInfoDictionary.ContainsKey(typeInfo.type.ToString()))
            {
                throw new Exception(string.Format("Identifier already declared {0} in file {1} line {2}",
                                                  typeInfo.type.ToString(), _symTable.FilePath, _currentNodePosition));
            }

            _symTable.TypeInfoDictionary.Add(typeInfo.type.ToString(), typeInfo);
        }