Index: asp3_wo_tecs/trunk/cfg/pass1.rb
===================================================================
--- asp3_wo_tecs/trunk/cfg/pass1.rb	(revision 305)
+++ asp3_wo_tecs/trunk/cfg/pass1.rb	(revision 306)
@@ -51,5 +51,5 @@
 #  ã®è²¬ä»»ãè² ããªãï¼
 #
-#  $Id: pass1.rb 32 2016-01-31 14:45:59Z ertl-hiro $
+#  $Id: pass1.rb 126 2016-05-03 06:53:08Z ertl-hiro $
 #
 
@@ -62,19 +62,19 @@
 #
 $symbolValueTable = {
-  "CHAR_BIT" => { :EXPR => "CHAR_BIT" },
-  "SCHAR_MAX" => { :EXPR => "SCHAR_MAX", :SIGNED => true },
-  "SCHAR_MIN" => { :EXPR => "SCHAR_MIN", :SIGNED => true },
-  "UCHAR_MAX" => { :EXPR => "UCHAR_MAX" },
-  "CHAR_MAX" => { :EXPR => "CHAR_MAX", :SIGNED => true },
-  "CHAR_MIN" => { :EXPR => "CHAR_MIN", :SIGNED => true },
-  "SHRT_MAX" => { :EXPR => "SHRT_MAX", :SIGNED => true },
-  "SHRT_MIN" => { :EXPR => "SHRT_MIN", :SIGNED => true },
-  "USHRT_MAX" => { :EXPR => "USHRT_MAX" },
-  "INT_MAX" => { :EXPR => "INT_MAX", :SIGNED => true },
-  "INT_MIN" => { :EXPR => "INT_MIN", :SIGNED => true },
-  "UINT_MAX" => { :EXPR => "UINT_MAX" },
-  "LONG_MAX" => { :EXPR => "LONG_MAX", :SIGNED => true },
-  "LONG_MIN" => { :EXPR => "LONG_MIN", :SIGNED => true },
-  "ULONG_MAX" => { :EXPR => "ULONG_MAX" }
+  "CHAR_BIT"  => { EXPR: "CHAR_BIT" },
+  "SCHAR_MAX" => { EXPR: "SCHAR_MAX", SIGNED: true },
+  "SCHAR_MIN" => { EXPR: "SCHAR_MIN", SIGNED: true },
+  "UCHAR_MAX" => { EXPR: "UCHAR_MAX" },
+  "CHAR_MAX"  => { EXPR: "CHAR_MAX",  SIGNED: true },
+  "CHAR_MIN"  => { EXPR: "CHAR_MIN",  SIGNED: true },
+  "SHRT_MAX"  => { EXPR: "SHRT_MAX",  SIGNED: true },
+  "SHRT_MIN"  => { EXPR: "SHRT_MIN",  SIGNED: true },
+  "USHRT_MAX" => { EXPR: "USHRT_MAX" },
+  "INT_MAX"   => { EXPR: "INT_MAX",   SIGNED: true },
+  "INT_MIN"   => { EXPR: "INT_MIN",   SIGNED: true },
+  "UINT_MAX"  => { EXPR: "UINT_MAX" },
+  "LONG_MAX"  => { EXPR: "LONG_MAX",  SIGNED: true },
+  "LONG_MIN"  => { EXPR: "LONG_MIN",  SIGNED: true },
+  "ULONG_MAX" => { EXPR: "ULONG_MAX" }
 }
 
@@ -90,4 +90,9 @@
 def ReadApiTableFile
   $apiTableFileNames.each do |apiTableFileName|
+    if /^(.+):(\w+)$/ =~ apiTableFileName
+      apiTableFileName = $1
+      apiPhase = $2.to_sym
+    end
+
     if !File.exist?(apiTableFileName)
       error_exit("`#{apiTableFileName}' not found")
@@ -99,7 +104,17 @@
       next if /^#/ =~ line			# ã³ã¡ã³ããã¹ã­ãã
 
-      fields = line.split(/\s+/)
-      staticApi = fields.shift
-      apiDef = { :API => staticApi }
+      fields = line.split(/\s+/)	# ãã£ã¼ã«ãã«åè§£
+
+      apiName = fields.shift		# APIåã®åãåºã
+      if /^(.+)\[(.+)\]$/ =~ apiName
+        apiName = $1
+        apiDef = { APINAME: apiName, API: $2 }
+      else
+        apiDef = { APINAME: apiName, API: apiName }
+      end
+      if !apiPhase.nil?
+        apiDef[:PHASE] = apiPhase
+      end
+
       apiParams = []
       fields.each do |param|
@@ -118,6 +133,7 @@
             apiParam[:ID_REF] = true
           when "."					# ç¬¦å·ç¡ãæ´æ°å®æ°å¼ãã©ã¡ã¼ã¿
-            apiParam[:UNSIGNED] = true
+            apiParam[:EXPTYPE] = "unsigned_t"
           when "+"					# ç¬¦å·ä»ãæ´æ°å®æ°å¼ãã©ã¡ã¼ã¿
+            apiParam[:EXPTYPE] = "signed_t"
             apiParam[:SIGNED] = true
           when "&"					# ä¸è¬æ´æ°å®æ°å¼ãã©ã¡ã¼ã¿
@@ -138,6 +154,11 @@
           end
         
-        when /^([{}])$/				# {ã¨}
-          apiParam = { :BRACE => $1 }
+        when "{"					# {
+          apiParam = { :BRACE => "{" }
+        when "{?"					# {?
+          apiParam = { :BRACE => "{", :OPTBRACE => true }
+
+        when "}"					# }
+          apiParam = { :BRACE => "}" }
 
         else
@@ -147,5 +168,5 @@
       end
       apiDef[:PARAM] = apiParams
-      $apiDefinition[staticApi] = apiDef
+      $apiDefinition[apiName] = apiDef
     end
     apiFile.close
@@ -174,5 +195,5 @@
 
       # å¼
-      if record[1].nil? || record[1] == ""
+      if record[1].nil? || record[1].empty?
         symbol[:EXPR] = variable
       else
@@ -180,14 +201,25 @@
       end
 
-      # ç¬¦å·ãã©ã°
-      if !(record[2].nil? || record[2] == "" || /^[uU]/ =~ record[2])
-        symbol[:SIGNED] = true
+      # å¼ã®å
+      if !record[2].nil? && !record[2].empty?
+        case record[2]
+        when /^[bB]/				# çå½å¤
+          symbol[:BOOL] = true
+        when /^[uU]/				# ç¬¦å·ç¡ãæ´æ°å¤
+          # ä½ãè¨­å®ããªã
+        else						# ç¬¦å·ä»ãæ´æ°å¤
+          symbol[:SIGNED] = true
+        end
       end
 
       # ã³ã³ãã¤ã«æ¡ä»¶
-      symbol[:CONDITION] = record[3]
-
-      # ã³ã³ãã¤ã«æ¡ä»¶ãæºããããªãæã®ããã©ã«ãå¤
-      symbol[:DEFAULT] = record[4]
+      if !record[3].nil? && !record[3].empty?
+        symbol[:CONDITION] = record[3]
+      end
+
+      # æ¡ä»¶ãæç«ããªãæã®å¼
+      if !record[4].nil? && !record[4].empty?
+        symbol[:ELSE_EXPR] = record[4]
+      end
 
       $symbolValueTable[variable] = symbol
@@ -218,5 +250,5 @@
   def getNextLine(withinApi)
     line = @cfgFile.gets
-    return nil if line.nil?
+    return(nil) if line.nil?
     @lineNo += 1
 
@@ -265,4 +297,7 @@
 class CfgParser
   @@lastApiIndex = 0
+  @@currentDomain = nil
+  @@currentClass = nil
+  @@nestDC = []
 
   def initialize
@@ -324,4 +359,27 @@
 
   #
+  #  æ¹è¡ã¨ç©ºç½æå­ãèª­ã¿é£ã°ã
+  #
+  def skipSpace(cfgFile, withinApi)
+    loop do
+      return if @line.nil?						# ãã¡ã¤ã«æ«ã§ããã°ãªã¿ã¼ã³
+      @line.lstrip!								# å
+é ­ã®ç©ºç½ãåé¤
+      return if @line != ""						# ç©ºè¡ã§ãªããã°ãªã¿ã¼ã³
+      @line = cfgFile.getNextLine(withinApi)	# æ¬¡ã®è¡ãèª­ã
+    end
+  end
+
+  #
+  #  æ¬¡ã®æå­ã¾ã§èª­ã¿é£ã°ã
+  #
+  def skipToToken(cfgFile, withinApi=true)
+    skipSpace(cfgFile, withinApi)
+    if @line.nil?							# ãã¡ã¤ã«æ«ã§ããã°ã¨ã©ã¼çµäº
+      error_exit("unexpexced end-of-file")
+    end
+  end
+
+  #
   #  ãã©ã¡ã¼ã¿ã1ã¤èª­ã
   #
@@ -334,17 +392,8 @@
     param = ""								# èª­ãã æå­å
     parenLevel = 0							# æ¬å¼§ã®ãã¹ãã¬ãã«
-  
     skipComma = @skipComma
     @skipComma = false
 
-    @line.lstrip!							# å
-é ­ã®ç©ºç½ãåé¤
-    while @line == ""						# ç©ºè¡ãèª­ã¿é£ã°ã
-      @line = cfgFile.getNextLine(true)
-      return nil if @line.nil?				# ãã¡ã¤ã«æ«ã§ããã°ãªã¿ã¼ã³
-      @line.lstrip!							# å
-é ­ã®ç©ºç½ãåé¤
-    end
-
+    skipToToken(cfgFile)					# æ¬¡ã®æå­ã¾ã§èª­ã¿é£ã°ã
     begin
       if parenLevel == 0
@@ -356,9 +405,9 @@
             return(parseParam(cfgFile))		# åå¸°å¼ã³åºã
           else
-            return(param)
+            return(param.strip)
           end
         when /^(\s*{)(.*)$/					# {
           if param != ""
-            return(param)
+            return(param.strip)
           else
             @line = $2
@@ -371,5 +420,5 @@
         when /^(\s*([)}]))(.*)$/			# }ã)
           if param != ""
-            return(param)
+            return(param.strip)
           else
             @line = $3
@@ -387,5 +436,5 @@
           @line = $2
         else								# è¡æ«
-          param += "\n"
+          param += " "
           @line = cfgFile.getNextLine(true)
         end
@@ -412,70 +461,137 @@
           @line = $2
         else								# è¡æ«
-          param += "\n"
+          param += " "
           @line = cfgFile.getNextLine(true)
         end
       end
     end while (@line)
-    return(param)
-  end
-
-  def parseApi(cfgFile)
+    return(param.strip)
+  end
+
+  def getParam(apiParam, param, cfgFile)
+    if param == ""
+      if !apiParam.has_key?(:OPTIONAL)
+        parse_error(cfgFile, "unexpected `,'")
+      end
+      return(param)
+    end
+
+    if apiParam.has_key?(:ID_DEF) || apiParam.has_key?(:ID_REF)
+      if (/^[A-Za-z_]\w*$/ !~ param)
+        parse_error(cfgFile, "`#{param}' is illegal object ID")
+      end
+      return(param)
+    end
+
+    if apiParam.has_key?(:STRING)
+      return(param.unquote)
+    else
+      return(param)
+    end
+  end
+
+  def parseApi(cfgFile, apiName)
     # éçAPIã®èª­ã¿è¾¼ã¿
     staticApi = {}
-    if (/^([A-Z_]+)\s*\((.*)$/ =~ @line)
-      apiName = $1
-      @line = $2
-
-      if $apiDefinition.has_key?(apiName)
-        staticApi[:API] = apiName
-        staticApi[:_FILE_] = cfgFile.getFileName
-        staticApi[:_LINE_] = cfgFile.getLineNo
-		apiDef = $apiDefinition[apiName]
-        param = parseParam(cfgFile)
-
-        apiDef[:PARAM].each do |apiParam|
-          if param.nil?						# ãã¡ã¤ã«æ«ã§ããã°ãªã¿ã¼ã³
-            error_exit("unexpexced end-of-file")
-            return(staticApi)
-          end
+    tooFewParams = false
+    skipUntilBrace = 0
+
+    skipToToken(cfgFile)					# æ¬¡ã®æå­ã¾ã§èª­ã¿é£ã°ã
+    if (/^\((.*)$/ =~ @line)
+      @line = $1
+
+      staticApi[:APINAME] = apiName
+      staticApi[:_FILE_] = cfgFile.getFileName
+      staticApi[:_LINE_] = cfgFile.getLineNo
+      apiDef = $apiDefinition[apiName]
+      param = parseParam(cfgFile)
+
+      apiDef[:PARAM].each do |apiParam|
+        return(staticApi) if param.nil?		# ãã¡ã¤ã«æ«ã§ããã°ãªã¿ã¼ã³
+
+        if skipUntilBrace > 0
+          # APIå®ç¾©ã}ã¾ã§ã¹ã­ããä¸­
           if apiParam.has_key?(:BRACE)
-            if param != apiParam[:BRACE]
-              parse_error(cfgFile, "'#{apiParam[:BRACE]}' expected")
+            case apiParam[:BRACE]
+            when "{"
+              skipUntilBrace += 1
+            when "}"
+              skipUntilBrace -= 1
+            end
+          end
+        elsif apiParam.has_key?(:OPTIONAL)
+          if /^([{})])$/ !~ param
+            store_param = getParam(apiParam, param, cfgFile)
+            if store_param != ""
+              staticApi[apiParam[:NAME]] = store_param
             end
             param = parseParam(cfgFile)
-          elsif apiParam.has_key?(:LIST)
-            staticApi[apiParam[:NAME]] = []
-            while /^([{})])$/ !~ param
-              if apiParam.has_key?(:STRING)
-                staticApi[apiParam[:NAME]].push(param.unquote)
-              else
-                staticApi[apiParam[:NAME]].push(param)
-              end
+          end
+        elsif apiParam.has_key?(:LIST)
+          staticApi[apiParam[:NAME]] = []
+          while /^([{})])$/ !~ param
+            staticApi[apiParam[:NAME]].push(getParam(apiParam, param, cfgFile))
+            param = parseParam(cfgFile)
+            break if param.nil?				# ãã¡ã¤ã«æ«ã®å ´å
+          end
+        elsif apiParam.has_key?(:OPTBRACE)
+          if param == apiParam[:BRACE]
+            param = parseParam(cfgFile)
+            break if param.nil?				# ãã¡ã¤ã«æ«ã®å ´å
+          else
+            if param == ""
               param = parseParam(cfgFile)
+              break if param.nil?			# ãã¡ã¤ã«æ«ã®å ´å
+            elsif /^([})])$/ !~ param
+              parse_error(cfgFile, "`{...}' expected before #{param}")
             end
-          elsif /^([{}])$/ =~ param
-            if !apiParam.has_key?(:OPTIONAL)
-              parse_error(cfgFile, "#{$1} unexpected")
-            end
-          else
-            if apiParam.has_key?(:STRING)
-              staticApi[apiParam[:NAME]] = param.unquote
-            else
-              staticApi[apiParam[:NAME]] = param
-            end
+            skipUntilBrace += 1          	# APIå®ç¾©ã}ã¾ã§ã¹ã­ãã
+          end
+        elsif !apiParam.has_key?(:BRACE)
+          if /^([{})])$/ !~ param
+            staticApi[apiParam[:NAME]] = getParam(apiParam, param, cfgFile)
             param = parseParam(cfgFile)
-          end
-        end
-        if param != ")"
-          parse_error(cfgFile, "')' expected")
-        end
-      else
-        parse_error(cfgFile, "unknown static API: #{apiName}")
+          elsif !tooFewParams
+            parse_error(cfgFile, "too few parameters before `#{$1}'")
+            tooFewParams = true
+          end
+        elsif param == apiParam[:BRACE]
+          param = parseParam(cfgFile)
+          tooFewParams = false
+        else
+          parse_error(cfgFile, "`#{apiParam[:BRACE]}' expected before #{param}")
+          # )ããã¡ã¤ã«æ«ã¾ã§èª­ã¿é£ã°ã
+          loop do
+            param = parseParam(cfgFile)
+            break if (param.nil? || param == ")")
+          end
+          break
+        end
+      end
+
+      # æå¾
+ããããã©ã¡ã¼ã¿ããã¹ã¦èª­ãã å¾ã®å¦ç
+      if param != ")"
+        begin
+          param = parseParam(cfgFile)
+          return(staticApi) if param.nil?	# ãã¡ã¤ã«æ«ã§ããã°ãªã¿ã¼ã³
+        end while param != ")"
+        parse_error(cfgFile, "too many parameters before `)'")
       end
     else
-        parse_error(cfgFile, "syntax error: #{@line}")
-    end
-    @line = ""
+      parse_error(cfgFile, "syntax error: #{@line}")
+      @line = ""
+    end
     return(staticApi)
+  end
+
+  def parseOpenBrace(cfgFile)
+    # {ã®èª­ã¿è¾¼ã¿
+    skipToToken(cfgFile)					# æ¬¡ã®æå­ã¾ã§èª­ã¿é£ã°ã
+    if (/^\{(.*)$/ =~ @line)
+      @line = $1
+    else
+      parse_error(cfgFile, "`{' expected before #{@line}")
+    end
   end
 
@@ -483,12 +599,8 @@
     cfgFiles = [ ConfigFile.new(cfgFileName) ]
     @line = ""
-    begin
+    loop do
       cfgFile = cfgFiles.last
-      while @line == ""									# ç©ºè¡ãèª­ã¿é£ã°ã
-        @line = cfgFile.getNextLine(false)
-        @line.sub!(/^[\s;]*/, "") unless @line.nil?		# å
-é ­ã®ç©ºç½ã¨";"ãåé¤
-      end
-
+
+      skipSpace(cfgFile, false)				# æ¹è¡ã¨ç©ºç½æå­ãèª­ã¿é£ã°ã
       if @line.nil?
         # ãã¡ã¤ã«æ«ã®å¦ç
@@ -497,11 +609,11 @@
           break								# ãã¼ã¹å¦ççµäº
         else
-          @line = ""
-          next								# å
+          @line = ""						# å
 ã®ãã¡ã¤ã«ã«æ»ã£ã¦ç¶ãã
         end
-      end
-
-      if /^#/ =~ @line
+      elsif /^;(.*)$/ =~ @line
+        # ;ã¯èª­ã¿é£ã°ã
+        @line = $1
+      elsif /^#/ =~ @line
         # ããªãã­ã»ããµãã£ã¬ã¯ãã£ããèª­ã
         case @line
@@ -509,5 +621,5 @@
           $includeFiles.push($1.strip)
         when /^#(ifdef|ifndef|if|endif|else|elif)\b/
-          directive = {:DIRECTIVE => @line.strip}
+          directive = { :DIRECTIVE => @line.strip }
           $cfgFileInfo.push(directive)
         else
@@ -515,25 +627,108 @@
         end
         @line = ""
+      elsif (/^([A-Z_][A-Z0-9_]*)\b(.*)$/ =~ @line)
+        apiName = $1
+        @line = $2
+
+        case apiName
+        when "KERNEL_DOMAIN"
+          if $supportDomain.nil?
+            parse_warning(cfgFile, "`KERNEL_DOMAIN' is not supported")
+          end
+          if !@@currentDomain.nil?
+            parse_error(cfgFile, "`DOMAIN' must not be nested")
+          end
+          @@currentDomain = "TDOM_KERNEL"
+          parseOpenBrace(cfgFile)
+          @@nestDC.push("domain")
+        when "DOMAIN"
+          if $supportDomain.nil?
+            parse_warning(cfgFile, "`DOMAIN' is not supported")
+          end
+          if !@@currentDomain.nil?
+            parse_error(cfgFile, "`DOMAIN' must not be nested")
+          end
+          domid = parseParam(cfgFile).sub(/^\((.+)\)$/m, "\\1").strip
+          if (/^[A-Za-z_]\w*$/ !~ domid)
+            parse_error(cfgFile, "`#{domid}' is illegal domain ID")
+          else
+            if !$domainId.has_key?(domid)
+              if $inputObjid.has_key?(domid)
+                # IDçªå·å
+¥åãã¡ã¤ã«ã«å®ç¾©ããã¦ããå ´å
+                $domainId[domid] = $inputObjid[domid]
+                if $domainId[domid] > 32
+                  error_exit("domain ID for `#{domid}' is too large")
+                end
+              else
+                $domainId[domid] = nil
+              end
+            end
+            @@currentDomain = domid
+          end
+          parseOpenBrace(cfgFile)
+          @@nestDC.push("domain")
+        when "CLASS"
+          if $supportClass.nil?
+            parse_warning(cfgFile, "`CLASS' is not supported")
+          end
+          if !@@currentClass.nil?
+            parse_error(cfgFile, "`CLASS' must not be nested")
+          end
+          @@currentClass = parseParam(cfgFile).sub(/^\((.+)\)$/m, "\\1").strip
+          @@classFile = cfgFile.getFileName
+          @@classLine = cfgFile.getLineNo
+          parseOpenBrace(cfgFile)
+          @@nestDC.push("class")
+        else
+          if $apiDefinition.has_key?(apiName)
+            # éçAPIã1ã¤èª­ã
+            staticApi = parseApi(cfgFile, apiName)
+            if staticApi.empty?
+              # ãã¡ã¤ã«æ«ãææ³ã¨ã©ã¼
+            elsif (staticApi[:APINAME] == "INCLUDE")
+              # INCLUDEã®å¦ç
+              includeFilePath = SearchFilePath(staticApi[:file])
+              if includeFilePath.nil?
+                parse_error(cfgFile, "`#{staticApi[:file]}' not found")
+              else
+                $dependencyFiles.push(includeFilePath)
+                cfgFiles.push(ConfigFile.new(includeFilePath))
+              end
+            else
+              # éçAPIã®å¦ç
+              if !@@currentDomain.nil?
+                staticApi[:DOMAIN] = @@currentDomain
+              end
+              if !@@currentClass.nil?
+                staticApi[:CLASS] = @@currentClass
+                staticApi[:CLASS_FILE_] = @@classFile
+                staticApi[:CLASS_LINE_] = @@classLine
+              end
+              staticApi[:INDEX] = (@@lastApiIndex += 1)
+              $cfgFileInfo.push(staticApi)
+            end
+          else
+            parse_error(cfgFile, "unknown static API: #{apiName}")
+          end
+        end
+      elsif (/^\}(.*)$/ =~ @line)
+        # }ã®å¦ç
+        if @@nestDC.size > 0
+          case @@nestDC.pop
+          when "domain"
+            @@currentDomain = nil
+          when "class"
+            @@currentClass = nil
+          end
+        else
+          error_exit("unexpected `}'")
+        end
+        @line = $1
       else
-        # éçAPIã1ã¤èª­ã
-        staticApi = parseApi(cfgFile)
-        if staticApi.empty?
-          # ææ³ã¨ã©ã¼
-        elsif (staticApi[:API] == "INCLUDE")
-          # INCLUDEã®å¦ç
-          includeFilePath = SearchFilePath(staticApi[:file])
-          if includeFilePath.nil?
-            parse_error(cfgFile, "`#{staticApi["file"]}' not found")
-          else
-            $dependencyFiles.push(includeFilePath)
-            cfgFiles.push(ConfigFile.new(includeFilePath))
-          end
-        else
-          # éçAPIã®å¦ç
-          staticApi[:INDEX] = (@@lastApiIndex += 1)
-          $cfgFileInfo.push(staticApi)
-        end
-      end
-    end while true
+        parse_error(cfgFile, "syntax error: #{@line}")
+        @line = ""
+      end
+    end
   end
 end
@@ -542,8 +737,40 @@
 #  cfg1_out.cã®çæ
 #
-def GenerateCfg1OutC
-  cfg1Out = GenFile.new(CFG1_OUT_C)
-
-  cfg1Out.append(<<EOS)
+module Cfg1OutC
+  #
+  #  éçAPIã®ãã¡ã¤ã«åã¨è¡çªå·ã®åºå
+  #
+  def self.OutLineNumber(cfgInfo)
+    @cfg1Out.add("#line #{cfgInfo[:_LINE_]} \"#{cfgInfo[:_FILE_]}\"")
+  end
+
+  #
+  #  ã¯ã©ã¹è¨è¿°ã®ãã¡ã¤ã«åã¨è¡çªå·ã®åºå
+  #
+  def self.OutClassLineNumber(cfgInfo)
+    @cfg1Out.add("#line #{cfgInfo[:CLASS_LINE_]} \"#{cfgInfo[:CLASS_FILE_]}\"")
+  end
+
+  #
+  #  ãã©ã¡ã¼ã¿ã«é¢ããå®ç¾©ã®åºå
+  #
+  def self.OutParamDef(param, index, apiParam, cfgInfo)
+    if apiParam.has_key?(:ID_DEF)
+      @cfg1Out.add("#define #{param}\t(<>)")
+    elsif apiParam.has_key?(:EXPTYPE)
+      OutLineNumber(cfgInfo)
+      @cfg1Out.add("const #{apiParam[:EXPTYPE]} #{CFG1_PREFIX}valueof_" \
+								"#{apiParam[:NAME]}_#{index} = " \
+								"(#{apiParam[:EXPTYPE]})(#{param});")
+    end
+  end
+
+  #
+  #  cfg1_out.cã®çæï¼ã¡ã¤ã³ã®å¦çï¼
+  #
+  def self.Generate
+    @cfg1Out = GenFile.new(CFG1_OUT_C)
+
+    @cfg1Out.append(<<EOS)
 /* #{CFG1_OUT_C} */
 #define TOPPERS_CFG1_OUT
@@ -551,10 +778,10 @@
 EOS
 
-  # ã¤ã³ã¯ã«ã¼ãããããã¡ã¤ã«
-  $includeFiles.each do |file|
-    cfg1Out.add("#include #{file}")
-  end
-
-  cfg1Out.append(<<EOS)
+    # ã¤ã³ã¯ã«ã¼ãããããã¡ã¤ã«
+    $includeFiles.each do |file|
+      @cfg1Out.add("#include #{file}")
+    end
+
+    @cfg1Out.add(<<EOS)
 
 #ifdef INT64_MAX
@@ -566,53 +793,74 @@
 #endif
 
-#include "target_cfg1_out.h"
+#include "#{CFG1_OUT_TARGET_H}"
 #include <limits.h>
 
 const uint32_t #{CFG1_MAGIC_NUM} = 0x12345678;
 const uint32_t #{CFG1_SIZEOF_SIGNED} = sizeof(signed_t);
-
 EOS
 
-  # å¤åå¾ã·ã³ãã«ã®å¦ç
-  $symbolValueTable.each do |symbolName, symbolData|
-    type = symbolData.has_key?(:SIGNED) ? "signed_t" : "unsigned_t"
-    if !symbolData[:CONDITION].nil?
-      cfg1Out.add("#if #{symbolData[:CONDITION]}")
-    end
-    cfg1Out.add("const #{type} #{CFG1_PREFIX}#{symbolName} = " \
-							"(#{type})(#{symbolData[:EXPR]});")
-    if !symbolData[:DEFAULT].nil?
-      cfg1Out.add("#else")
-      cfg1Out.add("const #{type} #{CFG1_PREFIX}#{symbolName} = " \
-							"(#{type})(#{symbolData[:DEFAULT]});")
-    end
-    if !symbolData[:CONDITION].nil?
-      cfg1Out.add("#endif")
-    end
-  end
-
-  # éçAPIï¼ããªãã­ã»ããµãã£ã¬ã¯ãã£ãã®å¦ç
-  $cfgFileInfo.each do |cfgInfo|
-    if cfgInfo.has_key?(:DIRECTIVE)
-      cfg1Out.add2(cfgInfo[:DIRECTIVE])
-    else
-      apiDef = $apiDefinition[cfgInfo[:API]]
-      apiIndex = cfgInfo[:INDEX]
-      cfg1Out.add("#line #{cfgInfo[:_LINE_]} \"#{cfgInfo[:_FILE_]}\"")
-      cfg1Out.add("const unsigned_t #{CFG1_PREFIX}static_api_" \
+    # å¤åå¾ã·ã³ãã«ã®å¦ç
+    $symbolValueTable.each do |symbolName, symbolData|
+      if symbolData.has_key?(:BOOL) || symbolData.has_key?(:SIGNED)
+        type = "signed_t"
+      else
+        type = "unsigned_t"
+      end
+      if symbolData.has_key?(:CONDITION)
+        @cfg1Out.add("#if #{symbolData[:CONDITION]}")
+      end
+      @cfg1Out.add("const #{type} #{CFG1_PREFIX}#{symbolName} = " \
+								"(#{type})(#{symbolData[:EXPR]});")
+      if symbolData.has_key?(:ELSE_EXPR)
+        @cfg1Out.add("#else")
+        @cfg1Out.add("const #{type} #{CFG1_PREFIX}#{symbolName} = " \
+								"(#{type})(#{symbolData[:ELSE_EXPR]});")
+      end
+      if symbolData.has_key?(:CONDITION)
+        @cfg1Out.add("#endif")
+      end
+    end
+    @cfg1Out.add
+
+    # ãã¡ã¤ã³IDã®å®ç¾©ã®çæ
+    $domainId.each do |domainName, domainVal|
+      if domainVal > 0
+        @cfg1Out.add("#define #{domainName} #{domainVal}")
+      end
+    end
+    @cfg1Out.add
+
+    # éçAPIï¼ããªãã­ã»ããµãã£ã¬ã¯ãã£ãã®å¦ç
+    $cfgFileInfo.each do |cfgInfo|
+      if cfgInfo.has_key?(:DIRECTIVE)
+        @cfg1Out.add2(cfgInfo[:DIRECTIVE])
+      else
+        apiDef = $apiDefinition[cfgInfo[:APINAME]]
+        apiIndex = cfgInfo[:INDEX]
+        OutLineNumber(cfgInfo)
+        @cfg1Out.add("const unsigned_t #{CFG1_PREFIX}static_api_" \
 										"#{apiIndex} = #{apiIndex};")
-      apiDef[:PARAM].each do |apiParam|
-        if apiParam.has_key?(:ID_DEF)
-          cfg1Out.add("#define #{cfgInfo[apiParam[:NAME]]}\t(<>)")
-        elsif (apiParam.has_key?(:SIGNED) || apiParam.has_key?(:UNSIGNED)) \
-										&& !cfgInfo[apiParam[:NAME]].nil?
-          type = apiParam.has_key?(:SIGNED) ? "signed_t" : "unsigned_t"
-          cfg1Out.add("#line #{cfgInfo[:_LINE_]} \"#{cfgInfo[:_FILE_]}\"")
-          cfg1Out.add("const #{type} #{CFG1_PREFIX}valueof_" \
-							"#{apiParam[:NAME]}_#{apiIndex} = " \
-							"(#{type})(#{cfgInfo[apiParam[:NAME]]});")
-        end
-      end
-      cfg1Out.add
+        apiDef[:PARAM].each do |apiParam|
+          next unless apiParam.has_key?(:NAME)
+          paramName = apiParam[:NAME]
+          next unless cfgInfo.has_key?(paramName)	# ãã©ã¡ã¼ã¿ããªãå ´å
+          paramData = cfgInfo[paramName]
+
+          if apiParam.has_key?(:LIST)
+            paramData.each.with_index(1) do |param, index|
+              OutParamDef(param, "#{apiIndex}_#{index}", apiParam, cfgInfo)
+            end
+          else
+            OutParamDef(paramData, "#{apiIndex}", apiParam, cfgInfo)
+          end
+        end
+        if cfgInfo.has_key?(:CLASS)
+          # ã¯ã©ã¹IDã®åå¾ã®ããã®å¦ç
+          OutClassLineNumber(cfgInfo)
+          @cfg1Out.add("const signed_t #{CFG1_PREFIX}valueof_CLASS_" \
+                      "#{apiIndex} = (signed_t)(#{cfgInfo[:CLASS]});")
+        end
+        @cfg1Out.add
+      end
     end
   end
@@ -644,4 +892,5 @@
   $dependencyFiles = $configFileNames.dup
   $includeFiles = []
+  $domainId = { "TDOM_KERNEL" => -1, "TDOM_NONE" => -2 }
   $configFileNames.each do |configFileName|
     CfgParser.new.parseFile(configFileName)
@@ -650,7 +899,24 @@
 
   #
+  #  ãã¡ã¤ã³IDã®å²å½ã¦å¦ç
+  #
+  nextDomainId = 1
+  $domainId.each do |domainName, domainVal|
+    if domainVal.nil?
+      while $domainId.has_value?(nextDomainId)
+        nextDomainId += 1
+      end
+      $domainId[domainName] = nextDomainId
+      if nextDomainId > 32
+        error_exit("too large number of user domains")
+      end
+      nextDomainId += 1
+    end
+  end
+
+  #
   #  cfg1_out.cã®çæ
   #
-  GenerateCfg1OutC()
+  Cfg1OutC::Generate()
 
   #
@@ -668,5 +934,5 @@
     end
 
-    depFile.print("#{CFG1_OUT_C} #{CFG1_OUT_DB}:")
+    depFile.print("#{CFG1_OUT_TIMESTAMP}:")
     $dependencyFiles.each do |fileName|
       depFile.print(" #{fileName}")
@@ -690,4 +956,5 @@
       db[:cfgFileInfo] = $cfgFileInfo
       db[:includeFiles] = $includeFiles
+      db[:domainId] = $domainId
     end
   end
